Skip to content

fix(android): serialize legacy gateway discovery - #131001

Merged
steipete merged 2 commits into
mainfrom
codex/android-ten-legacy-nsd
Aug 27, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/android-ten-legacy-nsd

Conversation

@steipete

Copy link
Copy Markdown
Contributor
Additional instructions

MUST: Keep Allow edits from maintainers enabled for this PR so maintainers can help update the branch when needed.

What Problem This Solves

Fixes an issue where users browsing nearby gateways in Android Gateway settings would see only some available gateways when several were advertised together on Android 12, 12L, or 13 (API 31–33).

On a real API 33 emulator, three task gateways were advertised before opening the ordinary app. Gateway settings showed only one. The production list still contained just that one after the full UI scan, although all three subsequently resolved successfully through the public Android SDK. The matched fixed replay exposes all three.

Why This Change Was Made

Legacy Android NSD accepts only one active resolution per client; submitting another before the first finishes is rejected. Discovery now owns that slot through the real success or failure callback and queues other discovered services. Losing an active service invalidates its result without releasing the still-live platform slot; lost queued services are removed, and an old completion cannot overwrite a rediscovered service.

The queue reuses the existing service-identity registry and has one iterative drain for synchronous SDK rejection and asynchronous completion. This replaces reflective fire-and-forget resolution rather than adding retries, delays, configuration, or trust policy. Android 14+ streaming discovery, address selection, wide-area DNS, and process-owned discovery lifetime are unchanged.

Production LOC: +51/-25 (net +26). Tests: +199/-9 (net +190). Changelog: +1. Growth is the required ownership of the legacy platform slot and pending service generations; shared identity handling absorbs the old duplicate setup, and seven added lines are house-format wrapping.

User Impact

Nearby gateway lists on supported older Android releases can expose all simultaneously advertised gateways instead of silently losing extra resolutions. Departed services are still removed. Pairing, credentials, permissions, connection policy, and settings do not change.

Evidence

Matched real Android flow

Observation Unchanged baseline Fixed app
Three real services advertised before app launch Confirmed Confirmed
Production list and real Gateway settings Only 1 of 3 after complete UI scan All 3 before independent resolution controls
Subsequent sequential Android SDK resolutions All 3 succeeded with matching advertised ports All 3 succeeded with matching advertised ports
Withdrawal of one published service Observer loss and production removal confirmed Observer loss and production removal confirmed; 2 remain
Fixture cleanup No cleanup failures No cleanup failures
JUnit Intended missing-publication failure, 63.248 seconds 1 test passed, 34.795 seconds

The independent discovery observer establishes advertisement availability, not a count of the production listener's callbacks. Both runs capture the initial app observation before independent SDK controls, so those controls cannot warm the resolver cache first. No credentials were supplied and no gateway connection was attempted. Elapsed times identify the runs, not a performance comparison.

Both runs used the same archived native test APK, SHA256 e4a44ab05d8ad2d45118c6dbbcc101af1e61face1bd2f2f285073f280628d8e8, on actual API 33 Google APIs ARM64. The platform-specific fixture is disposable proof infrastructure and is not included in this PR. Each run ended before task-process and emulator cleanup. Startup and accessibility warnings are retained in the evidence; this is not a warning-free-log claim.

Fixed APK SHA256 ab5d6b1bedf72371a283b8d7990bcacde40c61c3f7d43f81eb78a34f105a9ccd was built from the reviewed source snapshot before commit. Its packaged metadata records baseline 9bd50c803cce88f2ab387ddaf6cc29b4ef004005, not the later fix commit. All three files in cb8f669a648a8dce6c33e32e1a38f7c8a74bbf32 were byte-compared with that reviewed source archive; production SHA256 is 35f11b430afce3f12c7432a9fedba425b6b5ad6e7a5e3d1638f4ef0c4bbd80c1.

Before: one visible gateway despite three independently resolvable advertisements. After: all three visible before the SDK controls. Only synthetic task names, guest addresses, and empty credential fields appear in these unedited captures.

Before After
Before: only one of three advertised gateways is visible After: all three advertised gateways are visible

Regression and repository checks

  • Original 11 owner cases: five intended failures on unchanged production, then all 11 passed with the fix; executed method sets were compared exactly.
  • Both flavors: 22 tests each, 44 passing, covering queue ownership, lost/rediscovered generations, scope cancellation, synchronous rejection, existing address/status behavior, Bonjour decoding, network-state tracking, and fleet selection.
  • Both actual Android lint variants passed with no warnings/errors; all four unfiltered Kotlin-format checks, Play debug assembly, native localization verification, and canonical changed-file guard passed.
  • Final isolated P2 autoreview and independent source/local/native review found no actionable findings. An earlier review correctly identified that the disposable API33-only driver must not land; it was moved out of the PR checkout without changing the matched fixture.

