Repository navigation
perf(gateway): trim redundant startup session reads - #169138
Conversation
Keep the final writer-ordered authority and exclusivity check while removing the intermediate chat admission read. Read recovery metadata only when channel-source deduplication or active steering needs it. Preserve queue admission and recovery failure coverage. Synthetic concurrent-start measurements show a modest preparation tail improvement; ACK variation remains mixed.
|
🦞👀 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 changes before merge. What this changesThis PR removes a redundant chat-admission read and limits reply recovery reads to source deduplication and active steering. Example: A source-less webchat message queues behind an active run without requesting steering.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains Keep this PR open: it provides a useful, feature-owner-authored simplification absent from current main, with no actionable introduced defect found. Priority: P2 Before merge
FindingsNone. Agent review detailsHow this fits togetherGateway admission converts authorized chat requests into registered runs; the reply runner then selects steering, queueing, or execution against canonical session storage. flowchart TD
A[Chat request] --> B[Pending reservation]
B --> C[Session lifecycle admission]
C --> D[Writer ordered authority check]
D --> E[Registered run]
E --> F[Reply runner]
F --> G[Steering or followup queue]
F --> H[Durable input admission]
Technical reviewBest possible solution: Retain this focused read reduction while preserving authoritative admission and fresh recovery reads at their consuming boundaries. Do we have a high-confidence way to reproduce the issue? Current-main source establishes both unnecessary reads, and supplied baseline validation reports the intended queued-input failure; this read-only review did not execute a reproduction. Is this the best way to solve the issue? The narrow removal is appropriate because required consumers retain fresh reads and final admission preserves current authority, exclusivity, and session identity. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against ebdc7d54c084. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -4, Tests +68. Total +64 across 6 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 HistoryReview history (1 earlier review cycle)
Reviewed October 11, 2026, 10:48 AM ET / 14:48 UTC (Revision 2). |
|
Landing under the authorized inherited-failure exception for exact head
Changed core test shards, core lint, production types, security, architecture and source-contract guards passed on this exact head. The focused admission/ordering/custody run passed 60 tests; earlier Testbox runner/recovery coverage passed 282 tests and closure/CI-plan guards passed 143. Independent review is clean. No rerun, update-branch, or CI dispatch was used to chase green. |
* perf(gateway): trim redundant startup session reads Keep the final writer-ordered authority and exclusivity check while removing the intermediate chat admission read. Read recovery metadata only when channel-source deduplication or active steering needs it. Preserve queue admission and recovery failure coverage. Synthetic concurrent-start measurements show a modest preparation tail improvement; ACK variation remains mixed. * test(gateway): assert admission denial across reader closure timing
What Problem This Solves
Concurrent first messages repeat database-ordered session reads that do not establish an additional guarantee, adding work to an already contended startup path.
User Impact
Reduces unnecessary startup work and permits non-steering queued input to proceed without an unrelated recovery-metadata read. Session FIFO, cancellation, durable-input custody, and current caller/membership checks remain at their existing effect boundaries.
Why This Change Was Made
The pending chat reservation checks caller authority. Final writer-ordered admission then reads current session membership, checks authority and exclusivity, and registers the run synchronously. The intermediate lifecycle check now checks only the retained session target.
The reply runner reads recovery metadata only for channel-source deduplication or active steering. Ordinary source-less, non-steering turns do not consume that row. Their later durable-input admission still performs its required current read.
Production LOC delta: −4. Including the test-routing metadata, non-test code is −3 lines. No new cache, configuration option, schema, or compatibility path.
Evidence
Real isolated Gateway, real
sessions.createfollowed by firstchat.send, synthetic loopback Responses API, Node 26.8.1 on an 8-core Linux rig. The fixture uses the existingmaxConcurrent: 20setting. All state is isolated; no live deployment or real account data was used.Paired baseline
d1618ccd0b276f985711ff297b1b87a77bdad35dand candidate, warmed series, p50 / p95 milliseconds:A preceding 60-start burst series measured preparation 5088.1 / 5991.5 → 5117.6 / 5758.8 ms and ACK 1458.5 / 1667.9 → 1623.7 / 1799.6 ms. Preparation p95 improved in both series (4% and 16%); ACK variation is mixed, so this PR claims no reliable ACK latency improvement and no 1.5× overall speedup. Required database-ordered preparation remains the dominant cost.
The Gateway benchmark uses source imports and the normal compiled-worker preparation. The measurement replay reuses previously built E2E package artifacts through the repository's supported
OPENCLAW_E2E_SKIP_BUILD=1path.Validation provider: blacksmith-testbox, lease tbx_01m4nc5tbes89fesg9y9a0g195:
node scripts/run-vitest.mjs src/auto-reply/reply/agent-runner-recovery-read.test.ts— 3 passed. The queued-input regression fails on unchanged baseline with the intended recovery-read error. File wrapper time 38.68 s; first cold test 11.67 s, other cases 4/3 ms. This exercises the actual reply runner rather than adding a production-only test seam.node scripts/run-vitest.mjs src/auto-reply/reply/agent-runner.runreplyagent.e2e.test.ts src/auto-reply/reply/agent-runner-core.test.ts src/auto-reply/reply/restart-recovery-claim.lifecycle.test.ts src/gateway/server-methods/chat-send-admission-authority.test.ts src/gateway/server-methods/chat-send-admission.reads.test.ts src/gateway/server-methods/chat-send-ordering.test.ts— 282 passed; 387.17 s wrapper time.node --import ./scripts/tsx.mjs scripts/check-export-name-collisions.mts— passed.node scripts/run-vitest.mjs test/scripts/eager-import-closure.test.ts test/scripts/pr-wrapper-source-closure.test.ts test/scripts/ci-node-test-plan.test.ts test/scripts/ci-node-test-plan.commands.test.ts— 143 passed.node scripts/check-changed.mjs --staged— all preceding guards, formatting, core types and all 28 core-test type graphs passed; stopped at the unrelated unused-export scan.Rig
openclaw-node-01:node scripts/run-vitest.mjs src/gateway/gateway.test.tswith the isolated benchmark fixture — both variants passed; JSON measurements collected.node scripts/run-oxlint.mjs --tsconfig tsconfig.core.json src/gateway/server-methods/chat-send-admission.ts src/auto-reply/reply/agent-runner-run.ts src/auto-reply/reply/agent-runner-recovery-read.test.ts src/auto-reply/reply/agent-runner.runreplyagent.e2e.test.ts— 0 warnings, 0 errors. Scripts lint also passed.node --import ./scripts/tsx.mjs scripts/check-deadcode-exports.mtson the unchanged baseline reproduces the unused UI exports andloadSubagentMaintenanceCandidatesInDatabasefinding. None of those files or exports is changed here.Independent Codex reviews, including the test-only CI follow-up: scoped-clean, no actionable P0–P2 findings.
CI follow-up
The first PR run exposed two timing-dependent assertions in the existing admission-authority tests. On the unchanged CI base
89564fa3a101b437a485fbe501dd99281c9402ba, both fail identically (2 failed / 4 passed; 145.92 s wrapper time). Database closure can be observed as a handled{ok:false}denial, or reach a reader after its synchronous consumption has finished. The tests now assert denied admission and preserve reservation cleanup, same-ID retry, callback custody, all lease cleanup, and no dispatch. A rejected reader must still propagate its exact error. No production behavior was changed for these test repairs.Rig
openclaw-node-01, Node 24.19.0, isolated checkout at that CI base plus this PR:pnpm install --frozen-lockfile --prefer-offline— passed, 5.4 s.node scripts/run-vitest.mjs src/gateway/server-methods/chat-send-admission-authority.test.tson the unchanged base — reproduced both CI failures.node scripts/run-vitest.mjs src/gateway/server-methods/chat-send-admission-authority.test.ts src/gateway/server-methods/chat-send-admission.reads.test.ts src/gateway/server-methods/chat-send-ordering.test.ts src/gateway/server-methods/chat-send-pre-admission.test.ts src/gateway/server-methods/chat-send-work-admission.test.ts— 60 passed across five files, 205.74 s wrapper time.The first CI run also failed on unrelated Solid panel attribute/type declarations in unchanged UI files. Those are separate from the admission test repair.
The updated exact-head CI run also exposed an unrelated
chat-panel-layout.e2e.test.tsterminal-canvas visibility timeout. On unchanged CI baseebdc7d54c0842d96c4bb2fb2bb4be4758f07f255, the same file reproduces the same failure at line 379 (1 failed / 1 passed). It uses a mocked Gateway and does not execute the changed admission code. The rig changed-code gate passed its preceding guards and core production types, then stopped at the unchanged UI tab type errors from the earlier base; the focused gateway-method type graph reports those same UI errors.The final CI run also fails
test/scripts/managed-child-process.windows.test.ts:83because the unchanged helper exportsstopWindowsGatewayProcesswhile the test callsstopGatewayProcess. Runningnode scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.test.root.scripts.json --noEmiton unchangedebdc7d54c0842d96c4bb2fb2bb4be4758f07f255reproduces the identical TS2339 error. Both remaining failures are independently baseline-proven; all changed core test shards, core lint, production types, security, and architecture/source guards passed on exact head340cace36eb93ac3519b8f2b2a7f3ba7cee85cc0. No CI reruns were requested.A supplementary rig lint invocation stopped while preparing plugin SDK declarations (300-second artifact-preparation timeout); exact-head CI core lint passed and supplies that check. The rig was not retried.