Skip to content

perf(server): read only checkpoint capture baselines - #32114

Open
macodev00 wants to merge 5 commits into
pingdotgg:mainfrom
macodev00:perf/checkpoint-baseline-ordinals
Open

macodev00 wants to merge 5 commits into
pingdotgg:mainfrom
macodev00:perf/checkpoint-baseline-ordinals

Conversation

@macodev00

Copy link
Copy Markdown
Contributor

Checkpoint capture reads every ready checkpoint ordinal in its scope, although it only checks ordinal 0 and max(0, run.ordinal - 1). The work grows with checkpoint history on every capture. This is the smaller checkpoint-read issue reported in #24895.

The production capture caller now opts into baseline selection. The store derives the two ordinals from the decoded run inside the existing transaction and uses the existing unique scope/ordinal index. Calls without that option still return every ready ordinal, including the cancelled ordinal-one context's [0, 1] result.

This is a focused redundant-read defect under CONTRIBUTING.md's obvious-bug exception: unused historical rows are materialized and discarded, and the fix preserves capture decisions and events. No product behavior, public schema, migration, provider ownership, workspace selection, locking, or finalization changes. Current patches and discussions for #31012, #29521, #30862, #31349, #30875 and the closed duplicate #31844 were checked; their work is not included here.

Verification

Base and policy revision: 6577c6b6185167c0e502fa01f9e8e8f2dee6ff25.

  • Extended the existing capture test at its owning service/store layer. Before the fix, tracing the real SQLite statement's successful result records all 128 ready rows instead of [0, 127]; the ordinal-one cases also fail the bounded-index-plan assertion. After the fix, all 8 capture tests pass. The default full-context assertion, cancellation [0, 1], missing-baseline, rollback, and repeat-capture checks pass.
  • vp test run apps/server/src/orchestration-v2/CheckpointCaptureService.test.ts: 8 passed.
  • vp run check:changed upstream/main --concurrency 1: format, lint, both knip checks, generated GraphQL, 3 affected package typechecks, and 63 tests in 3 files passed. No repository-wide test run.
  • Independent read-only Codex review found no actionable findings. The reviewer independently compared event payloads and checked the SQLite plans with bound values.

Runtime transcript

Ran the actual CheckpointCaptureService, CheckpointService, EventSink, SQLite reader worker, and Git driver with isolated file-backed SQLite databases and disposable real Git repositories on macOS, Node 26.13.0, SQLite 3.54.0, Git 2.50.1. Each fixture seeded 4,000 checkpoint metadata records and created the real baseline refs used by capture. No user repositories, live T3 state, paid provider turns, or running application server were used.

Scenario Actual rows before → after Selected after Persisted events
Waiting run 4,000, both baselines ready 4,000 → 2 [0, 3999] 4
Both baseline rows marked missing 3,998 → 0 [] 6
Cancelled run 1 with later checkpoint history 4,000 → 1 [0] 3
Rolled-back run 4,000 → 2 [0, 3999] 0

Observed SQLite plans for the actual statement:

before: SEARCH orchestration_v2_projection_checkpoints
        USING INDEX orchestration_v2_projection_checkpoints_thread_idx (thread_id=?)
after:  SEARCH orchestration_v2_projection_checkpoints
        USING INDEX orchestration_v2_projection_checkpoints_scope_ordinal_idx
        (scope_id=? AND ordinal_within_scope=?)

The after trace identifies the reader connection. Before/after event types and payloads match after normalizing capture-clock timestamps; random event IDs are excluded from that comparison. Capture still records value.txt as one addition/one deletion, and git show <captured-ref>:value.txt returns the expected edited contents. Metadata marked missing produces the same baseline events. Cancellation stays cancelled, rollback emits nothing, and a repeated capture emits no additional events. Default full-context counts remain identical before/after.

This demonstrates bounded row selection and equivalent service behavior on synthetic history. It does not claim end-to-end latency, production-database benchmarking, or web/desktop/mobile/provider coverage.

Implemented and independently reviewed by GPT-6-based Codex agents using the Codex harness.

@github-actions github-actions Bot added vouch:unvouched Author is not yet trusted in the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Nov 6, 2026
@macroscopeapp

macroscopeapp Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at 2cbedc1

Macroscope's review found this PR approvable — Checkpoint capture reads only the two baseline ordinals it uses instead of loading checkpoint history. Existing capture behavior and the store’s default full-context reads remain unchanged, keeping the change narrowly scoped.

You can add or adjust custom eligibility rules. Learn more.

@coderabbitai

coderabbitai Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Checkpoint capture now requests baseline checkpoints from the projection store. The store can limit returned checkpoints to ordinal 0 and the preceding run ordinal. Tests cover this behavior for run ordinals 1 and 128.

Changes: Checkpoint capture

Layer / File(s) Summary
Ready baseline selection
apps/server/src/orchestration-v2/ProjectionStore.ts
getCheckpointCaptureContext accepts an option that limits returned checkpoints to ordinal 0 and max(0, run.ordinal - 1). Without the option, it applies no ordinal restriction.
Capture integration and validation
apps/server/src/orchestration-v2/CheckpointCaptureService.ts, apps/server/src/orchestration-v2/CheckpointCaptureService.test.ts
The capture service requests baseline checkpoints. Tests cover ordinals 1 and 128 and verify the preserved baseline ordinals.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Suggested reviewers: juliusmarminge, t3dotgg, revens2

Merge Risk: Minimal · up to bdec4

This change reduces redundant checkpoint reads during capture and leaves capture decisions unchanged. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "perf(server): read only checkpoint capture baselines" follows conventional commit format and names the main change. The changeset makes the production checkpoint capture caller read only or…
Description check Passed The description follows the template's main sections: Problem, Change, Scope, and Verification. It explains the redundant checkpoint reads and the opt-in baseline selection, links issue #24895, and gi…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "perf(server): read only checkpoint capture baselines" follows conventional commit format and names the main change. The changeset makes the production checkpoint capture caller read only ordinals 0 and max(0, run.ordinal - 1) through a new opt-in option on getCheckpointCaptureContext, which matches the title.

Full details: Description check

Explanation

The description follows the template's main sections: Problem, Change, Scope, and Verification. It explains the redundant checkpoint reads and the opt-in baseline selection, links issue #24895, and gives detailed verification steps with observed results. The template's Problem section asks for a short explanation with reproduction context, and the description covers that. The Scope section cites CONTRIBUTING.md's obvious-bug exception and names the issue. Verification includes test counts, SQLite plans, and a runtime transcript. The template's note about the agent model and harness is present at the end. The section headings are not labeled exactly as the template's HTML comments show, but the content maps to each required section. Remaining gaps are minor: the description does not label headings explicitly, and it mentions a comment-linked issue rather than a direct maintainer request.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 0c10f05 and bdec466.

Files selected for processing: 3

  • apps/server/src/orchestration-v2/CheckpointCaptureService.test.ts
  • apps/server/src/orchestration-v2/CheckpointCaptureService.ts
  • apps/server/src/orchestration-v2/ProjectionStore.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@maria-rcks

Copy link
Copy Markdown
Collaborator

Note

Written by gpt-6.1-sol on behalf of Maria

merged main without rebasing and resolved the checkpoint conflicts while preserving run-owned missing baselines. capture still reads only ordinal 0 and the previous run; default context reads remain complete. the diff stays at three files.

verified head 97e8a95d40cc9da58363e8eddd0726961ee4273c: all 31 reported checks pass, no conflicts, and two independent code reviews found no blockers. blacksmith vp run check:changed github/main passes on node 26.12.1, including lint, typecheck, and all 63 tests. no actionable bot findings remain. no live provider/client run or performance measurement was performed.

@navidnadali

Copy link
Copy Markdown
Contributor

+1

@juliusmarminge juliusmarminge added the takeover:in-progress A takeover lead is working on this PR label Nov 15, 2026
juliusmarminge and others added 2 commits November 15, 2026 04:34
Replace the tracer-captured SQL text and EXPLAIN QUERY PLAN assertions
with a direct check of the rows the baselines-only read returns.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@juliusmarminge

Copy link
Copy Markdown
Member

The automated pipeline stopped on this pull request and will not merge it:

the fix is written and reviewed, but proving it needs something no worker has:

  • Permanent blocker: the requested same-platform comparison needs macOS outside the device pool, which is unavailable under this brief.
  • Reduced baseline row reads, unchanged checkpoint decisions and persisted events, and unchanged default full-context reads were not demonstrated in the real app.
  • No stable capture latency medians, run spreads, captures, or uploaded driver were produced.

It stays open for a person to finish or close.

@juliusmarminge juliusmarminge added takeover:blocked Takeover blocked; reason in the PR body and removed takeover:in-progress A takeover lead is working on this PR labels Nov 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR conflicts with main. Rebase it or merge main into it. If it still conflicts after 7 days with no activity, it will be closed automatically.

See the conflict window.

@github-actions github-actions Bot added the needs-rebase Conflicts with its base branch. Closes after 7 days with no activity. label Nov 22, 2026
@navidnadali

Copy link
Copy Markdown
Contributor

Note

Written by Claude Opus 5.5 (Claude Code) on behalf of Navid