The additional synchronous-rejection case failed with StackOverflowError against the exact initial unlanded recursive candidate, then passed against the iterative fix in both flavors (65/85 ms). This is SDK-boundary unit stress evidence, not a claim of a shipped or native app crash.

The dependency contract was inspected directly in Android 13 NsdService and NsdManager callback/resolve handling, with Android 12 corroboration. Modern discovery and wide-area DNS were inspected as unchanged siblings. This does not claim a live wide-area DNS query, Android 14+ native replay, or gateway authentication/transport proof.

Named follow-up outside this fix: Android's release-task heuristic also matches Release inside a debug test filter. The original 11-case replay used a single-match wildcard for that method and verified the exact executed names; no signing settings or credentials changed.

AI-assisted with Codex; source, tests, and native evidence independently reviewed.

@clawsweeper

clawsweeper Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added app: android App: android size: M maintainer Maintainer-authored PR labels Aug 27, 2026
@steipete
steipete marked this pull request as ready for review August 27, 2026 15:47
@steipete steipete closed this Aug 27, 2026
@steipete steipete reopened this Aug 27, 2026
@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 Aug 27, 2026
@clawsweeper

clawsweeper Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 27, 2026, 12:53 PM ET / 16:53 UTC.

ClawSweeper review

What this changes

The PR serializes Android 12–13 NSD gateway resolutions so multiple nearby gateways are queued rather than silently omitted.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep open for normal maintainer handling. The queue repair is at the legacy resolver owner and no P0–P2 introduced defect was found; remove the release-owned changelog edit and complete platform-contract verification before merge.

