You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf(server): place turn items with one read and no read-back - #38897
TurnItemPositionStore.allocate runs for every turn-item.updated event the event sink stores, inside the commit
transaction, so each of its statements is a round trip to the SQLite writer worker. It reads the item's position and
its run's ordinal in two statements, and after inserting or moving a position it reads it back. A streamed snapshot of
an existing turn item pays one extra round trip and a new item two. #38544 batched provider commits and cut the other
per-snapshot round trips (savepoints, thread touch, high-water mark); these are left.
Change
Read the item's position and its run's ordinal in one statement. The run lookup is still skipped when there is no run
or the caller supplies its ordinal. Take the written position from RETURNING ordinal on the insert and the move; the
old read-back runs only when the write returns no row (another allocation placed the item first), with the same error if
the row is gone. Ordinals, run ranges, run_start placement and the reuse rules are unchanged.
Scope
A small fix for an obvious performance bug (redundant statements on the commit path), so no issue. It builds on #38544
and touches only the position store.
Verification
vp test run src/orchestration-v2/TurnItemPositionStore.test.ts (from apps/server): a new case counts statements
with Statement.CurrentTransformer while placing, reusing and moving an item whose run has ordinal 3. On main it
fails by assertion: (ordinal, statements) is [3000001, 4], [3000001, 2], [4000001, 3] instead of [3000001, 2], [3000001, 1], [4000001, 2]. With this change, 3/3 pass.
Runtime transcript: a file database with the writer worker, snapshots sent through consumeProviderEvents, counting
the messages posted to the writer for each snapshot's transaction. Identical on Linux x86_64 and macOS:
Writer messages per snapshot
main
This PR
Existing turn item, alone
8
7
New turn item, alone
10
8
Existing turn item, per job in a batch of 3
4
3
New turn item, per job in a batch of 3
6
4
Node or message, alone / per job in a batch
6 / 2
6 / 2
A batch's BEGIN, COMMIT, high-water mark and thread touches are shared and unchanged.
1,000 placements, then 1,000 reuses of the same items, each in one transaction, 31 alternating rounds.
Paired median speed-up 1.6× placing, 1.9× reusing; a second run agreed within 1%.
macOS (Apple M5 Max, Node 26.13.1, a machine busy with unrelated work, so the times are noisy): place 3,907 → 2,512 ms,
reuse 2,177 → 968 ms (paired 2.1×, 2.3×), with the same statement counts.
Every round on both stored the same ordinals. To reproduce from a checkout of this PR with dependencies installed: bash reproduce.sh <checkout> from https://gist.github.com/navidnadali/58c74e995ba247bb0c8dd0da1ac6e27f (it copies the two measurement files and main's position store
under a renamed key into apps/server/src/orchestration-v2/, runs them with vp test run, prints the summary and
removes the copies).
vp run check:changed passes. vp test run src/orchestration-v2 (from apps/server, with the provider replay
fixtures): 3,135/3,135. vp test run integration (from apps/server; all 26 *.integration.test.ts files): 387/387.
Not checked: end-to-end streaming latency in a running app.
Made with Claude Opus 5.5 via Claude Code. Reviewed by GPT-6.1 Sol via Codex.
Placing a turn item read its position and its run's ordinal in two
statements, and read the position back after inserting or moving it.
In a provider commit each statement is a round trip to the writer, so
a streamed snapshot of an existing item paid one extra round trip and a
new item two. Read both in one statement and take the written position
from RETURNING.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reviewing files that changed from the base of the PR and between b4bf73e and 4bf126a.
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
No actionable comments were generated in the recent review.
Walkthrough
TurnItemPositionStoreV2.allocate combines its initial position and run lookup, uses returned ordinals from updates and inserts, and reads the stored position if a write returns no row. A test checks SQL statement counts and allocated positions.
Changes: Position allocation
Layer / File(s)
Summary
Allocation reads, writes, and validation apps/server/src/orchestration-v2/TurnItemPositionStore.ts, apps/server/src/orchestration-v2/TurnItemPositionStore.test.ts
The allocation path fetches position and run data in one query. Updates and inserts return the allocated ordinal. If a write returns no row, the store looks up the stored position and preserves the missing-row error when none exists. The test checks statement counts and allocated positions.
This change reduces database round trips when placing turn items, and the position and ordinal logic is unchanged. No merge-blocking risk was found.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title "perf(server): place turn items with one read and no read-back" matches the main change. The PR reads the item position and run ordinal in one statement and takes the written position from R…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Description check
The description explains the problem (extra SQLite writer round trips in TurnItemPositionStore.allocate), the change (one combined read, RETURNING ordinal on insert and move, read-back only when the w…
Full details: Title check
Explanation
The title "perf(server): place turn items with one read and no read-back" matches the main change. The PR reads the item position and run ordinal in one statement and takes the written position from RETURNING instead of a read-back. It uses a conventional commit prefix and is specific about the change.
Full details: Description check
Explanation
The description explains the problem (extra SQLite writer round trips in TurnItemPositionStore.allocate), the change (one combined read, RETURNING ordinal on insert and move, read-back only when the write returns no row), the scope (small performance fix building on #38544, no issue needed), and verification with specific test commands, statement counts, and timing results. It follows the template's Problem, Change, Scope, and Verification sections and notes what was not checked. The template's guidance on the agent model line is satisfied by the note that the work was made with Claude Opus 5.5 via Claude Code. The title and Problem section do not restate a conventional commit title, but the template treats that as a guideline, and the description is otherwise complete.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
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 reported measurement requires macOS on an Apple M5 Max with Node 26.13.1; this worker is Linux x86_64, and macOS outside the device pool is unavailable. The instructions prohibit substituting another platform.
Placement/reuse/move statement counts, unchanged ordinals, and a median improvement exceeding run spread remain unverified on both commits. The scenario documentation explicitly excludes performance measurements because replay timing is simulated.
The automated pipeline stopped on this pull request and will not merge it:
the capture step could not show the problem on the base commit, so there is nothing to prove fixed.
Ran identical drivers sequentially in separate base/head worktrees. Each used three warm-ups and 41 measured fresh databases, with 1,000 placements, reuses, and moves in separate transactions. Repeated both sides pinned to CPU 7. Checked every returned ordinal and persisted row count/range. Uploaded both measurement sets and drivers, then removed both worktrees and scratch data.
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
size:M30-99 changed lines (additions + deletions).takeover:blockedTakeover blocked; reason in the PR bodyvouch:trustedAuthor is trusted by repo permissions or the VOUCHED list.
2 participants
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.
Note
Written by Claude Opus 5.5 on behalf of Navid
Problem
TurnItemPositionStore.allocateruns for everyturn-item.updatedevent the event sink stores, inside the committransaction, so each of its statements is a round trip to the SQLite writer worker. It reads the item's position and
its run's ordinal in two statements, and after inserting or moving a position it reads it back. A streamed snapshot of
an existing turn item pays one extra round trip and a new item two. #38544 batched provider commits and cut the other
per-snapshot round trips (savepoints, thread touch, high-water mark); these are left.
Change
Read the item's position and its run's ordinal in one statement. The run lookup is still skipped when there is no run
or the caller supplies its ordinal. Take the written position from
RETURNING ordinalon the insert and the move; theold read-back runs only when the write returns no row (another allocation placed the item first), with the same error if
the row is gone. Ordinals, run ranges,
run_startplacement and the reuse rules are unchanged.Scope
A small fix for an obvious performance bug (redundant statements on the commit path), so no issue. It builds on #38544
and touches only the position store.
Verification
vp test run src/orchestration-v2/TurnItemPositionStore.test.ts(fromapps/server): a new case counts statementswith
Statement.CurrentTransformerwhile placing, reusing and moving an item whose run has ordinal 3. Onmainitfails by assertion:
(ordinal, statements)is[3000001, 4], [3000001, 2], [4000001, 3]instead of[3000001, 2], [3000001, 1], [4000001, 2]. With this change, 3/3 pass.Runtime transcript: a file database with the writer worker, snapshots sent through
consumeProviderEvents, countingthe messages posted to the writer for each snapshot's transaction. Identical on Linux x86_64 and macOS:
mainA batch's
BEGIN,COMMIT, high-water mark and thread touches are shared and unchanged.1,000 placements, then 1,000 reuses of the same items, each in one transaction, 31 alternating rounds.
Linux x86_64 (Intel Xeon Platinum 8481C, 8 vCPUs, Debian 13, Node 26.13.1, idle machine):
mainPaired median speed-up 1.6× placing, 1.9× reusing; a second run agreed within 1%.
macOS (Apple M5 Max, Node 26.13.1, a machine busy with unrelated work, so the times are noisy): place 3,907 → 2,512 ms,
reuse 2,177 → 968 ms (paired 2.1×, 2.3×), with the same statement counts.
Every round on both stored the same ordinals. To reproduce from a checkout of this PR with dependencies installed:
bash reproduce.sh <checkout>from https://gist.github.com/navidnadali/58c74e995ba247bb0c8dd0da1ac6e27f (it copies the two measurement files andmain's position storeunder a renamed key into
apps/server/src/orchestration-v2/, runs them withvp test run, prints the summary andremoves the copies).
vp run check:changedpasses.vp test run src/orchestration-v2(fromapps/server, with the provider replayfixtures): 3,135/3,135.
vp test run integration(fromapps/server; all 26*.integration.test.tsfiles): 387/387.Not checked: end-to-end streaming latency in a running app.
Made with Claude Opus 5.5 via Claude Code. Reviewed by GPT-6.1 Sol via Codex.
🤖 Generated with Claude Code