Skip to content

test(chat): await outbox owners instead of wall-clock polling in session action tests - #165068

Merged
steipete merged 1 commit into
mainfrom
steipete/zealous-easley-9956f5
Oct 4, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/zealous-easley-9956f5

Conversation

@steipete

@steipete steipete commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: macos-swift (packages) can fail with timeouts in ChatViewModelSessionActionTests when 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. waitForOutboxRestore and waitForSend were Task.yield polls with a 15 s ContinuousClock deadline. The third was one waitUntil on the committed-session sessions.list refresh. 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:

  • Outbox restore. restoreOutboxMessages(session:) now returns the Task it already spawned, and production callers discard it. The two rewind/fork tests await that Task, then assert hasRestoredOutboxMessages and hasPendingOutboxCommandsForCurrentSession. Those are the same conditions the poll checked, so a restore that bails early now fails as an expectation instead of a timeout.
  • Outbox delivery after branch reconcile. The send happens in a flush pass started by the reconcile Task, which the test cannot reach directly. The fake transport now holds sendMessage at a SessionActionCompletionGate. Once the send arrives, the test takes the in-flight pass from outboxFlushTask, releases the gate, and awaits it. That also closes a latent race: the old poll returned on send arrival and then read the .awaitingConfirmation status that the flush writes only after the send returns.
  • outboxFlushTask replaces the isFlushingOutbox flag. 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.
  • Committed-session discovery. The fake listSessions now has an arrival gate, and the test awaits it instead of polling the request count.

No timeouts were lengthened and no retries were added. waitForOutboxRestore and waitForSend are deleted. The file now has no ContinuousClock or waitUntil left. Production code is net −1 line.

The shared loadAndWaitBootstrap helper in ChatViewModelTests was already converted to await vm.bootstrapTask on main (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.

  • Before, on the base (7ecc80a): 3 of 4 tests fail with 6 issues.
    • rewind waits for current session outbox confirmation and fork at message waits for current session outbox confirmation fail at Expectation failed: await self.waitForOutboxRestore(viewModel).
    • rewind list failure clears lease and later reconcile delivers fails at await self.waitForSend(transport), plus its three follow-on expectations, because delivery had not happened yet.
    • new session completion preserves attachment ownership acquired during creation passed 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.
  • After, on this head: all 4 tests (5 cases) pass under the identical flood. The delivery test finished at 420.3 s, as the backlog drained. That is far past any deadline it could have had, and the handle wait simply outlasts it.

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:

  • 20 of 20 clean standalone runs of ChatViewModelSessionActionTests. Each passed 44 tests in about 0.3–0.6 s, and up to 7 s while another suite ran alongside.
  • Owner sibling tests: every ChatViewModel*Tests and NativeConversation*Tests suite, 552 tests in 15 suites, passed in 4.4 s. This set covers all callers of the renamed flag and of restore.
  • 3 of 3 clean runs of the original shard on this head: CI's own macos-swift (packages) full-package swift test --parallel step 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.
  • Codex autoreview at the P1 threshold reported no actionable findings.

Checks. git diff --check is clean, and every added line fits the 120-column width. These test and OpenClawChatUI source 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

…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.
@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 19:55
@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 4, 2026, 5:57 PM ET / 21:57 UTC (Revision 2).

ClawSweeper review

What this changes

Native 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
Reviewed head: 5ba157a26cb97b50caa77bab5ca4f0d85241bd78

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) The focused owner-based synchronization repair preserves assertions and has strong recorded saturation and independently verified shard validation.
Proof confidence 🌊 off-meta tidepool Not applicable: Verified repository-admin authorship exempts this PR from ordinary external-contributor proof. The recorded saturation scenario exercises the changed restore and flush task owners; the separate flake-validation requirement is satisfied. No stored-data contract changes.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Verified repository-admin authorship exempts this PR from ordinary external-contributor proof. The recorded saturation scenario exercises the changed restore and flush task owners; the separate flake-validation requirement is satisfied. No stored-data contract changes.
Evidence reviewed 10 items Introduced patch and ownership: The pinned merge-base-to-head diff changes restore-task return plumbing, replaces the active-flush Boolean with its task handle, and updates existing tests. The verified test merge records the pinned main parent followed by the exact PR head; unrelated endpoint drift is excluded.
Completion ordering preserves assertions: The delivery test holds the fake send, captures the active flush task, releases the send, and awaits the flush before checking awaiting-confirmation state. Restore tests retain both prior readiness assertions. Production coalescing still requests a subsequent pass while one is active.
Still necessary on current main: Fetched main still contains both deadline-based outbox wait helpers and the committed-session request-count poll. The related merged PRs converted other waits rather than these remaining cases.
Findings None None.
Security None None.

How this fits together

The 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
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Other -15. Total -15 across 6 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 6 41 56 -15
Total 6 41 56 -15

Review metrics

Metric Value Why it matters
Flake validation 3 of 3 original-shard attempts passed on the reviewed head This resolves the previous review's outstanding repository-required validation request.

Technical review

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

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: This is a bounded test-reliability repair with no user-visible runtime change or urgent product regression.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Verified repository-admin authorship exempts this PR from ordinary external-contributor proof. The recorded saturation scenario exercises the changed restore and flush task owners; the separate flake-validation requirement is satisfied. 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 (1 earlier review cycle)
  • reviewed 2026-10-04T20:00:43.321Z sha 5ba157a :: needs changes before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Oct 4, 2026
@steipete
steipete merged commit cdcc70f into main Oct 4, 2026
244 checks passed
@steipete
steipete deleted the steipete/zealous-easley-9956f5 branch October 4, 2026 22:15
@steipete

steipete commented Oct 4, 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 5, 2026
…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.
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: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S 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