Skip to content

Commit 7c008e2

Browse files
feat(daemon): report the host CPU architecture in /health (callstack#3047)
1 parent 1433e11 commit 7c008e2

9 files changed

Lines changed: 51 additions & 8 deletions

File tree

‎packages/contracts/src/daemon-http.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,14 @@ test('buildDaemonHealthPayload takes the version from its caller and keeps the p
6464
},
6565
);
6666
});
67+
68+
test('buildDaemonHealthPayload reports the host arch in Apple naming when the caller passes one', () => {
69+
assert.equal(
70+
buildDaemonHealthPayload('agent-device-daemon', '0.20.9', { nodeArch: 'x64' }).hostArch,
71+
'x86_64',
72+
);
73+
assert.equal(
74+
buildDaemonHealthPayload('agent-device-daemon', '0.20.9', { nodeArch: 'arm64' }).hostArch,
75+
'arm64',
76+
);
77+
});

‎packages/contracts/src/daemon-http.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,26 @@ export type DaemonHealthPayload = {
5656
version: string;
5757
rpcProtocolVersion: number;
5858
instanceId?: string;
59+
hostArch?: string;
5960
upstream?: unknown;
6061
};
6162

6263
export function buildDaemonHealthPayload(
6364
service: DaemonHealthPayload['service'],
6465
version: string,
65-
options: { upstream?: unknown; instanceId?: string } = {},
66+
options: { upstream?: unknown; instanceId?: string; nodeArch?: string } = {},
6667
): DaemonHealthPayload {
6768
return {
6869
ok: true,
6970
service,
7071
version,
7172
rpcProtocolVersion: DAEMON_RPC_PROTOCOL_VERSION,
7273
...(options.instanceId !== undefined ? { instanceId: options.instanceId } : {}),
74+
...(options.nodeArch !== undefined ? { hostArch: appleHostArch(options.nodeArch) } : {}),
7375
...(options.upstream !== undefined ? { upstream: options.upstream } : {}),
7476
};
7577
}
78+
79+
function appleHostArch(nodeArch: string): string {
80+
return nodeArch === 'x64' ? 'x86_64' : nodeArch;
81+
}

‎src/__tests__/daemon-proxy.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ test('daemon proxy leaves health endpoint unauthenticated', async (t) => {
458458
assert.equal(typeof payload.version, 'string');
459459
assert.equal(payload.rpcProtocolVersion, DAEMON_RPC_PROTOCOL_VERSION);
460460
assert.equal(typeof payload.instanceId, 'string');
461+
assert.equal(typeof payload.hostArch, 'string');
461462
assert.deepEqual(payload.upstream, { ok: true });
462463
assert.equal(upstreamAuth, 'Bearer daemon-secret');
463464
assert.equal(upstreamTokenHeader, 'daemon-secret');

‎src/daemon-client/__tests__/daemon-client-health-compat.test.ts‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ import {
1515
* what the check itself accepts and refuses when a proxy sits in front of the daemon.
1616
*/
1717

18-
const DAEMON_LINK = { ok: true, service: 'agent-device-daemon', version: '98.0.0' } as const;
18+
const DAEMON_LINK = {
19+
ok: true,
20+
service: 'agent-device-daemon',
21+
version: '98.0.0',
22+
hostArch: 'arm64',
23+
} as const;
1924

2025
async function withHealthServer<T>(
2126
payload: Record<string, unknown>,
@@ -40,6 +45,7 @@ function proxyHealth(upstreamRpcProtocolVersion: number): Record<string, unknown
4045
service: 'agent-device-proxy',
4146
version: '99.0.0',
4247
rpcProtocolVersion: DAEMON_RPC_PROTOCOL_VERSION,
48+
hostArch: 'x86_64',
4349
upstream: { ...DAEMON_LINK, rpcProtocolVersion: upstreamRpcProtocolVersion },
4450
};
4551
}
@@ -51,10 +57,12 @@ test('a proxy whose daemon speaks the same protocol passes with the upstream lin
5157
const health = await readRemoteDaemonHealth({ baseUrl, token: 'proxy-token', pid: 0 });
5258
assert.equal(health.reachable, true);
5359
assert.equal(health.service, 'agent-device-proxy');
60+
assert.equal(health.hostArch, 'x86_64');
5461
assert.deepEqual(health.upstream, {
5562
service: 'agent-device-daemon',
5663
version: '98.0.0',
5764
rpcProtocolVersion: DAEMON_RPC_PROTOCOL_VERSION,
65+
hostArch: 'arm64',
5866
});
5967
});
6068
});
@@ -79,15 +87,17 @@ test('a proxy whose daemon speaks another protocol is refused, naming the daemon
7987
});
8088
});
8189

82-
test('a daemon health payload without an upstream link parses as before', async (t) => {
90+
test('a daemon health payload without an upstream link or host arch parses as before', async (t) => {
8391
if (await skipWhenLoopbackUnavailable(t)) return;
8492

93+
const { hostArch: _hostArch, ...legacyLink } = DAEMON_LINK;
8594
await withHealthServer(
86-
{ ...DAEMON_LINK, rpcProtocolVersion: DAEMON_RPC_PROTOCOL_VERSION },
95+
{ ...legacyLink, rpcProtocolVersion: DAEMON_RPC_PROTOCOL_VERSION },
8796
async (baseUrl) => {
8897
const health = await readRemoteDaemonHealth({ baseUrl, token: 'daemon-token', pid: 0 });
8998
assert.equal(health.reachable, true);
9099
assert.equal(health.upstream, undefined);
100+
assert.equal('hostArch' in health, false);
91101
assert.equal(health.rpcProtocolVersion, DAEMON_RPC_PROTOCOL_VERSION);
92102
},
93103
);

‎src/daemon-client/daemon-client-transport.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@ export type RemoteDaemonHealth = {
4040
version?: string;
4141
rpcProtocolVersion?: number;
4242
instanceId?: string;
43+
hostArch?: string;
4344
/** The daemon behind a proxy, as the proxy's health reported it. */
4445
upstream?: RemoteDaemonHealthLink;
4546
};
4647

4748
type RemoteDaemonHealthLink = Pick<
4849
RemoteDaemonHealth,
49-
'service' | 'version' | 'rpcProtocolVersion' | 'instanceId'
50+
'service' | 'version' | 'rpcProtocolVersion' | 'instanceId' | 'hostArch'
5051
>;
5152

5253
export async function canConnect(
@@ -203,6 +204,7 @@ function readHealthLink(parsed: Record<string, unknown>): RemoteDaemonHealthLink
203204
rpcProtocolVersion:
204205
typeof parsed.rpcProtocolVersion === 'number' ? parsed.rpcProtocolVersion : undefined,
205206
...(typeof parsed.instanceId === 'string' ? { instanceId: parsed.instanceId } : {}),
207+
...(typeof parsed.hostArch === 'string' ? { hostArch: parsed.hostArch } : {}),
206208
};
207209
}
208210

‎src/daemon/server/http-server.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,10 @@ export async function createDaemonHttpServer(options: {
583583
res.setHeader('content-type', 'application/json');
584584
res.end(
585585
JSON.stringify(
586-
buildDaemonHealthPayload('agent-device-daemon', readVersion(), { instanceId }),
586+
buildDaemonHealthPayload('agent-device-daemon', readVersion(), {
587+
instanceId,
588+
nodeArch: process.arch,
589+
}),
587590
),
588591
);
589592
return;

‎src/remote/daemon-proxy.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@ async function sendProxyHealth(
119119
res.setHeader('content-type', 'application/json');
120120
res.end(
121121
JSON.stringify(
122-
buildDaemonHealthPayload('agent-device-proxy', readVersion(), { upstream, instanceId }),
122+
buildDaemonHealthPayload('agent-device-proxy', readVersion(), {
123+
upstream,
124+
instanceId,
125+
nodeArch: process.arch,
126+
}),
123127
),
124128
);
125129
}

‎website/docs/docs/remote-proxy.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ the device-host VM must use the daemon's loopback port and local daemon token.
125125

126126
Remote clients read `/health` before issuing commands and compare the daemon RPC protocol version. Keep the client and proxy versions reasonably close; patch-level differences should normally work, but incompatible RPC protocol versions fail before commands run.
127127

128+
`/health` also reports `hostArch`, the CPU architecture of the proxy host and, under `upstream`, of the daemon host (`arm64` or `x86_64`). Simulators on that host run this architecture unless their runtime uses Rosetta, so a client that builds simulator apps for a remote host can compile only that slice. Older daemons omit the field.
129+
130+
```json
131+
{"ok":true,"service":"agent-device-proxy","version":"0.21.17","rpcProtocolVersion":2,"hostArch":"arm64","upstream":{"ok":true,"service":"agent-device-daemon","version":"0.21.17","rpcProtocolVersion":2,"hostArch":"arm64"}}
132+
```
133+
128134
## Cleanup
129135

130136
Run `agent-device disconnect` when the remote session is done. Stop the tunnel and the `agent-device proxy` process only when the host should stop accepting remote clients. Restarting the proxy generates a fresh token unless you supplied `--daemon-auth-token` explicitly.

‎website/docs/docs/security-trust.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ description: Security and trust guidance for agent-device local app automation,
1818
CLI commands run through a per-user background daemon:
1919

2020
- The daemon binds to `127.0.0.1` only, on ephemeral ports, for both its socket and HTTP transports. It is never reachable from the network unless you deliberately front it with your own proxy.
21-
- Command (RPC), upload, artifact-download, and `/admin/human-control/*` requests must present a token generated fresh on each daemon boot (24 random bytes). The only unauthenticated endpoint is `GET /health`, which intentionally returns a bare liveness response and nothing else; like the rest of the server it is reachable only via loopback. The token is stored in `daemon.json` inside the daemon state directory (`~/.agent-device` for packaged installs; source checkouts use a worktree-scoped directory under `~/.agent-device/dev/`) with `0600` permissions; whoever can read that file already has your user account.
21+
- Command (RPC), upload, artifact-download, and `/admin/human-control/*` requests must present a token generated fresh on each daemon boot (24 random bytes). The only unauthenticated endpoint is `GET /health`, which intentionally returns only liveness, package and protocol version, instance ID, and host CPU architecture; like the rest of the server it is reachable only via loopback. The token is stored in `daemon.json` inside the daemon state directory (`~/.agent-device` for packaged installs; source checkouts use a worktree-scoped directory under `~/.agent-device/dev/`) with `0600` permissions; whoever can read that file already has your user account.
2222
- A client reuses a running daemon only when the version matches its own and both sides can vouch for the same code, which the daemon records in `daemon.json` as its code origin. Two installs of one published version are the same artifact, so they have nothing further to compare and share one daemon; demanding a fingerprint between them made the second install replace a daemon already running its code and drop the live session on it (#2458). Every other pair is judged by the daemon's code fingerprint: a checkout compares its own, and a pair whose trees cannot match at all — a checkout against an install, or an install against a daemon too old to report an origin — restarts the daemon rather than run code it cannot identify. The fingerprint compares file sizes and timestamps, never contents, so an install whose files were hand-replaced under its own version is still not detected.
2323
- Artifact uploads are size-capped, filenames are sanitized, and archive extraction rejects path-traversal entries. Artifact downloads resolve through server-side IDs, never client-supplied paths.
2424

0 commit comments

Comments
 (0)