Repository navigation
test(gateway): wait for chat.send history run completion deterministically - #160479
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. Reviewed September 28, 2026, 10:39 AM ET / 14:39 UTC (Revision 2). ClawSweeper reviewWhat this changesUpdates two Gateway WebSocket chat tests to wait for a started run to finish before checking its final status. Merge readiness✅ Ready for maintainer review Current main still contains the one-second assertion race. The focused PR remains useful, and its updated validation addresses the prior review request. No introduced defect is evident. Priority: P2 Review scores
Verification
How this fits togetherGateway chat requests acknowledge a started run before its detached work finishes. These tests send WebSocket requests to a test Gateway, then check run status and session events. flowchart LR
A[WebSocket chat test] --> B[Chat send request]
B --> C[Started acknowledgment]
C --> D[Detached Gateway run]
D --> E[Observed run completion]
E --> F[Agent wait snapshot]
F --> G[Test assertion]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceTests 0. Total 0 across 1 file. View PR surface stats
Review metrics
Technical reviewBest possible solution: Use the existing observed-run completion signal for final-status assertions while retaining the deliberate active-run timeout probe. Do we have a high-confidence way to reproduce the issue? No deterministic local reproduction is recorded. Current main has the one-second wait, and the PR cites two CI timeout failures, while its local baseline runs passed. Is this the best way to solve the issue? Yes. The existing observer joins the work whose completion the tests assert, without changing production behavior or the intentional timeout probe. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 9fe93a204e3b. LabelsLabel 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)
|
|
@clawsweeper re-review — flake-validation tallies (20/20 standalone, 3 clean shard replays, siblings) are in the new "Flake validation" section of the PR body. |
|
🦞👀 Re-review progress:
|
31 upstream commits, including the deterministic wait for the gateway chat.send history test (openclaw#160479), which failed on the previous merge in a file this branch does not touch. No conflicts. No file changed on both sides, and upstream left the generated config baseline, the channel metadata and the lockfile unchanged in this range. build:docker ran in a separate detached checkout of this commit outside the nested node_modules install. Regenerating there changed nothing, so the counts stay at core 2464, channel 3788, plugin 4374 with the same hashes. The three generated-file checks pass there. Upstream deleted seven test files in this range. None of them were added or changed by this branch. Feishu: 106 files and 1853 tests in the extension project, 17 files and 312 tests in the database-workers project. The forwarder test and the routing guards pass, 1981 tests. tsgo:core, tsgo:extensions, tsgo:extensions:test, tsgo:test:root, the line-cap and assertion-safety ratchets against upstream/main, oxlint and oxfmt on the 43 changed code files all pass. check:max-lines-ratchet reports its line counts OK but fails the OPENCLAW_* environment variable budget at 484 against 483. Clean upstream 741c9cb fails it with the same count, and this branch adds no new OPENCLAW_* name.
…cally (openclaw#160479) Co-authored-by: VACInc <[email protected]>
Summary
High Level TLDR
Two gateway chat tests finished by calling
agent.waitwith a 1-second real-clock budget after starting achat.sendrun. On loaded CI runners the run can take longer than 1s, soagent.waitreturned{"status":"timeout"}and the test failed even though nothing was wrong. The tests now wait for the observed run to actually drain (waitForAgentRunDrained), then assertagent.waitwithtimeoutMs: 0returnsok. No wall-clock budget left in these assertions.What Problem This Solves
src/gateway/server.chat.gateway-server-chat.test.ts> "chat.send accepts the backing session id returned by chat.history" flakes on CI in PRs that do not touch the file:Root Cause
/context listrun throughchat.send, then callswaitForAgentRunOk(runId). That helper (line ~356) sendsagent.waitwithtimeoutMs = 1_000by default, so the assertion passes only if the run finishes inside 1s of real time.checks-node-changed-compact-large-*,agentic-control-plane-agent-chat) pushes it over 1s, andagent.waitcorrectly reportstimeout.waitForAgentRunDrained(runId). It joins the observed request plus its detached execution and effects viarequestExecution.waitForCompletion(runId), assertsgetActiveGatewayRootWorkCount() === 0, then callsagent.waitwithtimeoutMs: 0. The other started-run tests in this file (idem-img,idem-session-key-1, etc.) already use it. These two call sites were the only ones left on the 1s default.Why This Change Was Made / exact change
waitForAgentRunOk(runId)->waitForAgentRunDrained(runId).chat.sendrun, then a 1sagent.waitafter release), same change. The deliberatetimeoutMs: 40"still active" probe earlier in that test is untouched.Scope boundary
Only the two default-budget
waitForAgentRunOk(runId)call sites. Tests that intentionally exercise timeout behavior (timeoutMs: 0/40probes,expectAgentWaitTimeout) are unchanged.User Impact
None. This is test-only. It removes a CI flake that fails unrelated PRs.
Real behavior proof
Reproduction gap: on clean
mainthe original test passed 5/5 sequentially and 5/5 under 8-way concurrent pressure locally. The 1s overrun reproduces only on loaded CI runners (two independent CI failures above). The fix removes the wall-clock dependency, so it does not rely on reproducing the overrun.After patch (local Linux, Node from the repo toolchain):
What was not tested
Verification
pnpm test src/gateway/server.chat.gateway-server-chat.test.ts --maxWorkers=1: 41/41 pass, wall 55.6s. This includes compile. The change adds no new tests and no timers.node scripts/check-changed.mjs: exit 0 (oxfmt, core test typecheck for the gateway-server graph, lint, dead-export and ratchet guards).Evidence
The CI job links and local run output are above.
Flake validation
This follows the proof bar in
docs/help/testing/writing-tests.md"Flake triage", run on PR head4e71ce7a98in a local Linux worktree. No timeout changes.Root cause, classified per step 2: this is an ordering flake. The assertion ran before the owned completion signal.
agent.waitgot a 1s wall-clock budget instead of joining the observed request, detached execution, and effects. The fix waits on that owned signal (waitForAgentRunDrained).20 standalone runs of the file: 20/20 pass (41/41 tests each)
Wall per run (s): 66.6, 34.9, 31.2, 30.9, 39.0, 39.6, 41.7, 78.8, 47.2, 42.1, 49.0, 39.2, 34.3, 32.0, 32.6, 33.4, 31.0, 31.4, 34.5, 40.5. The spread comes from shard runs executing at the same time as extra host load.
Original shard
agentic-control-plane-agent-chat: 3 clean runs, in recorded plan orderI decoded the exact 59-file group, including its order, config (
test/vitest/vitest.gateway-server.config.ts) and env (OPENCLAW_VITEST_MAX_WORKERS=2), from the failing job'sOPENCLAW_NODE_TEST_GROUPS_GZIP_BASE64. Then I replayed it through the repo shard runner:src/gateway/server.sessions.preview-resolve.test.tsfailed at suite startup (see below)Unrelated failure in run 1:
server.sessions.preview-resolve.test.tsfailed Gateway startup withStartup failed: required secrets are unavailable. Error: Shared-state worker opening path changed(STATE_DATABASE_READ_ADMISSION_INVALIDATED, fromassertOpenClawStateWorkerActorPath). This PR does not touch that file or the state-worker path, and the error did not recur in runs 2 to 4. I'm reporting it here and not hiding it. It needs its own triage.Owner sibling tests: pass
The shard runs above also cover all 59 gateway-server sibling files in this lane.