Skip to content

fix(android): restore sticky node service - #104226

Merged
steipete merged 1 commit into
openclaw:mainfrom
NianJiuZst:codex/fix-android-sticky-service-recovery
Jul 11, 2026
Merged

steipete merged 1 commit into
openclaw:mainfrom
NianJiuZst:codex/fix-android-sticky-service-recovery

Conversation

@NianJiuZst

@NianJiuZst NianJiuZst commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where Android declared the node foreground service START_STICKY, but a process-death restart always stopped because onCreate() only accepted an already-existing process-local NodeRuntime. The OS restart therefore could not restore the node connection it was intended to keep alive.

Why This Change Was Made

onCreate() now establishes foreground notification state only. Every non-STOP onStartCommand() (including Android's null-intent sticky restart) starts one off-main recovery and atomically publishes a background-safe runtime. Ownership transfers to the service only after activation; cancellation, STOP, or activation failure disconnects an unowned runtime.

A cold STOP never constructs a runtime. STOP also uses a process-owned disconnect fallback so an Activity-created or concurrently constructing runtime is not stranded after the service scope ends. Newer start IDs are stopped again after a STOP so a queued start cannot leave a disconnected foreground service alive.

Cold recovery initializes NodeRuntime as background before publication and clears persisted microphone capture instead of briefly reviving foreground-only capabilities without an Activity.

User Impact

When Android recreates the sticky foreground service in a fresh process, OpenClaw can reconstruct the node runtime and resume its normal Gateway reconnect loop. Explicit STOP remains terminal and does not create or leak a runtime.

Evidence

AI-assisted change. I reviewed the service/process ownership races and background capability boundary.

Focused Robolectric coverage verifies:

  • null-intent sticky recovery creates and activates one runtime;
  • cold STOP does not create a runtime;
  • a queued recovery performs zero construction when STOP already won;
  • STOP racing recovery disconnects before ownership transfer;
  • a later start ID after STOP calls stopSelfResult again;
  • background runtime construction starts non-foreground and does not restore microphone capture.

Final local verification used both Android product flavors (Testbox unavailable for this contributor):

apps/android/gradlew -p apps/android --no-daemon \
  :app:testPlayDebugUnitTest :app:testThirdPartyDebugUnitTest \
  --tests ai.openclaw.app.NodeForegroundServiceTest \
  :app:runKtlintCheckOverMainSourceSet :app:runKtlintCheckOverTestSourceSet
# Play: 10 passed
# ThirdParty: 10 passed
# failures/errors/skipped: 0

git diff --check
.agents/skills/autoreview/scripts/autoreview --mode branch --base upstream/main

The repository native-i18n generator was also run and this PR commits the Android inventory line shifts caused by the service/runtime changes. The current base independently has two uncommitted MenuBar.swift inventory line shifts (321 -> 322); a non-Android branch reproduces that same remaining native:i18n:check failure, so this PR does not duplicate the unrelated macOS baseline update.

No physical-device process-kill test was run; the proof is deterministic service/runtime lifecycle coverage under Robolectric.

Agent Transcript

Redacted Codex session transcript: Android sticky service recovery
source: [LOCAL_SESSION]
redaction: local paths, credentials, raw tool output, system/developer prompts, and unrelated turns omitted

[user excerpt]
[P1] Android sticky 前台服务在进程回收后必然停止,无法恢复节点连接

[assistant]
Android sticky 分支的复核暴露了两个更隐蔽的稳定性问题:冷恢复 runtime 会短暂被当成“Activity 前台”,而冷 STOP 还可能在主线程等待 runtime 构造锁。我正在把恢复入口移到非 STOP 的 onStartCommand,让 STOP 不创建 runtime、不阻塞主线程,并把“初始前后台状态”作为 NodeRuntime 构造事实传入。

[tool summary]
Play and ThirdParty each passed all 10 NodeForegroundService tests, ktlint, and diff checks. The final branch review reported no actionable findings after the STOP-before-construction race was fixed.

@NianJiuZst
NianJiuZst force-pushed the codex/fix-android-sticky-service-recovery branch 2 times, most recently from 146bb6a to 25b2fd8 Compare July 11, 2026 06:45
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. labels Jul 11, 2026
@clawsweeper

clawsweeper Bot commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 11, 2026, 7:43 AM ET / 11:43 UTC.

Summary
The PR reconstructs a background-safe Android node runtime during sticky foreground-service restart, hardens STOP and ownership races, and adds focused Robolectric coverage.

PR surface: Other +257. Total +257 across 5 files.

Reproducibility: yes. at high confidence from current-main source: a fresh-process sticky restart has no process runtime and the service stops itself. This review did not run the path on an emulator or physical device.

Review metrics: none identified.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🐚 platinum hermit
Result: blocked until real behavior proof from a real setup is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Post redacted emulator or physical-device evidence showing process death, sticky service recreation, runtime activation, and Gateway reconnect; updating the PR body should trigger a fresh review, otherwise ask a maintainer to comment @clawsweeper re-review.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The PR provides focused Robolectric coverage and copied local output but no observed emulator or physical-device process-death recovery; added evidence should redact private identifiers, endpoints, credentials, and other sensitive data. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] No emulator or physical-device evidence demonstrates OS process death, null-intent sticky recreation, runtime activation, and Gateway reconnection.
  • [P1] Because the patch changes service/runtime ownership, an incorrect platform assumption could leave the Android node offline despite green unit tests.

