Repository navigation
perf: reduce database work before dispatching new messages - #182971
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 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2f2591c0fe
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Codex review: needs maintainer review before merge. What this changesThis PR adds a single-statement fast path for submitted-input lookups that find no existing message. Example: Submit a new message with idempotency key new-input:user in source-session-new.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored optimization removes database work still present on main, and source review found no actionable introduced defect. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherBefore message dispatch, the history worker checks the current physical session and durable input identity, returning comparison evidence to admission owners that retain custody and authorization decisions. flowchart TD
A[Submitted message] --> B[Chat admission]
B --> C[History worker]
C --> D[Single statement source lookup]
D --> E[No existing source]
D --> F[Bounded recovery transaction]
E --> G[Current owner admission decision]
F --> G
Technical reviewBest possible solution: Use the existing worker's single-statement absence check while preserving bounded recovery reads and current-owner admission checks. Do we have a high-confidence way to reproduce the issue? Current-main source shows the transaction envelope and separate session, pending-input, and transcript queries for a new key; no target code was executed during this read-only review. Is this the best way to solve the issue? The focused fast path uses the existing database owner, adds no cache or persistent state, and keeps positive-source recovery safeguards; no smaller complete correction was established. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 6255937198b0. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +47, Tests +107. Total +154 across 3 files. Added test files: 1. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
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, 6:49 PM ET / 22:49 UTC. |
…182971) Reduce the durable submitted-input source lookup from five SQL statements to one snapshot-consistent autocommit SELECT on SQLite and PostgreSQL. Keep restart, expired-memory, and attachment duplicate-dispatch protection, with the original bounded recovery transaction unchanged. The normal new-input path saves four statements without adding a worker request. The accepted rare recovery tradeoff is one additional statement for pending or committed input. Verified with both-engine count regressions, 56 focused behavior/prompt-prefix tests, three synthetic Gateway baseline/candidate pairs, and PostgreSQL owner review. Exact-head CI passes all static gates; the inherited PostgreSQL shard 2 fixture failure was independently fixed in openclaw#182990. Follow-up to openclaw#182334; single-statement precedent openclaw#182883.
What Problem This Solves
Every newly submitted message performs a five-statement durable duplicate-input lookup before dispatch, even when its idempotency key is new.
User Impact
Submitted messages retain the same durable reconnect, restart, and attachment protections while their source lookup uses one SQL statement. No configuration or schema change.
Why This Change Was Made
The current-session join, pending input, and committed transcript all belong to the same agent database. A single Kysely SELECT can read them in one statement snapshot on SQLite and PostgreSQL without an explicit read transaction. A positive metadata lookup falls through to the existing bounded-payload and projection-status transaction unchanged; the maintainer-approved tradeoff is one extra statement on this rare recovery path (pending 5→6; committed 8→9). The worker request and all current-session/custody checks remain.
Evidence
Acceptance rule, registered before the first run: for a current session with a new idempotency key, reduce source lookup from five SQL statements to exactly one autocommit SELECT; retain one worker request and zero runtime main-thread SQL. Pending and committed source results, oversized-input rejection, stale-projection refusal, session replacement, restart/expired-memory/attachment duplicate-dispatch handling, and prompt-prefix stability must hold. Both engines require deterministic count proof, and the final head requires all three PostgreSQL conformance shards and engine-owner review.
Synthetic live workload: frozen SQL harness v3.1.4, first turn, ten warm turns, restart turn, and warm non-regression. Baseline/candidate alternate; three pairs when load is below 64 and internal free space is at least 12 GiB, otherwise one pair. Report statement/request/main-thread medians and ranges, separating cold and warm and attributing the changed operation. The observer's causal-attribution limitations will be disclosed. CPU profiles cover the real Gateway and worker threads. Any timing comparison requires the campaign timing lock, load below 24, five alternating samples per arm, and median/p95/spread; no latency claim otherwise. A 20% worsening in a measured timing cell stops the change.
Validation on
ef6c367f320: 56 focused tests passed (39 Gateway admission/recovery, six source payload/projection, 11 prompt-prefix). Native count conformance passed all six SQLite/PostgreSQL cases: new input 1 SQL, pending recovery 6, committed recovery 9; session replacement and committed-source exclusion withpendingOnlyalso pass. The same tests fail on exact baseline4c3bf18daa6on both engines: new input is 5 statements, pending recovery 5, and committed recovery 8. Final PostgreSQL owner review approves this exact head. The completed real-Gateway measurements are below. The initial local PostgreSQL fixture omittedunaccent; after provisioning the standard extensions, the focused suite passed without a product change.Two independent Codex review rounds completed, and a coordinator-authorized review limited to the later CI repair is scoped-clean. Initial CI exposed an unsupported SQLite boolean bind in the new query; the repaired query selects a NULL committed-source expression for
pendingOnly, with an explicit regression assertion.Exact-head CI run 40139087907 completed with 39 successful jobs, 26 skipped, and two inherited failures. PostgreSQL shard 2 fails only seven
interactive-setup.integration.test.tsfixture cases missingruntime/standalone-runtime-profile.mjs, introduced by #182856, reproduced on main0f6631638b2e, and fixed independently by #182990; the aggregate gate consequently fails. PostgreSQL shards 1 and 3 pass. Types, lint, source contracts, Madge/Kysely guards, and baseline/worker/dialect ratchets pass. No all-green CI claim. Local core/tooling type-aware lint, source guards, zero runtime import cycles, T1 (170→170), and dialect (0→0) passed. Localcheck:changedremains non-green because its tsrs boundary/core/test preparation rejects the campaign-mandated internal virtual store. Exact-head CI supplies passing type proof. Canonical Knip baseline/candidate sets are identical: 1,136 script, 69 production, and 81 full-tree findings; zero new or removed findings and no resolution errors.The original recovery transaction stays unchanged, including payload-size bounds, optional pending-table handling, and projection checks. A pending input accepted after the fast lookup belongs to the next submit/recovery lookup, matching the existing snapshot behavior. No schema, cache, generation, or worker request is added. Production growth is 47 lines because preserving the bounded recovery path requires a separate small metadata query; deleting that path would weaken duplicate-dispatch and payload safeguards.
Shared-index open-PR comparisons cover all 80 overlapping main PR heads against main
9794c6abbb6f543642e2522132300861ca2c15b2. Candidateef6c367f320a0cbb1c5aeef8a47af827474e743aadds zero conflict paths or hunks compared with base-only merges.Related: #182334, #182883.
Real Gateway measurements
Frozen v3.1.4, three alternating baseline/candidate pairs. Each arm starts an isolated synthetic Gateway over real WebSocket transport, runs first and warm turns, a fixed five-minute idle window, and restart/first-turn recovery. Frozen file hashes (36) were verified unchanged. These are operation counts, not latency or CPU-speed measurements. Reproduction command (frozen harness v3.1.4):
python3 measure.py --repo <checkout> --out <synthetic-proof> --sha <tested-sha> --repetitions 1, alternating baseline4c3bf18daa6and candidateef6c367f320.The target saves exactly four statements per submitted turn in every pair. Warm MAIN stays zero. Whole-workload and phase counts contain intermittent background work. Raw ≥20% phase increases are retained below; the coordinator explicitly accepted the named background owners when present on baseline or in the historical census. The additional installStatusTracking batch is independently present in historical census runs. Other shifts include plugin metadata/leases, memory initialization, deletion/maintenance work, and operations crossing phase markers. No causal-attribution claim: all six runs report the observer’s known AsyncContext coverage limit; execution-phase and operation attribution remain available.
The final candidate profiling pass completed the same 14 submitted turns with 67 CPU profiles (2 main-thread and 65 worker-thread profiles). Samples were inspected for hot-path attribution only. Captured call trees include
readPendingInputSourceInDatabase; zero self samples at this sampling resolution support no CPU-speed estimate. Frequent application frames include database-admission relays. The first two separate committed benchmark entrypoints had setup failures (QA SDK export resolution; then worker-runtime driver import); neither is counted as successful hot-path proof. The successful pass uses the unchanged frozen workload plus an external launcher and the existing per-thread profiling preload; no harness or production source edits.Per-operation counts and raw phase increases (SQL / requests / MAIN)
Raw ≥20% cells
These are not waived by spread. Their per-operation deltas are recorded below and must satisfy the coordinator disposition rule.
Overlapping open PRs checked before landing
#183174, #183114, #182951, #182329, #182216, #182104, #180832, #180026, #178768, #178124, #178033, #177356, #177351, #175345, #175029, #174317, #174235, #173557, #173026, #170160, #169723, #169504, #169438, #169241, #169081, #168522, #168434, #167221, #167090, #166166, #166023, #165710, #165583, #164935, #164843, #164721, #164551, #163835, #163655, #163239, #162989, #162583, #162565, #162530, #161997, #161410, #160908, #160851, #159478, #159326, #159255, #158502, #158244, #157693, #157557, #157427, #156634, #155630, #154904, #153907, #153856, #151648, #150078, #149882, #149241, #148533, #146847, #146326, #145839, #141239, #141004, #140609, #139620, #136474, #129388, #126224, #124337, #121204, #107366, #93952.
All 80 base-only versus base-plus-candidate merge comparisons add zero conflict paths or hunks.