Skip to content

Commit 2a18699

Browse files
authored
Merge branch 'main' into fix/followup-104030
2 parents 6797aa2 + b2a6408 commit 2a18699

226 files changed

Lines changed: 9882 additions & 1331 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/openclaw-performance.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ jobs:
171171
MATRIX_REPEAT: ${{ matrix.repeat }}
172172
MATRIX_DEEP_PROFILE: ${{ matrix.deep_profile }}
173173
MATRIX_LIVE: ${{ matrix.live }}
174+
OPENCLAW_OCM_RUNTIME_BUILD_PROFILE: ${{ (inputs.profile || 'diagnostic') == 'diagnostic' && 'sourcePerformance' || '' }}
174175
steps:
175176
- name: Decide lane
176177
id: lane

‎.github/workflows/openclaw-release-telegram-qa.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,15 +1777,15 @@ jobs:
17771777
control_pid="$!"
17781778
trap "kill ${control_pid} >/dev/null 2>&1 || true" EXIT
17791779
proc_marker_visible=false
1780-
# The child PID exists before execve publishes command-scoped env.
1780+
# The background child can still expose the shell's pre-exec environment.
17811781
for _ in {1..100}; do
1782-
if tr "\0" "\n" <"/proc/${control_pid}/environ" |
1782+
if tr "\0" "\n" <"/proc/${control_pid}/environ" 2>/dev/null |
17831783
grep -Fxq "OPENCLAW_QA_PROC_CONTROL=visible"; then
17841784
proc_marker_visible=true
17851785
break
17861786
fi
17871787
kill -0 "$control_pid" >/dev/null 2>&1 || break
1788-
sleep 0.01
1788+
sleep 0.05
17891789
done
17901790
[[ "$proc_marker_visible" == "true" ]]
17911791
# Reading the marker is the proof; the probe may exit before cleanup.

‎apps/.i18n/native-source.json‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -179,95 +179,95 @@
179179
},
180180
{
181181
"kind": "conditional-branch",
182-
"line": 116,
182+
"line": 163,
183183
"path": "apps/android/app/src/main/java/ai/openclaw/app/NodeForegroundService.kt",
184184
"source": "Connected",
185185
"surface": "android",
186186
"id": "native.android.012c8499137972ad"
187187
},
188188
{
189189
"kind": "conditional-branch",
190-
"line": 116,
190+
"line": 163,
191191
"path": "apps/android/app/src/main/java/ai/openclaw/app/NodeForegroundService.kt",
192192
"source": "Talk mode active",
193193
"surface": "android",
194194
"id": "native.android.3e0889d921c92cab"
195195
},
196196
{
197197
"kind": "conditional-branch",
198-
"line": 278,
198+
"line": 358,
199199
"path": "apps/android/app/src/main/java/ai/openclaw/app/NodeForegroundService.kt",
200200
"source": " · Mic: Listening",
201201
"surface": "android",
202202
"id": "native.android.ae88801e6a1b3343"
203203
},
204204
{
205205
"kind": "conditional-branch",
206-
"line": 278,
206+
"line": 358,
207207
"path": "apps/android/app/src/main/java/ai/openclaw/app/NodeForegroundService.kt",
208208
"source": " · Mic: Pending",
209209
"surface": "android",
210210
"id": "native.android.7521acb4a7bc9a75"
211211
},
212212
{
213213
"kind": "ui-state-text",
214-
"line": 649,
214+
"line": 666,
215215
"path": "apps/android/app/src/main/java/ai/openclaw/app/NodeRuntime.kt",
216216
"source": "Offline",
217217
"surface": "android",
218218
"id": "native.android.c65b61de70a063e7"
219219
},
220220
{
221221
"kind": "conditional-branch",
222-
"line": 1512,
222+
"line": 1529,
223223
"path": "apps/android/app/src/main/java/ai/openclaw/app/NodeRuntime.kt",
224224
"source": "Cron job started.",
225225
"surface": "android",
226226
"id": "native.android.fef5049bc20826c7"
227227
},
228228
{
229229
"kind": "conditional-branch",
230-
"line": 1512,
230+
"line": 1529,
231231
"path": "apps/android/app/src/main/java/ai/openclaw/app/NodeRuntime.kt",
232232
"source": "Cron run queued.",
233233
"surface": "android",
234234
"id": "native.android.c39fb6f80dbf6820"
235235
},
236236
{
237237
"kind": "conditional-branch",
238-
"line": 1556,
238+
"line": 1573,
239239
"path": "apps/android/app/src/main/java/ai/openclaw/app/NodeRuntime.kt",
240240
"source": "Cron job disabled.",
241241
"surface": "android",
242242
"id": "native.android.b878b2913410055a"
243243
},
244244
{
245245
"kind": "conditional-branch",
246-
"line": 1556,
246+
"line": 1573,
247247
"path": "apps/android/app/src/main/java/ai/openclaw/app/NodeRuntime.kt",
248248
"source": "Cron job enabled.",
249249
"surface": "android",
250250
"id": "native.android.a45ec59239fbfff0"
251251
},
252252
{
253253
"kind": "conditional-branch",
254-
"line": 3149,
254+
"line": 3169,
255255
"path": "apps/android/app/src/main/java/ai/openclaw/app/NodeRuntime.kt",
256256
"source": "Failed: no secure gateway endpoint was detected. Enable gateway TLS or Tailscale Serve, or use a trusted private LAN address with Unencrypted selected.",
257257
"surface": "android",
258258
"id": "native.android.4b07456682e725d9"
259259
},
260260
{
261261
"kind": "conditional-branch",
262-
"line": 3151,
262+
"line": 3171,
263263
"path": "apps/android/app/src/main/java/ai/openclaw/app/NodeRuntime.kt",
264264
"source": "Failed: secure endpoint reached, but TLS fingerprint verification timed out. Check Tailscale Serve or gateway TLS and retry.",
265265
"surface": "android",
266266
"id": "native.android.467899bb510b8e34"
267267
},
268268
{
269269
"kind": "conditional-branch",
270-
"line": 3153,
270+
"line": 3173,
271271
"path": "apps/android/app/src/main/java/ai/openclaw/app/NodeRuntime.kt",
272272
"source": "Failed: couldn't reach the secure gateway endpoint for this host.",
273273
"surface": "android",
@@ -435,15 +435,15 @@
435435
},
436436
{
437437
"kind": "conditional-branch",
438-
"line": 1303,
438+
"line": 1327,
439439
"path": "apps/android/app/src/main/java/ai/openclaw/app/gateway/GatewaySession.kt",
440440
"source": "Connecting…",
441441
"surface": "android",
442442
"id": "native.android.1cbaba9cbffb2f97"
443443
},
444444
{
445445
"kind": "conditional-branch",
446-
"line": 1303,
446+
"line": 1327,
447447
"path": "apps/android/app/src/main/java/ai/openclaw/app/gateway/GatewaySession.kt",
448448
"source": "Reconnecting…",
449449
"surface": "android",

‎apps/android/app/build.gradle.kts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,11 @@ android {
164164
productFlavors {
165165
create("play") {
166166
dimension = "store"
167+
manifestPlaceholders["nodeForegroundServiceType"] = "connectedDevice|microphone"
167168
}
168169
create("thirdParty") {
169170
dimension = "store"
171+
manifestPlaceholders["nodeForegroundServiceType"] = "connectedDevice|microphone|location"
170172
}
171173
}
172174

‎apps/android/app/src/main/AndroidManifest.xml‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@
1313
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
1414
<uses-permission android:name="android.permission.CAMERA" />
1515
<uses-permission android:name="android.permission.RECORD_AUDIO" />
16-
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
17-
<uses-permission android:name="android.permission.READ_MEDIA_VISUAL_USER_SELECTED" />
18-
<uses-permission
19-
android:name="android.permission.READ_EXTERNAL_STORAGE"
20-
android:maxSdkVersion="32" />
2116
<uses-permission android:name="android.permission.READ_CONTACTS" />
2217
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
2318
<uses-permission android:name="android.permission.READ_CALENDAR" />
@@ -51,7 +46,7 @@
5146
<service
5247
android:name=".NodeForegroundService"
5348
android:exported="false"
54-
android:foregroundServiceType="connectedDevice|microphone" />
49+
android:foregroundServiceType="${nodeForegroundServiceType}" />
5550
<service
5651
android:name="androidx.appcompat.app.AppLocalesMetadataHolderService"
5752
android:enabled="false"

‎apps/android/app/src/main/java/ai/openclaw/app/NodeApp.kt‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import ai.openclaw.app.gateway.DeviceIdentityStore
77
import android.app.Application
88
import android.os.StrictMode
99
import androidx.room.withTransaction
10+
import kotlinx.coroutines.CoroutineScope
11+
import kotlinx.coroutines.Dispatchers
12+
import kotlinx.coroutines.SupervisorJob
13+
import kotlinx.coroutines.launch
1014
import kotlinx.coroutines.runBlocking
1115

1216
/**
@@ -15,6 +19,7 @@ import kotlinx.coroutines.runBlocking
1519
class NodeApp : Application() {
1620
val prefs: SecurePrefs by lazy { SecurePrefs(this) }
1721

22+
private val runtimeScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
1823
private val runtimeLock = Any()
1924
private var runtimeInstance: NodeRuntime? = null
2025

@@ -26,6 +31,13 @@ class NodeApp : Application() {
2631
runtimeInstance ?: NodeRuntime(this, prefs).also { runtimeInstance = it }
2732
}
2833

34+
/** Creates a cold-process runtime with foreground-only capabilities disabled before publication. */
35+
internal fun ensureBackgroundRuntime(): NodeRuntime =
36+
synchronized(runtimeLock) {
37+
runtimeInstance
38+
?: NodeRuntime(this, prefs, initialForeground = false).also { runtimeInstance = it }
39+
}
40+
2941
internal fun ensureScreenshotFixtureRuntime(): NodeRuntime =
3042
synchronized(runtimeLock) {
3143
check(BuildConfig.DEBUG) { "Android screenshot fixtures require a debug build" }
@@ -41,6 +53,13 @@ class NodeApp : Application() {
4153
*/
4254
fun peekRuntime(): NodeRuntime? = synchronized(runtimeLock) { runtimeInstance }
4355

56+
/** Disconnects the current or concurrently constructing runtime without blocking the caller. */
57+
internal fun disconnectRuntimeAsync() {
58+
// The process-owned scope outlives a stopping service, so cancellation cannot
59+
// strand an Activity-created runtime that the service has not observed yet.
60+
runtimeScope.launch { peekRuntime()?.disconnect() }
61+
}
62+
4463
/** Clears pairing auth without racing lazy process-runtime construction. */
4564
suspend fun resetGatewaySetupAuth(stableId: String): Boolean {
4665
val runtime =

‎apps/android/app/src/main/java/ai/openclaw/app/NodeForegroundService.kt‎

Lines changed: 87 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,75 @@ import android.content.Context
1010
import android.content.Intent
1111
import android.content.pm.PackageManager
1212
import android.content.pm.ServiceInfo
13+
import android.util.Log
1314
import androidx.core.app.NotificationCompat
1415
import androidx.core.app.ServiceCompat
1516
import androidx.core.content.ContextCompat
17+
import kotlinx.coroutines.CancellationException
1618
import kotlinx.coroutines.CoroutineScope
1719
import kotlinx.coroutines.Dispatchers
1820
import kotlinx.coroutines.Job
1921
import kotlinx.coroutines.SupervisorJob
2022
import kotlinx.coroutines.cancel
2123
import kotlinx.coroutines.flow.combine
2224
import kotlinx.coroutines.launch
25+
import kotlinx.coroutines.withContext
2326

2427
/** Foreground service that keeps the Android node connection and voice capture visible to the OS. */
2528
class NodeForegroundService : Service() {
2629
private val scope: CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
2730
private var notificationJob: Job? = null
31+
private var runtimeRestoreJob: Job? = null
32+
private var activeRuntime: NodeRuntime? = null
33+
private var latestStartId = 0
2834
private var voiceCaptureMode = VoiceCaptureMode.Off
2935

36+
@Volatile private var disconnectRequested = false
37+
3038
override fun onCreate() {
3139
super.onCreate()
3240
ensureChannel()
3341
val initial = buildNotification(title = "OpenClaw Node", text = "Starting…")
3442
startForegroundWithTypes(notification = initial)
43+
}
3544

36-
val runtime = (application as NodeApp).peekRuntime()
37-
if (runtime == null) {
38-
stopSelf()
39-
return
40-
}
45+
private fun startRuntimeIfNeeded(startId: Int) {
46+
if (activeRuntime != null || runtimeRestoreJob?.isActive == true || disconnectRequested) return
47+
val app = application as NodeApp
48+
runtimeRestoreJob =
49+
scope.launch(Dispatchers.Default) {
50+
try {
51+
restoreStickyRuntime(
52+
createRuntime = app::ensureBackgroundRuntime,
53+
disconnectRequested = { disconnectRequested },
54+
disconnectRuntime = NodeRuntime::disconnect,
55+
) { restoredRuntime ->
56+
withContext(Dispatchers.Main) {
57+
runtimeRestoreJob = null
58+
if (disconnectRequested) {
59+
false
60+
} else {
61+
activeRuntime = restoredRuntime
62+
observeRuntime(restoredRuntime)
63+
true
64+
}
65+
}
66+
}
67+
} catch (err: CancellationException) {
68+
throw err
69+
} catch (err: Throwable) {
70+
Log.e("OpenClawNodeService", "Failed to restore node runtime", err)
71+
withContext(Dispatchers.Main) {
72+
runtimeRestoreJob = null
73+
if (!disconnectRequested && !stopSelfResult(startId)) {
74+
startRuntimeIfNeeded(latestStartId)
75+
}
76+
}
77+
}
78+
}
79+
}
80+
81+
private fun observeRuntime(runtime: NodeRuntime) {
4182
// Keep the connection tuple atomic, then split connection and capture work so notification text
4283
// can update without restarting runtime-owned connection work.
4384
notificationJob =
@@ -101,10 +142,16 @@ class NodeForegroundService : Service() {
101142
flags: Int,
102143
startId: Int,
103144
): Int {
145+
latestStartId = maxOf(latestStartId, startId)
104146
when (intent?.action) {
105147
ACTION_STOP -> {
106-
(application as NodeApp).peekRuntime()?.disconnect()
107-
stopSelf()
148+
disconnectRequested = true
149+
runtimeRestoreJob?.cancel()
150+
runtimeRestoreJob = null
151+
activeRuntime?.disconnect()
152+
activeRuntime = null
153+
(application as NodeApp).disconnectRuntimeAsync()
154+
stopSelfResult(startId)
108155
return START_NOT_STICKY
109156
}
110157
ACTION_SET_VOICE_CAPTURE_MODE -> {
@@ -118,6 +165,14 @@ class NodeForegroundService : Service() {
118165
)
119166
}
120167
}
168+
if (disconnectRequested) {
169+
// A STOP can lose stopSelfResult to a newer queued start. Let the newest
170+
// start id close the service instead of leaving a disconnected FGS alive.
171+
stopSelfResult(startId)
172+
return START_NOT_STICKY
173+
}
174+
// START_STICKY recreates the service in a fresh process and calls this with a null intent.
175+
startRuntimeIfNeeded(startId)
121176
// Keep running; connection is managed by NodeRuntime (auto-reconnect + manual).
122177
return START_STICKY
123178
}
@@ -233,6 +288,31 @@ class NodeForegroundService : Service() {
233288
}
234289
}
235290

291+
/** Restores process-local state after Android recreates a sticky service in a fresh process. */
292+
internal suspend fun <T> restoreStickyRuntime(
293+
createRuntime: () -> T,
294+
disconnectRequested: () -> Boolean,
295+
disconnectRuntime: (T) -> Unit,
296+
activateRuntime: suspend (T) -> Boolean,
297+
) {
298+
// A queued recovery may begin after STOP; do not construct process state once
299+
// disconnect has already won. The post-create check still closes the race during construction.
300+
if (disconnectRequested()) return
301+
val runtime = createRuntime()
302+
var activated = false
303+
try {
304+
if (!disconnectRequested()) {
305+
activated = activateRuntime(runtime)
306+
}
307+
} finally {
308+
// Ownership transfers only after activation. Stop/cancellation during the
309+
// dispatcher hop must disconnect the recovered runtime instead of leaking it.
310+
if (!activated) {
311+
disconnectRuntime(runtime)
312+
}
313+
}
314+
}
315+
236316
internal fun foregroundServiceTypes(
237317
voiceMode: VoiceCaptureMode,
238318
backgroundLocationActive: Boolean,

0 commit comments

Comments
 (0)