Repository navigation
perf(sources): batch a live group's cursor and event ledger writes - #5693
Conversation
Live batch events are now built as DaemonEventRecord values and written through emit_daemon_events in one ledger transaction, so the advertised topic check reads those constructions as emit sites too. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013Vn4qhKjhyaVBG4aPiqNW4
The cursor upsert committed inside its _connect_ops block, which already commits on exit, so ops_batch published every cursor of a group on its own and could not roll the group back as a unit. Pass manage_transaction=False so the block (or the enclosing batch) owns it. The batch tests now exercise the cursor write the batch wraps. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013Vn4qhKjhyaVBG4aPiqNW4
|
You have reached your Codex usage limits for security reviews. Please try again later. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 60714a1c91
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
With the batch owning the upsert's commit, the first cursor write of a group left its transaction open, and the next read-modify-write (failure reset, mark failed) issued BEGIN IMMEDIATE inside it: "cannot start a transaction within a transaction" failed the group's admission. Take the write lock only when no transaction is open, and let the read-modify-write upsert leave the commit to its block or batch. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013Vn4qhKjhyaVBG4aPiqNW4
Summary
A published live group's cursor writes now share one writer admission and one ops transaction. A batch's session and message events share one ledger transaction.
Problem (evidence)
Numbers come from
devtools bench fresh-build(#5678). Each run cold-builds a sealed 144-file (276 MiB) private sample of Claude Code, Codex and Gemini sources throughpolylogued run --cold-build-indexon a shared host (load 18-35). Only aggregate numbers are quoted. Wall times move with host load; writer holds, stage timers and CPU seconds move less.The writer's hold ledger showed 144
cursor_fulladmissions totalling 44 s. Each file took its own writer round trip and ops commit. The daemon's event ledger committed once per session event, about 0.6 s per batch. The cursor upsert also committed inside its own_connect_opsblock, so a batch could not have been one transaction.Solution
CursorStore.ops_batch()defers commits inside anops_write_scopeto the end of the block and rolls back as a unit._record_full_cursorsrecords a group's cursors in one admission inside it.manage_transaction=False, so_connect_ops(or the enclosing batch) owns its commit. Cursor read-modify-writes (failure reset, mark failed, rebase) takeBEGIN IMMEDIATEonly when no transaction is open, so they run inside a batch the first upsert has already opened.emit_daemon_eventswrites severalDaemonEventRecords on one connection and commit. The live batch builds its session and message events with the new builders. The advertised-topic test now counts record constructions as production emit sites.Verification
devtools test tests/unit/sources/test_cursor_ops_write_scope.py "tests/unit/daemon/test_daemon_events_endpoint.py::TestAdvertisedTopicContracts": passed. Anti-vacuity: with a per-write commit, the first cursor is visible before the batch ends and survives a rollback. With an unconditionalBEGIN IMMEDIATE,test_ops_batch_holds_read_modify_writes_after_an_upsertraises "cannot start a transaction within a transaction". A benchmark run of an intermediate head hit exactly that failure, and it is fixed here.tests/unit/sources/test_cursor_lifecycle.pyandtests/unit/sources/test_live_cursor_persistence.py: three tests fail identically on master (test_sigkill_mid_transaction_leaves_no_torn_cursor_writeand the two lock-retry tests), so they are inherited, not caused here.cursor_fulltook 23 admissions totalling 2.07 s, down from 144 totalling 44 s.Residuals
batch.py and cursor.py are IN the derived schema-identity closure.
attempt_progressops writes (115 holds, 3.3 s) remain per-update.🤖 Generated with Claude Code
https://claude.ai/code/session_013Vn4qhKjhyaVBG4aPiqNW4