Skip to content

fix(agent): stub oversized history only on an empty summary - #132

Closed
cursor[bot] wants to merge 1 commit into
developmentfrom
cursor/critical-bug-identification-d77c
Closed

cursor[bot] wants to merge 1 commit into
developmentfrom
cursor/critical-bug-identification-d77c

Conversation

@cursor

@cursor cursor Bot commented Oct 18, 2026

Copy link
Copy Markdown

Session compaction deleted most of an oversized message when earlier lines had already filled the 64 KiB summary source.

Bug and impact

compact_session_via_llm summarizes the oldest turns once a session grows past max_context_messages. A single message larger than the 64 KiB summary source cannot be copied whole. The recent stub path still accepted that line when only a sliver of the buffer was free, then dropped it from the kept tail.

Concrete trigger: an ASAP task.request whose input is about 50 KiB, a short reply, then another task whose input is about 65 KiB, then enough short turns to exceed the default 40-message window. Both pastes fit in the 128 KiB session blob. Compaction summarized the first paste, cut the second to the leftover few kilobytes, and agent_persist_session wrote that result back. The rest of the second task was gone from the transcript and was never shown to the summarizer.

Root cause

summary_source_append_truncated returns success whenever the role wrapper and the [truncated] marker fit in the remaining bytes. The caller treated that success as "this message is fully consumed." A later line that can never fit a fresh source was therefore deleted after the model had seen only the leftover sliver.

Fix

Stub a never-fit line only when the summary source is still empty. Otherwise leave it in the session. This pass summarizes the prefix, and the next pass stubs the line against a full 64 KiB buffer. A never-fit first line is still stubbed, so compaction cannot stall with an empty source. Lines that would fit a fresh source keep the existing prefer-keep path.

Validation

make test_agent passes. The updated later-line regression uses a 50 KiB predecessor and a 65 KiB message: after the first turn the oversized end marker is still in the session and the predecessor is not, and a later turn still brings the session back down to the context cap. The existing first-line oversized test still requires the empty-source stub.

Open in Web聽View Automation聽

Compaction treated a truncated stub as the whole message. When earlier
lines had already filled the 64 KiB summary source, a later message
that cannot fit was cut to the leftover sliver and then dropped.
Stub that line only on an empty source so this pass summarizes the
prefix and the next pass keeps about 64 KiB of the oversized line.

Co-authored-by: esadrianno <esadrianno@gmail.com>
@adriannoes

Copy link
Copy Markdown
Collaborator

Superseded by #133: consolidated into the operator-authored branch fix/agent-compaction-empty-stub (same fix, re-validated with make test_agent, CI=true make test, make static). Closing in favor of the consolidation.

@adriannoes adriannoes closed this Oct 18, 2026
@adriannoes
adriannoes deleted the cursor/critical-bug-identification-d77c branch October 18, 2026 14:31
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.

2 participants