Skip to content

perf(sqlite): bound session receipt scope publication - #174395

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-sqlite-write-scope-snapshot-hotspot-20260919
Oct 16, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-sqlite-write-scope-snapshot-hotspot-20260919

Conversation

@steipete

@steipete steipete commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Session reads that discover a new receipt scope scan and hash every registered scope in the agent database. The bucketed snapshot introduced in #173410 reduced copying but retained this whole-inventory scan; cohort publication from #172404 avoids one publication per row but still pays it for each new cohort.

User Impact

Reduces main-thread work when history, session-list, and session-description reads retain facts for previously unseen sessions. Stored data, schemas, write admission, permission checks, and receipt invalidation are unchanged.

Why This Change Was Made

The receipt owner already knows which normalized scope keys it discovers or retires. Carry those keys through the existing publication boundary and visit only them in the same snapshot builder. Initial snapshots still include all scopes; general publications retain the sweep required to reclaim retirement shared by another isolate. Historical snapshot membership and live shared revision cells keep their existing semantics. Warm reads already publish nothing and retain that behavior.

Production delta: +16 lines across three existing modules. The small interface/iteration growth preserves immutable snapshots, cross-isolate retirement cleanup, and the original full-map traversal; it adds no cache, revision, schema, or second snapshot implementation. No new module or export.

Evidence

  • The focused regression fails on the original code: discovering one new scope reads 256 unrelated scope cells. It passes after the change with zero unrelated cell reads, and verifies immutable prior membership, cursor deltas, and retirement/recreation.
  • Existing receipt tests pass (3 tests; about 1 second Vitest time, 4.4 seconds initial wrapper wall time).
  • All 12 tests in src/infra/sqlite-database-admission.worker.test.ts pass, including publication after dispatch, scoped/unscoped commits, retirement replacement, rejected admission, and 5,000-task-message coverage. Two focused files together took 139.5 seconds including cold worker-bundle preparation; worker-file test execution was about 23 seconds. This integration proof is reused across the traversal-only refinement; the 3-test receipt file passes again on the final candidate (3.66 seconds wrapper wall time), and PR CI owns final-head broad proof.
  • Changed-file oxfmt, repository lint with config/tsconfig/oxlint.core.json, and git diff --check pass.
  • Independent Codex autoreview of the final combined candidate: scoped-clean through P2 with full receipt/admission/worker context. The staged full-sweep regression noted in an intermediate review is resolved.

Measurement

A synthetic owner-boundary benchmark on Linux/Node 26 starts each case with 5,000 session-key/session-ID pairs (10,000 scopes). It invokes the production receipt and admission registry owners. Baseline is 0dc31f5f6430; final source is 4d98937e1eba. Unprofiled main-thread CPU uses process.threadCpuUsage(), five rounds per case; separate V8 sampling includes allocations collected by minor and major GC.

Operation Before CPU ms/call After CPU ms/call Sampled allocated bytes/call, before → after
Discover one new session (two scopes), 500 calls 2.0367 0.0380 40,457 → 41,524
Discover 100 new sessions, 50 calls 7.5421 2.9374 2,805,158 → 2,804,058
Existing single-session read, 500 calls 0.00570 0.00565 5,421 → 5,471
Existing 100-session cohort, 6 × 1,000 calls 0.2535 0.2641 263,457 → 268,478
General admission publication, 500 calls 1.7179 1.7954 6,902 → 3,837

Discovery improves 53.6× for one session and 2.57× for a 100-session cohort. Allocation is neutral: unchanged bucket copying dominates. General-publication timing ranges overlap (before 1.56–1.90 ms, after 1.76–1.87 ms); its small sampled allocation floor does not establish an allocation win. A full-sweep iterator regression found during measurement was removed before landing by preserving the original Map.forEach traversal.

