Skip to content

fix(gateway): restore history when an in-flight turn fails after eviction - #180

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-management-0433
Draft

cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-management-0433

Conversation

@cursor

@cursor cursor Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

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_for drops the oldest key to make room before agent.run returns. The success path writes the run's messages back, which puts the key in the map again. The failure path only writes history when history_after_run_error captured 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 --noEmit
  • node 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.

Open in Web View Automation 

…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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant