Skip to content

perf: reuse empty plugin state and completed Crabbox readiness - #183223

Merged
steipete merged 3 commits into
mainfrom
dbasync/livestate
Oct 25, 2026
Merged

steipete merged 3 commits into
mainfrom
dbasync/livestate

Conversation

@steipete

@steipete steipete commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Background Reef reconciliation repeatedly probes an empty delivery namespace, and Crabbox maintenance repeatedly counts a retired allocation namespace. Reuse the facts already established by those owners: carry a worker-confirmed empty SQLite namespace through the existing bounded receipt-invalidated cache, retain Reef's lazy read operation, and remember successful legacy readiness in the existing Crabbox manager.

User Impact

Idle background reconciliation does less database work while retaining delivery, expiry, recovery and external-writer behavior. No public SDK signature or stored-data format changes.

Why This Change Was Made

PostgreSQL keeps physical empty probes for external committed-write visibility. Generic compound read snapshots remain because handlers can perform dependent reads. No schema, SQL text, public SDK signature, generation, or cross-store transaction changes.

Acceptance rule (recorded before measurement)

Run scripts/perf/plugin-state-polling.mts against a real isolated Gateway and loopback Reef relay, using both an empty inbox (--messages 0) and pending-review workload (--messages 18), each with a 60-second steady window after startup. Use scripts/bench-ingress-polling.mts --idle-seconds 60 --sparse-events 0 as the iMessage control. Count with the frozen campaign observer and keep boot and steady windows separate. Attribute namespace reads, exact-key reads, count probes, and single-statement transaction envelopes to their owners before editing.

A candidate must remove recurring statements and requests in the touched flow, keep runtime main-thread SQL at zero, and preserve TTL expiry, committed writes, recovery, and final effect authority. Reuse the existing write/receipt owner; retain direct reads without a complete invalidation contract. No schema or public SDK signature change is intended.

Run three alternating baseline/candidate count pairs when load is below 64 and internal free space is at least 12 GiB; otherwise use one pair and disclose the limit. Also run a frozen warm-turn control. Timing claims require the campaign timing lock, load below 24, and at least five alternating samples per arm on the same platform. Report median, p95 and range with cold and warm separated. Any adverse 20% cell stops acceptance. Without a qualified host, report counts and per-thread CPU profiles, not latency or CPU speedups.

If current main does not reproduce a target, record the observed per-minute rate and stop that item. Direct store loops do not substitute for the Gateway flow.

Design and protected behavior

The private worker reply identifies an actual empty probe. Only a prepared operation with an explicitly selected SQLite state owner may consume the cached empty namespace; first-use module validation still executes. The existing cache owns bounds, namespace-write invalidation, unknown-settlement invalidation, and TTL filtering. Every returned shortcut value is detached. The shortcut target joins the existing earlier-mutation settlement scope even when omitted from watchStores. Admission, quarantine, read-allowed, lifecycle and session-current checks remain.

Crabbox's manager shares one successful readiness fact across maintenance and allocation. Failure remains retryable and a new manager rechecks. The legacy online writer was removed in #133447; documented migration/recovery requires stopped owners and prohibits mixed old/new writers. Concurrent initial callers may perform duplicate checks; no in-flight join is added.

The simplification pass retained these existing owners rather than adding machinery. Production is +69/-22 (net +47 lines); the growth carries the confirmed fact and preserves handler preparation/ordering. Tests are +134/-31. The new committed Crabbox workload supplies real Gateway attribution without provisioning machines.

Attribution and baseline

Synthetic isolated Gateways and loopback transports only. Baseline production source 9fe8d3e95e0d; acceptance preregistered at c0bdbd4dc242 before measurement. Frozen v3.1.4 observer verified 36/36 hashes.

Workload Steady window SQL base → head Requests base → head Runtime MAIN
Reef empty inbox 60 s 21 → 17 13 → 9 0 → 0
Reef 18 pending review messages 60 s 21 → 17 13 → 9 0 → 0
Crabbox, one profile, zero workers 120 s 15 → 11 10 → 6 0 → 0
iMessage idle control 60 s 35 → 26 15 → 11 0 → 0

