Skip to content

feat(linux): discover gateways on the LAN via Bonjour - #108115

Merged
steipete merged 1 commit into
mainfrom
claude/desktop-gateway-discovery
Jul 15, 2026
Merged

steipete merged 1 commit into
mainfrom
claude/desktop-gateway-discovery

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

The Linux desktop companion could only install the CLI and start a local gateway. If a gateway was already running elsewhere on the LAN (another Mac, a home server), there was no way to find and open it — you had to know and type its URL. The native macOS/iOS apps already discover gateways over Bonjour; the desktop app did not.

Why This Change Was Made

  • New apps/linux/src-tauri/src/discovery.rs: one lifetime mdns-sd browser for _openclaw-gw._tcp.local., a fullname-keyed snapshot (resolved updates replace, goodbye/TTL removes), mirroring the gateway advertiser's TXT contract (extensions/bonjour/src/advertiser.ts) and the native clients' semantics.
  • New discover_gateways / connect_discovered_gateway Tauri commands; the bootstrap page lists discovered gateways (name, resolved host:port, TLS/HTTP badge) and connecting navigates the dashboard WebView to the resolved endpoint. Local install stays the primary path.
  • mdns-sd is a normal (cross-platform) dependency, so this rides on the macOS/Windows build enablement (build(linux): allow macOS and Windows test builds of the desktop app #108004) — the same code compiles on all three.
  • Navigation arbitration (main.rs): a single mutex governs local/remote/bootstrap/reconnect/watchdog navigation, re-checking remote intent and the watchdog generation inside the lock immediately before navigating, so a late local action or the reconnect watchdog cannot steal the WebView back after a remote selection; explicit Connect / tray "Open Dashboard" is the intent to return to local.

Security (mirrors the native clients — routing never trusts raw TXT): the dashboard URL is built only after strict DNS-label host validation (rejects :/@///userinfo), a live-snapshot tuple match, a direct-transport gate, and — for plaintext HTTP — a trusted host class (.local/.ts.net/loopback/RFC1918/CGNAT/link-local/ULA) and all-private resolved A/AAAA addresses. A hostile LAN advertiser pointing at a public host is rejected. Refs apps/macos/.../GatewayDiscoveryHelpers.swift:47-63, GatewayRemoteConfig.swift:197-245. mDNS instance names render via textContent (no XSS). A dead mDNS daemon/closed receiver triggers one bounded re-init on the next snapshot.

Also: the bootstrap header now uses the real Clawd mascot (ui/public/favicon.svg) instead of the abstract claw-mark placeholder, and the discovered-gateway row no longer clips its top border on hover (rows inside the overflow:auto list drop the generic button lift).

User Impact

The desktop app's "Connecting" screen now shows a live "Gateways on this network" list; one click opens a discovered gateway's Control UI. No tokens, no persisted state, no new config keys. Headless and other-platform behavior is unchanged.

Evidence

  • macOS (arm64, local): cargo build + cargo test green (16 tests, incl. 3 hostile-record host-validation rejections and nav-ordering); cargo fmt --check clean.
  • Linux (AWS Crabbox): cargo build + cargo test green (24 tests).
  • Live LAN test on this Mac: a real dns-sd advertiser (_openclaw-gw._tcp, Test Studio, steipete-mbp-4.local:18789) was discovered and rendered in the list within seconds; the mascot header and non-clipping hover border were verified by screenshot.
  • Adversarial autoreview (Codex gpt-5.6-sol xhigh) found 5 defects (1 security, 2 nav races, 2 robustness); all fixed and re-reviewed clean.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: linux plugin: linux-node size: XL maintainer Maintainer-authored PR labels Jul 15, 2026
@steipete steipete self-assigned this Jul 15, 2026
New discovery.rs browses _openclaw-gw._tcp with a lifetime mdns-sd
browser, keeps a fullname-keyed snapshot (resolved updates replace,
goodbye/TTL removes), and mirrors the native clients' TXT contract and
direct-selection gate (resolved SRV endpoint routing; tailnetDns is a
hint only). The bootstrap page lists discovered gateways and connecting
navigates the dashboard WebView to the resolved endpoint, validated
against the live snapshot; remote selection cancels the local watchdog
so an in-flight local bootstrap cannot steal the WebView back.
@steipete
steipete force-pushed the claude/desktop-gateway-discovery branch from 875884e to 6da87de Compare July 15, 2026 08:06

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6da87dea9e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +310 to +314
fn resolved_ip_address(address: &str) -> Option<IpAddr> {
address
.split_once('%')
.map_or(address, |(address, _scope)| address)
.parse()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve IPv6 link-local scopes when connecting

When a discovered plaintext gateway is reachable only via an IPv6 link-local address, resolved_ip_address strips the %iface scope before dashboard_url builds the URL with set_ip_host, so the WebView navigates to http://[fe80::...]:port/ without the interface needed to route it. The code explicitly treats link-local IPv6 as trusted and keeps the scoped string in addresses, so these gateways are shown as connectable but the connection fails on IPv6-only/link-local LANs; either carry the scoped address through URL construction or reject scoped link-local entries instead of enabling them.

Useful? React with 👍 / 👎.

@steipete
steipete merged commit b65a2d8 into main Jul 15, 2026
84 checks passed
@steipete
steipete deleted the claude/desktop-gateway-discovery branch July 15, 2026 08:22
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

SunMe1977 pushed a commit to SunMe1977/openclaw that referenced this pull request Jul 15, 2026
…penclaw#108115)

New discovery.rs browses _openclaw-gw._tcp with a lifetime mdns-sd
browser, keeps a fullname-keyed snapshot (resolved updates replace,
goodbye/TTL removes), and mirrors the native clients' TXT contract and
direct-selection gate (resolved SRV endpoint routing; tailnetDns is a
hint only). The bootstrap page lists discovered gateways and connecting
navigates the dashboard WebView to the resolved endpoint, validated
against the live snapshot; remote selection cancels the local watchdog
so an in-flight local bootstrap cannot steal the WebView back.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 16, 2026
…penclaw#108115)

New discovery.rs browses _openclaw-gw._tcp with a lifetime mdns-sd
browser, keeps a fullname-keyed snapshot (resolved updates replace,
goodbye/TTL removes), and mirrors the native clients' TXT contract and
direct-selection gate (resolved SRV endpoint routing; tailnetDns is a
hint only). The bootstrap page lists discovered gateways and connecting
navigates the dashboard WebView to the resolved endpoint, validated
against the live snapshot; remote selection cancels the local watchdog
so an in-flight local bootstrap cannot steal the WebView back.
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
…penclaw#108115)

New discovery.rs browses _openclaw-gw._tcp with a lifetime mdns-sd
browser, keeps a fullname-keyed snapshot (resolved updates replace,
goodbye/TTL removes), and mirrors the native clients' TXT contract and
direct-selection gate (resolved SRV endpoint routing; tailnetDns is a
hint only). The bootstrap page lists discovered gateways and connecting
navigates the dashboard WebView to the resolved endpoint, validated
against the live snapshot; remote selection cancels the local watchdog
so an in-flight local bootstrap cannot steal the WebView back.
steipete added a commit that referenced this pull request Oct 15, 2026
#173117)

* refactor(apps): consolidate Android and Linux lifecycle paths

Share transcript-content serialization without changing persisted JSON bytes,
and move identical camera/chat JPEG resizing and recycling into one owner.
Stop re-encoding an oversized JPEG when neither quality nor size can change.
Reuse the first wide-area DNS SRV response instead of requesting it again for
an address already present in its additional records.
Use the discovery receiver handle as its liveness authority and inline the
single-caller logind connection wrapper.

Best-effort tradeoffs accepted

- Swarm pagination no longer rescans a moving roster four times. The feature's
  #113850 tests synthesize moving offsets, not a human actual-use incident;
  skipped workers refresh on the next session event. Strictly advancing offsets
  also make a separate seen-offset set unnecessary.
- Synchronous swarm projection now runs inside its existing lock rather than
  publishing through a second snapshot/revalidation path (#113850). There is
  no asynchronous gap to defend, and async response ownership checks remain.
- Wear startup uses the active connection slot, not a third promotion map and
  claim-order counters. #116593/#116592 describe a source/emulator timing audit,
  not an independent human incident. Production requests are actor-serialized;
  reconnect exactly during prior-owner retirement may keep the reserved channel
  instead of the newest one. Restarting Talk recovers. Normal reconnect, audio
  owner settlement, physical generations and FIFO writes remain.
- Wear peer registrations no longer carry generations (#109341/#109433).
  The removed regression forced a deferred send failure after rediscovery;
  a stale failure can now evict that peer until discovery or its next request.
- Read-only Wear Pulse polling no longer has a second request generation or
  synchronous duplicate route checks (#122123 initial feature/synthetic tests).
  One canceled poller owns the work; phone/agent/session/route checks remain.
- Discovery no longer has an independent alive flag or cleanup generation
  (#108115 synthetic adversarial review). Cleanup finishes before the receiver
  handle becomes finished, so a replacement cannot lose its snapshot.

No signing, permission, dependency, schema, durability or Gateway protocol
changes. The standalone session-memory backend is untouched.

Net production reduction: 214 lines, excluding tests and 12 removed inline Rust
test lines. The scope pass and two fresh independent passes found no further
sound bulk cuts. Below-500 branch handoff for coordinator bundling.

Baseline regression proof: the original JPEG algorithm encodes the same input
42 times; original DNS discovery makes PTR/SRV/SRV/TXT requests despite resolving
the expected public endpoint. Both new regressions failed on those exact counts.

Independent final review: scoped-clean, no actionable P0-P2 findings. Runtime
and Madge cycles: zero. Lint-suppressions: 3/3 passed. Check-changed repository
invariants and native schema gate passed; corrected Android fixture formatting
passed its focused ktlint replay. Tauri all-targets build/tests passed on macOS:
325 unit and 7 native lifecycle tests.

Linux-only build/logind proof remains for coordinator CI: the shared Testbox
allocation queued and was stopped without executing commands; no active lease.
No release gate dispatched, Apple target touched or hosted sandbox test run.

Android proof: 229 focused phone tests passed across the complete batch and
repaired discovery-class replay, plus 7 Wear lifecycle tests. Phone Play,
third-party and Wear debug APK builds passed. Full discovery replay passed
16 tests plus 2 DNS TXT tests, with no errors, failures or skips. The initial
full-class failure was a fixture singleton leak, fixed with a shadow-owned
factory/reset; endpoint and packet assertions remain unchanged.

* refactor(ios): share manual gateway security rows

Use one rendering owner for the identical Settings and onboarding TLS picker
and helper text. Preserve each original binding setter, transport policy,
forced-TLS disabling, typography and row order. Keep security behavior tests;
consolidate duplicate typography checks at the shared rendering owner.

Regenerate the shrinking native source inventory: six label sites become three
with the same IDs and strings. No translation memory or public contract changes.

Independent P0-P2 review is scoped-clean. SwiftFormat and canonical source lint
pass. Native platform builds and focused tests remain in progress.

Best-effort tradeoffs accepted: none; rendering consolidation only.

* refactor(apple): share presentation rows and remove duplicate task bookkeeping

Use cancellation already owned by Quick Chat reads and hover-card avatar/progress
tasks instead of a second request ID or generation comparison. Keep queued
subscription generations, route checks and all write-patch settlement.

Share media-unavailable rendering and notification priority translation while
preserving typography, strings, modifier order, sound policy and authorization.
Trust the process-lifetime LiveActivity singleton and the onboarding Candidate
already passed by its owning ForEach. The exhaustive hydration switch still
rejects idle and disconnected states; only its duplicate early guard is removed.

Best-effort tradeoffs accepted: none added by this equivalent-owner batch.
The branch's ReplayKit SDK duplicate-completion and seeded-runtime re-read
tradeoffs remain documented in the initial consolidation commit.

Source lint, formatting, parse, localization verification and lint-suppressions
pass. Independent P0-P2 review's hydration finding is declined because the
retained exhaustive switch returns false for both cited states. Native builds
and focused tests remain in progress; app-hosted macOS execution is excluded.

* refactor(apple): consolidate chat transport and capture lifecycle

Share common chat RPC application logic while retaining platform route authority
and non-retrying macOS compaction. Replace ReplayKit's startup phase machine
with awaited start/stop settlement, share speech-resource teardown, and remove
redundant identity/observer bookkeeping and DEBUG forwarding fixtures.

Best-effort tradeoffs accepted:
- ReplayKit duplicate startup completions are unsupported. The introducing
  lifecycle PR #103072 cites synthetic coverage, not a human duplicate-callback
  incident; a violated SDK single-completion contract now fails visibly.
- A same-user runtime mutation after seed validation is no longer re-read.
  Feature PR #161709 cites fixture proof, not a report requiring that duplicate
  validation; the next normal resolution validates concrete state again.

No signing, entitlement, bundle ID, permission, protocol, schema, or dependency
changes. Phase E session memory is untouched. Native build/test verification
is still running; app-hosted macOS execution requires a disposable OS environment.

* refactor(wear): retain pulse polling lifecycle guards

Drop the wave-5 pulse polling simplification after independent review raised uncertainty around late non-cancellation errors. Restore the production owner and lifecycle test byte-for-byte to the bundle base; keep the rest of the Android/Linux and Apple bundle unchanged.

* refactor(apps): retain established Wear and screenshot paths

Drop Wear channel claim cleanup after review identified stale claims displacing newer active Talk owners. Restore its complete lifecycle regressions. Drop ChatProTab and OpenClawBrand cleanup after the hosted iPad screenshot timeout did not reproduce in serial exact head/base replays; no claim of a proven timeout repair. Keep independent Android DNS and JPEG performance fixes and the remaining y18/y19 native-app cleanup.

* refactor(apps): drop Linux lifecycle cleanup from bundle

Apply the coordinator drop-hunks rule after the Linux onboarding Review permissions test reached Connection Settings instead of Native permissions. Routing owners are unchanged; without conclusive Linux replay, restore all y18 Linux runtime files to origin/main ace1908. Preserve Android and Apple cleanup, including the DNS and JPEG fixes. Park the original Linux hunks separately for native investigation; no timeout repair or inherited-red attribution claimed.

* refactor(apps): drop shared chat RPC consolidation

Restore the existing iOS/macOS adapters, shared extension and tests after the exact-head shared Periphery intersection reported the moved pager and metadata identities unused in both consumers. Apply the coordinator drop-hunks rule rather than suppressing the scanner or rerunning CI for green. Preserve route/server-lease authority and macOS no-retry compaction.

* refactor(android): drop chat cleanup after native fixture failure

Apply the coordinator changed-path drop rule after ChatCompletedWorkLayoutTest.completedWorkSummaryKeepsEarlierToolFailureVisible timed out waiting for refreshed tool-error history in third-party CI. Restore chat models, cache, controller, swarm and associated test deltas as one conservative unit. No causal timing repair or inherited-main attribution is claimed. Keep both Android DNS and JPEG fixes and retained Apple cleanup.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 16, 2026
openclaw#173117)

* refactor(apps): consolidate Android and Linux lifecycle paths

Share transcript-content serialization without changing persisted JSON bytes,
and move identical camera/chat JPEG resizing and recycling into one owner.
Stop re-encoding an oversized JPEG when neither quality nor size can change.
Reuse the first wide-area DNS SRV response instead of requesting it again for
an address already present in its additional records.
Use the discovery receiver handle as its liveness authority and inline the
single-caller logind connection wrapper.

Best-effort tradeoffs accepted

- Swarm pagination no longer rescans a moving roster four times. The feature's
  openclaw#113850 tests synthesize moving offsets, not a human actual-use incident;
  skipped workers refresh on the next session event. Strictly advancing offsets
  also make a separate seen-offset set unnecessary.
- Synchronous swarm projection now runs inside its existing lock rather than
  publishing through a second snapshot/revalidation path (openclaw#113850). There is
  no asynchronous gap to defend, and async response ownership checks remain.
- Wear startup uses the active connection slot, not a third promotion map and
  claim-order counters. openclaw#116593/openclaw#116592 describe a source/emulator timing audit,
  not an independent human incident. Production requests are actor-serialized;
  reconnect exactly during prior-owner retirement may keep the reserved channel
  instead of the newest one. Restarting Talk recovers. Normal reconnect, audio
  owner settlement, physical generations and FIFO writes remain.
- Wear peer registrations no longer carry generations (openclaw#109341/openclaw#109433).
  The removed regression forced a deferred send failure after rediscovery;
  a stale failure can now evict that peer until discovery or its next request.
- Read-only Wear Pulse polling no longer has a second request generation or
  synchronous duplicate route checks (openclaw#122123 initial feature/synthetic tests).
  One canceled poller owns the work; phone/agent/session/route checks remain.
- Discovery no longer has an independent alive flag or cleanup generation
  (openclaw#108115 synthetic adversarial review). Cleanup finishes before the receiver
  handle becomes finished, so a replacement cannot lose its snapshot.

No signing, permission, dependency, schema, durability or Gateway protocol
changes. The standalone session-memory backend is untouched.

Net production reduction: 214 lines, excluding tests and 12 removed inline Rust
test lines. The scope pass and two fresh independent passes found no further
sound bulk cuts. Below-500 branch handoff for coordinator bundling.

Baseline regression proof: the original JPEG algorithm encodes the same input
42 times; original DNS discovery makes PTR/SRV/SRV/TXT requests despite resolving
the expected public endpoint. Both new regressions failed on those exact counts.

Independent final review: scoped-clean, no actionable P0-P2 findings. Runtime
and Madge cycles: zero. Lint-suppressions: 3/3 passed. Check-changed repository
invariants and native schema gate passed; corrected Android fixture formatting
passed its focused ktlint replay. Tauri all-targets build/tests passed on macOS:
325 unit and 7 native lifecycle tests.

Linux-only build/logind proof remains for coordinator CI: the shared Testbox
allocation queued and was stopped without executing commands; no active lease.
No release gate dispatched, Apple target touched or hosted sandbox test run.

Android proof: 229 focused phone tests passed across the complete batch and
repaired discovery-class replay, plus 7 Wear lifecycle tests. Phone Play,
third-party and Wear debug APK builds passed. Full discovery replay passed
16 tests plus 2 DNS TXT tests, with no errors, failures or skips. The initial
full-class failure was a fixture singleton leak, fixed with a shadow-owned
factory/reset; endpoint and packet assertions remain unchanged.

* refactor(ios): share manual gateway security rows

Use one rendering owner for the identical Settings and onboarding TLS picker
and helper text. Preserve each original binding setter, transport policy,
forced-TLS disabling, typography and row order. Keep security behavior tests;
consolidate duplicate typography checks at the shared rendering owner.

Regenerate the shrinking native source inventory: six label sites become three
with the same IDs and strings. No translation memory or public contract changes.

Independent P0-P2 review is scoped-clean. SwiftFormat and canonical source lint
pass. Native platform builds and focused tests remain in progress.

Best-effort tradeoffs accepted: none; rendering consolidation only.

* refactor(apple): share presentation rows and remove duplicate task bookkeeping

Use cancellation already owned by Quick Chat reads and hover-card avatar/progress
tasks instead of a second request ID or generation comparison. Keep queued
subscription generations, route checks and all write-patch settlement.

Share media-unavailable rendering and notification priority translation while
preserving typography, strings, modifier order, sound policy and authorization.
Trust the process-lifetime LiveActivity singleton and the onboarding Candidate
already passed by its owning ForEach. The exhaustive hydration switch still
rejects idle and disconnected states; only its duplicate early guard is removed.

Best-effort tradeoffs accepted: none added by this equivalent-owner batch.
The branch's ReplayKit SDK duplicate-completion and seeded-runtime re-read
tradeoffs remain documented in the initial consolidation commit.

Source lint, formatting, parse, localization verification and lint-suppressions
pass. Independent P0-P2 review's hydration finding is declined because the
retained exhaustive switch returns false for both cited states. Native builds
and focused tests remain in progress; app-hosted macOS execution is excluded.

* refactor(apple): consolidate chat transport and capture lifecycle

Share common chat RPC application logic while retaining platform route authority
and non-retrying macOS compaction. Replace ReplayKit's startup phase machine
with awaited start/stop settlement, share speech-resource teardown, and remove
redundant identity/observer bookkeeping and DEBUG forwarding fixtures.

Best-effort tradeoffs accepted:
- ReplayKit duplicate startup completions are unsupported. The introducing
  lifecycle PR openclaw#103072 cites synthetic coverage, not a human duplicate-callback
  incident; a violated SDK single-completion contract now fails visibly.
- A same-user runtime mutation after seed validation is no longer re-read.
  Feature PR openclaw#161709 cites fixture proof, not a report requiring that duplicate
  validation; the next normal resolution validates concrete state again.

No signing, entitlement, bundle ID, permission, protocol, schema, or dependency
changes. Phase E session memory is untouched. Native build/test verification
is still running; app-hosted macOS execution requires a disposable OS environment.

* refactor(wear): retain pulse polling lifecycle guards

Drop the wave-5 pulse polling simplification after independent review raised uncertainty around late non-cancellation errors. Restore the production owner and lifecycle test byte-for-byte to the bundle base; keep the rest of the Android/Linux and Apple bundle unchanged.

* refactor(apps): retain established Wear and screenshot paths

Drop Wear channel claim cleanup after review identified stale claims displacing newer active Talk owners. Restore its complete lifecycle regressions. Drop ChatProTab and OpenClawBrand cleanup after the hosted iPad screenshot timeout did not reproduce in serial exact head/base replays; no claim of a proven timeout repair. Keep independent Android DNS and JPEG performance fixes and the remaining y18/y19 native-app cleanup.

* refactor(apps): drop Linux lifecycle cleanup from bundle

Apply the coordinator drop-hunks rule after the Linux onboarding Review permissions test reached Connection Settings instead of Native permissions. Routing owners are unchanged; without conclusive Linux replay, restore all y18 Linux runtime files to origin/main c975ae3. Preserve Android and Apple cleanup, including the DNS and JPEG fixes. Park the original Linux hunks separately for native investigation; no timeout repair or inherited-red attribution claimed.

* refactor(apps): drop shared chat RPC consolidation

Restore the existing iOS/macOS adapters, shared extension and tests after the exact-head shared Periphery intersection reported the moved pager and metadata identities unused in both consumers. Apply the coordinator drop-hunks rule rather than suppressing the scanner or rerunning CI for green. Preserve route/server-lease authority and macOS no-retry compaction.

* refactor(android): drop chat cleanup after native fixture failure

Apply the coordinator changed-path drop rule after ChatCompletedWorkLayoutTest.completedWorkSummaryKeepsEarlierToolFailureVisible timed out waiting for refreshed tool-error history in third-party CI. Restore chat models, cache, controller, swarm and associated test deltas as one conservative unit. No causal timing repair or inherited-main attribution is claimed. Keep both Android DNS and JPEG fixes and retained Apple cleanup.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: linux docs Improvements or additions to documentation maintainer Maintainer-authored PR plugin: linux-node size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant