Register-when-ready Iroh hosts, bounded dial phases, cold-start release gate

Closed
AZ
2mo ago
+227-13

Fixes https://github.com/manaflow-ai/cmux/issues/9724 in three layers.

Summary

  • Mac register-when-ready: automatic-mode host startup starts relay activation eagerly and gives the relay a bounded window (automaticRelayReadinessTimeout, default 5s) to become usable, so the binding published at activation carries post-attach dialable hints instead of the half-ready bootstrap snapshot phones were racing. Only the cancellation-safe waitForUsableHomeRelay is awaited; timeout, broker error, or a hung credential install publishes the bootstrap policy exactly as before and leaves repair to the standard refresh-on-online path. Direct-only startup still skips readiness; the strict relay-only barrier is unchanged.
  • Bounded dial phases: CmxIrohClientSession.establishConnection awaited endpoint.connect with no clock on either the public or the private-fallback phase, which is where the dogfood trace burned a 16.2s hang against stale hints. Each phase now races the fork's cancellable ConnectAttempt against dialPhaseTimeout (default 5s); expiry cancels the FFI dial promptly, surfaces dialTimedOut (diagnostic kind timedOut), and a timed-out public phase still falls through to the private fallback.
  • Cold-start release gate: new --mode cold-start (GATE_SCENARIO=cold_start_dial) pins the launch-to-usable deadline to 20s on the gate's phone launch against the freshly relaunched Mac, making this race a permanent tripwire. Also selectable in the iroh-release-gate workflow matrix.

Evidence base: decoded cmuxdiag timeline from the PR 9430 dogfood round (discovery succeeded at t+7s; dial 1 connected then failed pairing after 7.6s; dial 2 hung 16.2s; dial 3 connected in 455ms; usable at ~t+43s), full decode in the issue.

Verification

  • Red/green regression pair for register-when-ready: commit 6c2984a123 adds the failing test (automatic startup published bootstrap hints, one registration), commit feb58d3407 turns it green.
  • swift test --package-path Packages/Shared/CmuxIrohTransport: 572 tests, 64 suites, all pass, including the new hung-dial bound test and the credential-installation race test updated to the bounded contract.
  • swift build --package-path Packages/iOS/CmuxMobileShell compiles the new scenario case.

Build and behavior verification (2026-08-07, tag irdy)

  • The app-target build caught a non-exhaustive scenario switch in the release-gate probe, fixed in 1cd310bef7 (cold-start reuses the standard probe legs).
  • macOS + iOS simulator builds green on tag irdy; sim app signed in and attached to the tagged Mac (workspace list live).
  • Behavior preflight of the fixed path: quit and relaunch the tagged Mac with the sim app open; the sim's terminal-events subscription re-established 22s after relaunch, including full Mac cold start, with no hung-dial churn. The pre-fix baseline on tag asrm was 70+ seconds with a 16.2s transportDialFailed hang (https://github.com/manaflow-ai/cmux/issues/9724).
  • iPhone: dev.cmux.ios.irdy built, signed, and installed on the personal iPhone; the signed launch retry is pending the phone being awake.

Pending verification

Deferred (documented in the issue)

  • Server-side ready flag on iroh_endpoint_bindings needs a schema migration via the cloud-vm-ops flow; this PR is client-only.
  • Between-retry hint re-fetch on iOS (registry context provider snapshot caches) is the remaining Layer 2 half, follow-up PR.

Notes

  • no autoreview, Codex review, Claude review, or second-model review was invoked

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


[!NOTE]
Cursor Bugbot is generating a summary for commit 1592f48833fe8d2bd4fe3785c85c96c909d03e7e. Configure here.


Summary by cubic

Prevents long post-restart dial hangs by publishing relay-ready hints during automatic host startup and by bounding each dial phase. Adds a cold-start release gate that relaunches the Mac and enforces a 20s launch-to-usable deadline via the orchestrator.

  • Bug Fixes

    • Automatic-mode CmxIrohHostRuntime eagerly activates relay and waits up to 5s for readiness before publishing; on timeout/error it publishes bootstrap and refreshes later. Direct-only behavior is unchanged.
    • CmxIrohClientSession bounds each dial phase with dialPhaseTimeout (default 5s); expiry cancels the connect, surfaces dialTimedOut, and public timeouts still fall back to private paths.
    • Diagnostic mapping adds .timedOut for dialTimedOut.
  • New Features

    • Release-gate mode cold-start (cold_start_dial) with a 20s launch-to-usable deadline; added to the workflow matrix, runner admission, probe switch, and scripts/run-iroh-release-gate.sh. The probe reuses standard usability checks; timing is enforced by the script.

Summary by CodeRabbit

  • New Features

    • Added cold-start release-gate testing for recently launched devices.
    • Added configurable connection and relay-readiness timeouts.
    • Added explicit timeout reporting for connection attempts.
    • Improved automatic relay startup and route publication.
  • Bug Fixes

    • Prevented stalled connections from blocking session establishment.
    • Improved startup when relay credentials or bindings are temporarily unavailable.
  • Tests

    • Added coverage for stalled dialing, cold-start scenarios, relay readiness, and startup lifecycle races.