Skip to content

test(chat): await outbox owners instead of wall-clock polls in outbox tests - #165187

Merged
steipete merged 5 commits into
mainfrom
steipete/ock-waits-b6-outbox
Oct 5, 2026
Merged

steipete merged 5 commits into
mainfrom
steipete/ock-waits-b6-outbox

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 ChatViewModelOutboxTests and ChatViewModelOutboxSettingsTests 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 outbox view model tests.

Why This Change Was Made

The outbox suites detected product progress with waitUntil, a 15 s wall-clock poll. Under the full parallel package run, the MainActor backlog makes multi-hop work outlive that deadline while it is still queued. Outbox restore, flush, reconcile, and terminal-write chains each need several hops. #165068 added the owner handles these tests need (outboxFlushTask and the restoreOutboxMessages Task) and converted the session-action suite. This PR removes all 115 waits in the two outbox suites.

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

  • Flushes. A flush that starts deep in a chain the test cannot reach is held at a fake arrival gate. The test takes outboxFlushTask, releases the gate, and awaits it, following the test(chat): await outbox owners instead of wall-clock polling in session action tests #165068 shape (finishOutboxFlush). For coalesced passes, the test also awaits the successor flush before asserting idle.
  • Restore and bootstrap. These await bootstrapTask and the restore Task.
  • Durable store events. ScriptedOutbox gains a terminal-write gate and a confirmation signal, so terminal-failure, park, and history-confirmation tests wait on the store owner's own write.
  • Request arrivals. The fake transport state gains a deadline-free waitForState that wakes on recorded sends, history reads, and branch listings, plus send and history arrival gates and a model-patch arrival wait.
  • Submission and badges. A submission is observed settled once isSubmittingDraft clears. Bubble and badge changes that no handle reaches use an Observation-driven wait.

After awaiting an owner, each test asserts the condition the old poll checked. No timeouts were lengthened and no retries were added. This is test-only; there are no production changes.

The Observation-driven wait lives here as waitForOutboxObservedState, because the shared waitForObservedState is introduced by the stacked #165157 series (#165178) and is not on main yet. Whichever of the two lands second folds this copy into the shared helper.

Evidence

Deterministic saturation probe, 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, which puts one MainActor hop past 15 s. The flood is held 420 s and starts first. It runs in the same swift test --package-path apps/shared/OpenClawKit --skip-build --disable-sandbox --filter 'ChatViewModelOutboxTests|ChatViewModelOutboxSettingsTests|AAMainActorSaturationProbe/' process, with a private HOME, CFFIXED_USER_HOME, OPENCLAW_STATE_DIR, and TMPDIR.

  • Before, on the base (b48245c): 30 of the 63 tests fail, with 64 issues, e.g. pre-CAS terminal result settled, offline bootstrap settled, initial outbox restore, and terminal write failure closes health with claim intact.
  • After, on this head: all 63 pass under the identical flood (Test run with 64 tests in 3 suites passed after 420.7 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 both outbox suites: 63 tests, 1.52–4.74 s of test time each (median 1.58 s).

  • Owner siblings: every ChatViewModel* and NativeConversation* suite (including NativeConversationOutboxTests, which shares these fakes). 552 tests in 15 suites passed.

  • Original shard: three clean runs of CI's macos-swift (packages) full-package swift test --parallel on final head cc7cb9704bd4fcf0ee416a92dd550560a57c7cac: attempt 1 (9m18s), attempt 2 (9m20s), attempt 3 (15m23s), alongside macos-swift (tests).

  • Codex autoreview at the P2 threshold, over several rounds. Three findings were fixed:

    • Two waits on one exact errorText could hang on a different message. The upgrade-guidance test now awaits the reconnect flush that publishes it: the fake's route-lease arrival is gated and outboxFlushTask is awaited. The retry test wakes on the next new non-nil error. I first tried a change-based trigger, and it flaked 5–7 of 20 full-suite runs, because errorText legitimately passes through nil and other messages.
    • The external-run reply test now wakes on any assistant reply before asserting its text.
    • Three terminal-write tests now await the coalesced successor flush before asserting idle.

    One finding was declined: awaiting both view models' flush handles in the shared-FIFO test. Those flushes start from metadata readiness, reconcile, and the retry scheduler, so no handle reaches them deterministically from the test. The store's change stream emits only on confirmation, so the confirmation wait is the deterministic arrival signal. Like every deadline-free wait, it would hang rather than fail if a send never confirmed.

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.

Related: #163792, #165068, #165157

Replace outbox and settings polls with flush-task completion, transport arrival gates,
shared store confirmations, and observed view-model state.
Preserve delivery, retry, draft, and settings assertions without production changes.
@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 23:21
@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, 1:09 AM ET / 05:09 UTC (Revision 2).

ClawSweeper review

What this changes

The PR replaces deadline-based polling in native chat outbox tests with task completion, request-arrival gates, store confirmations, and observed state changes.

Merge readiness

✅ Ready for maintainer review

The PR remains useful, with no actionable introduced defect found. The previous blocker is resolved: all three original-shard runs passed on the reviewed head.

Likely related people: steipete, a high-confidence routing candidate based on prior merged outbox work.

Priority: P2
Reviewed head: cc7cb9704bd4fcf0ee416a92dd550560a57c7cac

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused reliability repair with preserved assertions, substantial flake validation, and no actionable correctness finding.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied repository state identifies a MEMBER-authored test-only PR, so contributor runtime proof is exempt. The changed outbox-test synchronization has recorded saturation before/after evidence and three verified package-test passes; 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 test-only PR, so contributor runtime proof is exempt. The changed outbox-test synchronization has recorded saturation before/after evidence and three verified package-test passes; no stored-data contract changes.
Evidence reviewed 8 items Introduced scope: The pinned merge-base-to-head diff changes only the two outbox test files. The synchronization helpers and fake gates preserve explicit assertions; no production, dependency, workflow, or persisted-format change is introduced.
Owner lifecycle: The flush owner clears its task handle and starts a coalesced successor before finishing. The changed terminal-write tests await that successor before asserting idle. Canonical transcript evidence is persisted before command confirmation, supporting the new confirmation waits.
Still necessary on current main: Fetched main retains the outbox suites' wall-clock polls. The shared wait helper uses a 15-second deadline and 10-millisecond sleeps. The merged sibling PRs cover other suites or supply task handles; they do not implement this conversion.
Findings None None.
Security None None.

How this fits together

The native chat outbox persists messages while disconnected and delivers them when connectivity returns. These tests exercise its delivery, retry, confirmation, and settings behavior through the chat view model and SQLite store.

flowchart TD
  A[Test scenarios] --> B[Native chat view model]
  B --> C[SQLite outbox]
  B --> D[Scripted transport]
  C --> E[Completion and confirmation signals]
  D --> E
  E --> F[Delivery and state assertions]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Other +91. Total +91 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 513 422 +91
Total 2 513 422 +91

Review metrics

Metric Value Why it matters
Flake proof completion 3 of 3 original-shard attempts passed on the reviewed head The exact-head GitHub results resolve the previous review's outstanding validation requirement.

Technical review

Best possible solution:

Use owner completion and arrival signals to synchronize outbox tests while retaining independent delivery and durable-state assertions.

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

Yes: the documented saturation scenario targets the source-visible 15-second polling deadline and records before/after failures and recovery. This review inspected the mechanism but did not execute a current-main reproduction.

Is this the best way to solve the issue?

Yes: waiting for existing task owners and explicit arrivals removes load-sensitive deadlines while preserving the behavioral assertions and production contracts.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 1cebb5362f88.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This addresses bounded native-test flakiness without changing user-facing runtime behavior.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool 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 test-only PR, so contributor runtime proof is exempt. The changed outbox-test synchronization has recorded saturation before/after evidence and three verified package-test passes; no stored-data contract changes.

Evidence

What I checked:

  • Introduced scope: The pinned merge-base-to-head diff changes only the two outbox test files. The synchronization helpers and fake gates preserve explicit assertions; no production, dependency, workflow, or persisted-format change is introduced. (apps/shared/OpenClawKit/Tests/OpenClawKitTests/ChatViewModelOutboxTests.swift:59, cc7cb9704bd4)
  • Owner lifecycle: The flush owner clears its task handle and starts a coalesced successor before finishing. The changed terminal-write tests await that successor before asserting idle. Canonical transcript evidence is persisted before command confirmation, supporting the new confirmation waits. (apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatViewModel+Outbox.swift:761, cc7cb9704bd4)
  • Still necessary on current main: Fetched main retains the outbox suites' wall-clock polls. The shared wait helper uses a 15-second deadline and 10-millisecond sleeps. The merged sibling PRs cover other suites or supply task handles; they do not implement this conversion. (apps/shared/OpenClawKit/Tests/OpenClawKitTests/ChatViewModelOutboxTests.swift:542, 1cebb5362f88)
  • Previous review requirement satisfied: GitHub job metadata verified that jobs 111556874602, 111616752019, and 111619123868 are successful macos-swift (packages) attempts 1–3 on cc7cb97. Each separately reports a successful OpenClawKit tests step. This resolves the prior review's concrete rank-up request. (cc7cb9704bd4)
  • Flake validation: The supplied PR body records 30 of 63 tests failing on the base under MainActor saturation, all 63 passing after the change under the identical flood, 20 clean standalone runs, and 552 passing sibling tests. Reported standalone test time is 1.52–4.74 seconds. These are contributor-recorded observations; this read-only review did not execute tests. (cc7cb9704bd4)
  • Applicable validation policy: The repository's flake policy requires 20 standalone runs, three original-shard runs, and owner sibling tests. The supplied evidence now addresses all three requirements. Public docs: docs/help/testing/writing-tests.md. (docs/help/testing/writing-tests.md, cc7cb9704bd4)

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-04T23:27:45.438Z sha cc7cb97 :: needs changes before merge. :: none

@steipete
steipete merged commit 49fc679 into main Oct 5, 2026
242 checks passed
@steipete
steipete deleted the steipete/ock-waits-b6-outbox branch October 5, 2026 05:18
@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
… tests (openclaw#165187)

* test(chat): await outbox owners instead of wall-clock polls

Replace outbox and settings polls with flush-task completion, transport arrival gates,
shared store confirmations, and observed view-model state.
Preserve delivery, retry, draft, and settings assertions without production changes.

* test(chat): wake error waits on a change so a wrong message fails

* test(chat): wake error waits on the next new error

* test(chat): await the reconnect flush that publishes upgrade guidance

* test(chat): await coalesced successor flushes after terminal writes
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: L 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