Repository navigation
Description
When a compaction starts while Cursor waits on a tool result, summarizeForHostCompaction ends the held turn first and then summarizes in place. If a host Stop is still cancelling that Run, preparePriorSessionForFreshTurn waits for the cancel (up to 3 s for Cursor) and returns "none": the turn was never ended with the host's results. The compaction still summarizes in place, so the summary comes from a checkpoint taken before the tool ran, and afterwards the agent doesn't know the tool ran or what it returned.
The cause is that foreign and owesResults both test !held, so a held Run that existed when the compaction started counts as proof the turn was Cursor's own and complete. With "none" nothing was delivered, and the unanswered-tool-calls check that would import the host history is skipped.
It's a race and I haven't seen it in a live session. I found it while porting #205 to our fork and reproduced it with the test stub. (A second variant, the held Run lost while the compaction starts, no longer reproduces on ca3ea45: after #215 it imports as an unfinished held turn.)
Reproduction
- Host: OpenCode 2.4.x, plugin entrypoint
plugin-opencode2.js. 1.x goes through the same function. - Model:
composer-2.5in the test, but any model hits it. - The agent runs a shell call (
make) and the held Run waits for the result. Press Stop and start a compaction right away, before the cancel finishes. The compaction hook gets the history with themakeresult in it. - The test on the branch below does this with the stub server:
notifyHostInterrupt(…, "host-stop"), then the compaction.
CURSOR_PROVIDER_DEBUG=1 log from that test on upstream main ca3ea45, trimmed:
13:05:13.461Z host interrupt: cancelling Run sessionId=e551518a-… reason=host-stop pumping=false droppedPending=1
13:05:16.463Z host interrupt: Run sessionId=e551518a-… outcome=timeout afterMs=3002
13:05:16.463Z sessionManager.close: reason=host-interrupted pendingCount=0 blobs=0
13:05:16.469Z fresh turn: prior session e551518a-… was cancelled for the host's stop
13:05:16.469Z summarize: ended the held turn sessionKey=ses_native_compaction outcome=none
13:05:16.470Z summarize: conversationId=b3bb47de-… model=composer-2.5 checkpointBytes=7
13:05:16.483Z summarize: done conversationId=b3bb47de-… source=update chars=14
The make result in the hook's history never reaches Cursor; summarize_action runs on the checkpoint from before the shell call.
With the fix, the same test logs:
13:05:20.960Z summarize: ended the held turn sessionKey=ses_native_compaction outcome=none
13:05:20.961Z summarize: importing host history first sessionKey=ses_native_compaction reason=unanswered-tool-calls
No host log, since there's no live run. On the host side the compaction completes normally, so nothing looks wrong there.
Expected: when the compaction didn't end the held turn itself, treat it like a lost Run or a restart: if the last step's tool calls have no result in Cursor's checkpoint, import the host history before summarizing.
Actual: it summarizes the stale checkpoint in place, without the tool results.
Checked on upstream main ca3ea45: the test fails there and passes with the fix.
I have a fix branch ready if you want a PR. It sets a flag only when preparePriorSessionForFreshTurn actually ended the turn, and the foreign-history and unanswered-tool-calls checks use that flag instead of held: https://github.com/nkoynov/cursor-opencode-provider/tree/pr/compaction-unended-held-turn
Activity