Skip to content

test(gateway): await node-session owners and retire the wall-clock waitUntil - #166386

Merged
steipete merged 4 commits into
mainfrom
steipete/ock-waits-b7-gateway
Oct 7, 2026
Merged

steipete merged 4 commits into
mainfrom
steipete/ock-waits-b7-gateway

Conversation

@steipete

@steipete steipete commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: the native device-auth tests fail during connection when the MainActor is backed up, as it is when macos-swift (packages) runs the full OpenClawKit package in parallel. A gateway node-session test can also deadlock a constrained cooperative pool. This PR also removes the last 15 s wall-clock waits in OpenClawKit.

User Impact

No user-visible change. These were the last OpenClawKit callers of the 15 s wall-clock waitUntil, so this PR also deletes the helper.

Why This Change Was Made

This finishes the series from #165157, #165170, #165171, #165172, #165178, #165187, and #166373.

  • Gateway node-session waits (83). Each wait now awaits its owner or an arrival signal: deadline-free continuation waiters on the fake WebSocket task, session, and probes (sent-request counts, receive-handler registration, socket creation, connect-auth capture, cancellation and invocation counts), the existing gates, and owner Task completion. This code involves no MainActor, so the old waits timed out behind a busy cooperative pool.
  • The one in-flight receipt join. The join is visible only through a DEBUG-only counter inside the GatewayNodeSession actor. A DEBUG-only waitForComputerReceiptJoinsForTesting resumes where that counter increments. The maintainer approved this as an exception to production line-count neutrality; release builds are unchanged.
  • Native WebSocket fixture. NativeGatewayWebSocketFixture handled every accepted connection on .main under MainActor.assumeIsolated. Under a MainActor backlog, the handshake waited until the client's unchanged 6 s connect deadline expired, so all five device-auth tests failed during connection. The listener had already moved off main for the same reason. Connections and fixture state now live on one private serial queue, and test-facing reads synchronize with it.
  • waitUntil removed. With no callers left, the helper and its own tests are deleted. waitForObservedState remains as the shared Observation-driven fallback.

After awaiting an owner, each test asserts the condition the old poll checked. No timeouts were lengthened and no retries were added.

Evidence

Deterministic saturation probes (temporary, uncommitted), each held 420 s in the same swift test --package-path apps/shared/OpenClawKit --skip-build --disable-sandbox --filter '<suites>|<probe>' process, with a private HOME, CFFIXED_USER_HOME, OPENCLAW_STATE_DIR, and TMPDIR:

  • Cooperative-pool flood (LIBDISPATCH_COOPERATIVE_POOL_STRICT=1, 1,000 high-priority 20 ms spin-yield tasks, so each enqueued pool job waits about 20 s).
    • Before, on the base (9e56928): the test process deadlocked within a minute. disconnect during channel shutdown prevents stale channel install blocked the only pool thread inside a synchronous NSCondition gate, so neither the other tests nor the flood could run. This PR replaces that gate with the existing async shutdown gate.
    • With that one test skipped, the other 97 base tests passed under the flood. A pool backlog alone did not push these actor-based waits past their deadline: idle-actor hops run inline, and waitUntil re-checks once after its deadline. The gateway wait conversions are therefore preventive, removing the deadline class, rather than fixes for a reproduced timeout.
    • After, on this head: ✔ Test run with 98 tests in 4 suites passed after 420.005 seconds., with no test skipped.
  • MainActor flood (16,000 1 ms spin-yield tasks) on the device-auth suite. Before, on the base: 5 of 5 tests fail during connection (5 issues). After, on this head: ✔ Test run with 6 tests in 2 suites passed after 420.592 seconds..

Flake-fix proof bar (writing tests, Flake triage step 4), on this head:

  • 20 of 20 clean standalone runs of both gateway suites (97 tests, 30.473–30.541 s of test time each).
  • Owner siblings: every suite whose name contains Gateway (303 tests in 30 suites), plus every ChatViewModel* and NativeConversation* suite after the helper deletion. ✔ Test run with 303 tests in 30 suites passed after 30.518 seconds. (plus 2 XCTest tests, zero failures); ✔ Test run with 1702 tests in 126 suites passed after 5.595 seconds. (plus 18 XCTest tests, zero failures).
  • Original shard: since chore(ci): defer heavy PR jobs to later validation tiers #165231, PR CI no longer selects macos-swift; the full-package macos-swift (packages) shard runs in hourly main CI, which covers this change after merge (maintainer decision, same as the earlier series).
  • Codex autoreview at the P2 threshold raised one finding: that the connect-auth arrival wait could hang when a connect frame has no auth. I declined it, because the fake records params["auth"] ?? [:] for every connect frame, so the wait is already outcome-independent.

Checks. git diff --check is clean, and SwiftFormat lint is clean on every changed line. I did not run the full OpenClawKit suite locally, because its keychain fixtures reach the login keychain on this Mac.

Related: #165157, #165187, #166373

Replace the 83 waitUntil polls in the gateway node-session and native
device-auth tests with fake arrival continuations, existing gates, and
owner completion. A DEBUG-only receipt-join waiter in GatewayNodeSession
lets the in-flight receipt test await the join instead of polling.
Run listener and connection callbacks on one private serial queue.
Synchronize fixture reads and teardown while preserving the test-facing API.
Keep WebSocket frames and device-auth outcomes unchanged under executor load.
@clawsweeper

