Repository navigation
fix: compact with Cursor's own summary (summarize_action) - #205
Conversation
OpenCode compaction on a Cursor model reminted the conversation and sent the whole host transcript as one user message. When that overflowed, Cursor summarized the message together with the compaction request, the model answered without OpenCode's template, and compaction failed. Compaction now asks Cursor to summarize the session's own conversation with summarize_action, as Cursor CLI's /summarize does, on the same conversation id: - idle: summarize in place; the next turn continues on that checkpoint - held Run mid-turn: summarize a fork of its checkpoint, keep the Run, summarize in place when the turn ends - history Cursor does not hold: import it as earlier turns, then summarize - OpenCode 2.x: answered from the session compaction hook (no template check); background summaries are declined Rebuilt history now goes as up to five prepend_user_messages instead of inside the request, so Cursor summarizes what overflows and keeps the request. The 80% seed check applies only to routes with a measured silent cutoff (gpt-5.4-mini). Fixes #203
[Medium impact] The reviewed changes appear safe to merge, with no outstanding findings. SummaryThe PR replaces prompt-based compaction with Cursor’s native
All four supplied previous findings are addressed: foreign-provider history triggers import, Stop cancels the summary, cancellation has a fixed deadline, and interrupted tool results remain failures. No new actionable issues were found. Tests were inspected but not run.
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…swer - A summarize Run follows a host Stop for its whole length, not only its upload: the 2.x compaction hook has no abort signal and the Run is not in sessionManager. It sends cancel_action, drains until Cursor ends the Run (answering blob and request-context probes), and applies its checkpoint only once the summary completed. - OpenCode 1.x sends compaction a serialized transcript with no assistant messages, so the classic plugin reads the session's messages and reports whether the latest real answer was Cursor's. Another model's answer, or unreadable messages, imports the transcript instead of summarizing a checkpoint that may miss those turns. - Cover the new paths: hook prompt shapes, pump edges, an isolated import for a held Run without a checkpoint, a failed live summary after a fork, an aborted request, a failed snapshot save, nothing to compact.
|
Ran 4050150 end to end in a NixOS VM: T3 0.1.14-nightly.20261127.5359, OpenCode 2.4.2 (our build with a few patches), the opencode2 plugin entry, real Cursor key,
One thing that doesn't match the description: on 2.4 the held Run doesn't continue after a fork compaction. OpenCode's next request comes in as a fresh turn, the held Run is cancelled, and the live conversation is summarized right away. So every mid-turn compaction runs two summaries back to back (the fork took 18-105 s, the live one 25-45 s), and the turn goes on in a new Run: Smaller one: the import Run went out as Not covered: another model answering after Cursor's turns, then compacting on Cursor. OpenCode's free models refuse a history with Cursor's assistant turns ("OpenAI Chat assistant messages only support text, reasoning, and tool-call content"), so I could only run the order other model first, Cursor second. Typecheck, build and the touched tests pass (555). The full suite has the same failures as main 8e56dc2 on this machine (environment-dependent tests) and 43 more passing tests. |
After a host Stop, the summary Run sent cancel_action and drained until Cursor ended it. Frames Cursor kept sending renewed the read-idle watchdog, so a Run Cursor never ended kept its stream and listeners open. The drain now has the same fixed grace as a turn's Stop (HOST_INTERRUPT_GRACE_MS, 3 s), after which the stream is destroyed.
Neither OpenCode major resumes the held Run after a compaction: 1.x adds a synthetic "Continue" message and 2.4 opens the next request with a <conversation-checkpoint> user message. The fork summary therefore never let the held Run go on, and each mid-turn compaction ran two summaries. A mid-turn compaction now ends the held turn first, as a new user turn would: it delivers the tool results the host has (2.x from the hook's messages, 1.x from the session through the plugin), cancels calls without one and drains to turn_ended, then summarizes in place once. A turn that does not end cleanly is imported instead. The first Run that resumes the summarized checkpoint leaves out OpenCode's copy of the summary. The 2.x compaction hook's model call now carries the model's and the variant's settings, as OpenCode's own call through its route does.
|
Thanks, @nkoynov. Both findings were right, and 364cdec fixes them.
The order you couldn't run, another model answering after Cursor's turns and then compacting on Cursor, is covered by the latest-answer check on 1.x and by the history check on 2.x. A live run of it is pending on my side. |
The OpenCode 1.x plugin read the latest step's tool results for a mid-turn compaction straight from stored parts and turned an interrupted call's partial output into a successful result. It now runs those parts through normalizeClassicInterruptedResults first, as the request path does: an interrupted call stays a failure with its progress text, and a shell timeout or non-zero exit keeps its notice.
|
Re-ran 7aa7034 on the same setup (T3 0.1.14-nightly.20261127.5359, OpenCode 2.4.2, real key):
Both points from my last comment are fixed. A small thing I noticed, which 4050150 also did: the import Run carries a shorter system prompt than a normal first turn (24,907 vs 43,844 chars), and the first Run after the import then sends about 51k chars of user text for a one-line question, which lands in Cursor's Typecheck, build and the touched tests pass; the only failures are the same environment-dependent |
A compaction's history-import Run froze the conversation's baseline from the compaction call's prompt: OpenCode 2's compaction agent, or nothing for a 1.x transcript. The first ordinary Run then resent the session agent's whole prompt as a context update in Cursor's conversation category, where a later summary could drop it. That baseline is now provisional, kept in the snapshot so a restart honours it, and the conversation's first ordinary Run replaces it, and the frozen system rule, once with no update. Later prompt changes ride updates as before.
|
Thanks, @nkoynov, and good catch on the system prompt. b6301e7 fixes it. The import Run froze the conversation's baseline from the compaction call's own prompt: the compaction agent's on 2.4, or none at all for a 1.19 transcript. The first ordinary Run then saw a different agent and prompt, and resent the agent's whole prompt as a context update. That's your ~51k chars in Cursor's An import's baseline is now provisional, and the mark is kept in the snapshot so a restart honours it. The conversation's first ordinary Run replaces the baseline and the frozen system rule once, with no update. After that it is frozen as before, and later prompt changes are sent as updates again. I ran it live with the default model: an import carrying a compaction-agent prompt, then a turn whose agent prompt requires a closing token. The next Run's user text went from 5,559 to 329 chars. Cursor recalled the planted fact and followed the agent's rule on the resumed, summarized checkpoint, so it takes the replaced rule. With your 43.8k-char prompt, the saving should be the whole ~51k. |
|
b6301e7 fixes it: on the same setup the first Run after a history import sends 6,839 chars of user text (51,129 before, |
The cache log runbook still said compaction rotates conversationId. An in-place summary keeps that id and logs summarize: done. History import, foreign-history reseed, history rewrite, and a restored post-compaction rebase still rotate. Co-authored-by: Oleksiy Akimov <[email protected]>
|
On ebd44bf, CI on this head is green. CodeQL reports no new alerts. codecov/patch passed. |
Fixes #203
Problem
A compaction on a Cursor model reminted the conversation and sent the whole host transcript as one user message. When that message overflowed the window, Cursor's harness summarized it together with the compaction request, so the model answered something else and OpenCode failed with "Compaction summary did not match the required template".
Fix
Compaction now works the way Cursor CLI's
/summarizedoes: Cursor summarizes the session's own conversation with an emptysummarize_action, on the same conversation id. OpenCode's transcript is no longer sent as a prompt.turn_ended. Then the conversation is summarized in place, once. Cursor CLI never compacts a busy conversation from the client, and neither host resumes the held Run after a compaction: 1.x adds a synthetic "Continue" message, 2.4 opens the next request with a<conversation-checkpoint>user message. The first Run after a compaction leaves that copy of the summary out, since Cursor's checkpoint holds it. A turn Cursor does not end cleanly is imported instead.compactionhook with Cursor's summary, so OpenCode skips its own request and template check. The hook's call adds the model's and variant's settings, as OpenCode's own model call would. Background summaries are declined; Cursor summarizes in the background itself. A failed summary fails the compaction without a 413, so OpenCode neither shrinks nor retries it.Rebuilt history on every path (foreign history, unusable checkpoint, interrupted Run, compaction import) now goes as up to five
prepend_user_messagesinstead of inside the request. Cursor keeps only the last five, so the provider never sends more.The 80 % seed check is replaced: like Cursor CLI, the provider sends the whole history. Only a route measured to drop history silently is checked (
src/effective-context-data.ts, for nowgpt-5.4-miniat 56k input tokens).docs/effective-context.mddescribes how to find and record another one.No OCP change is needed: compaction is still detected only from the
chat.paramscompaction agent (1.x) and the 2.xcompactionhook.A/B results (live Cursor, 2026-11-28)
History with three codes planted at its start, middle and end; question: report the three codes.
summarize_actionon Auto: summary text, a checkpoint with summary archives, an emptyturn_ended; the next turn recalled every fact. At 219k tokens occupancy went from 219,259 to 6,299.UserMessageAction.conversation_history, Cursor CLI's own history import, is ignored by Cursor's cloud for this client, so the import uses prepended turns.Verification
bun test ./test: 3,710 pass. Threetest/review-publish.test.tstests timed out under full-suite load; that file passes alone (113 of 113). Newtest/native-compaction.test.ts(live, mid-turn on both majors, the 2.x summary copy, import, hook decline, a Stop, another Location's Run) andtest/compaction-run.test.ts(wire bytes from Cursor's field numbers).bun run typecheck,bun run build,test/architecture.test.tsclean.@nkoynov, thank you for the detailed report and the repro numbers. They showed exactly where the request disappeared. This takes Cursor CLI's route instead of the size guard on your branch, so a long session's compaction no longer depends on OpenCode shrinking its transcript.
Fixes #203
Problem
A compaction on a Cursor model reminted the conversation and sent the whole host transcript as one user message. When that message overflowed the window, Cursor's harness summarized it together with the compaction request, so the model answered something else and OpenCode failed with "Compaction summary did not match the required template".
Fix
Compaction now works the way Cursor CLI's
/summarizedoes: Cursor summarizes the session's own conversation with an emptysummarize_action, on the same conversation id. OpenCode's transcript is no longer sent as a prompt.turn_ended. Then the conversation is summarized in place, once. Cursor CLI never compacts a busy conversation from the client, and neither host resumes the held Run after a compaction: 1.x adds a synthetic "Continue" message, 2.4 opens the next request with a<conversation-checkpoint>user message. The first Run after a compaction leaves that copy of the summary out, since Cursor's checkpoint holds it. A turn Cursor does not end cleanly is imported instead.compactionhook with Cursor's summary, so OpenCode skips its own request and template check. The hook's call adds the model's and variant's settings, as OpenCode's own model call would. Background summaries are declined; Cursor summarizes in the background itself. A failed summary fails the compaction without a 413, so OpenCode neither shrinks nor retries it.Rebuilt history on every path (foreign history, unusable checkpoint, interrupted Run, compaction import) now goes as up to five
prepend_user_messagesinstead of inside the request. Cursor keeps only the last five, so the provider never sends more.The 80 % seed check is replaced: like Cursor CLI, the provider sends the whole history. Only a route measured to drop history silently is checked (
src/effective-context-data.ts, for nowgpt-5.4-miniat 56k input tokens).docs/effective-context.mddescribes how to find and record another one.The cache log runbook matches the in-place summary: the conversation id stays, and the log line is
summarize: done. A history import, a foreign-history reseed, a history rewrite, and a restored post-compaction rebase still rotate the id.No OCP change is needed: compaction is still detected only from the
chat.paramscompaction agent (1.x) and the 2.xcompactionhook.A/B results (live Cursor, 2026-11-28)
History with three codes planted at its start, middle and end; question: report the three codes.
summarize_actionon Auto: summary text, a checkpoint with summary archives, an emptyturn_ended; the next turn recalled every fact. At 219k tokens occupancy went from 219,259 to 6,299.UserMessageAction.conversation_history, Cursor CLI's own history import, is ignored by Cursor's cloud for this client, so the import uses prepended turns.Verification
bun test ./test: 3,710 pass. Threetest/review-publish.test.tstests timed out under full-suite load; that file passes alone (113 of 113). Newtest/native-compaction.test.ts(live, mid-turn on both majors, the 2.x summary copy, import, hook decline, a Stop, another Location's Run) andtest/compaction-run.test.ts(wire bytes from Cursor's field numbers).bun run typecheck,bun run build,test/architecture.test.tsclean.@nkoynov, thank you for the detailed report and the repro numbers. They showed exactly where the request disappeared. This takes Cursor CLI's route instead of the size guard on your branch, so a long session's compaction no longer depends on OpenCode shrinking its transcript.