Repository navigation
fix(gateway): restore history when an in-flight turn fails after eviction - #180
Draft
cursor[bot] wants to merge 1 commit into
Draft
cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
…tion A new chat can drop an in-flight conversation from the LRU map. If that turn throws before any assistant reply, the loaded history was never written back, so the next message in that chat started empty. Co-authored-by: moikapy <[email protected]>
This branch has not been deployed
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.
Bug and impact
Gateway conversation history lives only in memory. With the map at
max_conversations, a new chat evicts the least recently stored conversation while that conversation's turn is still running. If the model call then throws before any assistant or tool turn, the next message in the evicted chat is sent with an empty history. The bot forgets the conversation.Root cause
history_fordrops the oldest key to make room beforeagent.runreturns. The success path writes the run's messages back, which puts the key in the map again. The failure path only writes history whenhistory_after_run_errorcaptured a completed turn. A throw with no completed turn left the key missing.Fix
When a run throws, the key is already gone, and there is no partial turn to keep, store the history that was loaded for that run.
Validation
node node_modules/typescript/bin/tsc --noEmitnode node_modules/vitest/vitest.mjs run test/gateway_conversation_bounds.test.ts test/gateway.test.ts test/gateway_shutdown.test.ts(47 passed)The new test fills a 2-slot map, holds one chat in flight, lets a third chat evict it, fails that held run, and checks the next turn still sees the prior history.