Repository navigation
Conversation
ApprovabilityVerdict: Approved at Macroscope's review found this PR approvable — Optimizes OpenCode fork and rewind boundary selection by replacing sorting with a constant-space linear scan. Existing boundary behavior and external calls remain unchanged, with no new operational exposure. You can add or adjust custom eligibility rules. Learn more. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
@juliusmarminge could you review this when you have a moment? Written by Claude Sonnet 5.5 via Claude Code in T3 Code. |
|
Thanks for this. Before a bug fix is taken further, the bug is reproduced on current main, and here it did not appear. We measured this on main at dae8d6f. Timed on its own with shuffled histories, the current boundary selection takes about 0.08 ms at 1,000 turns, under 1 ms at 10,000, and roughly 2.5 to 4 ms at 65,536. A linear scan stays near 0.1 ms even at the largest size, so the extra work you describe is real. We then forked a real OpenCode thread five times from the web app on the same commit. The adapter's fork step took 37 to 105 ms, and almost all of that was OpenCode's own fork call. Everything else in the adapter, boundary selection included, took about 1 ms, and every fork kept the right history. Even at 65,536 turns the sort would add about 3 ms to an operation that already takes 40 to 100 ms in OpenCode, so we couldn't find a fork or rewind that is noticeably slow because of it. We're closing this as a change with no user-visible effect rather than a fix. If you have a real thread where forking or rewinding is slow, please open an issue with the history size and timings and we'll look again. Closing this pull request. If it still happens for you, please open an issue with the exact steps, what you see, and the version and platform you are on; a fix is picked up from there. |
Problem
Selecting an OpenCode fork/revert boundary filters, sorts and maps the later provider turns even though the result is one native message ID. The helper takes O(N log N) time and O(N) auxiliary space.
Solution
Keep the first selected-turn lookup, then scan for the lowest eligible later ordinal using scalar state. Strictly smaller ordinals replace the winner, preserving stable first-wins ties; missing native references and empty native IDs retain their existing behavior. Helper work becomes O(N) time and O(1) auxiliary space, with no input mutation or caller change.
Validation (tests written before production code):
vp run check:changed a21d788752695764028e6d26ba924f3963e05806 --concurrency 2passes: format, lint, Knip, 10 affected/dependent typechecks and 45 selected tests.Full overlapping PR diffs were inspected; none changes this boundary helper. Related fork-call-path work: #15777. This is a small algorithmic fix in an existing helper, with no feature, permission, provider protocol or contract change; no prior maintainer approval is claimed. To reproduce the unnecessary work, provide an unordered history with many later native turns: the previous implementation sorts the full filtered history before returning only its first usable ID. Operation bounds and source-level space analysis are not a wall-clock, allocated-byte or end-to-end latency claim.
TLDR
complexity-opencode.mp4
Model: GPT-6.1 Sol. Harness: Codex in T3 Code.