Repository navigation
perf(reef): attribute background plugin-state polling - #182247
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Carry the existing watched review receipt in parked inbox state. A decision mutation, policy or envelope change, or expiry resumes the normal trust and replay path. Avoid repeated replay claims and releases while an owner review is pending. Release note: reduce background SQL and worker requests for Reef messages waiting on owner review. No schema or public Plugin SDK change.
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. |
|
Codex review: needs maintainer review before merge. What this changesThis PR retains watched pending-review receipts so unchanged Reef inbox polls skip repeated trust reads and replay writes. Example: An isolated Gateway polls 18 Reef messages awaiting owner review.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it removes identifiable recurring Reef database work, preserves the review owner’s decisions, and has no concrete introduced correctness finding; the author’s explicit landing hold remains. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherReef receives encrypted envelopes from the relay, consults trust, replay and review state, and either parks them or proceeds through verification to ingress and acknowledgment. flowchart TD
A[Relay inbox poll] --> B[Reef message flow]
B --> C[Watched pending review receipt]
C --> D[Remain parked]
C --> E[Full trust and replay verification]
E --> F[Review and guard decision]
F --> D
F --> G[Ingress and acknowledgment]
Technical reviewBest possible solution: Retain pending receipts in the existing parked-entry owner while preserving full verification whenever their binding or validity changes. Do we have a high-confidence way to reproduce the issue? Current main enters composeInbound on each pending retry, claiming and releasing replay state before returning the pending outcome; the author also reports reproducing these statement shapes through an isolated Gateway. Is this the best way to solve the issue? The change follows the existing ownership contract by carrying the review owner’s watched fact, removing its forwarding adapter, and avoiding new schemas, generations or parallel decision owners. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 4e62be1ab7fd. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +41, Tests +113, Docs +29, Other +363. Total +546 across 8 files. Added test files: 1. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 24, 2026, 1:49 AM ET / 05:49 UTC. |
|
Merged via squash.
|
* docs(perf): preregister plugin-state polling workload * perf(reef): skip unchanged pending-review retries Carry the existing watched review receipt in parked inbox state. A decision mutation, policy or envelope change, or expiry resumes the normal trust and replay path. Avoid repeated replay claims and releases while an owner review is pending. Release note: reduce background SQL and worker requests for Reef messages waiting on owner review. No schema or public Plugin SDK change. * fix(perf): satisfy polling workload lint rules * test(reef): isolate pending-review regression coverage * test(reef): route receipt regressions through the database broker * test(reef): avoid shadowing the observed review receipt Co-authored-by: Peter Steinberger <[email protected]>
What Problem This Solves
Reef repeatedly claims and releases replay state for inbound messages still waiting for review. Every retry writes the same available → in-flight → available cycle and repeats review/trust reads. A real isolated Gateway with bundled Reef and a loopback relay reproduces the live statement shapes, including empty scoped expiry deletes when an unrelated expired entry exists.
Design
Keep the existing watched review operation receipt in the flow's existing parked-entry state, bound to the exact envelope, effective policy, and envelope expiry. Unchanged pending polls assert the receipt and stay parked before replay/trust work. Review mutations invalidate the receipt, and approval, denial, policy/envelope changes, and expiry resume the full existing verification path. No SQL, schema, or public SDK signature changes.
The first retry after a newly created review can still observe and retain its pending receipt. This keeps the change within the existing owner contract. The old private lookup and forwarding adapter are removed.
Named accepted edge: Plugin-state epochs are process-local, so a review decision written by another process does not wake a parked entry until Gateway restart or the 30-day envelope expiry. This is accepted because decisions come only through the in-Gateway
/reef reviewcommand:reviews.decidebumps the local epoch, invalidating the receipt so the entry is processed again. The edge is the same on SQLite and PostgreSQL.Acceptance rule — registered before measurement
Run the bundled Reef channel in an isolated Gateway on the head under test, using a loopback HTTP/WebSocket relay, synthetic identities, and 18 queued messages with pending reviews. Run an empty inbox control. Separately exercise an expired entry in an unrelated synthetic namespace to identify expiry-sweep coupling. Preserve the real replay, trust, review, and state workers. No operator state or external services are used.
Count SQL statements and worker requests per retry and steady-state minute; report main-thread and total work separately. Keep boot/first delivery separate from warm polls. The first run attributes statement shapes to callers. Any change must preserve replay exclusion, pending-review decisions, TTL visibility, quota behavior, and supported other writers without a public SDK or schema change.
A win removes recurring work without increasing warm SQL, requests, or main-thread work. For wall-clock/CPU comparisons, run at least five alternating samples per arm and report median, p95, and range separately for cold and warm. Every user-facing metric must hold or improve; a 20% adverse cell stops the candidate. Timed comparisons acquire the campaign timing lock and require load below 24. Counts and profiles are independent of wall-clock qualification.
If current main does not reproduce the pattern, record the fixture, measured rates, and gap and stop that item. A direct-store microbenchmark is insufficient.
Evidence
Five alternating baseline/candidate samples used the committed real-channel workload with 18 synthetic pending-review envelopes, a 40-second settle and 60-second steady window. Each arm performs two unchanged inbox polls per warm minute. The baseline production source is
3a342c570186, built atd5c6ffab025(its only diff from baseline is the preregistered workload document); the measured candidate runtime is9ef9f874fd83. Final headffd22dfb97ccchanges only a test callback name; production and workload bytes are identical. The frozen comparison separately rebuilds the final head.Run against each head's built entry and a fresh synthetic output directory;
OBSERVERpoints to frozen v3.1.4. The first sample adds--profile; the empty control uses--messages 0without--expired-peer.The owner removes 648 SQL statements and 144 requests per minute, or 18 statements / 4 requests per pending message retry. Two passive checkpoints also disappear, making the measured total reduction 650 statements (95.2%) and 144 requests (91.7%). No work moves onto the main thread. Empty-inbox controls match at 33 statements / 13 requests / 0 main-thread SQL, and all samples preserve two polls with zero acknowledgments or unexpected requests.
Captured 24 V8 thread profiles per first arm. These cover the complete process lifetime, including startup; the baseline exposes compare/apply, expiry-delete and replay-write work. Timing qualification waited more than 60 minutes, first for host load and an occupied lock, then for load below 24. The coordinator explicitly accepted the counts-plus-per-thread-profiles fallback on October 24; this PR makes no latency or CPU-speedup claim. Frozen v3.1.4 hashes pass (36 files). The first frozen baseline attempt stopped during synthetic account setup because its copied local stamps retained the documentation commit identity; it never started a Gateway and is not behavioral evidence. The replacement uses freshly built exact-baseline and final-head runtimes and verifies matching build-info/stamp identities plus native preparation before either frozen arm. The host-app restart interrupted its first baseline during idle; that incomplete sample is retained separately and excluded. Both resumed frozen arms completed all 14 turns, subagent, cron, compaction, shutdown and restart checks. The candidate needed a normal runtime-postbuild refresh for one missing Reef overlay after switching from baseline; exact commit identities were unchanged, and native preparation then reported build=false/runtime=false. All fixture children exited and all fixture ports closed. Knip reports 48 production / 43 full-tree / 6 script occurrences, with zero new entries. Production/full-tree results match reused same-base archive scans (whose dependency links can resolve candidate sources); all 35 reported files are byte-identical to baseline. The script scan was independently reproduced on the exact baseline in this worktree.
Frozen v3.1.4 control pair — accepted background placement
One completed alternating base/final-head pair, with a 60-second connected-idle window. This frozen control disables channels; the five-pair Reef reproduction above remains the owner-flow evidence. The raw comparison has three STOP cells: boot SQL 305→552 (+81.0%), boot requests 100→132 (+32.0%), and turn-03 requests 12→15 (+25.0%). The October 24 acceptance disposition explicitly accepts these cells as existing background-placement scatter, conditional on proving no Reef SQL executes in the frozen candidate. That condition is now verified below; it is separate from the accepted timing fallback.
Totals are 2,901→2,916 SQL (+15), 778→781 requests (+3), and 95→96 MAIN (+1). The following table reports the single observation in each arm, not a multi-sample estimate; each cell therefore also has identical median/p95/min/max. All cells, including smaller adverse moves, are retained.
Retained-ledger attribution shows substantial phase movement, but does not establish a complete offset: boot gains 247 SQL while connect loses 152 and first-turn loses 82 (combined +13). Boot
agentDatabaseDeletion.snapshotgains 14 SQL/3 requests and first-turn loses exactly 14/3; other startup operations move similarly, while some work is genuinely additional in this sample. The turn-03/turn-04 boundary moves six lease reads, one lease delete, and one two-event audit insertion into turn-03. Whole-run operation differences include one additional proactive-jobs request and one additional lifecycle-artifact-plan request. Restart MAIN adds onesession_key_contract.canonical_readyread. The retained candidate ledger identifies its owner asloadOpenClawAgentCanonicalValidationReceipt(src/state/openclaw-agent-canonical-validation-receipt.ts), called bycertifySessionCanonicalValidationPendingfromrunSessionStartupMigration. This is session canonical-validation startup maintenance, outside Reef. The same receipt reader executes on base at ledger indices 628 (first-turn), 2289 (compaction), and 2431 (idle-settle), all worker-thread reads; candidate index 2400 is the restart MAIN read. The receipt owner, readiness module, and startup migration module are byte-identical between base and the approved head. This does not claim a baseline restart MAIN read.The retained frozen candidate has zero Reef SQL stacks: all 2,916 executed statement entries have captured
fullStack/originStack, with zeroextensions/reefmatches. An independent pass over the raw observer records resolves executed site references and excludes prepare-only records: zero matches across 2,720 executed SQL sites (2,761 calls, expanded by the ledger to 2,916 statements). Base likewise has zero matches across 2,901 ledger statements. This satisfies the acceptance disposition without another run; no CPU or latency claim is made. Exact-head PostgreSQL review is approved forffd22dfb97cc.openclaw/ci-gatepasses, including types, lint, source/export contracts, Madge architecture and ratchets. T1 remains 170→170, compatibility 15→15, and dialect categories 0→0. Local declaration preparation rejects the mandated out-of-checkout pnpm virtual store; no containment bypass was used.native_signed_connect_preserves_product_fields_and_rejects_invalid_node_manifeststest. The affected file is byte-identical to the baseline; this is not claimed as an executed main-branch failure.Production delta is +41 lines: the existing parked Set becomes a receipt-bearing Map with exact-envelope/policy/TTL binding. No new generation, timer, schema, or generic state cache. A generic expiry-sweep redesign is unnecessary for this producer: eliminating the repeated calls removes its probes, deletes and writes together. The frozen-control disposition and exact-head PostgreSQL approval are satisfied for
ffd22dfb97cc; no source changes were made after that approval.Open-PR conflict comparison (55 overlapping main PRs)
Compared base
3a342c570186and candidateffd22dfb97ccagainst each pinned head from 2,657 open main PRs. All 55 overlapping heads are unchanged from the completed exact-head comparisons, which add zero conflicting paths and zero conflict hunks.b5cf2ab14490cb69b03e9c464a92429c25c6d9b6e3ff20555aed8180f8ba86fa13012988ecf01c151961871d6381c5f1022433d1daa30117a21b6dc36e1aba7c8c295ca7f4ecaca043276169ca3f6a4070accd3b804b31748af9b4e164f08f6efc5d1d5c83705ea5656d2577a359e092e3adc4edc655fa8ae3f591d1333d1aa70ab0c258bf0232649376d0f38d4f06f5622762b3ba98116130492c08cf24913fc0e9e7efb8c9926506dfd0889535a113687985e3a7c456b504a25424e93c038227eb8ed0000d45ee899f426af4675cff003de721d349d2b6248cf1774a210f97a98b4c35ddf42e31bd57511587cf101d10bb769a218b27a7b13237ebae122ad86db5fc15ce824c0db3edf2583347a03482c1deee87f58c6a9b4c5ebed9858af665196c9a6b23c3677719ea1928dfc4980b5e57cd0bcdb90ae22c8de5acf8a727f6161413b611cb2f0396