Skip to content

fix(ci): startup-recovery WebChat test fails when the host is loaded - #165156

Merged
steipete merged 2 commits into
mainfrom
steipete/fix-startup-recovery-webchat-queue-flake
Oct 5, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/fix-startup-recovery-webchat-queue-flake

Conversation

@steipete

@steipete steipete commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: server.startup-recovery-webchat.test.ts > queues WebChat behind recovery and keeps child context out of a reset parent fails intermittently on loaded hosts. It failed in 2 of 4 macOS replays of the agentic-control-plane-runtime-state shard (45 gateway-server files, --maxWorkers=4, load average 42-65) at base 7ecc80a:

AssertionError: expected [] to deeply equal [ 'webchat-canceled-during-recovery' ]
 ❯ src/gateway/server.startup-recovery-webchat.test.ts:325:76

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.send replies status: "started" before dispatch reaches runReplyAgent's enqueue-followup branch, 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 to enqueueFollowupRun at load ≈12. The test bridged that gap with vi.waitFor and 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:

  • After each chat.send, the test calls agent.wait for that run and expects { status: "pending", timeoutPhase: "queue" }.
  • The turn's onDeferred hook registers it in chatQueuedTurns inside enqueueFollowupRun, at insertion time.
  • An agent.wait that arrives before insertion waits for the chat dispatch terminal. Dispatch writes that terminal after the enqueue, and the wait then reports the queued registration.
  • The queue assertions are now synchronous. runReplyAgent calls scheduleFollowupDrain in 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.
  • No sleeps, polls or longer timeouts. The 30 s agent.wait bound 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.waitFor sites in this file. Two are 30 s polls on fake-provider requests. The other two follow the queue drain after chat.abort and after the survivor runs, and the queue owner exposes no completion signal for them.

Evidence

  • Deterministic repro of the root cause. A temporary 1500 ms delay was injected before enqueueFollowupRun (not committed). The old test failed with the exact CI signature (expected [] to deeply equal [ 'webchat-canceled-during-recovery' ] at 325:76). The new test passed under the same delay.
  • Standalone runs: 20/20 clean pnpm test src/gateway/server.startup-recovery-webchat.test.ts --maxWorkers=1 runs 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.
  • Shard runs: 3/3 clean runs of agentic-control-plane-runtime-state (45 files from createNodeTestShards(), 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.
  • Owner sibling tests: followup queue family (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.ts and src/gateway/operator-run-cancellation.test.ts: 24 files, 247 tests passed.
  • Static checks: oxfmt --check and oxlint are clean on the file. pnpm tsgo:core:test: 27/27 shards passed.
  • Cost (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 two agent.wait round 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.

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.
@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XS labels Oct 4, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 4, 2026
@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 4, 2026, 10:09 PM ET / October 5, 2026, 02:09 UTC (Revision 2).

ClawSweeper review

What this changes

The 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
Reviewed head: c5a9913e22f68a812e3b16c75cdc51bc300c3894

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused test repair with preserved behavioral coverage, a source-supported ordering barrier, and substantial reported flake validation.
Proof confidence 🌊 off-meta tidepool Not applicable: The repository-state author association is MEMBER, and this test-only change has no authority-chain proof trigger. The body reports real-Gateway integration replays with a local fake provider and delay-injection before/after results; those results were not independently rerun. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The repository-state author association is MEMBER, and this test-only change has no authority-chain proof trigger. The body reports real-Gateway integration replays with a local fake provider and delay-injection before/after results; those results were not independently rerun. No stored-data contract changes.
Evidence reviewed 10 items Pinned introduced change: The pinned base-to-head diff replaces two queue-state polling waits with agent.wait queue observations and synchronous assertions. It changes only test behavior; the exact canceled run remains the required in-flight turn.
Queue observation contract: The wait owner reports pending with timeoutPhase queue for an existing queued registration. When registration is not yet present, it awaits the source job observation and checks queued registration again before returning.
Admission and drain ordering: The enqueue-followup branch inserts the turn and schedules draining before its subsequent awaited work. The fixture uses zero WebChat debounce; with no canceled or priority source, drain preparation uses promise continuations and reserves the head before awaiting execution behind recovery.
Findings None None.
Security None None.

How this fits together

WebChat 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Tests -1. Total -1 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 1 21 22 -1
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 21 22 -1

Review metrics

None.

Technical review

Best 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.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a focused repair for a load-sensitive integration-test failure, with no user-facing runtime change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The repository-state author association is MEMBER, and this test-only change has no authority-chain proof trigger. The body reports real-Gateway integration replays with a local fake provider and delay-injection before/after results; those results were not independently rerun. No stored-data contract changes.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-04T22:18:04.494Z sha 3660adf :: needs maintainer review before merge. :: none

@steipete
steipete merged commit 9765dec into main Oct 5, 2026
95 checks passed
@steipete
steipete deleted the steipete/fix-startup-recovery-webchat-queue-flake branch October 5, 2026 02:12
@steipete

steipete commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 5, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant