Repository navigation
test(chat): await settling tasks instead of wall-clock polling in view model tests - #163792
Conversation
…w model tests ChatViewModelTests and ChatViewModelSessionActionTests detected product progress with 15 s wall-clock waits. Under a full parallel package run the MainActor backlog makes multi-hop work outlive those deadlines while still queued, so macos-swift (packages) flaked. Request-start waits now await the fakes' own arrival signals, completion waits await bootstrapTask, questionRefreshRetryTask, or a settling Task that handleTransportEvent, scheduleProgressCardFetch, and handleQuestionEvent now return, and the two cases no handle reaches use an Observation-driven wait. The waitForForkStart, waitForBranchSwitchActivityToClear, and waitForBranchReload deadline helpers are removed. Production code is net -8 lines: the return plumbing is funded by folding three repeated current-session guards in handleSessionsChangedEvent into one predicate.
|
🦞👀 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 3, 2026, 2:24 AM ET / 06:24 UTC (Revision 4). ClawSweeper reviewWhat this changesThe native chat tests await request signals and reconciliation tasks instead of wall-clock polling, with internal completion handles exposed by the chat view model. Merge readiness✅ Ready for maintainer review This remains useful work: current main still contains the affected deadline-based waits. No introduced correctness defect was found, and the supplied mergeability evidence resolves the previous conflict blocker. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw's shared Apple chat view model receives Gateway events and updates transcripts, questions, and progress cards. Its tests now synchronize with those operations before checking the resulting state. flowchart TD
A[Gateway events] --> B[Native chat view model]
B --> C[Session and freshness checks]
C --> D[Reconciliation tasks]
D --> E[Updated chat state]
F[Test request gates] --> G[Await completion]
D --> G
G --> H[Behavior assertions]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceOther -140. Total -140 across 6 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Keep synchronization at the existing task and request owners, preserving behavioral assertions without runner-speed deadlines. Do we have a high-confidence way to reproduce the issue? Yes, the current-main deadline waits and sequential MainActor work establish a clear source-backed failure mechanism, supported by the captured saturation results. This reviewer did not execute a reproduction. Is this the best way to solve the issue? Yes, awaiting existing completion owners and explicit request signals is a focused repair that preserves assertions and avoids extending timeouts or adding retries. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against c9381f9f0faf. 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.
|
…w model tests (openclaw#163792) ChatViewModelTests and ChatViewModelSessionActionTests detected product progress with 15 s wall-clock waits. Under a full parallel package run the MainActor backlog makes multi-hop work outlive those deadlines while still queued, so macos-swift (packages) flaked. Request-start waits now await the fakes' own arrival signals, completion waits await bootstrapTask, questionRefreshRetryTask, or a settling Task that handleTransportEvent, scheduleProgressCardFetch, and handleQuestionEvent now return, and the two cases no handle reaches use an Observation-driven wait. The waitForForkStart, waitForBranchSwitchActivityToClear, and waitForBranchReload deadline helpers are removed. Production code is net -8 lines: the return plumbing is funded by folding three repeated current-session guards in handleSessionsChangedEvent into one predicate.
What Problem This Solves
Fixes:
macos-swift (packages)intermittently fails with timeouts inChatViewModelTestsandChatViewModelSessionActionTestswhen the full OpenClawKit package runs its tests in parallel on a loaded runner. A local stress run of theChatfilter hit 21 such waits: question, Swarm, progress-card, and history "request starts" waits, plus branch switch, rewind, and fork start signals.User Impact
No user-visible change. PRs stop picking up a red
macos-swift (packages)job, and its reruns, from these suites.Why This Change Was Made
This is the follow-up to #163719, for the same flake class. These tests detected product progress with
waitUntil, which has a 15 s wall-clock deadline, or with awaitForForkStartrace against a 15 s sleep. Under a full parallel package run the MainActor carries a large backlog. Any wait whose condition needs several sequential MainActor hops expires while the product work is still queued, not stuck.Each listed wait now awaits a deterministic signal instead:
SessionSubscribeGate.waitUntilBlocked(), a newQuestionListGate.waitUntilWaiting(), orSessionActionCompletionGate.waitUntilStarted()without its sleep race. An ungatedsessions.listuses a non-blocking stream signal.waitForForkStart,waitForBranchSwitchActivityToClear, andwaitForBranchReloadare deleted. ThewaitForForkStartchange also converts four non-listed call sites that shared the helper.bootstrapTask(including the cancelled bootstrap it captured beforerefresh()),questionRefreshRetryTaskuntil the retry chain settles, or the test's ownTask.handleTransportEventnow returns the Task that settles the event's transcript or question reconciliation, in the same way the provider wizard actions do. That covers route-change, reconnect, and seqGap recovery, remote rewind and branch-switch reconciliation, and question events.scheduleProgressCardFetchandhandleQuestionEventreturn their fetch and refresh Tasks. The production event listener discards the value.event listener does not retain discarded view model. That test now probes delivery with a disconnect instead of a reconnect. The reconnect fan-out legitimately retains the model while its tasks run, so the old test was timing that drain, not listener retention.No timeouts were lengthened and no retries were added. Several assertions are now stricter, because they run after the owning work has settled instead of racing it. For example, the stale bootstrap is awaited before the "stale history is ignored" check.
Production code is net −8 lines. The return plumbing is funded by folding the three repeated
matchesCurrentSessionKey(incoming:agentId:current:)guards inhandleSessionsChangedEventinto one local predicate, with identical semantics. Tests are net −132 lines.Evidence
Deterministic saturation probe. A temporary suite, not committed, floods the MainActor with N yielding tasks that each spin 1 ms. Each MainActor hop then waits about N ms. The probe runs in the same filter as the target tests, with
swift test --package-path apps/shared/OpenClawKit --skip-build --disable-sandbox --filter '<tests>|<probe>'. Each run used a private HOME, CFFIXED_USER_HOME, OPENCLAW_STATE_DIR, and TMPDIR.main:ChatViewModelTests: 11 of the 12 listed tests fail with 12 issues; the parameterized route test fails both cases. Each fails at its listed "request starts" wait, for examplequestion get request,older Swarm capability request starts,first bootstrap history request is in flight,health inspected the current progress capability, andevent listener receives health.Swarm child lifecycle event still triggers canonical session refreshpassed narrowly at 30 s, because its request needs only one hop.ChatViewModelSessionActionTests:remote branch switch refreshes current transcript and branches onlyfails atunlocked.ChatViewModelTestscases and all 9ChatViewModelSessionActionTestscases pass, and every test finishes while the flood is still running. The suites took 297 s and 313 s inside a 420 s flood. The same tests unloaded take about 0.03 s.waitForForkStarttests from the stress run do not fail under any probe I could build. I tried the MainActor flood and a global-pool flood withLIBDISPATCH_COOPERATIVE_POOL_STRICT=1at about 10 s and about 25 s per hop. The helper's TaskGroup children inherit MainActor isolation, so its 15 s sleep starts behind the same backlog as the product path and never wins the race. Only the CPU-starved stress run let the sleep win. The fix removes that race outright; the started stream still controls ordering.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:
ChatViewModelTestsran 339 tests in about 1.2 s, andChatViewModelSessionActionTestsran 44 tests in about 0.1 s.Chatfilter, skippingChatMathBlockViewTests,ChatLinkPreviewRenderingTests, andChatMarkdownBlockSegmenterTests. Each run passed 1,431 tests in 107 suites in 10–12 s. This is the local stand-in for the original shard.macos-swift (packages)full-packageswift test --parallelstep, in run 37098830253, attempts 1–3, with the two reruns done by maintainer decision. Each run passed 2,167 tests in 183 suites, in 34.7 s, 137.7 s, and 144.8 s. The slower attempts ran on a loaded runner, which is the condition that used to trip these waits.openclaw/ci-gateis green on attempt 3.--filter ChatViewModelcovers 10 suites, and 528 of 528 passed.Checks.
swiftformat --lintandswiftlint --strictwith the iOS config are clean for the four touched sources. The test files are outside the configured lint scope.git diff --checkis clean. I did not run the full OpenClawKit suite locally, because it reaches the Keychain through the GenericPasswordKeychainStore and GatewayTLS 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