These are receipt-owner costs with session-shaped scope cardinality, not end-to-end RPC latency or a seeded database/Gateway result. Endpoint-level chat.history, sessions.list, and sessions.describe CPU/allocation were not obtained: the source-launched synthetic Gateway exceeded the bounded 240-second startup budget before startupSettled or any measured RPC. It reached HTTP bind at about 236 seconds, then began main-session recovery. This is a measurement setup limit, not a product-performance result. The seeded fixture contained 5,000 sessions and 6,000 retained runs (235,978,752-byte agent database; 11,780,096-byte shared database); no production data was used. The longer interleaved warm-cohort control is also neutral within noise: baseline range 0.225–0.268 ms, final 0.193–0.283 ms (6 × 1,000 calls per revision).

  • Broad typecheck/build/suites are delegated to PR CI under the requested validation policy. No Testbox/Crabbox lease was allocated.

Inherited CI failures

Final-head CI run 38930592365, attempt 1, has an inherited check-guards failure: the duplicate-scan coverage check rejects the tracked root file cli-parent-lifetime.mjs because it is missing from the scan targets and intentional exclusions. The actual CI merge is e9b674c63cfbfee93e4c990ebf79b051947ab35e, with main parent bb642e181e130153894a45f141a5368123bcd487 and this PR head 4d98937e1eba61da007294c4c44dd1a3808d2ad6.

The focused node scripts/check-duplicates.mjs --coverage subcheck fails identically on the PR head, the tested merge inventory, CI's unchanged main-parent inventory, and then-current main ec90dc1ef23dd9c9dd731479b4431d9b082b78d5: the only uncovered path is cli-parent-lifetime.mjs. Baseline inventories were loaded into isolated temporary Git indexes (GIT_INDEX_FILE plus git read-tree), without switching or changing the checkout; this subcheck reads only tracked paths and its static target list. The guard source is byte-identical across these revisions, and the uncovered file is unchanged between CI's main parent and tested merge. The tested merge changes only this PR's four SQLite files.

checks-fast-baseline-ratchets also fails its mock-export subcheck on the unchanged src/flows/doctor-plugin-source-captures.test.ts:32, which mocks ../process/supervisor/darwin-bun-process-census.js without an isolation annotation. A focused single-file reproduction using the production parser, resolver, mock scanner, and baseline comparison finds the identical ungrandfathered fingerprint 0f314816d50228e6240f1048998f802dd80d499ba91277a72f2a366e9c574dd2 on CI's main parent and tested merge. The guard, scanner, fixture, target module, and baseline ledger are unchanged by this PR.

Both inherited issues have since been repaired on main: cfb9b5082d60 adds the missing duplicate-scan target; cb196c383039 adds the fixture's isolation annotation. The focused mock reproduction is clean on newer main ecdf8d3b779d705940a90b9fc4fffad6ccf7e2ed. The older scheduled-main classifier is superseded by direct evidence from CI's exact main parent. All 42 substantive passing jobs include tests, typechecks, lint, and security; the two attributed guard failures cause the aggregate CI gate to fail. Landing uses the authorized inherited-failure exception. No CI rerun, unrelated source edit, or rebase was used to chase green.

@clawsweeper

clawsweeper Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review October 16, 2026 16:08
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-16T16:19:19.877226Z 4d98937 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.

@steipete
steipete merged commit e145264 into main Oct 16, 2026
153 of 158 checks passed
@steipete
steipete deleted the steipete/perf-micro-sqlite-write-scope-snapshot-hotspot-20260919 branch October 16, 2026 16:32
@steipete

Copy link
Copy Markdown
Contributor Author

Merged as e145264 under the authorized inherited-failure exception, with reviewed head 4d98937.

