Repository navigation
test(chat): await outbox owners instead of wall-clock polling in session action tests - #165068
Conversation
…ion action tests ChatViewModelSessionActionTests still detected outbox restore, outbox delivery, and committed-session discovery with 15 s wall-clock waits. Under a full parallel package run the MainActor backlog makes that multi-hop work outlive the deadline while still queued, so macos-swift (packages) can flake. Restore waits now await the Task that restoreOutboxMessages returns. The delivery wait holds the fake send at an arrival gate, then awaits the in-flight flush pass through outboxFlushTask, which replaces the isFlushingOutbox flag with the pass's own handle (same coalescing, nil while idle). The session-list wait uses a fake arrival gate. The waitForOutboxRestore and waitForSend helpers are removed. Production code is net -1 line.
|
🦞👀 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, 5:57 PM ET / 21:57 UTC (Revision 2). ClawSweeper reviewWhat this changesNative chat session-action tests now await outbox task completion and transport arrival signals instead of polling wall-clock deadlines. Merge readiness✅ Ready for maintainer review The PR remains useful and has no blocking findings. The previously requested three original-shard runs now pass on the reviewed head, satisfying the outstanding flake-validation requirement. Priority: P2 Review scores
Verification
How this fits togetherThe native chat outbox restores queued messages and delivers them through the Gateway transport. Session-action tests exercise that owner before checking rewind, fork, and delivery outcomes. flowchart TD
A[Queued chat messages] --> B[Outbox restore]
B --> C[Native chat view model]
C --> D[Single active delivery pass]
D --> E[Gateway transport]
E --> F[Recorded delivery state]
B --> G[Test completion waits]
F --> G
Before mergeNone. Agent review detailsSecurityNone. PR surfaceOther -15. Total -15 across 6 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep test synchronization tied to the existing outbox owners and preserve assertions on the completed transport and durable-state outcomes. Do we have a high-confidence way to reproduce the issue? Yes, source establishes the deadline-versus-queued-work mechanism, and the PR records a matching before/after MainActor saturation reproduction; this review did not execute it. Is this the best way to solve the issue? Yes, awaiting existing task completion and transport arrival signals removes scheduler-dependent deadlines while preserving the original behavioral assertions. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a58fe52a98b5. 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)
|
|
Merged via squash.
|
…ion action tests (openclaw#165068) ChatViewModelSessionActionTests still detected outbox restore, outbox delivery, and committed-session discovery with 15 s wall-clock waits. Under a full parallel package run the MainActor backlog makes that multi-hop work outlive the deadline while still queued, so macos-swift (packages) can flake. Restore waits now await the Task that restoreOutboxMessages returns. The delivery wait holds the fake send at an arrival gate, then awaits the in-flight flush pass through outboxFlushTask, which replaces the isFlushingOutbox flag with the pass's own handle (same coalescing, nil while idle). The session-list wait uses a fake arrival gate. The waitForOutboxRestore and waitForSend helpers are removed. Production code is net -1 line.
What Problem This Solves
Fixes:
macos-swift (packages)can fail with timeouts inChatViewModelSessionActionTestswhen the full OpenClawKit package runs its tests in parallel on a loaded runner. This is the last suite file in this flake class from #163719 and #163792 that still had wall-clock deadlines.User Impact
No user-visible change. PRs stop picking up a red
macos-swift (packages)job from these session-action outbox tests.Why This Change Was Made
Three waits remained in
ChatViewModelSessionActionTests.waitForOutboxRestoreandwaitForSendwereTask.yieldpolls with a 15 sContinuousClockdeadline. The third was onewaitUntilon the committed-sessionsessions.listrefresh. Under a full parallel package run the MainActor carries a large backlog. Outbox restore and branch-reconcile-then-deliver each need several sequential MainActor hops, so the deadline expires while the product work is still queued.Each wait now awaits its owner or a fake arrival signal:
restoreOutboxMessages(session:)now returns the Task it already spawned, and production callers discard it. The two rewind/fork tests await that Task, then asserthasRestoredOutboxMessagesandhasPendingOutboxCommandsForCurrentSession. Those are the same conditions the poll checked, so a restore that bails early now fails as an expectation instead of a timeout.sendMessageat aSessionActionCompletionGate. Once the send arrives, the test takes the in-flight pass fromoutboxFlushTask, releases the gate, and awaits it. That also closes a latent race: the old poll returned on send arrival and then read the.awaitingConfirmationstatus that the flush writes only after the send returns.outboxFlushTaskreplaces theisFlushingOutboxflag. It stores the flush pass's own handle and is nil while idle. Coalescing and ordering are unchanged. Five existing test reads of the flag are renamed mechanically.listSessionsnow has an arrival gate, and the test awaits it instead of polling the request count.No timeouts were lengthened and no retries were added.
waitForOutboxRestoreandwaitForSendare deleted. The file now has noContinuousClockorwaitUntilleft. Production code is net −1 line.The shared
loadAndWaitBootstraphelper inChatViewModelTestswas already converted toawait vm.bootstrapTaskonmain(35f6057), so it is not part of this diff.Evidence
Deterministic saturation probe. This is the same method as #163792. A temporary suite, not committed, floods the MainActor with 16,000 yielding tasks that each spin 1 ms, which puts one MainActor hop past 15 s. It holds the flood for 420 s and is named so that it starts first. It ran in the same
swift test --package-path apps/shared/OpenClawKit --skip-build --disable-sandbox --filter '<the 4 tests>|<probe>'process, with a private HOME, CFFIXED_USER_HOME, OPENCLAW_STATE_DIR, and TMPDIR.rewind waits for current session outbox confirmationandfork at message waits for current session outbox confirmationfail atExpectation failed: await self.waitForOutboxRestore(viewModel).rewind list failure clears lease and later reconcile deliversfails atawait self.waitForSend(transport), plus its three follow-on expectations, because delivery had not happened yet.new session completion preserves attachment ownership acquired during creationpassed at base after 144 s. Its request needs only one queued hop, so the probe did not reproduce that wait. It is converted anyway, because it is the same 15 s deadline over a queued Task.Flake-fix proof bar (writing tests, Flake triage step 4), all on this head with a private HOME, CFFIXED_USER_HOME, OPENCLAW_STATE_DIR, and TMPDIR:
ChatViewModelSessionActionTests. Each passed 44 tests in about 0.3–0.6 s, and up to 7 s while another suite ran alongside.ChatViewModel*TestsandNativeConversation*Testssuite, 552 tests in 15 suites, passed in 4.4 s. This set covers all callers of the renamed flag and of restore.macos-swift (packages)full-packageswift test --parallelstep in run 37230087479, attempts 1–3. The two reruns follow the maintainer's chosen route for this proof bar, as in test(chat): await settling tasks instead of wall-clock polling in view model tests #163792. Each passed 2,259 tests in 191 suites, in 31.5 s, 125.612 s, and 131.195 s.Checks.
git diff --checkis clean, and every added line fits the 120-column width. These test andOpenClawChatUIsource paths are outside the configured SwiftLint/SwiftFormat lint scope. I did not run the full OpenClawKit suite locally, because it reaches the Keychain through its keychain fixtures.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 waits has a deadline left.
Related: #163719, #163792