Skip to content

perf(sources): batch a live group's cursor and event ledger writes - #5693

Merged
Sinity merged 5 commits into
masterfrom
claude/perf-ops-batch
Sep 27, 2026
Merged

Sinity merged 5 commits into
masterfrom
claude/perf-ops-batch

Conversation

@Sinity

@Sinity Sinity commented Sep 27, 2026 •

Copy link
Copy Markdown
Owner

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 through polylogued run --cold-build-index on 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_full admissions 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_ops block, so a batch could not have been one transaction.

Solution

  • CursorStore.ops_batch() defers commits inside an ops_write_scope to the end of the block and rolls back as a unit. _record_full_cursors records a group's cursors in one admission inside it.
  • The cursor upsert runs with manage_transaction=False, so _connect_ops (or the enclosing batch) owns its commit. Cursor read-modify-writes (failure reset, mark failed, rebase) take BEGIN IMMEDIATE only when no transaction is open, so they run inside a batch the first upsert has already opened.
  • emit_daemon_events writes several DaemonEventRecords 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 unconditional BEGIN IMMEDIATE, test_ops_batch_holds_read_modify_writes_after_an_upsert raises "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.py and tests/unit/sources/test_live_cursor_persistence.py: three tests fail identically on master (test_sigkill_mid_transaction_leaves_no_torn_cursor_write and the two lock-retry tests), so they are inherited, not caused here.
  • Benchmark: on the combined branch, cursor_full took 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_progress ops writes (115 holds, 3.3 s) remain per-update.

🤖 Generated with Claude Code

https://claude.ai/code/session_013Vn4qhKjhyaVBG4aPiqNW4

Sinity and others added 4 commits September 28, 2026 00:20
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
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-27T22:42:16.915143Z 93ef91b New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 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".

Comment thread polylogue/sources/live/batch.py Resolved
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
@Sinity
Sinity merged commit 2c8d957 into master Sep 27, 2026
3 checks passed
@Sinity
Sinity deleted the claude/perf-ops-batch branch September 27, 2026 22:51
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