CI run 38930592365 completed with tests, typechecks, lint, and security passing. Its only substantive failures were:

  • check-guards: duplicate-scan coverage omitted cli-parent-lifetime.mjs. The focused coverage check failed identically on the PR head, CI merge, and unchanged CI main parent bb642e1. Fixed separately on main in cfb9b50.
  • checks-fast-baseline-ratchets: src/flows/doctor-plugin-source-captures.test.ts:32 lacked a mock-isolation annotation. The production scanner found the identical ungrandfathered fingerprint on CI's main parent and merge; the relevant source and baseline were unchanged by this PR. Fixed separately on main in cb196c3; the focused scan is clean after that fix.

These caused the aggregate CI gate failure. The final dependency and security-sensitive review statuses passed. No CI rerun or unrelated source change was used to obtain green. The lane-authorized exact-head merge API fallback avoided provisioning a native-helper worktree inside the excluded canonical checkout.

Measured receipt-owner CPU improved 2.0367 → 0.0380 ms for one new session and 7.5421 → 2.9374 ms for 100 new sessions. Allocation was neutral. End-to-end RPC CPU/allocation remains unmeasured because the isolated source Gateway did not finish startup within the bounded attempt; no endpoint-level speedup is claimed.

vincentkoc added a commit that referenced this pull request Oct 16, 2026
* commit 'a4c73619a5c': (29 commits)
  test: align model and Discord fixtures with runtime owners
  perf(sessions): reuse startup deletion discovery (#174408)
  fix(gateway): attribute ephemeral connections in normal logs (#174406)
  test(telegram): consolidate duplicate coverage (batch d117) (#173112)
  perf(doctor): avoid redundant backup and transcript reads (#174416)
  fix(update): avoid redundant reads for closed SQLite generations (#174426)
  fix(ui): Activity page tabs collapse to a few pixels on desktop (#173856)
  fix(decisions): skip prefilter for empty tool surfaces (#174269)
  perf(sqlite): retain unchanged database proofs across schema updates (#174409)
  refactor(test): remove duplicate export collision checks (#174391)
  fix: clear unused MCP and identity helper exports (#174421)
  fix(test): supply SQLite reliability fixture catalog
  refactor(mattermost): use the guarded transport directly (#174419)
  refactor(agents): trust prepared provider facts (#174388)
  fix(control-ui): open submenus immediately on click (#174292)
  test(anthropic): synchronize the late-send fixture with initialization
  refactor(ui): scope Plugins page state to Solid owners (#174281)
  perf(chat): pace board history refreshes and reuse cursors (#174407)
  perf(sqlite): bound session receipt scope publication (#174395)
  refactor(openrouter): share key budget test fixtures (#174340)
  ...
vincentkoc added a commit that referenced this pull request Oct 16, 2026
…157433

* commit '2e8bfec53fc1cf06c9e438f42b027a82e04ace9a': (29 commits)
  test: align model and Discord fixtures with runtime owners
  perf(sessions): reuse startup deletion discovery (#174408)
  fix(gateway): attribute ephemeral connections in normal logs (#174406)
  test(telegram): consolidate duplicate coverage (batch d117) (#173112)
  perf(doctor): avoid redundant backup and transcript reads (#174416)
  fix(update): avoid redundant reads for closed SQLite generations (#174426)
  fix(ui): Activity page tabs collapse to a few pixels on desktop (#173856)
  fix(decisions): skip prefilter for empty tool surfaces (#174269)
  perf(sqlite): retain unchanged database proofs across schema updates (#174409)
  refactor(test): remove duplicate export collision checks (#174391)
  fix: clear unused MCP and identity helper exports (#174421)
  fix(test): supply SQLite reliability fixture catalog
  refactor(mattermost): use the guarded transport directly (#174419)
  refactor(agents): trust prepared provider facts (#174388)
  fix(control-ui): open submenus immediately on click (#174292)
  test(anthropic): synchronize the late-send fixture with initialization
  refactor(ui): scope Plugins page state to Solid owners (#174281)
  perf(chat): pace board history refreshes and reuse cursors (#174407)
  perf(sqlite): bound session receipt scope publication (#174395)
  refactor(openrouter): share key budget test fixtures (#174340)
  ...
vincentkoc added a commit that referenced this pull request Oct 16, 2026
…/decision-onnx-v2-proof-20261016

* commit '2e8bfec53fc1cf06c9e438f42b027a82e04ace9a': (29 commits)
  test: align model and Discord fixtures with runtime owners
  perf(sessions): reuse startup deletion discovery (#174408)
  fix(gateway): attribute ephemeral connections in normal logs (#174406)
  test(telegram): consolidate duplicate coverage (batch d117) (#173112)
  perf(doctor): avoid redundant backup and transcript reads (#174416)
  fix(update): avoid redundant reads for closed SQLite generations (#174426)
  fix(ui): Activity page tabs collapse to a few pixels on desktop (#173856)
  fix(decisions): skip prefilter for empty tool surfaces (#174269)
  perf(sqlite): retain unchanged database proofs across schema updates (#174409)
  refactor(test): remove duplicate export collision checks (#174391)
  fix: clear unused MCP and identity helper exports (#174421)
  fix(test): supply SQLite reliability fixture catalog
  refactor(mattermost): use the guarded transport directly (#174419)
  refactor(agents): trust prepared provider facts (#174388)
  fix(control-ui): open submenus immediately on click (#174292)
  test(anthropic): synchronize the late-send fixture with initialization
  refactor(ui): scope Plugins page state to Solid owners (#174281)
  perf(chat): pace board history refreshes and reuse cursors (#174407)
  perf(sqlite): bound session receipt scope publication (#174395)
  refactor(openrouter): share key budget test fixtures (#174340)
  ...
vincentkoc added a commit that referenced this pull request Oct 16, 2026
…ision-accounting-native

* commit '2e8bfec53fc1cf06c9e438f42b027a82e04ace9a': (29 commits)
  test: align model and Discord fixtures with runtime owners
  perf(sessions): reuse startup deletion discovery (#174408)
  fix(gateway): attribute ephemeral connections in normal logs (#174406)
  test(telegram): consolidate duplicate coverage (batch d117) (#173112)
  perf(doctor): avoid redundant backup and transcript reads (#174416)
  fix(update): avoid redundant reads for closed SQLite generations (#174426)
  fix(ui): Activity page tabs collapse to a few pixels on desktop (#173856)
  fix(decisions): skip prefilter for empty tool surfaces (#174269)
  perf(sqlite): retain unchanged database proofs across schema updates (#174409)
  refactor(test): remove duplicate export collision checks (#174391)
  fix: clear unused MCP and identity helper exports (#174421)
  fix(test): supply SQLite reliability fixture catalog
  refactor(mattermost): use the guarded transport directly (#174419)
  refactor(agents): trust prepared provider facts (#174388)
  fix(control-ui): open submenus immediately on click (#174292)
  test(anthropic): synchronize the late-send fixture with initialization
  refactor(ui): scope Plugins page state to Solid owners (#174281)
  perf(chat): pace board history refreshes and reuse cursors (#174407)
  perf(sqlite): bound session receipt scope publication (#174395)
  refactor(openrouter): share key budget test fixtures (#174340)
  ...
vincentkoc added a commit that referenced this pull request Oct 16, 2026
…158510

* commit '26cbd409b9753a9318a6dc09f97b2f0b4b776a09': (29 commits)
  test: align model and Discord fixtures with runtime owners
  perf(sessions): reuse startup deletion discovery (#174408)
  fix(gateway): attribute ephemeral connections in normal logs (#174406)
  test(telegram): consolidate duplicate coverage (batch d117) (#173112)
  perf(doctor): avoid redundant backup and transcript reads (#174416)
  fix(update): avoid redundant reads for closed SQLite generations (#174426)
  fix(ui): Activity page tabs collapse to a few pixels on desktop (#173856)
  fix(decisions): skip prefilter for empty tool surfaces (#174269)
  perf(sqlite): retain unchanged database proofs across schema updates (#174409)
  refactor(test): remove duplicate export collision checks (#174391)
  fix: clear unused MCP and identity helper exports (#174421)
  fix(test): supply SQLite reliability fixture catalog
  refactor(mattermost): use the guarded transport directly (#174419)
  refactor(agents): trust prepared provider facts (#174388)
  fix(control-ui): open submenus immediately on click (#174292)
  test(anthropic): synchronize the late-send fixture with initialization
  refactor(ui): scope Plugins page state to Solid owners (#174281)
  perf(chat): pace board history refreshes and reuse cursors (#174407)
  perf(sqlite): bound session receipt scope publication (#174395)
  refactor(openrouter): share key budget test fixtures (#174340)
  ...
vincentkoc added a commit that referenced this pull request Oct 16, 2026
…esafe-decision-native

* commit '26cbd409b9753a9318a6dc09f97b2f0b4b776a09': (29 commits)
  test: align model and Discord fixtures with runtime owners
  perf(sessions): reuse startup deletion discovery (#174408)
  fix(gateway): attribute ephemeral connections in normal logs (#174406)
  test(telegram): consolidate duplicate coverage (batch d117) (#173112)
  perf(doctor): avoid redundant backup and transcript reads (#174416)
  fix(update): avoid redundant reads for closed SQLite generations (#174426)
  fix(ui): Activity page tabs collapse to a few pixels on desktop (#173856)
  fix(decisions): skip prefilter for empty tool surfaces (#174269)
  perf(sqlite): retain unchanged database proofs across schema updates (#174409)
  refactor(test): remove duplicate export collision checks (#174391)
  fix: clear unused MCP and identity helper exports (#174421)
  fix(test): supply SQLite reliability fixture catalog
  refactor(mattermost): use the guarded transport directly (#174419)
  refactor(agents): trust prepared provider facts (#174388)
  fix(control-ui): open submenus immediately on click (#174292)
  test(anthropic): synchronize the late-send fixture with initialization
  refactor(ui): scope Plugins page state to Solid owners (#174281)
  perf(chat): pace board history refreshes and reuse cursors (#174407)
  perf(sqlite): bound session receipt scope publication (#174395)
  refactor(openrouter): share key budget test fixtures (#174340)
  ...
vincentkoc added a commit that referenced this pull request Oct 16, 2026
…/decision-tool-v2-proof-20261016

* commit '26cbd409b9753a9318a6dc09f97b2f0b4b776a09': (29 commits)
  test: align model and Discord fixtures with runtime owners
  perf(sessions): reuse startup deletion discovery (#174408)
  fix(gateway): attribute ephemeral connections in normal logs (#174406)
  test(telegram): consolidate duplicate coverage (batch d117) (#173112)
  perf(doctor): avoid redundant backup and transcript reads (#174416)
  fix(update): avoid redundant reads for closed SQLite generations (#174426)
  fix(ui): Activity page tabs collapse to a few pixels on desktop (#173856)
  fix(decisions): skip prefilter for empty tool surfaces (#174269)
  perf(sqlite): retain unchanged database proofs across schema updates (#174409)
  refactor(test): remove duplicate export collision checks (#174391)
  fix: clear unused MCP and identity helper exports (#174421)
  fix(test): supply SQLite reliability fixture catalog
  refactor(mattermost): use the guarded transport directly (#174419)
  refactor(agents): trust prepared provider facts (#174388)
  fix(control-ui): open submenus immediately on click (#174292)
  test(anthropic): synchronize the late-send fixture with initialization
  refactor(ui): scope Plugins page state to Solid owners (#174281)
  perf(chat): pace board history refreshes and reuse cursors (#174407)
  perf(sqlite): bound session receipt scope publication (#174395)
  refactor(openrouter): share key budget test fixtures (#174340)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 17, 2026
* perf(sqlite): bound session receipt scope publication

* perf(sqlite): preserve full-sweep scope traversal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant