The Cursor V2 adapter has the same item-ordinal problem as Claude (#13864). Every item ordinal of the session sat in one Map that was copied on each new item (new Map(current) inside Ref.update) and never pruned, as was the per-turn counter map beside it. A long session paid O(items) memory and O(items²) copying.
What changed#
The ordinal map moves onto the turn (ActiveCursorTurn.itemOrdinals). It is mutated in place and goes away when the turn settles. The counter map is gone, because the map's size is the counter. OpenCode and Pi already allocate ordinals this way.
Why per-turn is safe#
Every resolveItemOrdinal call passes the active turn. The keys are Cursor call ids, text and reasoning segment ids scoped to run.runId, plan:/todos: call ids, and terminal-failure:${providerTurnId}. A subagent keeps its turnItemOrdinal on its own record (existing?.turnItemOrdinal ?? resolveItemOrdinal(...)), and that record also lives on the turn. Before the fix I instrumented resolveItemOrdinal to flag any hit on an ordinal a different turn had allocated, then ran the full replay suites plus the Cursor adapter tests: 79 Cursor allocations, 0 cross-turn hits. The instrumentation was not committed.
Benchmark#
A scratch, uncommitted script ran the resolver exactly as it was before and after, in 10 turns, resolving each item twice (first sight plus one later update):
| N items | before | after |
|---|
| 1,000 | 60 ms | 1 ms |
| 10,000 | 7.6 s | 4 ms |
| 50,000 | 253 s | 37 ms |
In #13864, the end-to-end benchmark through the real Claude adapter showed the same curve (50k items: 325.6 s before, 2.1 s after). A 50k-entry map retains about 1.8 MiB for the life of the session. After the fix, that memory is bounded by the largest single turn.
Verification#
vp test run with CursorAdapterV2.test.ts, OrchestratorReplayFixtures.integration.test.ts (which includes the 11 Cursor replay fixtures) and OrchestratorReplayRecovery.integration.test.ts: 3 files, 110 tests pass. The replay fixtures are unchanged.
- Before the fix, the cross-turn instrumentation run described above (14 files, 566 tests) found 0 Cursor hits.
vp exec tsc --noEmit -p . in apps/server: no errors.
vp lint on the touched file: only the existing layer unused-variable warning.
- Not run: repo-wide checks, live Cursor.
Model: Claude Opus 5.5 (Claude Code)
🤖 Generated with Claude Code
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed