fix(agent,memory): refuse session JSON truncation that wipes history - #70
Draft
cursor[bot] wants to merge 1 commit into
Draft
fix(agent,memory): refuse session JSON truncation that wipes history#70cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
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]>
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
When serialized session JSON exceeded
SESSION_JSON_MAX(128 KiB),append_exchange_to_session_jsonsilently clipped mid-JSON, returned 0, andsession_savepersisted a corrupt payload. The nextagent_runfailed 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 (skipsession_save)session_load: reject blobs that do not fit the caller buffer instead of clippingTest plan
make test_agent(includestest_session_overflow_does_not_corrupt_history)make test_memory(includestest_session_load_rejects_oversized)