Each baseline and candidate Reef arm performed two steady polls, with zero acknowledgments or unexpected relay requests. The target empty-delivery namespace SELECTs fall from four to zero per minute in both workloads; exact-key reads and transaction envelopes remain unchanged. Crabbox legacy count probes fall from four to zero per 120 seconds (two/minute). Per minute: four empty-delivery namespace SELECTs (target), four peer exact-key SELECTs and four BEGIN/COMMIT pairs (retained), four pairing-allowlist SELECTs (separate owner), and one placement SELECT. Crabbox reproduced four legacy count probes in 120 seconds = two/minute, matching the normalized live count family. One expected version check, no provisioning/provider operations, clean shutdown. iMessage issues two ordinary namespace reads rather than compound operations; it is a control.

Causality is recorded as background in this build, so the warm results below are phase counts rather than per-turn causal claims. Host load is above the qualified timing threshold; counts and per-thread profile attribution only, no latency or CPU-speed claim.

One baseline/candidate count pair on the same Mac under the preregistered loaded-host fallback (load roughly 70–100); each targeted median/p95/min/max equals the reported single observation. These are count savings, not latency or CPU-speed claims. Empty Reef removes 19% of steady statements and 31% of requests; Crabbox removes 27% of steady statements and 40% of requests. iMessage is a non-regression control; its lower totals are not attributed to this change.

Cold SQL/requests/MAIN: Reef empty 617/158/57 → 607/152/57; Reef pending 1133/264/57 → 1131/260/58; Crabbox 839/148/73 → 834/145/74; iMessage 813/137/74 → 816/135/74. The extra cold MAIN in pending Reef and Crabbox is the existing dynamic busy-timeout PRAGMA during admission, not a runtime query. All targeted shutdowns remain 22 SQL / 6 requests / 5 MAIN.

Adverse control cell: iMessage idle PASSIVE WAL checkpoints 2 → 3 (+50%); boot PASSIVE 2 → 2 and shutdown TRUNCATE 3 → 3. The checkpoint, admission and adapter bundle hashes match across arms. The coordinator explicitly accepted this unchanged periodic owner firing once more in the window; the raw adverse cell is retained here. Runtime MAIN remains zero throughout.

Final-head frozen warm control passed all 14 turns, cron, compaction, RPCs, restart and clean shutdown. The single baseline/candidate pair produced these counts; warm percentiles describe the ten distinct warm-turn phases, not repeated timing samples.

Warm control metric Baseline Candidate
Whole-run SQL / requests / total MAIN 2,881 / 782 / 94 2,888 / 784 / 95
Warm-turn SQL median; p95; range 47; 50; 46–50 46.5; 65; 46–65
Warm-turn requests median; p95; range 12; 14; 12–14 12; 19; 12–19
Runtime MAIN 0 0
Boot SQL / requests / MAIN 535 / 124 / 48 561 / 135 / 49
Warm turn 1 SQL / requests 50 / 14 65 / 19
Warm turn 2 SQL / requests 48 / 14 60 / 14
Idle settling SQL / requests 80 / 10 104 / 14
Restart connect SQL / requests 26 / 12 30 / 14

The adverse cells triggered a hold and were explicitly accepted by the coordinator after attribution. Across the whole run, state-lease SQL is 26→26: two seven-statement batches move from connect/first-turn into warm turns 1/2. Memory SQL is 146→146, with work moving from compaction into idle settling. Plugin-state table statements are 8→8; pluginState.entries stays 6 SQL / 6 requests, metadata reads 3/3, and deferred migrations 5/4. The extra two BEGIN/COMMIT pairs belong to one additional agentDatabaseDeletion.snapshot poll and one additional automationProactive.jobs poll, not plugin-state operations. Whole-run operation deltas: deletion snapshot +5 SQL, proactive jobs +3, index read −2, transcript instances −3, other worker operations +3, and the existing dynamic busy-timeout initializer +1 cold MAIN. Requests are +2 overall. Emitting-stack source audits cover 497 files at boot, 255/281 in warm turns 1/2, 109 during idle settling and 101 at restart-connect; every tracked source blob is identical between baseline and head, with no missing referenced chunks. No general warm-workload saving or latency improvement is claimed.

The first final-warm attempt failed before Gateway launch: account-fixture setup rejected runtime artifacts stamped with the earlier test/comment head because service state could not be inspected. The supported final-head build then passed, followed by the valid control above. No product result was inferred from failed setup and no guard was bypassed.

Evidence

The augmented empty-receipt work-count regression fails on base (two requests, expected one). The three Crabbox readiness/retry cases also fail on base. Candidate: all 81 focused core/SDK/Reef/Crabbox tests pass, including TTL/expiry receipts, namespace-write invalidation, pending target-write ordering, first-handler validation, failed readiness/recovery, and manager replacement. Format, basic lint and diff checks pass. Two isolated Codex reviews are scoped-clean P0–P2. One additional delta-only Codex review is clean for the CI correction: remove generic test-command input narrowing and place SAFETY comments directly beside unchanged assertions. The original CI diagnosed those two static failures; no runtime behavior changed. Final-head PG semantic approval is recorded for 1fad2c8ea4c2322db4fd083a09f2e805df17aa64; runtime tokens are unchanged by its CI correction. Exact-head CI run 40163897883 passes, including all three PostgreSQL conformance shards, types, type-aware lint, source contracts/export collisions, architecture/Madge, prompt snapshots, and database/T1/dialect ratchets. The latest required openclaw/ci-gate is successful. The local tsrs attempt stopped before compilation because the campaign-mandated internal virtual-store path is outside its checkout admission; the exact-head CI typechecks provide that proof. Canonical Knip 6.40.0 baseline/candidate comparisons are identical across all three configurations: production 13→13 findings, all exports 21→21, scripts 13→13, with zero additions/removals and empty diagnostic stderr. Raw scan exit 1 represents these same pre-existing findings on both arms, not a new gate failure.

The refreshed overlap index has #177691 at 22ea62d40ffb, #159178 at 57cd0bcdb90a9, and #135838 at 07e99af58674. Base-versus-candidate merge-tree comparisons add zero conflict paths or hunks; existing conflict-path counts remain 1→1, 30→30, and 126→126 respectively.

Additional count attribution workload (preregistered before execution)

Run scripts/perf/crabbox-state-polling.mts with a fresh synthetic state directory, bundled Crabbox provider, one profile, zero reserve workers, and a local version-only executable. Reject any provider command other than --version. After readiness and 70 seconds of settling, observe a 120-second steady window with the same frozen observer. This exercises the two existing minute-based reconciliation callers without provisioning a machine.

Require a reproduced steady legacy-lease count before accepting that attribution. A successful owner-admission optimization must reduce that steady count to zero, preserve failed migration refusal and retry after explicit recovery, and keep total statements/requests and runtime MAIN from increasing. Use the same count-pair and qualified-timing rules above. The current hypothesis is a completed legacy-namespace cutover: #133447 removed its online allocation writer; supported recovery only deletes rows, and offline migration requires exclusive custody.

@clawsweeper

clawsweeper Bot commented Oct 25, 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.

@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts size: XS labels Oct 25, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 25, 2026
@clawsweeper

clawsweeper Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR preregisters measurements and acceptance criteria for reducing background plugin-state reads.

Example: Measure Reef with 18 messages awaiting review.

  • Before: The remaining background reads have no dedicated acceptance document.
  • After: The document requires a 60-second steady measurement and preserves TTL, recovery, committed writes, and final-effect authority.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Sound documentation-only preregistration; the proposed runtime investigation remains unfinished.
Proof confidence 🌊 off-meta tidepool Not applicable: This patch adds only an acceptance document and explicitly makes no after-fix performance claim.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Docs · Worth it: Yes
User problem: Background reconciliation may perform avoidable database reads, but the remaining cost has not yet been measured.
Reason: The maintainer-authored preregistration sets a bounded, measurable investigation without claiming an unproven improvement.

Merge readiness

✅ Ready for maintainer review

Keep open as a maintainer-owned draft investigation; the introduced acceptance document is coherent and has no actionable defects.

Priority: P3
Reviewed head: c0bdbd4dc2423642cf36f7d0831e376b34bb7ba8

Before merge

None.

Findings

None.

Agent review details

How this fits together

Reef reconciliation reads durable plugin state through existing operation owners; the referenced workload runs an isolated Gateway against a synthetic loopback relay and records SQL statements and worker requests.

flowchart LR
  A[Synthetic messages] --> B[Loopback Reef relay]
  B --> C[Isolated Gateway]
  C --> D[Reef operation owners]
  D --> E[Plugin state workers]
  E --> F[SQL and request observations]
Loading

Technical review

Best possible solution:

Retain the acceptance document and let the investigation establish any remaining optimization at the existing state owner.

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

The document specifies a credible production-path reproduction, but this draft reports no measurement and establishes no remaining runtime defect.

Is this the best way to solve the issue?

Preregistering owner attribution and measurable acceptance before optimization is appropriate, and the diff adds no unnecessary production machinery or test scaffolding.

AGENTS.md: found and applied where relevant.

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

Security

None.

Evidence

What I checked:

  • Pinned introduced scope: The introduced diff adds only the acceptance document; the verified test merge likewise adds only that document. (scripts/perf/plugin-state-live-reads.md:1, c0bdbd4dc242)
  • Existing production-path workload: The referenced workload accepts message counts and measurement duration, launches a real Gateway, waits for relay polling, and separates startup from the steady phase. (scripts/perf/plugin-state-polling.mts:329, c0bdbd4dc242)
  • Earlier optimization is distinct: perf(reef): attribute background plugin-state polling #182247 already optimized unchanged pending-review retries using existing watched receipts; this draft investigates remaining namespace, exact-key, and count reads rather than claiming that earlier saving. (scripts/perf/plugin-state-polling.md:1, dc3ce57887ff)
  • CI failure attribution: The failing PR-context check requests named problem and evidence sections in the PR body; its annotations identify no defect caused by the Markdown diff. (c0bdbd4dc242)
  • Policy and inspection limits: Read the complete root and scripts guidance; no deeper scripts AGENTS.md or maintainer-notes directory exists. Diff whitespace checks passed and the checkout remained clean. Historical blame could not read an older workload blob, but commit metadata established prior area contributions. (scripts/AGENTS.md:1, c0bdbd4dc242)

PR surface

Docs +29. Total +29 across 1 file. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 0 0 0 0
Docs 1 29 0 +29
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 29 0 +29

Labels

Label changes:

  • add P3: The current patch documents an investigation and changes no runtime behavior.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P3: The current patch documents an investigation and changes no runtime behavior.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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 25, 2026, 12:22 AM ET / 04:22 UTC.

@steipete steipete changed the title perf(reef): reduce background plugin state reads perf: reuse empty plugin state and completed Crabbox readiness Oct 25, 2026
@steipete
steipete marked this pull request as ready for review October 25, 2026 04:46
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 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-25T04:48:56.530410Z 6371344 Draft marked ready
ℹ️ 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation plugin: file-transfer extensions: crabbox channel: reef Channel integration: reef size: L and removed size: XS labels Oct 25, 2026
@steipete
steipete merged commit fffa5e9 into main Oct 25, 2026
147 of 155 checks passed
@steipete
steipete deleted the dbasync/livestate branch October 25, 2026 06:17
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 26, 2026
…law#183223)

Reuse worker-confirmed empty SQLite plugin-state observations through the existing bounded receipt-invalidated cache, retain Reef read operations, and retain successful Crabbox legacy readiness at its manager. Keep TTL expiry, mutation settlement, first-handler validation, failure retries, generic snapshots and PostgreSQL external-write visibility. No schema or public SDK signature changes.

Synthetic Gateway counts: Reef steady 21 to 17 SQL and 13 to 9 requests per minute; Crabbox 15 to 11 SQL and 10 to 6 requests per two minutes. Runtime main-thread SQL remains zero. Focused owner and SDK tests, isolated review rounds and exact-head CI including all three PostgreSQL shards pass.

The retired Crabbox legacy writer was removed in openclaw#133447.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: reef Channel integration: reef docs Improvements or additions to documentation extensions: crabbox P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. plugin: file-transfer rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant