Repository navigation
refactor(opencode): cut per-step turn prep - #29
Merged
Merged
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ry backoff Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…l per step Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
This was referenced Aug 24, 2026
|
The following comment was made by an LLM, it may be inaccurate: |
There was a problem hiding this comment.
All reported issues were addressed across 6 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
…che, index-aligned after() Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
All reported issues were addressed across 4 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
…baseline Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Issues are disabled on this fork. Consolidates #23, #25, #26, #27, #28 (closed in favor of this) — one commit per concern, individually revertable.
Type of change
What does this PR do?
Five commits attacking per-step turn prep, in order:
prep_ms+ttft_steponturn.done— the derived overhead (ttft − provider_ttft) silently absorbed tool wall-clock on tool-first turns (firstTokenAtonly set on text/reasoning, handle resets per step): prod sample showed a 192s "overhead" on a 217.9s turn.prep_ms(turnStart → first provider request, first-attempt stamped so retry backoff is excluded — cubic review, addressed) is correct by construction;ttft_stepflags cross-step pairs. Additive; no existing field changes.history_ms/tools_ms/context_ms/snapshot_ms, so each following commit has a fleet-wide before/after.runLoopreloaded and re-hydrated the whole session from SQLite every step (O(history × steps)). The runner lock makes the turn the single writer, so: load once, then fetch only rows with id > last-seen (newMessageV2.after, ids are monotonic) — which also preserves mid-turn queued user messages exactly as today — with a full reload whenever the tail contains compaction/summary rows.snapshot.track()git chain forks and runs during provider TTFT; an idempotentawaitSnapshotjoins at the real constraint points (tool execute wrapper + step-start).trackis mutex-locked so the fiber serializes safely;orDie+forkIn(scope)keep failure/interruption semantics.How did you verify your code works?
Full
packages/opencodesuite over the stack: 3129 pass; only failures are the pre-existingTruncatedate bug (fixed in #24) and a pty test that passes 9/9 in isolation (full-suite load flake). Purpose-built coverage: newturn.donefields test (scripted tool-first two-step turn:ttft_step === 2,prep_ms ≤ ttft_ms, phase fields ≥ 0);snapshot-tool-race.test.tsguards the barrier; multi-step/subtask/question/compaction suites guard history threading.bun run typecheckclean,bun run lint0 errors.Checklist
🤖 Generated with Claude Code
Summary by cubic
Cuts per-step turn prep and makes
turn.donetiming accurate. Previously we reloaded history and instructions every step and misattributed prep/TTFT on tool-first turns; now we cache per turn, overlap the snapshot with provider TTFT, use fresh per-step snapshots, serialize the snapshot barrier so concurrent tools share one baseline, and emit honest, additive timing fields.prep_ms(turn start → first provider request),ttft_step(step index for TTFT), and per-phase timings:history_ms,tools_ms,context_ms,snapshot_ms. Stamps the first request once so retry backoff is excluded.MessageV2.after(sessionID, time, id)(index-aligned on(time_created, id)); falls back to full recompute if the tail contains compaction/summary rows.snapshot.track()with the provider request; tools (including MCP) and step-start events block on anawaitSnapshotbarrier. Uses a fresh snapshot per step after the first join and serializesawaitSnapshotso concurrent tools share one baseline.Review focus
packages/opencode/src/session/prompt.ts: per-turn history cache withafter(), pre-reminder cache, timing aggregation andturn.donefields, per-turn instruction resolution, TTFT step capture.packages/opencode/src/session/processor.ts: snapshot overlap and serializedawaitSnapshotbarrier (KeyedMutex); fresh per-step snapshots; first-request stamping to exclude retry backoff; exposessnapshotMs.packages/opencode/src/session/message-v2.ts: newafter(sessionID, time, id)query using(time_created, id)for index alignment.packages/opencode/src/session/tools.ts: built-in and MCP tools await the snapshot before execution.Rollout notes
prep_ms,ttft_step, and phase metrics.Written for commit 243bcaa. Summary will update on new commits.