Skip to content

Commit e4c25bd

Browse files
authored
fix(gateway): clarify URL override auth recovery
1 parent 24d89e6 commit e4c25bd

120 files changed

Lines changed: 2275 additions & 1026 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.

‎CHANGELOG.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ Docs: https://docs.openclaw.ai
1313
### Fixes
1414

1515
- **iOS Voice Wake cleanup:** avoid initializing the microphone audio pipeline while disabling inactive Voice Wake, preventing simulator launch aborts and unnecessary audio setup.
16+
- **Cron duration validation:** reject positive durations that truncate below one millisecond instead of silently scheduling a zero-duration interval. (#100311) Thanks @qingminglong.
17+
- **Skill workshop proposals:** preserve the terminal newline in generated proposal Markdown while still rejecting blank raw content. (#100293) Thanks @anyech.
18+
- **Agent tool inputs and LSP startup:** treat blank optional integer arguments as absent, and fail embedded LSP startup immediately when its child process cannot spawn. (#100273, #99922) Thanks @snotty and @cxbAsDev.
19+
- **Gateway and memory diagnostics:** report failed start-session persistence and close-time memory work instead of silently discarding those failures. (#100313, #100308) Thanks @masatohoshino and @lin-hongkuan.
20+
- **Unicode and plugin package verification:** match native slice semantics for reversed UTF-16 bounds, and reject published plugin packages that omit `openclaw.plugin.json`. (#100014, #99904) Thanks @Simon-XYDT and @849261680.
21+
- **Android invoke cancellation:** preserve coroutine cancellation through camera handlers and the Gateway invoke boundary so cancelled work cannot emit a stale result. (#99916) Thanks @xialonglee.
22+
- **Codex native hook relay diagnostics:** avoid bridge registry writes before the local relay server begins listening. (#100300) Thanks @nankingjing.
1623
- **Agent stop recovery:** prevent late-aborting prompts from reacquiring orphaned session locks after teardown, so `/stop` leaves the conversation ready for the next turn.
1724
- **Message delivery status:** report failed and partially failed best-effort channel delivery instead of returning a success-shaped message-tool result. (#99928) Thanks @masatohoshino.
1825
- **WhatsApp credential recovery:** restore malformed primary auth state from a valid backup during startup. (#99070) Thanks @LeonidasLux.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,15 +371,15 @@
371371
},
372372
{
373373
"kind": "conditional-branch",
374-
"line": 1096,
374+
"line": 1098,
375375
"path": "apps/android/app/src/main/java/ai/openclaw/app/gateway/GatewaySession.kt",
376376
"source": "Connecting…",
377377
"surface": "android",
378378
"id": "native.android.1cbaba9cbffb2f97"
379379
},
380380
{
381381
"kind": "conditional-branch",
382-
"line": 1096,
382+
"line": 1098,
383383
"path": "apps/android/app/src/main/java/ai/openclaw/app/gateway/GatewaySession.kt",
384384
"source": "Reconnecting…",
385385
"surface": "android",

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,8 @@ class GatewaySession(
10151015
try {
10161016
onInvoke?.invoke(InvokeRequest(id, nodeId, command, params, timeoutMs))
10171017
?: InvokeResult.error("UNAVAILABLE", "invoke handler missing")
1018+
} catch (err: CancellationException) {
1019+
throw err
10181020
} catch (err: Throwable) {
10191021
invokeErrorFromThrowable(err)
10201022
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import ai.openclaw.app.gateway.GatewaySession
66
import android.content.Context
77
import kotlinx.coroutines.Dispatchers
88
import kotlinx.coroutines.flow.MutableStateFlow
9+
import kotlinx.coroutines.CancellationException
910
import kotlinx.coroutines.withContext
1011
import kotlinx.serialization.json.Json
1112
import kotlinx.serialization.json.JsonPrimitive
@@ -55,6 +56,8 @@ class CameraHandler(
5556
)
5657
}.toString()
5758
GatewaySession.InvokeResult.ok(payload)
59+
} catch (err: CancellationException) {
60+
throw err
5861
} catch (err: Throwable) {
5962
val (code, message) = invokeErrorFromThrowable(err)
6063
GatewaySession.InvokeResult.error(code = code, message = message)
@@ -83,6 +86,8 @@ class CameraHandler(
8386
val r = camera.snap(paramsJson)
8487
camLog("success, payload size=${r.payloadJson.length}")
8588
r
89+
} catch (err: CancellationException) {
90+
throw err
8691
} catch (err: Throwable) {
8792
camLog("inner error: ${err::class.java.simpleName}: ${err.message}")
8893
camLog("stack: ${err.stackTraceToString().take(2000)}")
@@ -93,6 +98,8 @@ class CameraHandler(
9398
camLog("returning result")
9499
showCameraHud("Photo captured", CameraHudKind.Success, 1600)
95100
return GatewaySession.InvokeResult.ok(res.payloadJson)
101+
} catch (err: CancellationException) {
102+
throw err
96103
} catch (err: Throwable) {
97104
camLog("outer error: ${err::class.java.simpleName}: ${err.message}")
98105
camLog("stack: ${err.stackTraceToString().take(2000)}")
@@ -123,6 +130,8 @@ class CameraHandler(
123130
val r = camera.clip(paramsJson)
124131
clipLog("success, file size=${r.file.length()}")
125132
r
133+
} catch (err: CancellationException) {
134+
throw err
126135
} catch (err: Throwable) {
127136
clipLog("inner error: ${err::class.java.simpleName}: ${err.message}")
128137
clipLog("stack: ${err.stackTraceToString().take(2000)}")
@@ -157,6 +166,8 @@ class CameraHandler(
157166
return GatewaySession.InvokeResult.ok(
158167
"""{"format":"mp4","base64":"$base64","durationMs":${filePayload.durationMs},"hasAudio":${filePayload.hasAudio}}""",
159168
)
169+
} catch (err: CancellationException) {
170+
throw err
160171
} catch (err: Throwable) {
161172
clipLog("outer error: ${err::class.java.simpleName}: ${err.message}")
162173
clipLog("stack: ${err.stackTraceToString().take(2000)}")

‎apps/android/app/src/test/java/ai/openclaw/app/gateway/GatewaySessionInvokeTest.kt‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,47 @@ class GatewaySessionInvokeTest {
763763
)
764764
}
765765

766+
@Test
767+
fun nodeInvokeRequest_doesNotSendResultAfterCancellation() =
768+
runBlocking {
769+
val json = testJson()
770+
val connected = CompletableDeferred<Unit>()
771+
val invokeStarted = CompletableDeferred<Unit>()
772+
val invokeResult = CompletableDeferred<Unit>()
773+
val lastDisconnect = AtomicReference("")
774+
val serverWebSocket = AtomicReference<WebSocket?>(null)
775+
val server =
776+
startGatewayServer(json) { webSocket, id, method, _ ->
777+
serverWebSocket.set(webSocket)
778+
when (method) {
779+
"connect" -> {
780+
webSocket.send(connectResponseFrame(id))
781+
webSocket.send(
782+
"""{"type":"event","event":"node.invoke.request","payload":{"id":"invoke-cancelled","nodeId":"node-1","command":"camera.snap","timeoutMs":5000}}""",
783+
)
784+
}
785+
"node.invoke.result" -> invokeResult.complete(Unit)
786+
}
787+
}
788+
val harness =
789+
createNodeHarness(connected = connected, lastDisconnect = lastDisconnect) {
790+
invokeStarted.complete(Unit)
791+
throw CancellationException("cancelled")
792+
}
793+
794+
try {
795+
connectNodeSession(harness.session, server.port)
796+
awaitConnectedOrThrow(connected, lastDisconnect, server)
797+
withTimeout(TEST_TIMEOUT_MS) { invokeStarted.await() }
798+
799+
assertNull(withTimeoutOrNull(250) { invokeResult.await() })
800+
} finally {
801+
serverWebSocket.get()?.close(1000, "done")
802+
delay(100)
803+
shutdownHarness(harness, server)
804+
}
805+
}
806+
766807
@Test
767808
fun sendNodeEventDetailed_sendsPresenceAlivePayloadAndReturnsStructuredResponse() =
768809
runBlocking {

‎docs/docs_map.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4821,6 +4821,12 @@ Do not edit it by hand; run `pnpm docs:map:gen`.
48214821
- Route: /platforms/android
48224822
- Headings:
48234823
- H2: Support snapshot
4824+
- H2: Mirror and control Android from a remote Mac
4825+
- H3: Before you begin
4826+
- H3: Enable ADB over TCP
4827+
- H3: Allow only the controller Mac
4828+
- H3: Connect and start mirroring
4829+
- H3: Troubleshooting
48244830
- H2: Connection runbook
48254831
- H3: Prerequisites
48264832
- H3: 1. Start the Gateway

‎docs/platforms/android.md‎

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ summary: "Android app (node): connection runbook + Connect/Chat/Voice/Canvas com
33
read_when:
44
- Pairing or reconnecting the Android node
55
- Debugging Android gateway discovery or auth
6+
- Mirroring or controlling an Android device from a remote Mac
67
- Verifying chat history parity across clients
78
title: "Android app"
89
---
@@ -21,6 +22,100 @@ The official Android app is available on [Google Play](https://play.google.com/s
2122

2223
System control (launchd/systemd) lives on the Gateway host — see [Gateway](/gateway).
2324

25+
## Mirror and control Android from a remote Mac
26+
27+
[scrcpy](https://github.com/Genymobile/scrcpy) mirrors an Android screen in a macOS window and
28+
forwards keyboard and pointer input through Android Debug Bridge (ADB). This is an operator-side
29+
workflow, separate from the OpenClaw node connection. It is useful when the Android device and the
30+
Mac are in different locations but share a private Tailscale network.
31+
32+
### Before you begin
33+
34+
- Install Tailscale on the Android device and the Mac, and connect both to the same tailnet.
35+
- On Android, enable **Developer options** and **USB debugging**. Android 16 places **Wireless
36+
debugging** under **Settings > System > Developer options**. See [Android developer
37+
options](https://developer.android.com/studio/debug/dev-options).
38+
- Install scrcpy and ADB on the Mac:
39+
40+
```bash
41+
brew install scrcpy
42+
brew install --cask android-platform-tools
43+
```
44+
45+
- Keep the Android device available for the first connection. Android must approve each Mac's ADB
46+
key before that Mac can control the device.
47+
48+
### Enable ADB over TCP
49+
50+
For the initial setup, connect the Android device by USB to a trusted computer and approve its
51+
debugging prompt. Then run:
52+
53+
```bash
54+
adb devices
55+
adb tcpip 5555
56+
```
57+
58+
You can now disconnect USB. If port 5555 stops listening after a device reboot or debugging reset,
59+
repeat this local setup step. Android 11 and later can also establish the initial trust with
60+
**Wireless debugging > Pair device with pairing code** and `adb pair`.
61+
62+
### Allow only the controller Mac
63+
64+
Tailnets with restrictive grants must explicitly allow the controller Mac to reach TCP port 5555
65+
on the Android device. Add a narrow rule to the tailnet policy, replacing the example addresses
66+
with the two devices' stable Tailscale IPs:
67+
68+
```json5
69+
{
70+
grants: [
71+
{
72+
src: ["<remote-mac-tailnet-ip>"],
73+
dst: ["<android-tailnet-ip>"],
74+
ip: ["tcp:5555"],
75+
},
76+
],
77+
}
78+
```
79+
80+
See [Tailscale grants](https://tailscale.com/docs/reference/syntax/grants) for host aliases and other
81+
selectors. Do not grant this port to the public internet or expose it with Funnel: an authorized ADB
82+
client has broad control of the device.
83+
84+
### Connect and start mirroring
85+
86+
On the remote Mac:
87+
88+
```bash
89+
adb connect <android-tailnet-ip>:5555
90+
adb devices
91+
scrcpy --serial <android-tailnet-ip>:5555
92+
```
93+
94+
The first `adb connect` from this Mac shows an authorization dialog on Android. Unlock the device,
95+
confirm the key fingerprint, and select **Always allow from this computer** only when the Mac is
96+
trusted. A successful `adb devices` entry ends in `device`; `unauthorized` means the on-device prompt
97+
has not been approved.
98+
99+
Once the scrcpy window opens, use it directly or target it with a macOS screen-automation tool such
100+
as [Peekaboo](https://peekaboo.sh/). scrcpy carries the display and input; Tailscale provides only the
101+
private network path.
102+
103+
### Troubleshooting
104+
105+
- `Connection timed out`: verify the tailnet grant for TCP 5555. A successful `tailscale ping` proves
106+
peer reachability, not that policy permits this TCP port. Test with
107+
`nc -vz <android-tailnet-ip> 5555` from the Mac.
108+
- `unauthorized`: unlock Android and approve the remote Mac's ADB key, or remove the stale workstation
109+
under **Wireless debugging > Paired devices** and pair it again.
110+
- `Connection refused`: reconnect locally and run `adb tcpip 5555` again.
111+
- More than one device listed: keep the explicit `--serial <android-tailnet-ip>:5555` argument.
112+
113+
When finished, close scrcpy and disconnect ADB:
114+
115+
```bash
116+
adb disconnect <android-tailnet-ip>:5555
117+
```
118+
24119
## Connection runbook
25120

26121
Android node app ⇄ (mDNS/NSD + WebSocket) ⇄ **Gateway**

‎extensions/browser/src/browser/pw-session.get-page-for-targetid.extension-fallback.test.ts‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,15 @@ describe("pw-session getPageForTargetId", () => {
146146
urls: ["https://alpha.example", "https://beta.example"],
147147
}).pages;
148148

149-
const fetchSpy = vi.spyOn(globalThis, "fetch").mockResolvedValue({
150-
ok: true,
151-
json: async () => [
152-
{ id: "TARGET_A", url: "https://alpha.example" },
153-
{ id: "TARGET_B", url: "https://beta.example" },
154-
],
155-
} as Response);
149+
const fetchSpy = vi.spyOn(globalThis, "fetch").mockResolvedValue(
150+
new Response(
151+
JSON.stringify([
152+
{ id: "TARGET_A", url: "https://alpha.example" },
153+
{ id: "TARGET_B", url: "https://beta.example" },
154+
]),
155+
{ headers: { "content-type": "application/json" } },
156+
),
157+
);
156158

157159
try {
158160
const resolved = await getPageForTargetId({
@@ -180,13 +182,15 @@ describe("pw-session getPageForTargetId", () => {
180182
});
181183
const [, pageB] = pages;
182184

183-
const fetchSpy = vi.spyOn(globalThis, "fetch").mockResolvedValue({
184-
ok: true,
185-
json: async () => [
186-
{ id: "TARGET_A", url: "https://alpha.example" },
187-
{ id: "TARGET_B", url: "https://beta.example" },
188-
],
189-
} as Response);
185+
const fetchSpy = vi.spyOn(globalThis, "fetch").mockResolvedValue(
186+
new Response(
187+
JSON.stringify([
188+
{ id: "TARGET_A", url: "https://alpha.example" },
189+
{ id: "TARGET_B", url: "https://beta.example" },
190+
]),
191+
{ headers: { "content-type": "application/json" } },
192+
),
193+
);
190194

191195
try {
192196
const resolved = await getPageForTargetId({

‎extensions/browser/src/browser/routes/tabs.attach-only.test.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ describe("browser tab routes attachOnly loopback profiles", () => {
3939

4040
const fetchMock = vi.fn(async (url: unknown) => {
4141
expect(String(url)).toBe("http://127.0.0.1:9222/json/list");
42-
return {
43-
ok: true,
44-
json: async () => [
42+
return new Response(
43+
JSON.stringify([
4544
{
4645
id: "PAGE-1",
4746
title: "WordPress",
4847
url: "https://example.com/wp-login.php",
4948
webSocketDebuggerUrl: "ws://127.0.0.1:9222/devtools/page/PAGE-1",
5049
type: "page",
5150
},
52-
],
53-
} as unknown as Response;
51+
]),
52+
{ headers: { "content-type": "application/json" } },
53+
);
5454
});
5555
vi.stubGlobal("fetch", fetchMock);
5656

‎extensions/browser/src/browser/server.control-server.test-harness.ts‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -551,15 +551,12 @@ export function makeResponse(
551551
body: unknown,
552552
init?: { ok?: boolean; status?: number; text?: string },
553553
): Response {
554-
const ok = init?.ok ?? true;
555-
const status = init?.status ?? 200;
556-
const text = init?.text ?? "";
557-
return {
558-
ok,
554+
const status = init?.status ?? (init?.ok === false ? 500 : 200);
555+
const responseBody = init?.text ?? JSON.stringify(body);
556+
return new Response(responseBody, {
559557
status,
560-
json: async () => body,
561-
text: async () => text,
562-
} as unknown as Response;
558+
headers: { "content-type": "application/json" },
559+
});
563560
}
564561

565562
function mockClearAll(obj: Record<string, { mockClear: () => unknown }>) {

0 commit comments

Comments
 (0)