Skip to content

fix(agent,memory): refuse session JSON truncation that wipes history - #70

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

fix(agent,memory): refuse session JSON truncation that wipes history#70
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-management-4ba6

Conversation

@cursor

@cursor cursor Bot commented Aug 20, 2026

Copy link
Copy Markdown

Summary

When serialized session JSON exceeded SESSION_JSON_MAX (128 KiB), append_exchange_to_session_json silently clipped mid-JSON, returned 0, and session_save persisted a corrupt payload. The next agent_run failed to parse the session and treated history as empty (permanent wipe on the following save).

Trigger

Near-cap session (~124 KiB of valid JSON) plus a fat assistant reply (e.g. ASAP path allows up to 256 KiB response while session cap is 128 KiB). Reproduced with a regression test; pre-fix truncation yields unparseable JSON.

Fix

  • append_exchange_to_session_json / compact_session_via_llm: return -1 instead of truncating (skip session_save)
  • session_load: reject blobs that do not fit the caller buffer instead of clipping

Test plan

  • make test_agent (includes test_session_overflow_does_not_corrupt_history)
  • make test_memory (includes test_session_load_rejects_oversized)
  • Negative check: restoring old truncation makes the new agent test fail
Open in WebView Automation

When serialized session JSON exceeded SESSION_JSON_MAX, append_exchange
silently clipped mid-JSON and still returned success, so session_save
persisted corrupt payloads. The next agent_run parse failed and history
was treated as empty. Refuse oversize writes instead, and reject
oversized loads in session_load.

Co-authored-by: esadrianno <[email protected]>
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