Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/adr/0006-daemon-rpc-protocol-version.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Accepted

- Before remote JSON-RPC requests, compare the daemon's `rpcProtocolVersion` from `/health`, or send them on the checked route, where the server makes that comparison.
- The checked route reaches its authentication verdict exactly as `/rpc` does, then refuses protocol skew before dispatch, with HTTP 409 and a typed `x-agent-device-refusal` header.
- A client uses the checked route only when `connect` recorded it for the connection. It never resends a checked call on a response, and never falls back to `/rpc` after one.
- Package `version` is diagnostic only and must not be used as a compatibility gate.
- Allow a missing `rpcProtocolVersion` unless a later security or protocol decision explicitly retires legacy compatibility.
- A persistent client may cache a successful probe if `/health` advertises an instance ID for the daemon endpoint and, for a proxy, for its upstream daemon.
Expand Down Expand Up @@ -92,6 +93,12 @@ A daemon that serves `checked-rpc` also serves `script-artifacts`, so the route

The route, not a header, is what makes the check safe.
Released daemons and proxies answer an unknown route with 404 before dispatch, and they ignore unknown headers on `/rpc`.
A 404 is still not proof of non-dispatch, because a gateway can answer for a command that ran.
So a client does not discover the route.
`connect` records `daemonRpc: "checked"` from the remote-config profile only when `/health` advertises `checked-rpc` on the endpoint and, for a proxy, on its `upstream`.
With it recorded, a 404 that is not a JSON-RPC answer fails with `remote_checked_rpc_unsupported` and `dispatched: 'unknown'`, and the client does not resend.
A flow with remote side effects before its command keeps the `/health` probe and the instance headers for every call: an upload, and a lease allocate or heartbeat.
Only a connect that never opened is evidence that nothing left: a refused one fails at once, and a timed-out one runs fresh `/health` probes within the command's budget, then sends once.

## Alternatives Considered

