Skip to content

test(chat): await send and run-event owners instead of wall-clock polls - #165157

Merged
steipete merged 3 commits into
mainfrom
steipete/ock-waits-b1-send-helpers
Oct 5, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/ock-waits-b1-send-helpers

Conversation

@steipete

@steipete steipete commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: macos-swift (packages) intermittently fails with Timeout waiting for: … in ChatViewModelTests when 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

ChatViewModelTests detects product progress with waitUntil, a 15 s wall-clock poll. In CI the whole package runs in one parallel swift test process. 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:

  • The send owner. OpenClawChatViewModel.send() now returns the Task it already spawned (@discardableResult). Production callers ignore it. sendMessageAndEmitFinal awaits it, and tests that polled for post-send state (pending run starts, local run owned) await it too.
  • Run-event refreshes. handleChatEvent, handleAgentEvent, and the agent lifecycle handler now return the history-refresh Task they already started, and handleTransportEvent passes 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 through handleTransportEvent and await that Task.
  • Request arrivals. The fake transport state, AsyncCounter, and AsyncStringRecorder gain a deadline-free wait(until:). It resumes on the first recorded change that satisfies the condition. waitForLastSentRunId and waitForSentRunId use it, and so do the "patch starts" and "refresh starts" waits. ToolActivityRecorder gets the same for tool-activity callbacks.
  • No reachable owner. The few remaining cases, such as streaming text from an emitted delta and a seq-gap marker, use the existing Observation-driven 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 in loadSlashCommandsIfNeeded, 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.

  • Before, on the base (a44817c): 29 of the 40 tests fail, with 33 issues. 22 of them are Timeout waiting for: transport send called, the shared send helpers' poll. The rest are request-start and refresh waits such as abortRun called, older model patch starts, lifecycle end refresh clears pending run, and pre-gap transient state.
  • After, on this head: all 40 pass under the identical flood (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:

  • 20 of 20 clean standalone runs of ChatViewModelTests.swift (ChatViewModelTests + ChatViewModelSessionManagementTests, 347 tests, 1.15–1.90 s of test time each (median 1.20 s)).
  • Owner siblings: every ChatViewModel* and NativeConversation* suite, 552 tests in 15 suites, passed.
  • Original shard: three clean runs of CI's macos-swift (packages) full-package swift test --parallel on exact head 0185f741e9920c797e94a6cd792684a8031e7b56: attempt 1 (7m38s), attempt 2 (12m06s), and attempt 3 (12m12s), alongside macos-swift (tests).
  • Codex autoreview at the P2 threshold reported no actionable findings.

Checks. git diff --check is 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

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

@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 5, 2026, 12:52 AM ET / 04:52 UTC (Revision 4).

ClawSweeper review

What this changes

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

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, behavior-preserving repair has strong scoped flake evidence and now satisfies the previously missing shard-validation requirement.
Proof confidence 🦞 diamond lobster (5/6) Not applicable: The supplied repository state identifies a member-authored internal test-reliability PR, so the external-contributor runtime gate does not apply. Captured saturation results exercise the changed native chat test entrypoints, and three exact-head package jobs corroborate recovery; 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 supplied repository state identifies a member-authored internal test-reliability PR, so the external-contributor runtime gate does not apply. Captured saturation results exercise the changed native chat test entrypoints, and three exact-head package jobs corroborate recovery; no stored-data contract changes.
Evidence reviewed 7 items Pinned introduction reviewed: Reviewed the merge-base-to-head delta, rather than endpoint drift. Production changes return existing tasks and preserve admission guards, event filtering, task scheduling, and refresh operations.
Completion and arrival semantics: The shared send helper awaits the send owner before asserting transport and pending-run facts. Recorded-state waiters register and evaluate conditions within their actor; converted gated tests release their gates before awaiting completion.
Current main still needs this batch: Fetched main retains the void-returning send method and polling in the shared send helpers. Earlier merged batches address other waits and do not supersede this contribution; no fixing release was established.
Findings None None.
Security None None.

How this fits together

OpenClaw'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
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Other -2. Total -2 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 3 610 612 -2
Total 3 610 612 -2

Review metrics

Metric Value Why it matters
Original shard validation 3 of 3 successful runs on the reviewed head The additional runs satisfy the repository's flake-validation requirement and resolve the prior review blocker.

Technical review

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded native-test reliability repair with no demonstrated user-facing runtime regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster 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 supplied repository state identifies a member-authored internal test-reliability PR, so the external-contributor runtime gate does not apply. Captured saturation results exercise the changed native chat test entrypoints, and three exact-head package jobs corroborate recovery; 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 (3 earlier review cycles)
  • reviewed 2026-10-04T22:18:50.111Z sha 0185f74 :: needs changes before merge. :: none
  • reviewed 2026-10-04T22:31:28.582Z sha 0185f74 :: needs changes before merge. :: none
  • reviewed 2026-10-04T23:05:10.486Z sha 0185f74 :: needs changes before merge. :: none

@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 6, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL 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