Repository navigation
test(chat): await send and run-event owners instead of wall-clock polls - #165157
Conversation
send() now returns the Task that validates and delivers the captured draft, so tests can await the send owner. The fake chat transport state, AsyncCounter, and AsyncStringRecorder gain wait(until:) waiters that resume on the first recorded change satisfying them. The shared send helpers use them instead of 15 s wall-clock polls.
Replace 104 wall-clock waits in 40 tests with owner completion, fake arrival signals, and observed state. Return existing chat and lifecycle refresh tasks without changing behavior.
|
🦞👀 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 5, 2026, 12:52 AM ET / 04:52 UTC (Revision 4). ClawSweeper reviewWhat this changesThe PR replaces native chat test polling with task completion and recorded-state signals, returning existing send and event-refresh tasks so tests can await them. Merge readiness✅ Ready for maintainer review The PR remains useful and has no actionable findings. Three successful original-shard runs on the reviewed head resolve the previous validation blocker; no additional required action remains. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw's shared native chat view model receives composer submissions and Gateway events, then updates conversation history and run activity. These tests exercise that owner and its transport boundary. flowchart TD
A[Composer submission] --> C[Native chat view model]
B[Gateway events] --> C
C --> D[Send and history tasks]
D --> E[Conversation and run state]
D --> F[Test completion signals]
E --> G[Behavior assertions]
F --> G
Before mergeNone. Agent review detailsSecurityNone. PR surfaceOther -2. Total -2 across 3 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep native chat assertions synchronized with their existing work owners and arrival signals, preserving production scheduling and behavior. Do we have a high-confidence way to reproduce the issue? Yes: current-main polling has a fixed deadline over queued MainActor work, and the captured before/after saturation results demonstrate that mechanism. The reviewer did not execute the reproduction. Is this the best way to solve the issue? Yes: awaiting existing task owners and recorded arrivals removes scheduler-dependent deadlines while retaining behavior assertions and established production scheduling. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 48c08e6ccba6. 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
History |
|
Merged via squash.
|
…ls (openclaw#165157) * test(chat): add deadline-free waits over recorded test state send() now returns the Task that validates and delivers the captured draft, so tests can await the send owner. The fake chat transport state, AsyncCounter, and AsyncStringRecorder gain wait(until:) waiters that resume on the first recorded change satisfying them. The shared send helpers use them instead of 15 s wall-clock polls. * test(chat): await send and event completion in view model tests Replace 104 wall-clock waits in 40 tests with owner completion, fake arrival signals, and observed state. Return existing chat and lifecycle refresh tasks without changing behavior. * test(chat): drop assertions repeated by observed waits
What Problem This Solves
Fixes:
macos-swift (packages)intermittently fails withTimeout waiting for: …inChatViewModelTestswhen the full OpenClawKit package runs its tests in parallel on a loaded runner.User Impact
No user-visible change. PRs stop picking up a red
macos-swift (packages)job from the chat view model send and run-event tests.Why This Change Was Made
ChatViewModelTestsdetects product progress withwaitUntil, a 15 s wall-clock poll. In CI the whole package runs in one parallelswift testprocess. The MainActor carries a large backlog there, so a send, an event refresh, or a bootstrap that needs several MainActor hops outlives the deadline while it is still queued. #163719 and #163792 fixed the same class elsewhere. About 470 such waits remain in this file. This PR converts the shared send helpers and the 40 tests that use them (104 waits), and adds the small facilities the follow-up batches reuse.Each wait now awaits its owner or an arrival signal, so a backlog can delay it but cannot expire it:
OpenClawChatViewModel.send()now returns the Task it already spawned (@discardableResult). Production callers ignore it.sendMessageAndEmitFinalawaits it, and tests that polled for post-send state (pending run starts,local run owned) await it too.handleChatEvent,handleAgentEvent, and the agent lifecycle handler now return the history-refresh Task they already started, andhandleTransportEventpasses it through, which is the test(chat): await settling tasks instead of wall-clock polling in view model tests #163792 shape. Tests that waited for a final, error, aborted, seq-gap, or lifecycle refresh to land now deliver the event throughhandleTransportEventand await that Task.AsyncCounter, andAsyncStringRecordergain a deadline-freewait(until:). It resumes on the first recorded change that satisfies the condition.waitForLastSentRunIdandwaitForSentRunIduse it, and so do the "patch starts" and "refresh starts" waits.ToolActivityRecordergets the same for tool-activity callbacks.waitForObservedState.After awaiting an owner, each test asserts the condition the old poll checked, so a regression fails as an expectation instead of timing out. No timeouts were lengthened and no retries were added. Production code is net 0 lines: the attribute line on
send()is funded by merging two adjacent guards inloadSlashCommandsIfNeeded, and the event handlers are pure return-plumbing.The remaining ChatViewModelTests waits and the smaller ChatViewModel suites follow in stacked PRs that reuse these facilities.
Evidence
Deterministic saturation probe. This uses the same method as #163792 and #165068. A temporary suite, not committed, floods the MainActor with 16,000 yielding tasks that each spin 1 ms. That puts one MainActor hop past 15 s. The flood is held 420 s, and the suite is named so it starts first. It runs in the same
swift test --package-path apps/shared/OpenClawKit --skip-build --disable-sandbox --filter '<the 40 tests>|AAMainActorSaturationProbe/'process, with a private HOME, CFFIXED_USER_HOME, OPENCLAW_STATE_DIR, and TMPDIR.Timeout waiting for: transport send called, the shared send helpers' poll. The rest are request-start and refresh waits such asabortRun called,older model patch starts,lifecycle end refresh clears pending run, andpre-gap transient state.Test run with 41 tests in 2 suites passed after 420.0 seconds).Flake-fix proof bar (writing tests, Flake triage step 4), on this head with a private HOME, CFFIXED_USER_HOME, OPENCLAW_STATE_DIR, and TMPDIR:
ChatViewModelTests.swift(ChatViewModelTests+ChatViewModelSessionManagementTests, 347 tests, 1.15–1.90 s of test time each (median 1.20 s)).ChatViewModel*andNativeConversation*suite, 552 tests in 15 suites, passed.macos-swift (packages)full-packageswift test --parallelon exact head0185f741e9920c797e94a6cd792684a8031e7b56: attempt 1 (7m38s), attempt 2 (12m06s), and attempt 3 (12m12s), alongsidemacos-swift (tests).Checks.
git diff --checkis clean. I did not run the full OpenClawKit suite locally, because its keychain fixtures reach the login keychain on this Mac.Not committed as a regression test. The repro needs a sustained multi-minute MainActor flood, which is far over the test cost budget. The structural guard is that none of the converted tests has a deadline left.
Related: #163719, #163792, #165068