Repository navigation
perf: avoid extra transactions for pending input lookups - #182883
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 maintainer review before merge. What this changesThis PR documents acceptance criteria for removing redundant transaction statements from pending-input ID lookups. Example: Retrieve a retained pending input through chat.message.get.
Review scores
ProductKind: Docs · Worth it: Yes · Fix scope: Partial Merge readiness✅ Ready for maintainer review Keep this maintainer-authored draft open: its acceptance plan matches current source, and the proposed optimization remains unimplemented; the document introduces no actionable defect. Priority: P3 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherGateway message retrieval delegates pending-input IDs to the session history owner, whose worker returns bounded stored messages and current-session facts. flowchart LR
A[Gateway WebSocket request] --> B[Message get handler]
B --> C[Pending input history owner]
C --> D[History reader worker]
D --> E[Bounded database SELECT]
E --> F[Message response]
Technical reviewBest possible solution: Complete the optimization in the existing history kernel while preserving counted-list snapshots, payload bounds, and session checks. Do we have a high-confidence way to reproduce the issue? Source confirms that ID lookups skip the count but retain the explicit snapshot wrapper; no runtime reproduction or measurement was performed. Is this the best way to solve the issue? The plan appropriately reuses the existing single-statement page owner and preserves multi-query listing snapshots; simplification steps 1–3 reveal no unnecessary machinery or test scaffolding. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against aaecd52e6bff. SecurityNone. EvidenceWhat I checked:
PR surfaceDocs +29. Total +29 across 1 file. Added test files: 0. View PR surface stats
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, 5:14 PM ET / 21:14 UTC. |
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. |
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 #182990. Follow-up to #182334; single-statement precedent #182883.
…2883) Retrieve retained pending inputs with one bounded SELECT instead of wrapping it in BEGIN/COMMIT. Keep the shared snapshot for count-and-page listings and preserve current-session checks, payload bounds, and authorization. Synthetic Gateway WebSocket proof: every cold, warm, and missing-ID lookup uses 1 SQL statement instead of 3, with the same worker request and zero runtime main-thread SQL. Owner and handler regression tests cover the public flow. No schema, cache, write-transaction, or worker-routing change.
…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
chat.message.getopens an explicit read transaction when retrieving one retained pending input. The lookup is already one SELECT, including the current-session scalar and a byte-bounded payload, so BEGIN and COMMIT add two unnecessary SQL statements.User Impact
Retrieve retained pending inputs with the same content, payload limits, current-session checks, missing-ID behavior and authorization, using one SQL statement instead of three. Count-and-page listings retain their snapshot. There is no schema, cache, write-transaction or worker-routing change.
Why This Change Was Made
Route ID lookups through the existing count-free page path and remove the now-redundant conditional around the listing count. Production diff: +5/−7 lines, net −2; the existing test is +60/−53 (net +7), and the reusable workload/protocol add 126/29 lines. The existing owner regression now covers both count-free context and ID lookup, including visibility of an input committed after an empty read; its SQL counter also captures native
exectransaction envelopes. A committed synthetic WebSocket workload reproduces the public flow.Evidence
Acceptance registered in this PR before the first run:
chat.message.get; also check a missing ID.One committed baseline/candidate pair passed all 12 lookups per arm with zero SQL errors: baseline
8704e103e12, candidatedf661e7d663. Counts use frozen observer v3.1.4; its 36 frozen files were verified. The observer's causal hook misses the current AsyncContext, so these are phase-file execution windows, not causal-turn attribution. Host 1-minute load was 75.09/86.43; 41/40 per-thread CPU profiles were captured for attribution only. No latency, CPU-speedup or memory claim.The two raw threshold crossings were inspected and accepted by the campaign coordinator: cold requests 6→8 comprise the same one lookup plus an extra background proactive-job request and execute; shutdown 16/4/6→23/4/13 comprises seven existing
gateway-owner-lease.releasestartup-checkpoint admission reads. Those owners are byte-identical between arms. Boot MAIN is 120 on both, and runtime lookup MAIN remains zero. The saving attributed to this patch is exactly two SQL statements per lookup, with no worker-request saving claimed.Rerun with a fresh synthetic
--state-dir, the frozen observer inNODE_OPTIONS,SQLMEASURE_OUTpointing to a directory containing a phase file, and:Owner and real handler proof: 18 tests passed in
session-pending-input-history.test.tsandchat-message-get-handler.test.ts. The ID regression is red on the original code (expected one statement, received three), while the existing context case passes. Two Codex autoreview rounds completed; final diff scoped-clean through P2. Formatting, basic and type-aware lint passed. PostgreSQL review approved the single-statement snapshot semantics. Knip matched baseline exactly: production 67/67, script 1,136/1,136 and full-tree 77/77 findings, with no new findings. CI initially found TS7022 in the benchmark response; final head501ad566352adds its explicit result type without changing production or runtime behavior. Local script typecheck stopped before source analysis at the mandated internal virtual-store containment guard; final-head CI passed script/test types, production types and all five core test-type shards. Core lint, source contracts and architecture also passed. Final-head CI run 40136190832 passed all type, lint, contract, architecture, ratchet and build checks. PostgreSQL shards 1/3 and 3/3 passed; shard 2/3 failed seven interactive-setup cases because the synthetic runtime lacksstandalone-runtime-profile.mjs, which newer main code imports. That fixture and import are outside this diff. The campaign coordinator explicitly classified this as inherited red main from #182856 (4a38dbdb6b1), assigned the fix to REDMAIN14, and authorized unaffected lanes to land under RELAXED LANDING v4 while citing their failed run/job. This PR touches neither the fixture nor the import. PostgreSQL shard 2 remains failed; no passing claim or rerun is made.Open-main overlap census covered 2,694 heads. Only #177351 at
4ba6e39ad497b1f2b838f084996fc886862ddf3doverlaps; comparing current mainad9f81409c251b03450a05465e44fd225b8b289cwith the integrated candidate gives the same 18 conflict files / 27 hunks, zero added. Its kernel conflicts are in the separate recovery-filter section.The inventory found no justified warm PRAGMA deletion: equal timeout assignments already skip, while maintenance transitions, pinned snapshots, integrity/recovery checks and nested write savepoints protect real behavior. Unreproduced handoff and transcript-identity candidates remain unchanged.