Skip to content

feat(opencode): per-phase prep timings on turn.done - #25

Closed
PierrotAWB wants to merge 1 commit into
turn-timing-metricsfrom
turn-phase-timings
Closed

PierrotAWB wants to merge 1 commit into
turn-timing-metricsfrom
turn-phase-timings

Conversation

@PierrotAWB

@PierrotAWB PierrotAWB commented Aug 24, 2026 •

Copy link
Copy Markdown
Collaborator

Issue for this PR

Issues are disabled on this fork; motivation below. Stacked on #23 (extends the same turn.done line); re-target to dev after #23 merges.

Type of change

  • New feature

What does this PR do?

prep_ms (#23) says how much time the harness spends before the provider request; this says where it goes. Four additive fields on turn.done, accumulated across the turn's steps with plain Date.now() pairs:

  • history_ms — loading session history from SQLite (filterCompactedEffect, runs every step)
  • tools_ms — SessionTools.resolve
  • context_ms — the system-prompt/instructions/model-message Effect.all
  • snapshot_ms — the pre-stream git snapshot.track() in the processor (exposed via a snapshotMs handle getter, mirroring firstTokenAt)

These four are the optimization targets of the per-step-prep workstream; this instrumentation lands first so each later change has a fleet-wide before/after, and so the p90 tail can be attributed before anyone chases it.

How did you verify your code works?

Extended the #23 turn.done test: all four fields present and ≥ 0 on a scripted two-step turn. bun run typecheck clean, bun run lint 0 errors, prompt.test.ts + compaction.test.ts 112/112.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

🤖 Generated with Claude Code


Summary by cubic

Breaks down turn preparation time into four phases and logs them on turn.done. Previously we only emitted prep_ms; now we also emit history_ms, tools_ms, context_ms, and snapshot_ms to attribute pre-request latency.

  • Instruments history loading, tools resolution, context construction, and pre-stream snapshot capture; accumulates per step and emits on turn.done.
  • Adds snapshotMs to Handle/ProcessorContext and measures pre-stream snapshot.track() in the processor; exposes via handle.snapshotMs.
  • Updates tests to assert the four new fields and adapts fakes to include snapshotMs.

Migration

  • Add snapshotMs to any custom Handle implementations or test fakes.

Written for commit 6cb104c. Summary will update on new commits.

Review in cubic

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

The following comment was made by an LLM, it may be inaccurate:

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

Re-trigger cubic

@PierrotAWB

Copy link
Copy Markdown
Collaborator Author

Consolidated into #29 (one commit per concern there; review history for the prep_ms retry semantics is on this PR's threads).

@PierrotAWB PierrotAWB closed this Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant