Skip to content

perf: reuse plugin state lists and defer unused ACP reads - #169988

Merged
steipete merged 6 commits into
mainfrom
dbasync/reqbatch2
Oct 12, 2026
Merged

steipete merged 6 commits into
mainfrom
dbasync/reqbatch2

Conversation

@steipete

@steipete steipete commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Warmed chat turns repeatedly ask the database worker for unchanged plugin-state namespace lists. Reuse the existing Gateway-owned observation cache for bounded lists (64 namespaces / 8 MiB), invalidate them from committed write receipts, filter expiry, and return detached values. Cold reads retain the existing worker path. This removes three requests and three statements per ordinary warmed turn in both live comparisons.

Move ACP metadata lookup from generic subagent preparation to the actual completed-candidate reactivation owner. Keep the ACP exclusion and live authority check at that effect. ACP metadata remains 2 requests / 1 statement per warmed turn in this workload; no warmed saving is claimed for that change.

Removed checks and accepted edges:

  • Repeated namespace SELECTs: owner-held snapshots and in-process write receipts are authoritative. Live out-of-process writes are outside the Gateway ownership contract; offline replacement is observed at the next physical admission.
  • ACP precheck before candidate selection: a turn without a completed candidate has no reactivation effect to authorize. Actual candidates still check lifecycle-bound ACP metadata before mutation.

No schema, migration, update, Doctor, plugin-loading, service-lifecycle or SDK changes. Changed owners have T1 0 → 0, with no synchronous fallback. Diff: 271 additions / 26 deletions / 12 files.

Evidence

Live measurements

Two complete alternating baseline/candidate pairs, each with 13 turns plus child, control, cron, compaction and shutdown. The frozen shared v1 harness reports ten wall-clock warmed windows per run, including overlapping maintenance; these are not v2 causal counts. All runs exited zero, conserved successful native SQL exactly, and had no missing SQL contexts or duplicate sends. The failed intervening baseline is excluded.

Baseline: abfcd2c06ce5. Candidates: 15f4ac02b6c0 and a034f3754033 (identical production change; later commits only repair tests). Integration head b8a5468fe9e0 incorporates main's existing export fix; final head c9be46eecfa6 adds only fixture runtime-config preparation. Neither is mislabeled as a measured head.

Values below are mean; median [min–max]. MAIN is the total across ten warmed windows.

Metric Pair 1 base Pair 1 candidate Pair 2 base Pair 2 candidate
All-thread statements 382.2; 369.5 [366–407] 402.8; 408 [367–445] 398.5; 391.5 [365–459] 400.5; 407 [363–433]
Worker requests 85.4; 82 [80–93] 91.6; 91.5 [79–104] 91.6; 89.5 [81–118] 90.9; 92 [78–99]
Requests outside usage 67.4; 64 [62–75] 73.6; 73.5 [61–86] 73.6; 71.5 [63–100] 73.1; 74 [60–81]
Warm MAIN total 0 1 1 1
Plugin entries requests / SQL per window 3 / 3 0 / 0 3.1 / 3.1 0 / 0
ACP metadata requests / SQL per window 2 / 1 2 / 1 2 / 1 2 / 1
Whole-workload statements / requests / MAIN 10,401 / 1,732 / 1,972 10,895 / 1,842 / 2,112 10,871 / 1,843 / 2,110 10,674 / 1,783 / 2,002

Plugin entries fall 53 requests / 53 SQL → 4 / 4 over the whole workload in both pairs. Pair 2 baseline includes one additional background plugin read. This proves the owner saving, not an aggregate warmed-turn or latency improvement: raw medians still rise. The broader 15-request aim is not claimed.

Shared-family attribution

Shared SQL per warmed window Pair 1 base → candidate Pair 2 base → candidate
Exact-entry facts 5.8 → 6.9 6.7 → 6.8
Actor hydration 4.4 → 4.9 4.6 → 4.5
Entry-cache snapshots 0.4 → 1.0 0.8 → 1.0
Row facts: primary / payload / with envelopes 1 / 3 / 5 → 1 / 3 / 5 1.2 / 3.6 / 6 → 1.1 / 3.3 / 5.5
Watermarks 2 → 2 2.2 → 2.1

The successful unchanged-baseline replay closely reproduces the first candidate's whole-workload totals and shared reads. Pair 2 whole-workload exact facts fall 117→110, actor hydration 72→70, watermarks 36→34, and primary row facts 22→20; snapshots change 23→24. The initial rise does not reproduce as a consistent whole-workload increase.

