Skip to content

fix(recovery): surgically remove unrecoverable reasoning instead of n…#47

Open
zuhairthabit wants to merge 2 commits into
yxlao:mainfrom
zuhairthabit:fix/surgical-reasoning-recovery
Open

fix(recovery): surgically remove unrecoverable reasoning instead of n…#47
zuhairthabit wants to merge 2 commits into
yxlao:mainfrom
zuhairthabit:fix/surgical-reasoning-recovery

Conversation

@zuhairthabit
Copy link
Copy Markdown

…uking history

The recover strategy previously dropped all but the leading system messages and the latest user message whenever any thinking-mode tool-call assistant was missing cached reasoning_content. In long sessions this silently discarded almost the entire conversation (observed in production: 307 of 309 messages dropped), causing the model to "forget" the ongoing task.

Replace the nuclear latest_user strategy with surgical removal: drop only the assistant message(s) whose reasoning_content cannot be restored, together with their associated tool results, while preserving all surrounding context. The assistant<->tool pairing invariant is maintained (no orphaned tool messages), so upstream requests stay valid.

Also:

  • Only consult the recovery-notice boundary when the first repair pass finds genuine cache misses, so a stale notice no longer permanently truncates later turns.
  • Suppress the user-facing recovery notice for surgical removals: context is preserved, so there is no need to plant a boundary marker that could trigger truncation on subsequent turns.
  • Add direct regression coverage for single/multiple misses in long conversations and for the no-tool-calls case; update existing tests that encoded the old nuclear contract.

zuhairthabit and others added 2 commits May 29, 2026 07:50
…uking history

The `recover` strategy previously dropped all but the leading system
messages and the latest user message whenever any thinking-mode tool-call
assistant was missing cached reasoning_content. In long sessions this
silently discarded almost the entire conversation (observed in production:
307 of 309 messages dropped), causing the model to "forget" the ongoing task.

Replace the nuclear `latest_user` strategy with surgical removal: drop only
the assistant message(s) whose reasoning_content cannot be restored, together
with their associated tool results, while preserving all surrounding context.
The assistant<->tool pairing invariant is maintained (no orphaned tool
messages), so upstream requests stay valid.

Also:
- Only consult the recovery-notice boundary when the first repair pass finds
  genuine cache misses, so a stale notice no longer permanently truncates
  later turns.
- Suppress the user-facing recovery notice for surgical removals: context is
  preserved, so there is no need to plant a boundary marker that could trigger
  truncation on subsequent turns.
- Add direct regression coverage for single/multiple misses in long
  conversations and for the no-tool-calls case; update existing tests that
  encoded the old nuclear contract.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
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