Expand All @@ -102,6 +109,7 @@ Released daemons and proxies answer an unknown route with 404 before dispatch, a
- **Negotiate full schemas.** This is more precise, but it is too much machinery for the current JSON-RPC boundary.
- **Persist the `/health` answer in the client state directory (#5134).** It saves the probe across CLI processes, but it adds a local trust boundary and cache rules, and a rollback to a daemon that ignores instance headers would dispatch on a stale view.
- **Send the protocol as a header on `/rpc`.** Released daemons ignore unknown headers and dispatch anyway.
- **Fall back to `/health` and `/rpc` after a 404 on the checked route.** A 404 can come after dispatch, so the fallback could run a command twice.

## Consequences

Expand Down
2 changes: 2 additions & 0 deletions packages/command-surface/src/command-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ function buildFlags(options: InternalRequestOptions): CommandFlags {
daemonBaseUrl: options.daemonBaseUrl,
daemonTransport: options.daemonTransport,
daemonServerMode: options.daemonServerMode,
daemonRpc: options.daemonRpc,
daemonRpcTarget: options.daemonRpcTarget,
...leaseScopeToCommandFlags(leaseScope),
provider: options.provider,
providerSessionId: options.providerSessionId,
Expand Down
5 changes: 5 additions & 0 deletions packages/contracts/src/cli-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
} from '@agent-device/kernel/contracts';
import type {
CloudProviderProfileFields,
DaemonRpcMode,
RemoteConfigMetroOptions,
} from './remote-config-fields.ts';
import type { ScreenshotRequestFlags } from './screenshot.ts';
Expand All @@ -40,6 +41,10 @@ export type CliFlags = CloudProviderProfileFields &
daemonAuthToken?: string;
daemonTransport?: DaemonTransportPreference;
daemonServerMode?: DaemonServerMode;
/** No CLI token: the connection `connect` recorded sets it. */
daemonRpc?: DaemonRpcMode;
/** No CLI token: the fingerprint of the checked target `connect` approved. */
daemonRpcTarget?: string;
proxyHost?: string;
proxyPort?: number;
publicOrigin?: string;
Expand Down
6 changes: 6 additions & 0 deletions packages/contracts/src/client-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ export type AgentDeviceClientConfig = RemoteConnectionProfileFields &
* {@link DaemonBinding}.
*/
daemonBinding?: DaemonBinding;
/**
* The fingerprint of the checked RPC target `connect` approved. The CLI sets it from the
* connection record, and checked RPC then applies only to that exact target. SDK callers leave it
* unset.
*/
daemonRpcTarget?: string;
session?: string;
lockPolicy?: DaemonLockPolicy;
lockPlatform?: PlatformSelector;
Expand Down
7 changes: 6 additions & 1 deletion packages/contracts/src/daemon-http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,18 @@ export type CheckedRpcProtocolRefusal =
| typeof DAEMON_HTTP_REFUSALS.protocolMismatch;

/** Why a checked RPC call failed. */
const DAEMON_CHECKED_RPC_REASONS = {
export const DAEMON_CHECKED_RPC_REASONS = {
// The checked RPC call named no RPC protocol. An intermediary that strips request headers causes
// this.
protocolMissing: { reason: 'remote_rpc_protocol_missing' },
// The daemon or proxy speaks a different RPC protocol from the caller. After authentication,
// `details.service`, `details.version` and `details.rpcProtocolVersion` name the side that refused.
protocolMismatch: { reason: 'remote_rpc_protocol_mismatch' },
// The connection sets `daemonRpc: checked`, but the remote does not serve checked RPC: `connect`
// found no `checked-rpc` capability in its `/health`, or a command got the route answered as
// unknown. A command is never resent, because an ingress may have answered for one that ran.
// Update the remote daemon or proxy, or remove `daemonRpc` from the connection.
routeUnsupported: { reason: 'remote_checked_rpc_unsupported' },
Comment thread
thymikee marked this conversation as resolved.
Resolved
} as const satisfies ReasonTable<'remote connection'>;

/**
Expand Down
2 changes: 2 additions & 0 deletions packages/contracts/src/facades/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ export type {
ProviderConnectionVerification,
} from '../provider-connection.ts';
export {
DAEMON_RPC_MODES,
PROVIDER_DEVICE_ORIENTATIONS,
PROVIDER_DEVICE_TYPES,
PROVIDER_PROFILE_FIELD_FLAG_ALIASES,
PROVIDER_PROFILE_FIELD_FLAGS,
} from '../remote-config-fields.ts';
export type {
CloudProviderProfileFields,
DaemonRpcMode,
ProviderDeviceOrientation,
ProviderDeviceType,
RemoteConfigMetroOptions,
Expand Down
16 changes: 16 additions & 0 deletions packages/contracts/src/remote-config-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ export type ProviderDeviceOrientation = (typeof PROVIDER_DEVICE_ORIENTATIONS)[nu
export const PROVIDER_DEVICE_TYPES = ['real', 'virtual'] as const;
export type ProviderDeviceType = (typeof PROVIDER_DEVICE_TYPES)[number];

/**
* How a client sends a remote command. `health` reads `/health` before each command RPC. `checked`
* sends a standalone command on the checked RPC route, where the server refuses protocol skew
* itself, so the command takes one round trip. Only the remote-config profile sets it, and
* `connect` records it only when every link of the remote advertises `checked-rpc`.
*/
export const DAEMON_RPC_MODES = ['health', 'checked'] as const;
export type DaemonRpcMode = (typeof DAEMON_RPC_MODES)[number];

export type CloudProviderProfileFields = {
providerApp?: string;
providerOsVersion?: string;
Expand Down Expand Up @@ -130,6 +139,13 @@ export type RemoteConnectionProfileFields = {
daemonAuthToken?: string;
daemonTransport?: DaemonTransportPreference;
daemonServerMode?: DaemonServerMode;
/**
* How a remote command is sent; see `DaemonRpcMode`. The CLI sets it only from the connection
* `connect` recorded. An SDK caller that sets `checked` opts in explicitly: its standalone
* commands are not fenced to one daemon instance, and a remote that does not serve the checked
* route answers 404, which fails typed (`remote_checked_rpc_unsupported`) and is never resent.
*/
daemonRpc?: DaemonRpcMode;
tenant?: string;
sessionIsolation?: SessionIsolationMode;
runId?: string;
Expand Down
Loading
Loading