Skip to content

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

Done

Description

@nkoynov

summarizeForHostCompaction imports the host history before summarizing when Cursor's checkpoint is missing part of it (a foreign answer, unanswered tool calls, a pending rewrite, latestAnswer other/unknown). Three cases slip through. In each one it summarizes the stale checkpoint in place and the summary is missing part of the conversation. All three are deterministic, not races. I found them while porting #205 to our fork, and none came up in our VM runs, so the logs below are from the test stub.

1. A request Cursor never checkpointed

A turn's Run fails before Cursor saves a checkpoint, for example a dropped connection or an error early in the stream. The provider keeps a lost-request record so the next turn resends it. If a compaction comes next, it summarizes the old checkpoint, which doesn't have that request. After the summary the checkpoint changes, so carryLostRequest sees a different checkpoint key and drops the record without resending it. The user's last message ends up neither in the summary nor resent.

upstream: summarize: conversationId=b3bb47de-… model=composer-2.5 checkpointBytes=7
fixed:    summarize: importing host history first sessionKey=ses_native_compaction reason=lost-request

2. A host history rewrite restored after a restart

OpenCode rewrote the history (another provider's compaction, a revert), then the process restarted before the next Cursor turn. The snapshot restores the rewrite as postCompactionRebase, and a normal turn honors it in resolveTurnConversationReset. The compaction only asks awaitHostHistoryRewrite, which no longer knows about the rewrite after the restart, so it summarizes the pre-rewrite conversation. After a revert, that brings the reverted work back. It also ignores opencodeHistoryRewrite in the call's provider options, which the turn path reads too.

upstream: conversation persistence: restored sessionKey=ses_native_compaction conversationId=b3bb47de-… checkpoint=7B
          summarize: conversationId=b3bb47de-… model=composer-2.5 checkpointBytes=7
fixed:    summarize: importing host history first sessionKey=ses_native_compaction reason=host-history-rewrite

3. OpenCode 1.x latest-answer check

compactionFacts in src/plugin.ts skips every summary message before it checks the provider, and it counts any Cursor message as an answer. So it reports latestAnswer: "cursor" and the compaction summarizes in place in two cases:

  • Cursor answered, then the user switched to another model just to compact, then switched back and compacted again. The other model's summary is skipped.
  • Another model answered, then a Cursor turn failed without running tools (rate limit, error before the first step). The failed turn counts as Cursor's answer, so the other model's answer is missed.

Reproduction

  • Host: OpenCode 2.4.2 (plugin-opencode2.js) for 1 and 2, OpenCode 1.x with the classic plugin for 3.
  • Model: any Cursor model; composer-2.5 in the tests.
  • Case 1: send a message and make the turn fail before Cursor checkpoints it (cut the network until the retries give up), then /compact.
  • Case 2: compact with another provider (or revert a message), restart OpenCode, then compact on Cursor.
  • Case 3: the message sequences above, then /compact on 1.x.
  • Each case has a test on the branch below that fails on upstream main 4c63544: two in native-compaction.test.ts, one in plugin.test.ts. The plugin test's second case also fails there on its own.

No host log: nothing in our live runs hit these. On the host side the compaction completes normally.

Expected: import the host history first in all three cases, as for a foreign answer or a pending rewrite.

Actual: the summary is made from a checkpoint that lacks the lost request, keeps the rewritten history, or misses the other model's work.

I have a fix branch ready if you want a PR. It adds the lost-request check and the restored and option-based rewrite checks to the import decision, and the 1.x plugin counts another model's summary and skips a failed Cursor turn without tools: https://github.com/nkoynov/cursor-opencode-provider/tree/pr/compaction-import-checks

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions