perf(server): bound OpenCode history hydration#4348
Conversation
- Limit routine OpenCode thread reads to the latest 100 messages. - Page older messages only when rollback requires additional turns. - Abort and surface session history reads that exceed 15 seconds. - Add focused paging, timeout, and cancellation coverage.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 335f2f6. Configure here.
ApprovabilityVerdict: Approved Performance optimization that bounds OpenCode history hydration to 100 messages with a 15-second timeout, preventing unbounded fetching. Changes are well-tested with comprehensive pagination and timeout test cases. No new features or schema changes—purely defensive performance improvement. You can customize Macroscope's approvability policy. Learn more. |
- Determine history exhaustion from the raw API page before deduplication. - Advance pagination from the raw oldest message boundary. - Add rollback coverage for full pages that overlap the preceding page.

Closes #3601
Summary
Verification
./node_modules/.bin/vp test run apps/server/src/provider/Layers/OpenCodeAdapter.test.ts(33 passed)./node_modules/.bin/vp run --filter t3 typecheck(passes; three unrelated existing Effect suggestions remain inorchestration/decider.ts)Note
Medium Risk
Changes how thread snapshots are built and how rollback resolves targets across paginated history; incorrect paging could mis-revert long threads, though behavior is covered by new adapter tests.
Overview
OpenCode thread hydration is capped so routine reads no longer pull the entire session history from the SDK.
readThreadnow loads a single page of 100 messages viasession.messages(limit/ optionalbefore) instead of unbounded history.readThreadtherefore exposes at most the 100 most recent assistant turns—a deliberate behavior change for performance.rollbackThreadusesreadOpenCodeMessagesForRollbackto walk older pages only until it has enough assistant messages to pick the revert target, with deduplication and extra pagination when a full page overlaps the previous cursor.Each history page goes through
readOpenCodeMessagePage: 15s timeout,AbortSignalpassed into the SDK call, and a clear timeout error on stall.runOpenCodeSdknow takes a callback(signal) => Promise<...>so cancellation can reach the client.Tests extend the runtime mock for paged
messages, hang/abort, and overlap, and add coverage for read bounds, rollback paging, overlap continuation, and timeout behavior.Reviewed by Cursor Bugbot for commit 8e48e6d. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Bound OpenCode history hydration to paginated reads with a 15s timeout
readThreadnow reads only the latest 100 messages (one page) instead of the full session history, with a 15-second timeout per request.rollbackThreaduses a newreadOpenCodeMessagesForRollbackhelper that pages backwards through history only as far as needed to locate the target assistant message, deduplicating overlapping page boundaries.runOpenCodeSdkin opencodeRuntime.ts now passes anAbortSignalto the SDK callback so timed-out reads are cleanly cancelled.readThreadno longer returns messages beyond the most recent 100; sessions with long histories will see a truncated turn list.Macroscope summarized 8e48e6d.