Maintainer options:

  1. Require real restart proof (recommended)
    Keep merge blocked until redacted Android emulator or device evidence demonstrates the full fresh-process sticky recovery.
  2. Accept reviewed lifecycle coverage
    An Android owner may explicitly accept the focused tests and source-level lifecycle evidence without device proof.

Next step before merge

  • [P1] No actionable code defect remains; the active PR needs an Android owner to enforce or explicitly waive the real-behavior proof gate.

Maintainer decision needed

  • Question: Require emulator or physical-device process-death proof before merging this external Android sticky-service fix, or explicitly waive that gate?
  • Rationale: The implementation matches the existing lifecycle architecture and focused tests cover the races, but the contributor has not observed the actual OS-managed restart path.
  • Likely owner: steipete — This person is the active assignee and review requester and appears in recent history for the affected Android paths.
  • Options:
    • Require real restart proof (recommended): Ask for redacted emulator or physical-device logs or a recording showing process death, null-intent recreation, runtime activation, and Gateway reconnect.
    • Waive with owner sign-off: An Android owner explicitly accepts the deterministic lifecycle tests and reviewed platform assumptions as sufficient.

Security
Cleared: The exact current head changes only Android lifecycle code, tests, and generated line inventory, with no concrete security or supply-chain concern; the visible SSRF thread belongs to an unrelated dropped hunk.

Review details

Best possible solution:

Keep the focused single-runtime lifecycle design and merge only after redacted real Android restart proof or an explicit Android-owner waiver of that proof gate.

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

Yes at high confidence from current-main source: a fresh-process sticky restart has no process runtime and the service stops itself. This review did not run the path on an emulator or physical device.

Is this the best way to solve the issue?

Yes. The patch repairs the canonical service/singleton boundary, performs expensive construction off-main, preserves Activity foreground adoption, and avoids adding a fallback or duplicate runtime path.

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P1: The PR fixes an Android node workflow that remains disconnected after OS process death.
  • merge-risk: 🚨 availability: The changed service/runtime ownership determines whether the Android node reconnects and shuts down cleanly.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR provides focused Robolectric coverage and copied local output but no observed emulator or physical-device process-death recovery; added evidence should redact private identifiers, endpoints, credentials, and other sensitive data. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Other +257. Total +257 across 5 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 5 278 21 +257
Total 5 278 21 +257

What I checked:

Likely related people:

  • steipete: The live PR is assigned to this person with review requests initiated, and they authored the recent current-main commit carrying the affected Android service and runtime paths. (role: assignee and recent area contributor; confidence: high; commits: e8cbc62e3e44; files: apps/android/app/src/main/java/ai/openclaw/app/NodeForegroundService.kt, apps/android/app/src/main/java/ai/openclaw/app/NodeRuntime.kt)
  • Ayaan Zaidi: Merged history shows the largest contribution count across the central Android service, application, and runtime files, including prior lazy-runtime and gateway auto-connect behavior. (role: feature-history contributor; confidence: high; commits: 64e412e57e72, 0443ee82be77; files: apps/android/app/src/main/java/ai/openclaw/app/NodeForegroundService.kt, apps/android/app/src/main/java/ai/openclaw/app/NodeApp.kt, apps/android/app/src/main/java/ai/openclaw/app/NodeRuntime.kt)
  • Michael Faath: Recent merged work on Android voice teardown and reply behavior overlaps the foreground capability and disconnect boundary affected by this patch. (role: adjacent voice-runtime contributor; confidence: medium; commits: 628fc2119257, 5942b1062eb4; files: apps/android/app/src/main/java/ai/openclaw/app/NodeRuntime.kt)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.
Review history (5 earlier review cycles)
  • reviewed 2026-07-11T07:00:34.722Z sha 25b2fd88bc4321e9a54cae4700f05f22bcf7b7f0 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-11T07:09:00.420Z sha 25b2fd88bc4321e9a54cae4700f05f22bcf7b7f0 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-11T07:17:25.250Z sha 25b2fd88bc4321e9a54cae4700f05f22bcf7b7f0 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-11T08:03:34.814Z sha 9b1c718faeb3d05cb6da0bce91e9c0fd5420f15e :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-11T11:34:30.245Z sha 5e1e4f193a157c430252ae17e50e45bdc8dc39dc :: needs real behavior proof before merge. :: none

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. label Jul 11, 2026
@NianJiuZst
NianJiuZst force-pushed the codex/fix-android-sticky-service-recovery branch from 25b2fd8 to 9b1c718 Compare July 11, 2026 07:35
@steipete steipete self-assigned this Jul 11, 2026
@steipete
steipete requested review from a team as code owners July 11, 2026 11:27
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: discord Channel integration: discord channel: googlechat Channel integration: googlechat channel: line Channel integration: line channel: matrix Channel integration: matrix channel: slack Channel integration: slack channel: telegram Channel integration: telegram channel: tlon Channel integration: tlon channel: voice-call Channel integration: voice-call channel: zalouser Channel integration: zalouser app: ios App: ios app: macos App: macos app: web-ui App: web-ui gateway Gateway runtime extensions: diagnostics-otel Extension: diagnostics-otel extensions: memory-core Extension: memory-core extensions: open-prose Extension: open-prose labels Jul 11, 2026
@github-actions

github-actions Bot commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

Dependency graph guard cleared

This PR no longer has blocked dependency graph changes. A future dependency graph change requires a fresh /allow-dependencies-change comment after the guard blocks that new head SHA.

  • Current SHA: 8f00b831199f2590965c31fa079b27be93f5b919

Comment thread scripts/anthropic-prompt-probe.ts Dismissed
@steipete
steipete force-pushed the codex/fix-android-sticky-service-recovery branch from 5e1e4f1 to 8f00b83 Compare July 11, 2026 11:35
@openclaw-barnacle openclaw-barnacle Bot removed docs Improvements or additions to documentation channel: discord Channel integration: discord channel: googlechat Channel integration: googlechat channel: line Channel integration: line channel: matrix Channel integration: matrix channel: slack Channel integration: slack labels Jul 11, 2026
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

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

Labels

app: android App: android merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants