Skip to content

Keep compaction boundaries aligned with raw user text - #335

Merged
tylerreckart merged 5 commits into
mainfrom
fix/compaction-preamble-first-query
Sep 21, 2026
Merged

tylerreckart merged 5 commits into
mainfrom
fix/compaction-preamble-first-query

Conversation

@cursor

@cursor cursor Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem

strip_compaction_preambles stored the compaction cut boundary so remap after API/TUI reload can find the first kept turn in SQLite. Two strips were too greedy:

  1. rfind("\n\nQUERY: ") took the last orchestrator wrapper. A user turn that embeds that same delimiter (for example quoting docs) stored only the suffix. The DB row still has the full user text, so find_compaction_boundary misses and remap_compaction_onto_history fail-opens (covered_until=0: summary plus the entire hydrated history).
  2. After that, any remaining leading [ + first blank line was treated as a pitfalls/intent envelope. User text that starts with a bracket block ([NOTE]\n\n…) or a [KNOWN PITFALLS] lesson body that contains \n\n was truncated the same way.

Transcript replay already documents the user-typed QUERY: case; compaction did not.

Fix

Strip only known orchestrator envelopes:

  • [OPEN TODOS] … [END OPEN TODOS]
  • [KNOWN PITFALLS … [END KNOWN PITFALLS]
  • first \n\nQUERY: wrapper (index master)
  • leading [INTENT] … through the following blank line (specialist ingress)

Do not rfind the QUERY mark and do not treat arbitrary [ + \n\n as a preamble.

Tests

unit_context_compaction — embedded QUERY delimiter, user text starting with [ plus an inner-blank pitfalls block, specialist INTENT-only strip, remap of the embedded-QUERY boundary. 30/30 passed locally.

Independently mergeable against main (0456350). Code hunks (context_compaction.cpp, test_context_compaction.cpp) do not overlap #321–#334. CHANGELOG [Unreleased] will need a rebase after whichever sibling merges first.

Open in Web View Automation 

Note

Medium Risk
Changes how compaction boundaries are derived from stored user messages; incorrect stripping would still fail-open to full history, but wrong cuts could affect context windows after session reload.

Overview
Fixes compaction boundary stripping so stored cut points still match SQLite after reload.

strip_compaction_preambles no longer uses rfind on \n\nQUERY: (first wrapper only) and no longer treats any leading [ block before a blank line as orchestrator junk. It now removes only known envelopes: [OPEN TODOS], [KNOWN PITFALLS], the index \n\nQUERY: prefix, and a leading [INTENT] block. User turns that quote \n\nQUERY: or start with [NOTE]-style text keep full content, so boundary_content_matches / remap_compaction_onto_history do not fail-open to covered_until=0.

Unit tests cover embedded QUERY, bracket user text, INTENT-only strip, and remap with an embedded-QUERY boundary; CHANGELOG documents the fix.

Reviewed by Cursor Bugbot for commit b236841. Bugbot is set up for automated code reviews on this repo. Configure here.

strip_compaction_preambles used rfind on the orchestrator QUERY
wrapper and then sliced at the first blank line after any leading
'['. User turns that embed that delimiter or start with a bracket
block stored a truncated boundary, so remap after reload failed
open (full history plus summary).

Strip only known OPEN TODOS / KNOWN PITFALLS / INTENT envelopes
and take the first QUERY wrapper so the persisted boundary matches
the SQLite row.

Co-authored-by: Tyler Reckart <tylerreckart@users.noreply.github.com>
Keep both Unreleased changelog entries.

Co-authored-by: Cursor <cursoragent@cursor.com>
@cursor

cursor Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor Author

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_71576940-fe63-41f0-9889-aaf1e1be5c92)

@tylerreckart
tylerreckart enabled auto-merge (squash) September 21, 2026 13:30
Keep both Unreleased changelog entries.

Co-authored-by: Cursor <cursoragent@cursor.com>
Keep both Unreleased changelog entries.

Co-authored-by: Cursor <cursoragent@cursor.com>
Keep both Unreleased changelog entries.

Co-authored-by: Cursor <cursoragent@cursor.com>
@tylerreckart
tylerreckart merged commit 52e0a32 into main Sep 21, 2026
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.

3 participants