Pair 2 snapshots contain 6→8 memory corpus inventories plus 2→2 cron list operations. The entire +1.5 domain-publication requests/window belongs to memory index/cache/source operations, matching those extra debounce-driven syncs. Extra writable entry reads originate in the same corpus path; duplicate row-facts reads originate in unchanged projection refresh. The trace cannot assign every individual hydration to a causal turn, so residual variation remains disclosed.

Every warm MAIN observation is the same unchanged cron deletion-journal read: readAgentDeletionPathFenceRows → readAgentDeletionJournal → isAgentDeletionBlocked → cron scheduler maintenance. It appears in both sides of pair 2. Starting host loads were 77/114 and 75/119 on 32 CPUs; no unloaded-host or speedup claim is made.

Verification and landing

Two Codex autoreview rounds completed without actionable findings. Changed-file oxfmt, oxlint and diff checks pass. Regression coverage includes namespace read-your-writes through native and worker writes, deletion/clear, empty lists, expiry, detached caller values, uncertain publication, and ACP metadata written before later reactivation. Focused ACP reactivation proof passed all six tests (393.32s suite / 497.16s command on the loaded host).

Prior exact-head CI run 38276378240 passed types, lint, source contracts, Madge, database worker/T1 and dialect ratchets, builds and the changed tests. Its sole failure was the untouched agent-deletion integration case: CI saw a 30s sessions.create client timeout. A focused local comparison timed out at the 120s test budget on both baseline and candidate; this demonstrates an inherited local timeout, not identical reproduction of the CI signature. No assertions, retries or budgets were weakened; the issue is recorded in the campaign's main-repair inbox.

Integrated-head CI exposed a test fixture that wrote config without preparing its runtime snapshot under newer main. The two-line fixture correction is pushed in c9be46eecfa6, with no production or assertion changes; final CI 38291358999 passes the corrected ACP shard. Its remaining behavioral failure is the untouched server.codex-failure-recovery.test.ts cancellation case: the runner stops after 300s without output (exit 143, zombie child). Scheduled main 38285052539 also fails chat.send cancels during physical exit without reacquisition, with 180s test plus 180s cleanup timeouts. The test and CLI-watchdog files are byte-identical between that main head and this PR. This is the same failing case, not an identical runner-exit signature; no assertion, retry or budget was changed. All typecheck, lint, source-contract, Madge and database-ratchet jobs have passed; the inherited cancellation failure is recorded for the main-repair owner. Knip production and script export scans passed locally; both full-tree attempts reached the unchanged 600s limit under host load. Exact-head CI 38295362419 then passed the production and full-tree export commands with pinned Knip 6.32.2 (97.6s and 115.8s). Its --exports --exclude duplicates selects the same six canonical export categories. The later unused-file scan reports only src/state/openclaw-state-schema-v10-retirement.test-support.ts. Scheduled main 38278478317 reports the identical rule/file; the file blob is identical (623ae457f179), and main already removed it in bcd41d1aae8d6. This is an inherited static diagnostic, with no exception added. The supplementary full-suite run was canceled after capturing the missing Knip proof; the completed ordinary PR run remains the broad behavioral evidence. Native provisioning rejects external lane worktrees, so landing uses the authorized head-pinned REST squash with the disclosed inherited failures.

The supplementary run also reported config-readiness (applied-restart-required), startup WAL inspection (expected 2 integrity calls, got 3), and cron occurrence-fence cleanup (cleanupPending) failures. Saved scheduled-main run 38285052539 contains the same three test/error signatures. Its UI catalog test captured the known JSDOM native-animation-frame/FakeTimers warning; that source-identical fixture issue is already owned by the main-repair lane, without a claimed exact-main failure reproduction. These are recorded in the main-repair inbox.

The supplementary catalog performance test failed in fixture setup with Codex session catalog is still loading. A focused comparison on baseline abfcd2c06ce5 and candidate c9be46eecfa6, both Node 24.21.0 with --maxWorkers=1, instead timed out at the same unchanged 120s test budget (429.51s / 676.90s Vitest durations; candidate rebuilt the compiler cache). This demonstrates the local timeout on both heads, not identical reproduction of the CI readiness error. The test, fixture and catalog source are unchanged by this PR; no product regression was demonstrated. The distinct CI readiness signature and local timeout are retained as a main-repair follow-up, without weakening assertions or budgets.

@clawsweeper

clawsweeper Bot commented Oct 12, 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 docs Improvements or additions to documentation gateway Gateway runtime size: M labels Oct 12, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 12, 2026
@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR caches plugin-state namespace lists and defers ACP metadata reads until completed-subagent reactivation.