The pipeline stopped this for lack of a same-platform run in the real app on macOS, so here is one on an Apple silicon Mac (M5 Max, 18 cores, macOS 27.0.1, Node 26.13.1): main at 2c4310eb06 against this PR rebased onto it, same install and launch steps, both run from source. The rebase has two conflicts, both mechanical (#35925 reshaped the two lines this PR edits); the resolution and the rebased diff are in the gist, and the branch itself still needs it.

One t3 serve per checkout, each with its own base dir and port. A driver signs in to both the way t3 thread does and runs them in lock step, one run in flight across both servers: 8 new threads with one run each, then one thread with 1,031 runs, the driver editing a file before each run. The provider is an ACP instance running apps/server/scripts/acp-mock-agent.ts: a capture that finds 1,024 checkpoints in its scope is the 1,024th run of one thread, capture never calls the provider, and identical turns are what make the two databases comparable row for row.

Checkpoints in the scope at capture (n = 8 per side) Rows returned, main / PR Statement ms, main: p50 [min-max] Statement ms, PR Capture ms p50 [max], main / PR
none (first run of a new thread) 0 / 0 0.030 [0.021-0.132] 0.041 [0.027-0.148] 109 [135] / 119 [140]
128-135 128-135 / 2 0.229 [0.166-0.768] 0.075 [0.044-0.195] 159 [186] / 177 [188]
1,024-1,031 1,024-1,031 / 2 3.968 [1.267-4.995] 0.052 [0.038-0.084] 111 [117] / 111 [150]

Rows come from a first run with an env-gated, logging-only probe (the same diff on both). Times come from a second run without it, from the server's own sqlite span for this statement and its orchestrationV2.checkpointCapture.execute span; the 1-minute load average during that run had a median of 16.9 (range 8.8-35.3, 18 cores). Over all 1,039 captures, main's statement returned 531,995 rows and this PR's 2,060. Main's plan searches the thread index, and SQLite's .scanstats shows it visiting all 1,024 rows at 1,024 checkpoints; this PR's plan uses the scope/ordinal index and visits 2. So the baseline read no longer grows with history. Capture time is mostly Git, typically 100-200 ms here (over all 1,039 captures, p50 160 / 159 ms and p90 235 / 241 ms, main / PR), and doesn't change measurably at these sizes.

Same decisions and rows: the two inputs capture decides on (ordinal 0 preserved, baseline preserved) matched for all 1,039 captures. After normalising random ids, checkpoint ref hashes, timestamps and each side's scratch path, both databases hold the same 30,231 events in the same order per thread, and every column of all 30 thread-scoped tables matches (17 of them have rows, among them 1,039 runs and 1,048 checkpoints, all ready). The database comparison held in both runs; the decision inputs come from the instrumented run. On copies of the instrumented run's two databases, getCheckpointCaptureContext without the option returned the same ordinals on main and on this PR for every run (up to all 1,032 ordinals of the long thread). With the option, this PR returned exactly that set intersected with {0, max(0, ordinal - 1)}.

Not covered: real provider turns, the desktop client (this is the server driven over its MCP endpoint), Linux, nested repositories, and stopped or cancelled runs or missing or failed checkpoints in the live run (every run here completed; the existing capture tests cover those and pass on the rebased branch). Also histories past 1,031 runs, and a repeat of the timed run: there was one timed run, with n = 8 per row on a busy shared machine, so there is no run-to-run spread. Separately, outside this PR: the repository-scope baseline query from #35925, in the same context read, also searches the thread index (1,024 rows visited at 1,024 checkpoints, none returned here), so the context read as a whole still grows on both sides.

Driver, probe, scripts, raw results and the rebased diff: https://gist.github.com/navidnadali/c412bf3a637b2859a1ddfe083454da78

Made with Claude Opus 5.5 via Claude Code. Reviewed by GPT-6.1 Sol via Codex. Independently verified by Claude Fable 5.2.

@juliusmarminge juliusmarminge added takeover:in-progress A takeover lead is working on this PR and removed takeover:blocked Takeover blocked; reason in the PR body labels Nov 23, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@juliusmarminge

Copy link
Copy Markdown
Member

The automated pipeline stopped on this pull request and will not merge it:

someone else pushed to perf/checkpoint-baseline-ordinals (head is now bdec466); the pipeline does not build on commits it did not review

It stays open for a person to finish or close.

@juliusmarminge juliusmarminge added takeover:blocked Takeover blocked; reason in the PR body and removed takeover:in-progress A takeover lead is working on this PR labels Nov 23, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-rebase Conflicts with its base branch. Closes after 7 days with no activity. size:S 10-29 changed lines (additions + deletions). takeover:blocked Takeover blocked; reason in the PR body vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants