Skip to content

perf(sqlite): stop reserializing shared admission maps - #172886

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-sab-postmessage-segv-20260919
Oct 15, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-sab-postmessage-segv-20260919

Conversation

@steipete

@steipete steipete commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

SQLite admission exchange still serialized Maps holding SharedArrayBuffers on every worker operation in the host reply, and retained native-worker carriers resent their complete admission environment on every child creation. This keeps V8's shared-buffer serializer under sustained pressure during worker churn; it matches the shape of a production SIGSEGV.

Change

  • Give each direct SQLite worker slot one ordered admission cursor, seeded from the snapshot inherited at Worker construction.
  • Give each retained native-worker carrier one inherited registry, then merge only admission deltas before starting a child.
  • Carry unchanged state-integrity and maintenance buffers in the worker's opening context rather than ordinary commands.
  • Send empty-map retirement tombstones, and reset cursors when a captured publication was not delivered.
  • Batch registry publication after admission installation.

The 12-file production change is +185/-46 lines. The state is required by the retained-carrier contract: a carrier may start descendants after its own Worker inherited the environment, so it needs an ordered cursor and local projection to pass current admission facts once at each child start.

Evidence and measurement

An isolated Node 26.10.0 synthetic stress harness used 5,000 admission records, 16 rotating workers, and a target rate of 200 messages/s while SharedArrayBuffers were created, replaced, retired, and workers exited:

  • Pre-delta shape, complete Maps in both directions: 5,084 messages in 300 seconds, 16.94 messages/s, 382 worker replacements.
  • Current-main shape, outbound deltas but complete host receipts: 13,212 messages in 180 seconds, 73.39 messages/s, 218 worker replacements.
  • This change, deltas both directions with stable buffers only at startup: 35,987 messages in 180 seconds, 199.89 messages/s, 239 worker replacements.
  • Extended this-change run: 59,994 messages in 300 seconds, 199.96 messages/s, 399 worker replacements.

The native SIGSEGV did not reproduce in these bounded runs. The pre-change throughput collapse does reproduce the dangerous serializer pressure. The change is 2.72x faster than the current-main message shape and sustains the requested 200 messages/s rate.

Proof

  • Changed-file oxfmt --threads=1: passed.
  • Changed-file type-aware oxlint: passed.
  • git diff --check: passed.
  • Focused local Vitest: unavailable before collection because the installed native TypeScript process panics in readFile with Symbol(Symbol.dispose) is not a function; PR CI provides the full gates.
  • independent subagent review (autoreview route unavailable)

@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 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-15T07:21:14.307576Z c63e985 PR opened
ℹ️ 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.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 15, 2026
@clawsweeper

clawsweeper Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR sends SQLite admission deltas through worker replies and retained carriers while avoiding repeated transfers of unchanged shared buffers.

Example: A Gateway retains 5,000 admission records while creating additional workers.

  • Before: Host admission replies and retained-carrier creation messages repeatedly serialize complete shared-buffer maps.
  • After: The intended implementation sends changed entries after bootstrap; the reviewed patch currently fails admitted dispatch with ReferenceError.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The performance direction is useful, but supplied measurements bypass the changed production owner and a confirmed runtime error breaks admitted worker dispatch.
Proof confidence 🦪 silver shellfish (2/6) This maintainer-authored PR is outside the ordinary contributor proof gate; its synthetic benchmark measures serialization shapes, while CI demonstrates failure in the actual broker path rather than successful after-fix behavior.
Patch quality 🧂 unranked krab (1/6) 1 actionable review finding remain.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Worker churn and large admission maps consume Gateway CPU and reduce responsiveness through repeated shared-buffer serialization.
Reason: The maintainer-authored direction extends an established optimization without adding configuration or changing persisted formats; the synthetic measurements support its performance rationale.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

⛔ Needs changes before merge - 1 item remains

This PR addresses useful SQLite serialization overhead, but an undefined slot reference breaks admitted worker dispatch and must be repaired before merge.

Priority: P2
Reviewed head: c63e985058c8fc8e4b1780a3f7062c24d7bcc807

Before merge

  • Pass the dispatch slot into the admission helper (P1) - prepareSqliteWorkerOperationAdmission is a module-level function with no slot parameter or local binding, but the new code reads slot.databaseAdmissionCursor. Any dispatch with a database path or admission factory throws ReferenceError before posting the request, breaking ordinary SQLite-backed operations. Exact-head CI confirms this through pairing-store approval and allowlist operations. Pass the dispatch slot from dispatchSqliteWorkerJob and use it for both cursor access and reset.

Findings

  • [P1] Pass the dispatch slot into the admission helper — src/infra/sqlite-worker-broker-reply.ts:169-172

Tests

  • Missing end-to-end proof: The supplied synthetic message-shape benchmark does not exercise the changed production broker and retained-carrier paths.
Agent review details

How this fits together

The SQLite broker transfers database validation facts between the Gateway, direct workers, and retained native-worker carriers; workers consume those facts while existing owners separately authorize database operations.

flowchart TD
  Gateway --> Broker
  Broker --> Registry
  Registry --> DirectWorker
  Registry --> Carrier
  Carrier --> ChildWorker
  DirectWorker --> SQLite
  ChildWorker --> SQLite
Loading

Technical review

Best possible solution:

Keep the delta optimization and pass the actual dispatch slot into the admission helper so its cursor binding and reset callback use the correct owner.

Do we have a high-confidence way to reproduce the issue?

Source confirms the repeated full-map transport paths, while the reported native crash remains unproven; exact-head CI independently demonstrates the introduced undefined-slot failure.

Is this the best way to solve the issue?

Extending the existing per-receiver cursor and merging deltas in retained carriers is a coherent performance repair, but the admission helper must receive its slot before this implementation can work.

Full review comments:

  • [P1] Pass the dispatch slot into the admission helper — src/infra/sqlite-worker-broker-reply.ts:169-172
    prepareSqliteWorkerOperationAdmission is a module-level function with no slot parameter or local binding, but the new code reads slot.databaseAdmissionCursor. Any dispatch with a database path or admission factory throws ReferenceError before posting the request, breaking ordinary SQLite-backed operations. Exact-head CI confirms this through pairing-store approval and allowlist operations. Pass the dispatch slot from dispatchSqliteWorkerJob and use it for both cursor access and reset.
    Confidence: 1

Overall correctness: patch is incorrect
Overall confidence: 0.99

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 8e9038d23129.

Provenance checked

  • Admission snapshots and changed-entry transport keeps the original intent (79345a8: Reduce full-map retransmission while preserving complete bootstrap, ordered receiver cursors, and shared-cell invalidation.)
  • Admission installation and publication keeps the original intent (325ae88: Publish only changed or retired facts, preserving generation guards and retired-peer reclamation; batching retains that purpose.)
  • Actor maintenance context keeps the original intent (32d14ad: Keep actor-owned maintenance holds across commands so scheduled WAL work cannot disturb recovery captures.)
  • Retained native-worker environment inheritance keeps the original intent (fcd59e6: Descendants inherit the caller's current SQLite runtime facts; the new carrier projection preserves complete child bootstrap while receiving deltas.)

Testing

Proof path: none.

Security

None.

Evidence

Acceptance criteria:

  • pnpm tsgo:core
  • pnpm test src/pairing/pairing-store.worker.test.ts --maxWorkers=1
  • pnpm test src/infra/sqlite-database-admission.worker.test.ts src/infra/sqlite-database-admission.retention.test.ts src/infra/sqlite-worker-operation-admission.test.ts src/infra/worker-native-lifecycle.test.ts --maxWorkers=1
  • git diff --check

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 79345a8 adds src/infra/sqlite-database-admission-record.ts:394 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 79345a8c2f45; files: src/infra/sqlite-database-admission-record.ts)

PR surface

Source +139. Total +139 across 12 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 12 185 46 +139
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 12 185 46 +139

Review metrics

Metric Value Why it matters
Production versus test LOC Production +185/-46; tests +0/-0 Cursor state and the retained carrier projection support the stated transport contract; existing production-path tests already expose the dispatch regression.

Labels

Label changes:

  • add P2: The underlying work improves Gateway serialization performance; the introduced dispatch failure is separately a blocking P1 finding.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🦪 silver shellfish and patch quality is 🧂 unranked krab.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: The underlying work improves Gateway serialization performance; the introduced dispatch failure is separately a blocking P1 finding.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🦪 silver shellfish and patch quality is 🧂 unranked krab.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 15, 2026, 3:36 AM ET / 07:36 UTC.

@steipete

Copy link
Copy Markdown
Contributor Author

CI is red only in ui/src/e2e/session-management.sidebar.e2e.test.ts: both nests spawned sessions pin variants time out with expected 4 to be +0. The same focused file fails identically on the unchanged main parent d388ca43e08a7997f680cc7fa06548849bcf364f (9 passed, 2 failed). This lane changes only SQLite worker admission internals, so the UI failure is pre-existing and outside the changed path. No CI rerun was requested.

@steipete
steipete merged commit b2c4d5f into main Oct 15, 2026
129 of 132 checks passed
@steipete
steipete deleted the steipete/perf-micro-sab-postmessage-segv-20260919 branch October 15, 2026 08:11
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 16, 2026
* perf(sqlite): stop reserializing shared admission maps

* fix(sqlite): bind admission cursor to dispatch slot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant