Skip to content

test(chat): await session and model refresh owners in view model tests - #165171

Merged
steipete merged 2 commits into
mainfrom
steipete/ock-waits-b3
Oct 5, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/ock-waits-b3

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 session-refresh, model-catalog, and history-invalidation tests.

Why This Change Was Made

Follows #165170 (rebased onto main after it landed; patch-identical to the proven head 6df213a). These tests detected product progress with waitUntil, a 15 s wall-clock poll. In CI the whole package runs in one parallel swift test process, and the MainActor carries a large backlog there. Work that needs several MainActor hops outlives the deadline while it is still queued. #163719, #163792, and #165157 fixed the same class. This PR converts the second third of the remaining ChatViewModelTests waits: 64 tests, 121 waits.

Each wait now awaits its owner or an arrival signal, so a backlog can delay it but cannot expire it:

  • Session and model refreshes. A current-session sessions.changed event now returns the model-catalog refresh Task it already starts. The metadata and model-selection event returns one Task that settles both its model refresh and its swarm-capability refresh. Both Tasks still start exactly as before, in the same order.
  • Settings lane, bootstrap, and send. Tests await waitForPendingSessionSettings, bootstrapTask, and the send() Task.
  • Request arrivals. These use transport.waitForState and the counter wait(until:) from test(chat): await send and run-event owners instead of wall-clock polls #165157.
  • No reachable owner. These use 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 −1 line: two adjacent guards in appendFinalChatMessageIfPresent are merged.

Evidence

Deterministic saturation probe, the same method as #163792 and #165157. 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 '<this batch's tests>|AAMainActorSaturationProbe/' process, with a private HOME, CFFIXED_USER_HOME, OPENCLAW_STATE_DIR, and TMPDIR.

  • Before, on the base (a44817c): 28 of the 64 tests fail, with 61 issues, e.g. invalidation history read starts, sessions loaded, committed message recovers after invalidation, and capability lease acquisition started.
  • After, on this head: all 64 pass under the identical flood (Test run with 65 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:

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, #165157

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

@steipete
steipete marked this pull request as ready for review October 4, 2026 22:46
@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, 4:34 AM ET / 08:34 UTC (Revision 4).

ClawSweeper review

What this changes

The PR replaces native chat test polling with completion and arrival signals, and returns handles for existing session and model refresh work.

Merge readiness

✅ Ready for maintainer review

This remains useful work that current main does not contain. No actionable introduced defect was found, and the prior conflict, timing, and shard-policy concerns are resolved by the current merge result and recorded evidence.

Priority: P2
Reviewed head: e988b1205d480b189f1362bad128dd020acc3e83

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, sound synchronization repair with convincing saturation evidence and resolved prior review concerns.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Recorded native Swift saturation output exercises the changed synchronization in the actual test entrypoint: 28 tests fail before conversion and all 64 pass afterward under the identical MainActor flood. The introduced test lines and production hunks match the previously proven batch after rebase; standalone and sibling runs supplement that evidence, and the hourly-main shard substitution is documented. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): Recorded native Swift saturation output exercises the changed synchronization in the actual test entrypoint: 28 tests fail before conversion and all 64 pass afterward under the identical MainActor flood. The introduced test lines and production hunks match the previously proven batch after rebase; standalone and sibling runs supplement that evidence, and the hourly-main shard substitution is documented. No stored-data contract changes.
Evidence reviewed 9 items Pinned production changes preserve existing operations: The introduced delta starts model and Swarm refreshes in the existing order and joins their completion handles; current-session patch events return the existing model-refresh task. The combined final-message guard is equivalent to the previous guards.
Tests retain their observable assertions: Read the complete introduced test patch. Completion waits are followed by the previous state assertions; arrival counts use lower-bound waits followed by exact expectations, and stale settings tests capture the original target before replacement.
Current main still needs this batch: Fetched main retains the committed-message recovery poll and the unjoined metadata refresh implementation. Merged sibling PRs cover different batches rather than superseding these changes; the supplied latest release predates this October work.
Findings None None.
Security None None.

How this fits together

OpenClaw's shared Apple chat view model receives Gateway events and refreshes conversation history, model choices, and capabilities. These tests verify the resulting state after the responsible asynchronous work finishes.

flowchart TD
  A[Gateway events] --> B[Native chat view model]
  B --> C[Session and model refreshes]
  C --> D[Conversation and capability state]
  C --> E[Completion handles]
  F[Test actions and arrival signals] --> B
  E --> G[Test assertions]
  D --> G
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Other -128. Total -128 across 2 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 2 444 572 -128
Total 2 444 572 -128

Review metrics

Metric Value Why it matters
Standalone suite cost 347 tests; 1.15–1.47 seconds of test time; 20 clean runs The recorded duration addresses the previous cost-evidence request without adding a multi-minute saturation test to recurring CI.

Technical review

Best possible solution:

Keep asynchronous work owned by the existing refresh tasks and let tests assert outcomes after completion without wall-clock polling.

Do we have a high-confidence way to reproduce the issue?

Yes: current source uses 15-second polling deadlines around queued MainActor work, and the recorded saturation run demonstrates the failure mechanism. This read-only review did not execute the native tests.

Is this the best way to solve the issue?

Yes: awaiting existing work owners and retaining outcome assertions follows the established merged pattern and avoids increasing timeout budgets or adding retries.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 6272c4760b9d.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. Recorded native Swift saturation output exercises the changed synchronization in the actual test entrypoint: 28 tests fail before conversion and all 64 pass afterward under the identical MainActor flood. The introduced test lines and production hunks match the previously proven batch after rebase; standalone and sibling runs supplement that evidence, and the hourly-main shard substitution is documented. No stored-data contract changes.

Label justifications:

  • P2: This is a bounded native test-reliability repair with no reported user-visible behavior change.
  • 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. Sufficient (terminal): Recorded native Swift saturation output exercises the changed synchronization in the actual test entrypoint: 28 tests fail before conversion and all 64 pass afterward under the identical MainActor flood. The introduced test lines and production hunks match the previously proven batch after rebase; standalone and sibling runs supplement that evidence, and the hourly-main shard substitution is documented. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. Recorded native Swift saturation output exercises the changed synchronization in the actual test entrypoint: 28 tests fail before conversion and all 64 pass afterward under the identical MainActor flood. The introduced test lines and production hunks match the previously proven batch after rebase; standalone and sibling runs supplement that evidence, and the hourly-main shard substitution is documented. No stored-data contract changes.

Evidence

What I checked:

  • Pinned production changes preserve existing operations: The introduced delta starts model and Swarm refreshes in the existing order and joins their completion handles; current-session patch events return the existing model-refresh task. The combined final-message guard is equivalent to the previous guards. (apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatViewModel+TransportEvents.swift:54, e988b1205d48)
  • Tests retain their observable assertions: Read the complete introduced test patch. Completion waits are followed by the previous state assertions; arrival counts use lower-bound waits followed by exact expectations, and stale settings tests capture the original target before replacement. (apps/shared/OpenClawKit/Tests/OpenClawKitTests/ChatViewModelTests.swift:9365, e988b1205d48)
  • Current main still needs this batch: Fetched main retains the committed-message recovery poll and the unjoined metadata refresh implementation. Merged sibling PRs cover different batches rather than superseding these changes; the supplied latest release predates this October work. (apps/shared/OpenClawKit/Tests/OpenClawKitTests/ChatViewModelTests.swift:9470, 6272c4760b9d)
  • Recorded before-and-after saturation evidence: The captured PR body reports 28 of 64 tests failing before the conversion under a 16,000-task MainActor flood, then all 64 passing under the identical 420-second flood. It also records 20 standalone passes, 347 tests per run taking 1.15–1.47 seconds, and 552 passing sibling tests. These observations exercise the changed test synchronization through the native Swift test entrypoint. (6df213acea9f)
  • Proof survives the rebase: Compared the GitHub-recorded old batch delta against the local pinned introduced delta. All 1,003 added and removed test lines match exactly, with normalized SHA-256 d354417a6656e4db331fbd22aa7950a94abae373e1296f28c0fc939ab5cc3e58. The old production delta retrieved through GitHub also matches the current production hunks. Local inspection of the earlier commit failed because required objects were unavailable; GitHub read APIs supplied the comparison. (apps/shared/OpenClawKit/Tests/OpenClawKitTests/ChatViewModelTests.swift, e988b1205d48)
  • Prior merge conflict is resolved: The verified test merge has the pinned base and head parents, and its production result contains precisely the introduced refresh-handle changes. Live GitHub reports the same head as mergeable; pending routine checks do not establish a patch defect. (apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatViewModel+TransportEvents.swift:54, bb2e3daaabf5)

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:52:27.826Z sha 6df213a :: needs changes before merge. :: none
  • reviewed 2026-10-04T23:20:45.911Z sha 6df213a :: needs changes before merge. :: none
  • reviewed 2026-10-05T08:22:20.233Z sha 6df213a :: blocked before merge. :: none

@steipete
steipete force-pushed the steipete/ock-waits-b2 branch from 5b45958 to 2bdf553 Compare October 5, 2026 05:15
Base automatically changed from steipete/ock-waits-b2 to main October 5, 2026 08:15
Replace 121 polls in 64 tests with task, settings-queue, fake-arrival,
and Observation completion signals while retaining their assertions.
Return existing metadata and model refresh tasks with zero net source growth.
@steipete
steipete force-pushed the steipete/ock-waits-b3 branch from 6df213a to e988b12 Compare October 5, 2026 08:28
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Oct 5, 2026
@steipete
steipete merged commit 3b8ccf8 into main Oct 5, 2026
80 of 81 checks passed
@steipete
steipete deleted the steipete/ock-waits-b3 branch October 5, 2026 08:52
@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
openclaw#165171)

* test(chat): replace B3 wall-clock polls with completion signals

Replace 121 polls in 64 tests with task, settings-queue, fake-arrival,
and Observation completion signals while retaining their assertions.
Return existing metadata and model refresh tasks with zero net source growth.

* test(chat): settle both metadata refreshes through one handle
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. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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