Repository navigation
fix(ci): startup-recovery WebChat test fails when the host is loaded - #165156
Conversation
chat.send acknowledges "started" before dispatch inserts the turn into the followup queue, so the default 1 s vi.waitFor polls on the queue state failed on loaded hosts (observed at load averages of 42-65 in the agentic-control-plane-runtime-state shard). Await agent.wait's queued observation (status pending, timeoutPhase queue), which the queued-turn registration publishes when insertion commits, then assert the queue state synchronously: insertion starts the drain, which reserves the queue head before any RPC response can be observed.
|
🦞👀 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. Reviewed October 4, 2026, 10:09 PM ET / October 5, 2026, 02:09 UTC (Revision 2). ClawSweeper reviewWhat this changesThe startup-recovery WebChat test waits for queue admission through agent.wait before checking queued messages and the exact in-flight turn. Merge readiness✅ Ready for maintainer review This PR remains useful: current main still polls at both assertion sites, and the related merged cancellation fix does not replace those waits. The queue-admission barrier preserves the recovery scenario and strengthens its assertions; no actionable defect was found. Priority: P2 Review scores
Verification
How this fits togetherWebChat sends enter the Gateway and may queue behind startup recovery. This integration test checks cancellation, surviving-turn execution, and isolation of child context after a session reset. flowchart TD
A[WebChat test client] --> B[Gateway accepts send]
B --> C[Followup queue registration]
C --> D[Agent wait reports queued]
C --> E[Drain waits behind recovery]
D --> F[Assert queue and in-flight turn]
E --> G[Cancel one turn and run survivor]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceTests -1. Total -1 across 1 file. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Use the existing Gateway queue observation as the test barrier while retaining recovery, cancellation, survivor, and reset-context coverage. Do we have a high-confidence way to reproduce the issue? Yes, source establishes that send acknowledgement can precede queue admission while current main polls for that later state. The captured body reports a matching delay-injection failure and after-fix pass; this review did not execute tests. Is this the best way to solve the issue? Yes, waiting through the existing queue-observation API is narrower and more reliable than extending polling budgets, and the exact in-flight identity remains asserted. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against deac9742f37f. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
Merged via squash.
|
…openclaw#165156) chat.send acknowledges "started" before dispatch inserts the turn into the followup queue, so the default 1 s vi.waitFor polls on the queue state failed on loaded hosts (observed at load averages of 42-65 in the agentic-control-plane-runtime-state shard). Await agent.wait's queued observation (status pending, timeoutPhase queue), which the queued-turn registration publishes when insertion commits, then assert the queue state synchronously: insertion starts the drain, which reserves the queue head before any RPC response can be observed.
What Problem This Solves
Fixes:
server.startup-recovery-webchat.test.ts > queues WebChat behind recovery and keeps child context out of a reset parentfails intermittently on loaded hosts. It failed in 2 of 4 macOS replays of theagentic-control-plane-runtime-stateshard (45 gateway-server files,--maxWorkers=4, load average 42-65) at base 7ecc80a:User Impact
No user-visible change. CI and local proof runs stop going red on this test when the host is busy.
Why This Change Was Made
Root cause: an ordering flake in the test, not a product race.
chat.sendrepliesstatus: "started"before dispatch reachesrunReplyAgent'senqueue-followupbranch, so by contract the followup queue cannot yet be observed at the ACK. Dispatch first prepares the session, auth profile and agent runner. Temporary probes measured about 650 ms from the ACK toenqueueFollowupRunat load ≈12. The test bridged that gap withvi.waitForand its default 1000 ms wall-clock budget, which loaded hosts exceed. The survivor's composite queue check that follows used the same poll.The fix waits on the gateway's owned queue-admission signal instead:
chat.send, the test callsagent.waitfor that run and expects{ status: "pending", timeoutPhase: "queue" }.onDeferredhook registers it inchatQueuedTurnsinsideenqueueFollowupRun, at insertion time.agent.waitthat arrives before insertion waits for the chat dispatch terminal. Dispatch writes that terminal after the enqueue, and the wait then reports the queued registration.runReplyAgentcallsscheduleFollowupDrainin the same synchronous block as the enqueue. The drain reserves the queue head (inFlight.add) using only promise continuations (no I/O wait), so the in-flight state is current before any RPC answer reaches the test.agent.waitbound is the API wait bound the file already uses, not a polling budget.The precondition the test cares about is unchanged: the canceled turn is held in flight behind recovery before the survivor is queued. The assertions are the same or stricter. The ordered item list and the exact in-flight run id replace the old length-only checks.
This supersedes the 30 s budget that #165168 gave the first poll: the queue-admission wait needs no wall-clock budget. #165168 also fixed the spurious survivor retry this investigation surfaced, where the survivor's first drain attempt failed with the canceled sibling's abort reason.
Out of scope and unchanged: the later
vi.waitForsites in this file. Two are 30 s polls on fake-provider requests. The other two follow the queue drain afterchat.abortand after the survivor runs, and the queue owner exposes no completion signal for them.Evidence
enqueueFollowupRun(not committed). The old test failed with the exact CI signature (expected [] to deeply equal [ 'webchat-canceled-during-recovery' ]at325:76). The new test passed under the same delay.pnpm test src/gateway/server.startup-recovery-webchat.test.ts --maxWorkers=1runs on macOS at 1-minute load averages of 30–68. The test took 18–61 s, well past the ~23 s of the original failure.agentic-control-plane-runtime-state(45 files fromcreateNodeTestShards(),node scripts/run-vitest.mjs run --config test/vitest/vitest.gateway-server.config.ts <files> --maxWorkers=4) at load averages of 37–57. Each run: 45/45 files, 171 passed and 1 skipped; this test took 16–30 s.src/auto-reply/reply/queue*.test.ts,src/auto-reply/reply/queue/*.test.ts),src/gateway/chat-queued-turns.test.ts,src/gateway/agent-turn/agent-wait-dedupe.test.ts,src/gateway/server.chat-abort-settlement.test.tsandsrc/gateway/operator-run-cancellation.test.ts: 24 files, 247 tests passed.oxfmt --checkandoxlintare clean on the file.pnpm tsgo:core:test: 27/27 shards passed.pnpm test <file> --maxWorkers=1): unchanged. Before: 22.8 s test / 56 s wall at load ≈12. After: 19.2 s test / 60 s wall on a similar host. The change adds twoagent.waitround trips and removes the polling. This single-test file was already above the 5 s target before this PR; it boots a real Gateway plus startup recovery, and this PR does not change that. CI seconds will follow from this PR's run.