Repository navigation
perf(gateway): reduce redundant approval and placement queries - #168995
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. |
|
Codex review: needs real behavior proof before merge. What this changesThis PR reduces repeated approval, placement, and group-catalog queries using returned write rows and existing worker readers. Example: Resolve approval approval-1 with allow-once, then retry with deny.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 4 items remain Keep this useful performance PR open; the previously reported selected-database regression remains unresolved. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherGateway approval and placement owners process operator decisions and session moves through SQLite workers; their records feed lifecycle recovery and authorization immediately before node transport. flowchart LR
A[Operator requests] --> B[Gateway owners]
B --> C[SQLite workers]
C --> D[Shared database]
C --> E[Committed publications]
E --> B
D --> F[Final authority read]
B --> F
F --> G[Node transport]
Technical reviewBest possible solution: Keep the query reductions while preserving the selected physical database and immediate final transport authorization. Do we have a high-confidence way to reproduce the issue? Source establishes that asynchronous preparation honors databaseOptions.database.path while synchronous consumption can read the default store and invalidate a valid grant; no runtime reproduction was executed. Is this the best way to solve the issue? RETURNING and transaction-local fact reuse fit the existing owners, but the synchronous grant reader must retain the same database selection as asynchronous preparation. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 7fb80f69f66a. Merge-risk optionsMaintainer options:
Provenance checked
TestingProof path: in-process harness. SecurityNeeds attention: No privilege bypass was established, but the changed final grant-read boundary requires authority validation. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -140, Tests -46, Docs +7, Other -33. Total -212 across 32 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes: No label 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 HistoryReview history (3 earlier review cycles)
Reviewed October 11, 2026, 5:56 AM ET / 09:56 UTC (Revision 4). |
…law#168995) Use mutation RETURNING rows for approval transitions and placement completion, route move lookups through the existing worker, and fetch group ordering/defaults together. Remove redundant internal rereads while retaining current authority checks at real effects. The final Gateway lane inventory falls from 44 to 41 T1 expressions; released synchronous SDK and incognito-owner constraints remain documented. Direct approval probes save one statement per insert, resolve, consume, deny, and expiry operation, with one worker request and no main-thread SQL. Three alternating workload pairs record 456.0 to 451.0 median warmed statements and 90.8 to 90.4 requests; the warm difference is unchanged session-owner timing, not claimed as this change's saving. Accept recoverable preparation after out-of-band same-session cancellation; exact completion still rejects it. No schema, format, retention, or permission change.
First-parent upstream fd0fc62..f4f4868 (8 commits: openclaw#169033 collaboration/workshop SQLite bookkeeping, 952c102, openclaw#155464 active turns during worker dispatch, openclaw#168995 approval/placement queries, openclaw#154286 telegram polling workers, 194a08e, openclaw#169045 code-mode catalog bytes, openclaw#159697 talk voice permissions). Conflicts: - session-sharing-store.native.ts: upstream folded the member lookup and delete into one DELETE ... RETURNING with a no-row early return; our recipient-authority advance now follows that return, so only an actual removal revokes access (same order as before the merge). - worker-access inventory: took upstream, regenerated (632 files, 2442 calls). sharing-store receipt/worker auto-merged: upstream's category plan (keys only) is disjoint from our authority.capture command. Refs #1475 Co-Authored-By: Claude Opus 5.5 <[email protected]>
What Problem This Solves
Approval transitions and placement moves read rows again after their owner already has the authoritative state. Placement move lookups also retain a synchronous Gateway path despite an existing worker operation. Group-catalog snapshots issue separate queries for order and defaults.
User Impact and Design
Use INSERT/UPDATE RETURNING for approval insert, resolution, denial, consumption, and expiry, and for placement completion/draining. Keep the approval decision and mutation in the same transaction, with the security check intact. Route placement move reads through the existing worker, delete the superseded synchronous readers, and remove redundant internal source/move and membership rereads. Load group order and defaults together. No schema, stored-format, permission, public SDK, update, or lifecycle change.
The lane's source inventory is 43 → 40 T1 expressions on the paired base, and 44 → 41 against the final integrated main parent (which reclassified one retained restart-clear compatibility primitive as T1), excluding the separately owned GitHub publication family. The original 92-call assignment included that family. This is a bounded cutover, not a claim that Gateway T1 has reached zero. Remaining calls need an owner or compatibility redesign: released synchronous placement/standing-grant SDK methods, native approval commit callbacks that must remain atomic, workspace-reservation authority at an external effect, process-held incognito databases, and deprecated synchronous Mention Inbox operations. Their contracts and retirement paths are recorded in
worker-access.md; no new compatibility path is added.SQL Measurement
Three alternating pairs, M/C/M/C/M/C, on one otherwise idle AWS c7a.8xlarge using the shared workload unchanged. Base
18941faa9629ce0a9fa318f979351fd385878850; candidateb60c2bb48c6ba4cafab351b662571bd6d2c7c626. Final headb6df4ae33403643a5e1cddd0658d29493e827bf3includes two main integrations. Only the generated inventory conflicted; it was regenerated. Upstream placement recovery and SDK deprecation-warning changes merged cleanly. The PR-owned SQL edits remain unchanged, so the paired proof is reused under the campaign integration rule.The measured base is already below the 500 warmed-statement aim. The raw warmed median falls by 5.0 statements and 0.4 requests, but that difference comes from unchanged session-owner work (
database.prepareWrite,session.turn.commit, exact-entry/row-fact reads). It is not attributed to this PR. The repeatable shared-harness saving issessionGroups.snapshot: 5 → 4 statements, one request in both versions, during boot. Warmed paths touched by this PR do not add work.The largest candidate/base phase-duration median ratio is 1.057; warmed duration is 15.780 → 15.796 seconds. First-turn and warmed medians do not rise. Connect +4 and shutdown +6 are within the campaign's absolute non-turn tolerance: unchanged session prewarm/registry timing, audit-prune busy-timeout statements, and agent clean-close bookkeeping account for those deltas. No extra pair was needed.
A separate synthetic probe invokes the public asynchronous approval owner after warming the database, using the same all-thread statement observer. Both revisions produce the expected outcomes:
Removed Checks and Accepted Edges
Evidence
node scripts/run-vitest.mjs <21 files> --maxWorkers=1wall time was 1034.23s, including cold worker compilation/cleanup; Vitest reported 690.58s for the 20-file shard and 77.07s for the E2E shard. No new CI test job was added.check:changedpassed on the measured candidate, including types, Knip, type-aware lint, source contracts, T1 and dialect ratchets. Madge and export collisions passed. On the merged head, type-aware lint, export collisions, the generated inventory check, Madge, and T1/dialect ratchets passed.src/infra/agent-run-terminal-writes.ts: captureAgentRunTerminalWriteContext; the full-tree and scripts scans pass. The merged-headcheck:changedstops at the inherited max-lines suppression insrc/web-search/runtime.test.ts. Both exact findings were reproduced on maine7e3b949ae134060cc8c2a7cd8d224ad27edcd91with its frozen dependencies installed; neither affected file nor the relevant baselines/configs are changed by this PR. These are the only static exceptions. Required changed-file static checks were run separately after that stop; no PR-caused static finding remains.b6df4ae33403643a5e1cddd0658d29493e827bf3: CI run 38129718475. Earlier CI failures in the changed code were fixed; the earlier session-files failure also failed in scheduled main run 38122045725 and disappeared after integrating main.LOC against the integrated main parent: production +137 / −277, tests +128 / −174, docs/tooling +11 / −34, generated inventory +12 / −15; 32 files total.