clawsweeper Bot commented Oct 7, 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. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 7, 2026
@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 6, 2026, 10:14 PM ET / October 7, 2026, 02:14 UTC (Revision 2).

ClawSweeper review

What this changes

The PR replaces native Gateway test polling with completion signals, moves WebSocket fixture callbacks to a private serial queue, and removes the unused polling helper.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main retains the affected polling helper and MainActor-bound fixture. The reviewed patch has no blocking findings, and the recorded saturation evidence supports the reliability fixes.

Priority: P2
Reviewed head: 5b1e269694f1971dd3fcd04c2621496f3243bcd4

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused owner synchronization, complete helper retirement, and unusually thorough before/after load evidence support an above-average patch with no blocking findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Recorded macOS saturation runs exercise GatewayNodeSession through the real URLSession client and local native WebSocket fixture, showing recovery from the connection failures after queue isolation. The separate cooperative-pool run covers the asynchronous shutdown-gate repair; standalone and sibling runs supplement those observations. The latest commit changes only a comment, and no stored-data contract changes.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): Recorded macOS saturation runs exercise GatewayNodeSession through the real URLSession client and local native WebSocket fixture, showing recovery from the connection failures after queue isolation. The separate cooperative-pool run covers the asynchronous shutdown-gate repair; standalone and sibling runs supplement those observations. The latest commit changes only a comment, and no stored-data contract changes.
Evidence reviewed 7 items Introduced change boundary: The pinned merge-base-to-head diff contains the Gateway test conversions, fixture queue change, helper removal, and a DEBUG-only receipt-join waiter. Base-only workflow and product changes are outside this PR's introduced delta.
Current main still needs the fixture repair: At the fetched main revision, accepted connections still enter MainActor and start their callbacks on the main queue; the PR moves them to the fixture's private serial queue.
Complete polling-helper retirement: Current main still defines the 15-second waitUntil helper. The reviewed checkout has no remaining waitUntil calls or AsyncWaitTimeoutError references in OpenClawKit; the deleted tests specifically covered that removed helper.
Findings None None.
Security None None.

How this fits together

OpenClawKit connects native Apple clients to the Gateway through WebSockets. Its tests exercise connection, authentication, reconnect, and invocation behavior using scripted sockets and a local native WebSocket fixture.

flowchart TD
  A[Native Gateway tests] --> B[Node session owner]
  B --> C[Scripted socket signals]
  A --> D[Real URLSession client]
  D --> E[Local WebSocket fixture]
  E --> F[Private serial queue]
  C --> G[Completion and behavior assertions]
  F --> G
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Other -34. Total -34 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 461 495 -34
Total 6 461 495 -34

Review metrics

None.

Technical review

Best possible solution:

Keep native fixture progress independent of MainActor load and synchronize test assertions with the owners that produce their results.

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

Yes: the recorded MainActor and cooperative-pool saturation scenarios establish focused reproduction paths, and current-main source retains the corresponding mechanisms. This read-only review did not execute them.

Is this the best way to solve the issue?

Yes: owner signals and a single fixture queue address the synchronization failures directly while preserving behavior assertions and the existing transport deadlines.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster 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 repairs bounded native-test reliability failures and a constrained-pool deadlock without changing user-visible release behavior.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): Recorded macOS saturation runs exercise GatewayNodeSession through the real URLSession client and local native WebSocket fixture, showing recovery from the connection failures after queue isolation. The separate cooperative-pool run covers the asynchronous shutdown-gate repair; standalone and sibling runs supplement those observations. The latest commit changes only a comment, and no stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. Recorded macOS saturation runs exercise GatewayNodeSession through the real URLSession client and local native WebSocket fixture, showing recovery from the connection failures after queue isolation. The separate cooperative-pool run covers the asynchronous shutdown-gate repair; standalone and sibling runs supplement those observations. The latest commit changes only a comment, and 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)
  • vincentkoc: 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-07T02:02:59.020Z sha 38d3700 :: needs maintainer review 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 7, 2026
@steipete
steipete merged commit 27ba972 into main Oct 7, 2026
73 checks passed
@steipete
steipete deleted the steipete/ock-waits-b7-gateway branch October 7, 2026 02:35
@steipete

steipete commented Oct 7, 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 7, 2026
…itUntil (openclaw#166386)

* test(gateway): await node-session owners instead of wall-clock polls

Replace the 83 waitUntil polls in the gateway node-session and native
device-auth tests with fake arrival continuations, existing gates, and
owner completion. A DEBUG-only receipt-join waiter in GatewayNodeSession
lets the in-flight receipt test await the join instead of polling.

* test(gateway): handle native fixture connections off the MainActor

Run listener and connection callbacks on one private serial queue.
Synchronize fixture reads and teardown while preserving the test-facing API.
Keep WebSocket frames and device-auth outcomes unchanged under executor load.

* test(openclawkit): delete the wall-clock waitUntil helper

* test(gateway): fix receipt waiter comment lint
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: 🦞 diamond lobster Very strong PR readiness with only minor 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