Skip to content

Import host history when a compaction checkpoint is missing it - #215

Merged
oakimov merged 2 commits into
mainfrom
cursor/issue-214-compaction-import-a164
Dec 2, 2026
Merged

oakimov merged 2 commits into
mainfrom
cursor/issue-214-compaction-import-a164

Conversation

@oakimov

@oakimov oakimov commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Compaction on a Cursor model summarized the current checkpoint in place when that checkpoint did not hold the host's latest history. The missing turns never entered the summary, and they were not sent again on the next turn. #214 is those three cases.

A request whose Run failed before Cursor checkpointed it stayed in the lost-request record. summarizeForHostCompaction in src/language-model.ts summarized the old checkpoint anyway. The summary replaced the checkpoint, and carryLostRequest in src/lost-request.ts dropped the record because the checkpoint key no longer matched.

A host history rewrite restored after restart was also ignored. An ordinary turn honors postCompactionRebase and opencodeHistoryRewrite in resolveTurnConversationReset. Compaction only called awaitHostHistoryRewrite, which is empty after a restart, so it summarized the pre-rewrite conversation.

On OpenCode 1.x, compactionFacts in src/plugin.ts skipped every summary before it checked the provider. Another model's compaction summary was ignored and the previous Cursor message counted as the latest answer. A Cursor turn that failed before it ran tools counted the same way.

@nkoynov's 1f5b5b7 is the right set of checks: import when the lost request still matches the live checkpoint, when a rewrite was restored or sent on the call, and when the latest answer is not Cursor's. This builds on that fix and covers four cases it left open.

A history rewrite — still pending, restored from the snapshot, or opencodeHistoryRewrite on the call — closes a Run that is still waiting on tools, the same way a fresh turn does, and then imports the host transcript. An already-aborted compaction throws before that close, so the waiting Run stays open. A lost request is still judged after a normal drain, so a continuation that already checkpointed its tool results is summarized in place.

A lost request causes an import only when its Run never reached turn_ended. settleLostRequest marks a finished turn. The record stays so the next turn can still carry the text, and compaction summarizes that checkpoint in place. A finished turn that echoes the same checkpoint bytes no longer remints, and a failed summary no longer clears that checkpoint. When the matching text is missing from the host transcript, the import appends it before the acknowledgement.

On OpenCode 1.x, another model's message, including a compaction summary, is that model's latest answer. A Cursor turn that failed with no tool results is skipped. An older step's tool results are not replayed.

test/native-compaction.test.ts, test/plugin.test.ts, and test/lost-request.test.ts cover a lost request on the current checkpoint and on a stale one, a lost request for another conversation, restart with and without opencodeHistoryRewrite, repeated compaction, compaction while a Run is pending or already aborted, an unusable summary and its retry, a checkpoint replaced mid-flight, separate sessions and a task session, the 1.x answer cases, warm checkpoint reuse, and continuation after completed tool results.

Fixes #214

Open in Web Open in Cursor 

Compaction summarized Cursor's checkpoint in place when a request's Run
never finished, when a host history rewrite lived only on the restored
snapshot or the call, and when OpenCode 1.x's latest answer was another
model's summary or a Cursor error with no tools. Import those cases,
keep a finished turn on its checkpoint, and close a Run the rewrite discarded.

Co-authored-by: Oleksiy Akimov <[email protected]>
@codecov

codecov Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.65072% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/language-model.ts 96.11% 7 Missing ⚠️

📢 Thoughts on this report? Let us know!

@oakimov
oakimov marked this pull request as ready for review December 2, 2026 09:25
@greptile-apps

greptile-apps Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5RetriggerView in Greptile

[Medium impact] The reviewed changes appear safe to merge; no actionable issues were found.

Summary

Compaction now imports host history when the live checkpoint misses a request or the host has rewritten the conversation.

  • Compaction imports host history when its checkpoint is missing turns.
  • OpenCode 1.x compaction follows the latest completed assistant answer.

No actionable issues found. Review was static; tests were inspected but not run.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Host requests compaction] --> B{Checkpoint holds host history?}
  B -->|Yes| C[Summarize current conversation]
  B -->|No| D[Import history into separate conversation]
  D --> E{Import finishes with checkpoint?}
  E -->|No| F[Discard import and keep prior state]
  E -->|Yes| G{Prior session unchanged?}
  G -->|No| F
  G -->|Yes| H[Adopt imported conversation]
  H --> C
  C --> I{Summary usable and session unchanged?}
  I -->|Yes| J[Save summary checkpoint]
  I -->|No| K[Keep checkpoint and fail compaction]
Loading

Reviews (1) · Last reviewed commit: "fix: preserve checkpoint continuity duri..." · Reviewed by Greptile

oakimov commented Dec 2, 2026

Copy link
Copy Markdown
Owner Author

@nkoynov Thanks for the repros in #214. Would you be able to test this PR on your OpenCode setup?

On 2.x, please check that /compact includes a request whose Run failed before Cursor saved a checkpoint, and that compaction after a restart uses the rewritten history. If you have 1.x handy, please also try compacting with another provider, then switching back to Cursor and compacting again.

Please share your OpenCode version and which cases you were able to try.

@nkoynov

nkoynov commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Tested d7ee20a in a NixOS VM: OpenCode 2.4.3 (opencode2 plugin entry), T3 0.1.14-nightly.20261201.5580, real Cursor key, CURSOR_PROVIDER_DEBUG=1, model claude-opus-5-5 300k Fast High.

  • Lost request: one good turn, then I blocked outbound 443 in the VM and sent a message with a new fact. The Run failed with no checkpoint stored ("Cursor Run failed after 11 attempts: Cursor HTTP/2 connection failed"). I unblocked and ran /compact: summarize: importing host history first … reason=lost-request, and the next turn recalled the fact that was only in the lost request.
  • Rewrite after restart: two Cursor turns, /compact on opencode/big-pickle, one more big-pickle turn, then I restarted T3's service so OpenCode got a new process, switched back and ran /compact on Cursor. The new process logged conversation persistence: restored … and then summarize: importing host history first … reason=host-history-rewrite, and the next turn recalled all three facts, including the one from the big-pickle turn. I didn't try a revert, since the 2.x plugin only records another provider's compaction as a rewrite.
  • Normal /compact: summarized in place, with no import line and recall 2/2.
  • 1.x: not tried, I don't have a 1.x host set up.

The import Runs went out as effort=high, fast=true. Typecheck, build and the touched tests pass.

@oakimov
oakimov merged commit ca3ea45 into main Dec 2, 2026
12 checks passed
@oakimov
oakimov deleted the cursor/issue-214-compaction-import-a164 branch December 2, 2026 13:04
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.

Compaction summarizes Cursor's checkpoint in place when it lacks host history: a lost request, a rewrite restored after restart, 1.x latest answer

3 participants