feat: sticky session for multi-turn conversation continuity#162
Merged
Conversation
added 2 commits
May 10, 2026 17:02
Add account/sticky-session.js module that binds (callerKey, modelKey) to a specific upstream account so multi-turn conversations stay on the same account throughout their lifetime. Without this, the pool selects a different account for every request and the cascade_id from the previous turn becomes invalid — context is lost mid-task. Integration: - auth.js getApiKey() now accepts optional callerKey and checks sticky binding before falling through to normal pool selection - chat.js handler calls setStickyBinding() after successful response completion, binding the caller to the account that just handled their last message Configuration (opt-in): STICKY_SESSION_ENABLED=1 # default: 0 (off) STICKY_SESSION_TTL_MS=1800000 # default: 30 minutes STICKY_SESSION_MAX=10000 # default: 10000 max bindings Fixes: dwgx#93, dwgx#133 (context loss mid-task)
The sticky session binding was only set in nonStreamResponse, missing the primary streaming path used by Claude Code, Cursor, and all OpenAI stream:true clients. Added setStickyBinding call in streamResponse success path (after poolCheckin, guarded by isStickyEnabled()).
dwgx
added a commit
that referenced
this pull request
May 12, 2026
This was referenced May 13, 2026
Closed
This was referenced Jun 2, 2026
Closed
dwgx
pushed a commit
that referenced
this pull request
Jun 4, 2026
* feat: sticky session for multi-turn conversation continuity Add account/sticky-session.js module that binds (callerKey, modelKey) to a specific upstream account so multi-turn conversations stay on the same account throughout their lifetime. Without this, the pool selects a different account for every request and the cascade_id from the previous turn becomes invalid — context is lost mid-task. Integration: - auth.js getApiKey() now accepts optional callerKey and checks sticky binding before falling through to normal pool selection - chat.js handler calls setStickyBinding() after successful response completion, binding the caller to the account that just handled their last message Configuration (opt-in): STICKY_SESSION_ENABLED=1 # default: 0 (off) STICKY_SESSION_TTL_MS=1800000 # default: 30 minutes STICKY_SESSION_MAX=10000 # default: 10000 max bindings Fixes: #93, #133 (context loss mid-task) * fix: add sticky binding in streaming response path (Oracle review) The sticky session binding was only set in nonStreamResponse, missing the primary streaming path used by Claude Code, Cursor, and all OpenAI stream:true clients. Added setStickyBinding call in streamResponse success path (after poolCheckin, guarded by isStickyEnabled()). --------- Co-authored-by: Chen Jiangjiang <chenjiangjiang@kt51.cc>
dwgx
added a commit
that referenced
this pull request
Jun 4, 2026
dwgx
pushed a commit
that referenced
this pull request
Jun 4, 2026
* feat: sticky session for multi-turn conversation continuity Add account/sticky-session.js module that binds (callerKey, modelKey) to a specific upstream account so multi-turn conversations stay on the same account throughout their lifetime. Without this, the pool selects a different account for every request and the cascade_id from the previous turn becomes invalid — context is lost mid-task. Integration: - auth.js getApiKey() now accepts optional callerKey and checks sticky binding before falling through to normal pool selection - chat.js handler calls setStickyBinding() after successful response completion, binding the caller to the account that just handled their last message Configuration (opt-in): STICKY_SESSION_ENABLED=1 # default: 0 (off) STICKY_SESSION_TTL_MS=1800000 # default: 30 minutes STICKY_SESSION_MAX=10000 # default: 10000 max bindings Fixes: #93, #133 (context loss mid-task) * fix: add sticky binding in streaming response path (Oracle review) The sticky session binding was only set in nonStreamResponse, missing the primary streaming path used by Claude Code, Cursor, and all OpenAI stream:true clients. Added setStickyBinding call in streamResponse success path (after poolCheckin, guarded by isStickyEnabled()). --------- Co-authored-by: Chen Jiangjiang <chenjiangjiang@kt51.cc>
dwgx
added a commit
that referenced
this pull request
Jun 4, 2026
dwgx
pushed a commit
that referenced
this pull request
Jun 4, 2026
* feat: sticky session for multi-turn conversation continuity Add account/sticky-session.js module that binds (callerKey, modelKey) to a specific upstream account so multi-turn conversations stay on the same account throughout their lifetime. Without this, the pool selects a different account for every request and the cascade_id from the previous turn becomes invalid — context is lost mid-task. Integration: - auth.js getApiKey() now accepts optional callerKey and checks sticky binding before falling through to normal pool selection - chat.js handler calls setStickyBinding() after successful response completion, binding the caller to the account that just handled their last message Configuration (opt-in): STICKY_SESSION_ENABLED=1 # default: 0 (off) STICKY_SESSION_TTL_MS=1800000 # default: 30 minutes STICKY_SESSION_MAX=10000 # default: 10000 max bindings Fixes: #93, #133 (context loss mid-task) * fix: add sticky binding in streaming response path (Oracle review) The sticky session binding was only set in nonStreamResponse, missing the primary streaming path used by Claude Code, Cursor, and all OpenAI stream:true clients. Added setStickyBinding call in streamResponse success path (after poolCheckin, guarded by isStickyEnabled()). --------- Co-authored-by: Chen Jiangjiang <chenjiangjiang@kt51.cc>
dwgx
added a commit
that referenced
this pull request
Jun 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an opt-in sticky session feature that binds a caller (identified by
callerKey) to a specific upstream Windsurf account for the duration of a multi-turn conversation.Problem
When using Claude Code, Cursor, or any multi-turn agent with WindsurfAPI, the account pool selects a different account for each request. The
cascade_idfrom the previous turn is only valid on the originating account — switching accounts mid-conversation causes context loss (#93, #133).Solution
New module
src/account/sticky-session.jsmaintains an in-memory binding map:(callerKey, modelKey)— model dimension prevents cross-model collisionIntegration
src/auth.js:getApiKey()now accepts optionalcallerKeyparameter, checks sticky binding firstsrc/handlers/chat.js: callssetStickyBinding()after successful responseConfiguration (opt-in)
Backward Compatibility
STICKY_SESSION_ENABLEDdefaults to0(off)callerKeyisnullby default ingetApiKey(), existing callers unaffectedCloses #93, #133