Priority: P2
Reviewed head: 55ce4effe334ca17af97c7aaa9e9878fa8521a2b

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The targeted implementation and behavioral tests are solid, with one small release-process cleanup and a platform-contract verification gap.
Proof confidence 🌊 off-meta tidepool Not applicable: The author is a repository member, so the external-contributor proof gate does not apply; the PR body nevertheless includes submitted native API-33 before/after evidence.
Patch quality 🐚 platinum hermit (4/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The author is a repository member, so the external-contributor proof gate does not apply; the PR body nevertheless includes submitted native API-33 before/after evidence.
Evidence reviewed 6 items Current-main behavior: Current main still sends each legacy discovery directly through the reflective one-shot resolver, so the central change is not already present.
Owner-boundary repair: The introduced path deduplicates by service identity, retains the active legacy resolution until its terminal callback, and advances the FIFO queue afterward.
Behavioral regression coverage: Added API-33 cases cover sequential resolution, terminal failure, queued loss, loss then rediscovery, cancellation, and synchronous rejection without adding a production test seam.
Findings 1 actionable finding [P3] Remove the release-owned changelog entry
Security None None.

How this fits together

Android Gateway settings and onboarding turn nearby DNS-SD advertisements into selectable gateway endpoints. Android 12–13 use one-shot resolution, while Android 14+ uses streaming callbacks.

flowchart LR
  A[Nearby gateway advertisements] --> B[Android NSD discovery]
  B --> C{Android version}
  C -->|12-13| D[One-slot resolution queue]
  C -->|14+| E[Streaming service callback]
  D --> F[Gateway endpoint registry]
  E --> F
  F --> G[Onboarding and Settings list]
Loading

Before merge

  • Remove the release-owned changelog entry (P3) - CHANGELOG.md is release-owned in this repository; normal PRs must carry release-note context in their body or commit metadata instead. Remove this introduced entry before merge.
  • Resolve merge risk (P1) - The fix has a net production increase of 26 lines; persistent queue state and a terminal callback listener appear necessary, and the previous reflective resolver path is removed, but no net-neutral form was independently established.
  • Resolve merge risk (P1) - Direct Android 12–13 NSD framework source could not be retrieved in this offline environment, leaving the single-handler callback-dispatch assumption unverified by this review.
  • Complete next step (P2) - This current maintainer-authored PR needs its small release-process cleanup and ordinary platform/CI review rather than a repair-lane branch.

Findings

  • [P3] Remove the release-owned changelog entry — CHANGELOG.md:73
Agent review details

Security

None.

PR surface

Docs +1, Other +216. Total +217 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 0 0 0 0
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 2 250 34 +216
Total 3 251 34 +217

Review metrics

Metric Value Why it matters
Production vs test LOC production +26 net; tests +190 net The new production state owns legacy resolve-slot lifetime; tests add coverage for the queue’s terminal and rediscovery cases.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep the queue at the legacy resolver owner, remove the release-owned changelog hunk, and verify the Android NSD callback contract before exact-head Android CI completes.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep the queue at the legacy resolver owner, remove the release-owned changelog hunk, and verify the Android NSD callback contract before exact-head Android CI completes.

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

Unclear for independent reproduction: the PR body supplies an API-33 before/after replay, but this read-only environment could not run it or retrieve the Android framework contract.

Is this the best way to solve the issue?

Unclear: the repair is at the correct ownership boundary and preserves Android 14+ behavior, but the Android 12–13 callback-dispatch contract still needs direct confirmation.

Full review comments:

  • [P3] Remove the release-owned changelog entry — CHANGELOG.md:73
    CHANGELOG.md is release-owned in this repository; normal PRs must carry release-note context in their body or commit metadata instead. Remove this introduced entry before merge.
    Confidence: 0.99

Overall correctness: patch is correct
Overall confidence: 0.87

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against aa0647d06d27.

Labels

Label changes:

  • add P2: This repairs a bounded reliability defect in gateway discovery on supported Android 12–13 devices.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The author is a repository member, so the external-contributor proof gate does not apply; the PR body nevertheless includes submitted native API-33 before/after evidence.

Label justifications:

  • P2: This repairs a bounded reliability defect in gateway discovery on supported Android 12–13 devices.
  • 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 author is a repository member, so the external-contributor proof gate does not apply; the PR body nevertheless includes submitted native API-33 before/after evidence.

Evidence

What I checked:

Likely related people:

  • Hannes Rudolph: Git blame identifies commit 1fd1d3c as the source of the legacy discovery and direct resolver implementation this PR replaces. (role: original feature author; confidence: high; commits: 1fd1d3ccb975; files: apps/android/app/src/main/java/ai/openclaw/app/gateway/GatewayDiscovery.kt)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Remove the introduced CHANGELOG.md entry.
  • Confirm Android 12–13 NSD callback dispatch against the framework source, then await exact-head Android checks.

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.

@steipete

Copy link
Copy Markdown
Contributor Author

Maintainer disposition for the latest review and its Rank-up moves: retaining the existing changelog entry under explicit maintainer instruction for this user-facing repair. The requested removal is consciously declined; this is a changelog-policy exception only, not a waiver of CI, review, or platform verification. The follow-up commit only relocates that unchanged line to avoid a parallel insertion conflict; the entire Android subtree is byte-identical to the previously tested commit.

The Android 12–13 callback-dispatch contract is now directly verified against primary framework source. Android 12 NsdManager creates one HandlerThread/ServiceHandler at lines514–517 and directly dispatches discovery and terminal resolution callbacks at415–420 and450–457. Android 13 NsdManager routes binder callbacks through its manager handler (497–569); the exact discovery and resolution overloads used here choose Runnable::run (903–904 and1058–1059), so their listener callbacks stay on that handler. The server-side one-active-resolution rule is explicit in Android 12 NsdService (388–407) and Android 13 NsdService (404–423). These checks close the hosted review's framework-source access gap; they do not claim a separate native Android 12 run.

Production growth is explicitly accepted: +51/−25, net+26; tests +199/−9, net+190. The state belongs to the legacy resolver and retains the physical platform slot until its terminal callback, including loss/rediscovery identity and caller cancellation. A lock around the asynchronous call would end too early, and coroutine cancellation does not cancel the outstanding legacy platform request. The repair reuses listener identity storage and removes the reflective one-shot path and ignored failure callback. Iterative draining handles synchronous rejection without the stack overflow demonstrated by the rejected recursive candidate. This is a concrete ownership/lifetime justification, not an assertion that every possible net-neutral implementation was disproved. Android 14+ and wide-area paths remain unchanged.

The refreshed exact head 55ce4effe334ca17af97c7aaa9e9878fa8521a2b now has successful CI, including all six Android jobs, actual native-i18n source verification, security checks, and the required openclaw/ci-gate. Local proof includes the original11 regression cases and44 tests across both app flavors, both lint tasks and all four module style checks. The paired native API33 evidence already embedded above uses the same test APK: baseline publishes and displays only one of three advertised gateways; the fix publishes and displays all three before the independent SDK controls run, then removes the withdrawn gateway and completes cleanup. Native proof covers that task-owned native API33 discovery flow, not TCP/authentication delivery or a physical-device fleet. Both literal Rank-up moves and the production-growth risk are therefore explicitly dispositioned without another source change or a repair-lane rerun.

@steipete
steipete merged commit fd7e9bb into main Aug 27, 2026
70 checks passed
@steipete
steipete deleted the codex/android-ten-legacy-nsd branch August 27, 2026 17:26
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

threely-lab pushed a commit to threely-lab/openclaw that referenced this pull request Aug 28, 2026
* fix(android): serialize legacy gateway discovery resolution

* chore(android): avoid parallel changelog insertion conflict
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 28, 2026
* fix(android): serialize legacy gateway discovery resolution

* chore(android): avoid parallel changelog insertion conflict
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: android App: android maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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