Example: Read receipt-test/receipts twice with first={count:1}, then register second={count:2}.

  • Before: Every list read requests the database worker.
  • After: Repeated reads reuse detached cached values; registration invalidates the list so the next read includes both entries.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A coherent optimization with useful owner-boundary regressions and reported live measurements, but limited independently inspectable runtime evidence.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; its body reports Gateway workload measurements for namespace reuse, while raw traces are unlinked and deferred ACP exclusion has focused harness coverage.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Ordinary chat turns perform avoidable database-worker round trips.
Reason: The established area owner directs a bounded extension of existing machinery and records the managed-writer tradeoff.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-directed optimization remains absent from current main, and no actionable introduced defect was found.

Priority: P2
Reviewed head: c9be46eecfa673a432438b90fd1b86dff7101f4f

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Focused regression execution is reported passing, but failing-base execution is not supplied.
Agent review details

How this fits together

Gateway turns consume plugin-state lists and subagent records; workers supply cold reads, committed receipts invalidate cached lists, and reactivation checks ACP metadata before guarded registry replacement.

flowchart TD
A[Gateway turn] --> B[Plugin state owner]
B --> C[Namespace cache]
B --> D[SQLite worker]
D --> E[Committed receipts]
E --> C
A --> F[Completed subagent selection]
F --> G[ACP metadata check]
G --> H[Guarded registry replacement]
Loading

Technical review

Best possible solution:

Extend the existing receipt-backed cache and retain candidate-specific ACP exclusion in the established reactivation owner.

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

Current-main source shows repeated namespace worker reads and ACP preparation before completed-candidate selection; this read-only review executed no target code.

Is this the best way to solve the issue?

The patch reuses existing cache, publication, worker, and reactivation owners while preserving expiry, caller-owned values, admission checks, public interfaces, and stored formats.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Plugin-state cache and worker fast path keeps the original intent (01e1892: Reuse committed observations through publication receipts while preserving TTL, caller isolation, and writer authority.)
  • ACP exclusion timing changes intended behavior with a stated reason (12c5644: Consume canonical lifecycle-bound ACP metadata with Doctor owning legacy repair; this PR explains why exclusion can wait until a completed candidate exists.)
  • Completed-subagent replacement keeps the original intent (fd1467d: Preserve run, session, and Gateway ownership across awaited persistence and follow-up adoption.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +106, Tests +130, Docs +9. Total +245 across 12 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 6 125 19 +106
Tests 5 137 7 +130
Docs 1 9 0 +9
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 12 271 26 +245

Review metrics

Metric Value Why it matters
Reported plugin-list workload saving 53 requests / 53 statements → 4 / 4 in both comparisons Supports the affected operation’s saving without establishing overall latency improvement.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Removes repeated database work during ordinary turns without an established urgent user-facing failure.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • 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.

History

Review history (7 earlier review cycles)
  • reviewed 2026-10-12T15:56:24.983Z sha 8270523 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-12T16:13:50.322Z sha 5ddc606 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-12T16:45:52.508Z sha a034f37 :: needs changes before merge. :: none
  • reviewed 2026-10-12T17:25:20.712Z sha a034f37 :: needs changes before merge. :: none
  • reviewed 2026-10-12T18:28:23.075Z sha b8a5468 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-12T18:37:56.048Z sha c9be46e :: needs maintainer review before merge. :: none
  • reviewed 2026-10-12T19:05:25.442Z sha c9be46e :: needs maintainer review before merge. :: none

Reviewed October 12, 2026, 3:34 PM ET / 19:34 UTC (Revision 8).

The ACP read now belongs to execution after candidate selection. Preserve the cancellation proof while expecting the accepted run terminal error envelope.
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Oct 12, 2026
The regression now performs a real shared-state mutation, which requires the existing forked database-worker test group rather than the thread-only gateway core shard.
@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 12, 2026
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 12, 2026
@steipete
steipete merged commit 46c46b1 into main Oct 12, 2026
240 of 327 checks passed
@steipete
steipete deleted the dbasync/reqbatch2 branch October 12, 2026 19:43
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 13, 2026
…69988)

Reuse bounded Gateway-owned plugin-state namespace lists with write-receipt invalidation, expiry filtering, and detached return values. This removes three worker requests and statements per ordinary warmed turn in two live comparisons. Move ACP metadata lookup to completed-subagent reactivation while retaining its effect-time authority check.

Add read-your-writes, deletion, expiry, mutation-isolation, uncertain-publication, and ACP reactivation regressions. No schema, SDK, update, or synchronous database path changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M 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