Skip to content

Complete Iroh diagnostics and connection recovery - #10119

Merged
azooz2003-bit merged 23 commits into
mainfrom
feat-iroh-product-final
Aug 13, 2026
Merged

azooz2003-bit merged 23 commits into
mainfrom
feat-iroh-product-final

Conversation

@azooz2003-bit

@azooz2003-bit azooz2003-bit commented Aug 13, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • port actionable, privacy-safe Iroh recovery diagnostics and route analysis onto current main
  • bound reconnect dial phases and preserve route/session attribution
  • keep a live authenticated Iroh RPC session connected while a secondary subscription probe is in flight

Verification

  • swift test --package-path Packages/Shared/CmuxIrohTransport --filter CmxIrohClientSessionTests --filter CmxIrohDiagnosticFailureTests --filter CmxIrohRegistryContextProviderStalenessTests --filter CmxIrohConnectionCloseAttributionTests --jobs 4
  • swift test --package-path Packages/iOS/CmuxMobileShell --filter ReconnectRouteSelectionTests --filter IrohConnectionRecoveryOwnerTests --filter IrohZeroTouchDiscoveryTests --filter PresenceDiscoveryInvalidationTests --jobs 1
  • python3 -m unittest scripts/tests/test_analyze_ios_network_log.py

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


Summary by cubic

Completes Iroh connection diagnostics and recovery: per-phase dial timeouts prevent hangs, stale discovery is invalidated on evidence, and reports now link dial attempts to admitted sessions with privacy-safe identifiers. Previously, dials could block until an outer deadline and discovery reuse could redial corpse routes; now, hung legs fail fast, fresh snapshots are fetched when needed, and cancellation ownership and remote close reasons are recorded.

  • Transport and diagnostics
    • Adds per-phase dial bounds with .dialTimedOut; records leg success/failure in CmuxIrohClientSession and classifies route errors.
    • Links dial attempts to sessions via optional CmxByteTransportDiagnosticSessionIdentifying; emits .transportDialSessionLinked, .transportDialCancelled, and .transportCloseReason.
    • Whitelists remote close reason tokens end-to-end (DiagnosticRemoteCloseReason), records them from server close paths, and ignores free‑form lookalikes.
    • Standardizes build stamps with DiagnosticBuildStamp and adds peer-alias “surface” to network events in CMUXMobileCore.
  • Discovery freshness and recovery behavior
    • CmxIrohRegistryContextProvider tracks stale peers/device IDs and forces a single‑flight fresh broker snapshot after empty/unreachable plans or presence route pushes; CmxIrohClientRuntime exposes invalidateDiscoverySnapshot(forMacDeviceID:), which CmuxMobileShell calls on route updates.
    • Coalesces recovery during startup reconnects; keeps an authenticated Iroh RPC session connected while a secondary subscription probe is in flight; CmuxMobileRPC now emits a cancelled event with a DiagnosticCancellationReason and includes sessionID on connected.
  • Tooling and docs
    • Adds scripts/analyze-ios-network-log.py with tests to turn exported logs into actionable verdicts, and docs/ios-network-reliability.md for the test workload.

Migration

  • No breaking changes. Custom CmxIrohClientContextProvider implementations can optionally implement noteDialFailure to improve staleness invalidation; CmxByteTransportDiagnosticSessionIdentifying is optional.

Written for commit 99d1ea7. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • New Features

    • Added richer network diagnostics for connection attempts, cancellations, session linking, close reasons, discovery, routing, and recovery.
    • Added configurable dial timeouts with clearer timeout and failure reporting.
    • Added discovery-cache invalidation and refreshed stale network information automatically.
    • Added a network-log analyzer with human-readable and JSON output.
    • Added sanitized diagnostic build stamps and localized diagnostic messages.
  • Bug Fixes

    • Improved recovery behavior, connection correlation, failure classification, and duplicate cancellation handling.
    • Prevented connected sessions from being incorrectly marked as reconnecting.

…eliability

# Conflicts:
#	Packages/Shared/CMUXMobileCore/Sources/CMUXMobileCore/DiagnosticEventCode.swift
#	Packages/Shared/CMUXMobileCore/Tests/CMUXMobileCoreTests/DiagnosticEventPresentationTests.swift
#	Packages/Shared/CmuxIrohTransport/Sources/CmuxIrohTransport/CmxIrohClientSession.swift
#	Packages/Shared/CmuxIrohTransport/Sources/CmuxIrohTransport/CmxIrohRegistryContextProvider.swift
@azooz2003-bit
azooz2003-bit merged commit 4e4df03 into main Aug 13, 2026
5 of 6 checks passed
@coderabbitai

coderabbitai Bot commented Aug 13, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d140429e-18f9-49fc-8a19-f732321538c7

📥 Commits

Reviewing files that changed from the base of the PR and between 2f5ba2d and 99d1ea7.

📒 Files selected for processing (59)
  • Packages/Shared/CMUXMobileCore/Sources/CMUXMobileCore/AppLog.swift
  • Packages/Shared/CMUXMobileCore/Sources/CMUXMobileCore/CmxTransport.swift
  • Packages/Shared/CMUXMobileCore/Sources/CMUXMobileCore/DiagnosticBuildStamp.swift
  • Packages/Shared/CMUXMobileCore/Sources/CMUXMobileCore/DiagnosticEventCode.swift
  • Packages/Shared/CMUXMobileCore/Sources/CMUXMobileCore/DiagnosticEventPresentation.swift
  • Packages/Shared/CMUXMobileCore/Sources/CMUXMobileCore/DiagnosticReport.swift
  • Packages/Shared/CMUXMobileCore/Sources/CMUXMobileCore/DiagnosticTaxonomy.swift
  • Packages/Shared/CMUXMobileCore/Sources/CMUXMobileCore/Resources/Localizable.xcstrings
  • Packages/Shared/CMUXMobileCore/Sources/CMUXMobileCore/TransportIncidentPolicy.swift
  • Packages/Shared/CMUXMobileCore/Tests/CMUXMobileCoreTests/AppLogTests.swift
  • Packages/Shared/CMUXMobileCore/Tests/CMUXMobileCoreTests/DiagnosticBuildStampTests.swift
  • Packages/Shared/CMUXMobileCore/Tests/CMUXMobileCoreTests/DiagnosticEventPresentationTests.swift
  • Packages/Shared/CMUXMobileCore/Tests/CMUXMobileCoreTests/DiagnosticLogTests.swift
  • Packages/Shared/CmuxIrohTransport/Sources/CmuxIrohTransport/CmxConnectivityByteTransport.swift
  • Packages/Shared/CmuxIrohTransport/Sources/CmuxIrohTransport/CmxConnectivityEngine.swift
  • Packages/Shared/CmuxIrohTransport/Sources/CmuxIrohTransport/CmxConnectivityPeerSession.swift
  • Packages/Shared/CmuxIrohTransport/Sources/CmuxIrohTransport/CmxIrohClientContextProvider.swift
  • Packages/Shared/CmuxIrohTransport/Sources/CmuxIrohTransport/CmxIrohClientRuntime.swift
  • Packages/Shared/CmuxIrohTransport/Sources/CmuxIrohTransport/CmxIrohClientSession.swift
  • Packages/Shared/CmuxIrohTransport/Sources/CmuxIrohTransport/CmxIrohClientSessionError.swift
  • Packages/Shared/CmuxIrohTransport/Sources/CmuxIrohTransport/CmxIrohConnectionCloseAttribution.swift
  • Packages/Shared/CmuxIrohTransport/Sources/CmuxIrohTransport/CmxIrohConnectionDiagnosticRecorder.swift
  • Packages/Shared/CmuxIrohTransport/Sources/CmuxIrohTransport/CmxIrohDiagnosticFailure.swift
  • Packages/Shared/CmuxIrohTransport/Sources/CmuxIrohTransport/CmxIrohLibConnection.swift
  • Packages/Shared/CmuxIrohTransport/Sources/CmuxIrohTransport/CmxIrohRegistryContextProvider.swift
  • Packages/Shared/CmuxIrohTransport/Sources/CmuxIrohTransport/CmxIrohRuntimeContextRouter.swift
  • Packages/Shared/CmuxIrohTransport/Sources/CmuxIrohTransport/CmxIrohServerSession.swift
  • Packages/Shared/CmuxIrohTransport/Tests/CmuxIrohTransportTests/CmxConnectivityPeerSessionTests.swift
  • Packages/Shared/CmuxIrohTransport/Tests/CmuxIrohTransportTests/CmxIrohClientRuntimeAuthorizationTests.swift
  • Packages/Shared/CmuxIrohTransport/Tests/CmuxIrohTransportTests/CmxIrohClientSessionTests.swift
  • Packages/Shared/CmuxIrohTransport/Tests/CmuxIrohTransportTests/CmxIrohConnectionCloseAttributionTests.swift
  • Packages/Shared/CmuxIrohTransport/Tests/CmuxIrohTransportTests/CmxIrohConnectionDiagnosticRecorderTests.swift
  • Packages/Shared/CmuxIrohTransport/Tests/CmuxIrohTransportTests/CmxIrohDiagnosticFailureTests.swift
  • Packages/Shared/CmuxIrohTransport/Tests/CmuxIrohTransportTests/CmxIrohLibEndpointTests.swift
  • Packages/Shared/CmuxIrohTransport/Tests/CmuxIrohTransportTests/CmxIrohRegistryContextProviderStalenessTests.swift
  • Packages/Shared/CmuxIrohTransport/Tests/CmuxIrohTransportTests/CmxIrohRegistryContextProviderTests.swift
  • Packages/Shared/CmuxIrohTransport/Tests/CmuxIrohTransportTests/CmxIrohServerSessionTests.swift
  • Packages/Shared/CmuxIrohTransport/Tests/CmuxIrohTransportTests/TestDialingIrohEndpoint.swift
  • Packages/Shared/CmuxIrohTransport/Tests/CmuxIrohTransportTests/TestIrohClientContextProvider.swift
  • Packages/Shared/CmuxIrohTransport/Tests/CmuxIrohTransportTests/TestIrohDialResult.swift
  • Packages/iOS/CmuxMobileRPC/Sources/CmuxMobileRPC/MobileCoreRPCSession.swift
  • Packages/iOS/CmuxMobileRPC/Sources/CmuxMobileRPC/MobileRPCTransportConnectEvent.swift
  • Packages/iOS/CmuxMobileRPC/Tests/CmuxMobileRPCTests/MobileRPCTransportConnectEventTests.swift
  • Packages/iOS/CmuxMobileShell/Sources/CmuxMobileShell/MobileConnectionRecoveryOwner.swift
  • Packages/iOS/CmuxMobileShell/Sources/CmuxMobileShell/MobileIrohMacDiscovering.swift
  • Packages/iOS/CmuxMobileShell/Sources/CmuxMobileShell/MobileShellComposite+ConnectionDiagnostics.swift
  • Packages/iOS/CmuxMobileShell/Sources/CmuxMobileShell/MobileShellComposite+ConnectionRecovery.swift
  • Packages/iOS/CmuxMobileShell/Sources/CmuxMobileShell/MobileShellComposite+ManualAttachTicket.swift
  • Packages/iOS/CmuxMobileShell/Sources/CmuxMobileShell/MobileShellComposite+PresenceRouteSync.swift
  • Packages/iOS/CmuxMobileShell/Sources/CmuxMobileShell/MobileShellComposite.swift
  • Packages/iOS/CmuxMobileShell/Tests/CmuxMobileShellTests/IrohConnectionRecoveryOwnerTests.swift
  • Packages/iOS/CmuxMobileShell/Tests/CmuxMobileShellTests/IrohZeroTouchDiscoveryTests.swift
  • Packages/iOS/CmuxMobileShell/Tests/CmuxMobileShellTests/PresenceDiscoveryInvalidationTests.swift
  • Sources/Mobile/MobileHostIrohRuntime.swift
  • docs/ios-network-reliability.md
  • ios/cmux/AppCompositionRoot.swift
  • ios/cmuxPackage/Sources/cmuxFeature/MobileIrohRuntimeComposition.swift
  • scripts/analyze-ios-network-log.py
  • scripts/tests/test_analyze_ios_network_log.py

📝 Walkthrough

Walkthrough

The change adds transport diagnostic correlation, bounded dial timeouts, remote close classification, discovery-cache invalidation, mobile recovery diagnostics, sanitized build stamps, and an iOS network-log analyzer.

Changes

Diagnostic contracts and presentation

Layer / File(s) Summary
Diagnostic contracts and presentation
Packages/Shared/CMUXMobileCore/Sources/CMUXMobileCore/*
Diagnostic event codes, payload decoding, failure correlation, cancellation and remote-close taxonomies, localization, build-stamp generation, and incident policy now support transport diagnostics. Tests cover event values, presentation, routing, and metadata sanitization.

Transport dialing and close attribution

Layer / File(s) Summary
Transport dialing and close attribution
Packages/Shared/CmuxIrohTransport/Sources/CmuxIrohTransport/*, Packages/Shared/CmuxIrohTransport/Tests/CmuxIrohTransportTests/*
Transport sessions expose diagnostic session IDs. Public and private dial phases enforce configurable timeouts. Dial failures, peer aliases, remote close reasons, and server close reasons are classified and recorded. Tests cover timeout, routing, relay selection, close attribution, and diagnostic events.

Discovery freshness and invalidation

Layer / File(s) Summary
Discovery freshness and invalidation
Packages/Shared/CmuxIrohTransport/Sources/CmuxIrohTransport/CmxIrohRegistryContextProvider.swift, Packages/Shared/CmuxIrohTransport/Tests/CmuxIrohTransportTests/*, ios/cmuxPackage/Sources/cmuxFeature/MobileIrohRuntimeComposition.swift
Discovery fetches are coalesced and tracked by peer and device. Empty plans and stale failures trigger refreshes. Runtime APIs invalidate discovery for one device or all devices. Tests cover concurrency, revisions, cooldowns, presence invalidation, and cached-context behavior.

Mobile connection and recovery diagnostics

Layer / File(s) Summary
Mobile connection and recovery diagnostics
Packages/iOS/CmuxMobileRPC/Sources/CmuxMobileRPC/*, Packages/iOS/CmuxMobileShell/Sources/CmuxMobileShell/*, Packages/iOS/CmuxMobileShell/Tests/CmuxMobileShellTests/*
RPC connection events include session IDs and explicit cancellation events. Shell diagnostics include peer and attempt correlation. Recovery replacement rules distinguish automatic, manual, and connection-method triggers. Stale route failures invalidate discovery. Tests cover cancellation, recovery replacement, and route invalidation.

Build metadata and network-log analysis

Layer / File(s) Summary
Build metadata and network-log analysis
Sources/Mobile/MobileHostIrohRuntime.swift, ios/cmux/AppCompositionRoot.swift, scripts/*, docs/ios-network-reliability.md
Application composition uses the shared diagnostic build-stamp utility. A Python CLI parses current and legacy network logs, correlates connection and recovery events, evaluates route and relay policy, and emits human-readable or JSON verdicts. Documentation defines the reliability workload and pass criteria.

Estimated code review effort: 5 (Critical) | ~120 minutes

Sequence Diagram(s)

sequenceDiagram
  participant MobileShellComposite
  participant MobileCoreRPCSession
  participant CmxIrohClientSession
  participant CmxIrohRegistryContextProvider
  participant NetworkLogAnalyzer
  MobileShellComposite->>MobileCoreRPCSession: start connection attempt
  MobileCoreRPCSession->>CmxIrohClientSession: connect using transport
  CmxIrohClientSession->>CmxIrohRegistryContextProvider: resolve or refresh discovery
  CmxIrohRegistryContextProvider-->>CmxIrohClientSession: return dial context
  CmxIrohClientSession-->>MobileCoreRPCSession: return transport or classified failure
  MobileCoreRPCSession-->>MobileShellComposite: record connected or cancelled event
  MobileShellComposite->>NetworkLogAnalyzer: provide exported network log
  NetworkLogAnalyzer-->>MobileShellComposite: return structured verdict
Loading
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat-iroh-product-final

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant