Repository navigation
perf(channels): avoid rereading ingress queue mutations - #174393
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. |
|
Codex review: needs maintainer review before merge. What this changesThis PR replaces redundant ingress-queue reads with rows returned directly by insert and update statements. Example: Accept and claim event-1 containing {"text":"first"} in lane chat-1.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this is a focused, maintainer-directed optimization that current main does not contain; source review found no actionable correctness or security defect, but required CI remains red. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherChannel adapters submit serialized inbound events to the shared-state writer; the durable ingress queue returns admission and claim records for ordered dispatch, settlement, and replay. flowchart LR
A[Channel adapter] --> B[Ingress queue API]
B --> C[Shared state writer]
C --> D[Ingress mutation kernel]
D --> E[Durable event table]
E --> D
D --> F[Admission or claim record]
F --> G[Channel dispatch]
Technical reviewBest possible solution: Retain the existing writer owner and use mutation-returned rows while preserving duplicate reads, claim predicates, and corrupt-row recovery. Do we have a high-confidence way to reproduce the issue? Current-main source shows the redundant enqueue, claim, and resubmission reads; no runtime reproduction or performance measurement was executed during this read-only review. Is this the best way to solve the issue? Using RETURNING is a small, coherent optimization supported by the existing synchronous query executor, with no cache or competing state owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 89557502c7ca. Provenance checked
TestingProof path: none. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +1, Tests +16, Docs +3. Total +20 across 3 files. Added test files: 0. 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 16, 2026, 12:26 PM ET / 16:26 UTC. |
…158510 * commit '236ceb85e92ac8cb5bdc58a4a70bd79cbebd1094': (24 commits) feat(decisions): run typed tasks with prepared model credentials (#157225) fix(gateway): retain observer slots until model work settles (#174262) refactor(ui): own assistant content subscriptions in Solid (#174035) refactor(logging): remove package and snapshot debug instrumentation (#174431) fix: show native Talk speech separately from completed answers (#172598) test(ui): forbid new controller host consumers (#174446) chore(deps): refresh dependencies with a seven-day cutoff (#174410) perf(ui): reduce idle native session catalog polling (#174404) refactor(test): remove unused Signal fixture overrides (#174445) fix: surface DNS zone and Linux camera read failures (#174424) fix(doctor): keep at most three standalone Doctor captures (#174415) perf(cron): reuse session writer for completed run alias cleanup (#174413) feat(database): legacy SQLite migrations complete before PostgreSQL port (#174399) perf(channels): avoid rereading ingress queue mutations (#174393) feat(control-ui): keep link readers scoped to their pane session (#173652) test(ui): wait for desktop widget placement before pinning (#174439) refactor(ui): compose remaining plugin classes (#174441) perf(control-ui): shrink transcript overscan and settle skipped row sizes synchronously (#173690) fix(sessions): quietly settle archived delivery endpoints (#174442) perf(sessions): keep config loading out of transcript workers (#174414) ...
…esafe-decision-native * commit '236ceb85e92ac8cb5bdc58a4a70bd79cbebd1094': (24 commits) feat(decisions): run typed tasks with prepared model credentials (#157225) fix(gateway): retain observer slots until model work settles (#174262) refactor(ui): own assistant content subscriptions in Solid (#174035) refactor(logging): remove package and snapshot debug instrumentation (#174431) fix: show native Talk speech separately from completed answers (#172598) test(ui): forbid new controller host consumers (#174446) chore(deps): refresh dependencies with a seven-day cutoff (#174410) perf(ui): reduce idle native session catalog polling (#174404) refactor(test): remove unused Signal fixture overrides (#174445) fix: surface DNS zone and Linux camera read failures (#174424) fix(doctor): keep at most three standalone Doctor captures (#174415) perf(cron): reuse session writer for completed run alias cleanup (#174413) feat(database): legacy SQLite migrations complete before PostgreSQL port (#174399) perf(channels): avoid rereading ingress queue mutations (#174393) feat(control-ui): keep link readers scoped to their pane session (#173652) test(ui): wait for desktop widget placement before pinning (#174439) refactor(ui): compose remaining plugin classes (#174441) perf(control-ui): shrink transcript overscan and settle skipped row sizes synchronously (#173690) fix(sessions): quietly settle archived delivery endpoints (#174442) perf(sessions): keep config loading out of transcript workers (#174414) ...
…/decision-tool-v2-proof-20261016 * commit '236ceb85e92ac8cb5bdc58a4a70bd79cbebd1094': (24 commits) feat(decisions): run typed tasks with prepared model credentials (#157225) fix(gateway): retain observer slots until model work settles (#174262) refactor(ui): own assistant content subscriptions in Solid (#174035) refactor(logging): remove package and snapshot debug instrumentation (#174431) fix: show native Talk speech separately from completed answers (#172598) test(ui): forbid new controller host consumers (#174446) chore(deps): refresh dependencies with a seven-day cutoff (#174410) perf(ui): reduce idle native session catalog polling (#174404) refactor(test): remove unused Signal fixture overrides (#174445) fix: surface DNS zone and Linux camera read failures (#174424) fix(doctor): keep at most three standalone Doctor captures (#174415) perf(cron): reuse session writer for completed run alias cleanup (#174413) feat(database): legacy SQLite migrations complete before PostgreSQL port (#174399) perf(channels): avoid rereading ingress queue mutations (#174393) feat(control-ui): keep link readers scoped to their pane session (#173652) test(ui): wait for desktop widget placement before pinning (#174439) refactor(ui): compose remaining plugin classes (#174441) perf(control-ui): shrink transcript overscan and settle skipped row sizes synchronously (#173690) fix(sessions): quietly settle archived delivery endpoints (#174442) perf(sessions): keep config loading out of transcript workers (#174414) ...
…157433 * commit '3dd7f576829fd8ec1fd395acb59f3d4f9e999166': (24 commits) feat(decisions): run typed tasks with prepared model credentials (#157225) fix(gateway): retain observer slots until model work settles (#174262) refactor(ui): own assistant content subscriptions in Solid (#174035) refactor(logging): remove package and snapshot debug instrumentation (#174431) fix: show native Talk speech separately from completed answers (#172598) test(ui): forbid new controller host consumers (#174446) chore(deps): refresh dependencies with a seven-day cutoff (#174410) perf(ui): reduce idle native session catalog polling (#174404) refactor(test): remove unused Signal fixture overrides (#174445) fix: surface DNS zone and Linux camera read failures (#174424) fix(doctor): keep at most three standalone Doctor captures (#174415) perf(cron): reuse session writer for completed run alias cleanup (#174413) feat(database): legacy SQLite migrations complete before PostgreSQL port (#174399) perf(channels): avoid rereading ingress queue mutations (#174393) feat(control-ui): keep link readers scoped to their pane session (#173652) test(ui): wait for desktop widget placement before pinning (#174439) refactor(ui): compose remaining plugin classes (#174441) perf(control-ui): shrink transcript overscan and settle skipped row sizes synchronously (#173690) fix(sessions): quietly settle archived delivery endpoints (#174442) perf(sessions): keep config loading out of transcript workers (#174414) ...
…/decision-onnx-v2-proof-20261016 * commit '3dd7f576829fd8ec1fd395acb59f3d4f9e999166': (24 commits) feat(decisions): run typed tasks with prepared model credentials (#157225) fix(gateway): retain observer slots until model work settles (#174262) refactor(ui): own assistant content subscriptions in Solid (#174035) refactor(logging): remove package and snapshot debug instrumentation (#174431) fix: show native Talk speech separately from completed answers (#172598) test(ui): forbid new controller host consumers (#174446) chore(deps): refresh dependencies with a seven-day cutoff (#174410) perf(ui): reduce idle native session catalog polling (#174404) refactor(test): remove unused Signal fixture overrides (#174445) fix: surface DNS zone and Linux camera read failures (#174424) fix(doctor): keep at most three standalone Doctor captures (#174415) perf(cron): reuse session writer for completed run alias cleanup (#174413) feat(database): legacy SQLite migrations complete before PostgreSQL port (#174399) perf(channels): avoid rereading ingress queue mutations (#174393) feat(control-ui): keep link readers scoped to their pane session (#173652) test(ui): wait for desktop widget placement before pinning (#174439) refactor(ui): compose remaining plugin classes (#174441) perf(control-ui): shrink transcript overscan and settle skipped row sizes synchronously (#173690) fix(sessions): quietly settle archived delivery endpoints (#174442) perf(sessions): keep config loading out of transcript workers (#174414) ...
…wner cases Upstream's openclaw#174393 added a competing enqueue/claim case on a frozen clock and a resubmission case on the wall clock. Every kernel transition here writes a strictly-forward updated_at (nextUpdatedAt), so the claim lands on 101 past the frozen 100, and the resubmission case takes the seed clock below its explicit transition times, as in 41277c5. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UJeJ4awZGktQ8rkwNhdueo
…wner cases Upstream's openclaw#174393 added a competing enqueue/claim case on a frozen clock and a resubmission case on the wall clock. Every kernel transition here writes a strictly-forward updated_at (nextUpdatedAt), so the claim lands on 101 past the frozen 100, and the resubmission case takes the seed clock below its explicit transition times, as in 41277c5. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01PiKbtQbHKKfq82arnmwBYp
) Return accepted enqueues, claims, and resubmissions directly from their existing writer mutations. Remove redundant reads while preserving duplicate payloads, lane ordering, claim ownership, failure history, and coalescing behavior. Use portable INSERT/UPDATE RETURNING; no schema or SDK change. Extend owner regressions for competing enqueue/claim requests and cleared resubmission state. Validation: 83 focused tests, final-head CI, and two clean Codex review rounds. See the PR for measured statement/request counts and static-gate evidence.
What Problem This Solves
Every accepted durable inbound channel message rereads its freshly inserted row, then rereads its row twice while claiming it. These statements add work before dispatch without adding information to the serialized queue owner.
User Impact
Reduces database work for durable channel ingress while preserving duplicate suppression, lane ordering, coalescing windows, claim ownership, failure recovery, and retained payloads. No schema, SDK, configuration, or update behavior changes.
Why This Change Was Made
Use portable Kysely
INSERT/UPDATE ... RETURNINGwithin the existing shared-state writer transaction. Successful enqueues return their inserted row; duplicate enqueues still read the retained original. Claims update only pending rows and return the new claim. Resubmission retains the original failed record and returns the update's new row. The superseded reads are deleted; there is no cache, fallback, or second owner.Removed-read ledger:
Queue ordering snapshots and claim-token checks remain: they protect concurrent lane selection and settlement by the actual claimant.
Evidence
Two independent Codex review rounds: no actionable P0–P2 findings. All 83 focused queue, claim-ownership, drain, and Telegram coalescing tests pass. Final-head CI passes all 36 selected jobs, including production/test types, type-aware lint, source contracts, Madge, selected tests, and database worker/dialect ratchets. Changed-file formatting and
git diff --checkpass. The integrated-head Knip export scan has no ingress findings. Its two inherited unused exports,resolveTrustedEnterpriseGitHubAccountIdandresolveTrustedEnterpriseGitHubMetadatainsrc/gateway/github-user-identity.ts, reproduce on baseline0dc31f5f6430; that file, both Knip configurations, package manifest, and lockfile are byte-identical on integrated head7790d4f98043and main parent07667dcc8f4d. This is the only static-gate exception and is routed for follow-up.Initial CI found one unbound-method error in the changed test, corrected by binding the extracted helper. Two unrelated guard failures were repaired on main and incorporated through a merge; final CI is green.
Ingress-owner T1 call sites: 0 → 0; global ratchet 222 → 222 (compatibility 12 → 12). Changed-file dialect groups 0 → 0. The kernel is already in the worker-only inventory; no Gateway-thread SQL is introduced.
Change size: production +22/−21 (net +1), tests +47/−31 (net +16), docs +3. Tests extend existing cases to cover competing enqueues/claims and cleared resubmission state. No update cell is required for this queue-only change.
Completed measurement
Three alternating pairs completed in order M1, C1, M2, C2, M3, C3. Frozen base
0dc31f5f6430and production candidate1e25889547ffused Node 24.22.0 / SQLite 3.54.0 with compile caching disabled. The production and documentation blobs match the merged change; the integrated head only adds a test-helper binding correction. Counts include native transaction statements and actual worker wire requests; prepare calls are not counted as executed SQL. All accepted runs have zero native SQL errors. No latency claim is made on the busy shared host.Durable ingress
Values are median [min–max] across three runs per side. These owner flows exclude separate assertion reads and include transaction overhead.
The fixed durable ingress path saves 3 SQL statements per message (16.7%), with requests unchanged. Accepted enqueue is 4→3 SQL / 1 request; claim-next including its snapshot is 11→9 / 2; completion stays 3 / 1. A direct claim is 5→3 / 1, and failed-event resubmission is 5→4 / 1. These values repeat in every pair. Caller-main SQL stays zero. The Telegram cases exercise production admission, drain, dedupe and coalescing with mocked remote API/model boundaries; they are not live Telegram tests.
Warmed turns and outbound control
These ranges pool all 30 warmed turns per side, rather than just three run medians. Causal values attribute work to the turn; raw values retain everything executed during its window.
All 150 outbound replies use exactly 7 SQL statements / 2 requests / 0 MAIN each. QA traffic bypasses the durable ingress queue; its attachment and forward-like groups are controls, not Telegram coalescing proof.
Shared v3 raw phases
Each cell is median [min–max] across the three runs. These are complete phase windows, including unchanged startup, maintenance and other background owners.
Telegram whole-test polling caveat
The existing fixtures poll every 10 ms. Setup, assertions, teardown and timer-driven
list/staleClaimsoperations are retained below; these totals are not per-message costs. The explicit assertions separately account for 13 SQL / 5 requests per scenario (two duplicate replay enqueues and three list reads). The fixed message-operation subset above is the repeatable comparison.Raw-count attribution and limits
The raw warm median rises by 0.5 SQL, while the total over all 30 warm samples falls 2,227→2,217 SQL. Turn-attributed totals are exactly 2,118 SQL / 696 requests / 0 MAIN on both sides. Native shape differences are +1 WAL checkpoint, +2 plugin-state SELECTs, −7 lease-currency SELECTs, and −6 config/transaction statements. Raw warm request totals are 711→714 (+2 state-read-pool tasks and +1 startup-handler-prewarm task); the request median stays 23. Every warm MAIN statement is existing post-ready plugin-lifecycle lease work through
openclaw-state-lease-store.ts/state-lease.ts, rather than ingress. Those real background reads remain in the raw ranges above.The raw first-turn SQL median rises 763→891, and its causal median is 217→226 SQL / 61→63 requests / 0 MAIN. Across the three first-turn windows the net +153 SQL comprises +124 background schema DDL, +8 background PRAGMAs, +3 FTS savepoints, +7 other background statements, and +11 foreground statements. Native stacks attribute these to unchanged agent-database admission, cold read-scope/model-catalog admission, session-entry/transcript reads and lifecycle work. The +11 foreground difference is retained rather than relabeled as background. Phase placement also varies at restart; the full phase table preserves it.
The shared v3 workload executes none of the changed enqueue/claim/resubmit operations in any arm. It has exactly four unchanged ingress-health reads/tasks per run and no ingress SQL/request stacks in warm windows. Together with unchanged causal warm counts and whole-workload medians (4,080 SQL / 1,052 requests on both sides), the exact-operation audit attributes these variations to unchanged owners. No fourth pair was needed, and none of these raw variations is claimed as an ingress saving.
Both independent native recounts pass: all six inbound-owner/Telegram arms and all six QA/v3 arms. All 11,828 QA/v3 wire requests have unique per-run IDs and wire markers. An initial Telegram observation that missed nested-worker SQL was rejected; an external preload adapter repaired observation after the test environment cleared
NODE_OPTIONS. The accepted six arms use identical instrumentation, and the shared harness and production source were not modified for observation. A zero-event C1 idle-settle window was verified against its phase markers and raw events before aggregation filled its missing analyzer row with zero.