Repository navigation
Add a provider-neutral remote compute abstraction - #443
Open
Kevin Kitts (kittskevin) wants to merge 61 commits into
Open
Kevin Kitts (kittskevin) wants to merge 61 commits into
Kevin Kitts (kittskevin) wants to merge 61 commits into
Conversation
This was referenced Dec 2, 2026
A design record for running a session's agent runtime on a remote compute target. The core rule: an untrusted remote runtime never sees worker credentials or worker files. It covers the trust boundary and threat model, compute targets and providers, session placement, the worker's model credential broker, the remote tool policy, runtime binding, the store-owned state policy with its opaque-archive store contract, provider requirements, rollout, and future work. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…redential broker Introduces the provider-neutral remote compute surface for PilotSwarm workers: - ComputeTarget, ComputeProvider and ComputeRegistry (compute-target.ts): a worker opts in via computeTargets / computeProviders (or registerComputeProvider() before start()), resolving session.computeTarget.targetId -> target.kind -> provider. Targets are recursively JSON-validated and deep-frozen, provider metadata is snapshotted, and the registry is sealed and validated fail-closed at start(). Session teardown invokes provider.releaseSession() (bounded, remote sessions only), and worker.stop() invokes provider.dispose() with a bounded timeout. - Immutable session placement (client.ts, cms.ts, session-proxy.ts): createSession validates and persists computeTarget (rejecting incompatible local workspaces); duplicate creates and resumeSession enforce placement immutability; spawned child sessions inherit computeTarget so remote-isolated sessions cannot escape to local worker execution. - RemoteRuntimeBinding (remote-runtime.ts) and SessionManager.bindRemoteRuntime / releaseRemoteRuntime: returns an opaque binding token (preventing ABA detach), skips worker workspace defaults/paths/MCP/skillDirectories, clears remote state on shutdown(), and settles terminal RemoteRuntimeError refusals cleanly in runTurn. - Worker-side model credential broker (compute-runtime.ts): allowlists provider fields, refuses baseUrl query/fragment credentials, pins each placeholder to its permitted header names, scopes RemoteRuntimeRequestHandler per bound session, enforces HTTPS/origin/path/traversal checks, and refuses redirects and WebSocket transports. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A remote runtime's task list names pids on its own machine. The shell cancel and shutdown kills added for local tool shells bind those pids against this worker's process table, so a remote runtime could name a worker process and have it killed. A remote session's ManagedSession now uses REMOTE_PROCESS_HOST: it reads and signals nothing here, and the cancel still reaches the remote runtime. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A session that starts another (a sub-agent, a Workflow child, or an agent session) built its createSession placement options inline at three call sites. inheritedPlacementOptions now decides it once: a session on a compute target passes that target alone and drops the worker's folder defaults and working directory; any other session passes its folders. A workspace chosen for a child of a session on a compute target is now refused before any folder is checked, instead of being dropped silently. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
SessionManager kept the remote bindings, their model grants, the compute registry, the admission checks and the config stripping inline in its turn path. RemoteRuntimeHost now owns them; SessionManager keeps only the warm session handles and forwards its remote methods, now marked @internal. Everything a remote runtime must not receive is removed in one last step (isolateSessionConfig) instead of in three places. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A target now has id, kind, statePolicy, displayName, enabled and config, plus the settings block of its own state policy (storeOwned for store-owned). This module checks only that the block is plain JSON and freezes it; the policy's module validates its contents when the worker starts. The archive cap and phase deadlines, which only the store-owned policy reads, leave this module, and so does ParsedComputeTarget: parseComputeTarget returns the frozen target. Removed with no reader: class (one allowed value), name (between the routing id and displayName, never read or checked), and the release reasons ended, evicted and worker_shutdown (only deleted is sent; a worker stop calls dispose). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The worker forwards a model provider config to a remote runtime only through a fixed field list, and refuses any other field. A new field in the model catalog would therefore break every remote session at turn start while local sessions kept working, and no test used a real catalog. A contract test now builds each provider config as the worker does (a catalog entry for every brokered provider type, plus the example catalog) and requires that each passes the filter with no real key in it, and that the allowlist equals the fields the catalog produces. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A start that failed after the compute registry was checked left the worker marked as starting, so a later start() returned at once without starting anything, and a concurrent start() returned before the first one finished. start() now keeps the start in progress: concurrent callers share its promise, and the starting flag and the promise are cleared when it settles, whatever the outcome. The registry is still checked and sealed synchronously when start() is called. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
stop() disposes the compute providers but kept the sealed registry, so a later start() would route session releases to disposed providers and could not register new ones. A worker whose providers stop() disposed now refuses start() with a ComputeTargetError that says to create a new worker. A worker without compute providers restarts as before. registerComputeProvider() during or after start now throws ComputeTargetError, like the registry does. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… start A turn of a session that names a compute target this worker does not have enabled was refused as retryable and retried before it failed, on every new message. When the worker has a compute registry, the runTurn gate and the session manager now refuse such a session with a ComputeTargetError, which settles the turn as not retryable. A worker with no registry still refuses for a retry, since another worker may serve the target. Both places use one helper, RemoteRuntimeHost.requireBinding, so the refusal text lives in one place. This worker implements no state policy, so start() now refuses every enabled compute target before the durable runtime starts, instead of starting it with its policy settings unchecked. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
SessionManager.destroySession told the compute provider a session was deleted whenever a session was destroyed, which also happens when it completes, is cancelled or fails, and it read the target from worker memory only, so an evicted or cold session was never released. The destroy no longer releases anything. After a local destroy (the destroySession activity and worker.destroySession) and after the deleteSession activity soft-deletes a session, a worker with compute providers reads the catalog row and the stored creation config, and tells the target's provider only when the row is deleted or gone. The reads are bounded and never fail the activity. A delete command destroys the session before it soft-deletes the row, so in that flow the release comes from the deleteSession activity. A delete through PilotSwarmClient.deleteSession, or of a session with no live orchestration, runs no worker activity, so the release stays best effort; the releaseSession doc now says so and that a provider must also expire session resources on its own. A release request now always names its target, and the registry no longer sends one to every provider. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
On a database without the creation_config column, a target was kept only in one client's memory, so another client could start the session on a worker. The catalog's createSession now refuses a creation config that names a target there, before any write, and the client refuses a target when its catalog cannot store creation configs at all. The catalog compared placement only when the row already had a stored config, so a duplicate create could add a target to an existing row whose config was null. A create that names a target now takes the per-id advisory lock that refuseDeleted creates use and reads whether its row existed before the create proc runs; the decision is the new pure function createChangesComputePlacement, which refuses adding, changing or removing a target once a row exists. Creates that name no target run the same statements as before. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The cold spawn-tool capture resolved workspace defaults, attached the parent's folders and ran the snapshot preamble before getOrCreate refused a parent on a compute target, and then failed with an error that looked retryable. captureSpawnToolsV1 now refuses such a parent with a ComputeTargetError at the top of the activity, and again right after it reads the parent's config from the catalog for an older capture, before any folder, store or snapshot work. The external checkWorkspace activity now reads the session's creation config together with its row, and refuses a session on a compute target with code COMPUTE_TARGET_INVALID before the workspace provider is called. The hydrate, dehydrate and checkpoint paths are left as they are: the hydrateSession activity runs only for legacy inputs that ask for hydration, checkpoint() and dehydrate() have no callers, and the eviction sweep dehydrates only a session with a local directory, which a session on a compute target never gets. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
createSession refused a compute target only together with a workspace; it accepted non-null workspaceDefaults and a workingDirectory, and resumeSession and the config merge before a send accepted any folder for a session whose stored config names a target. One helper, assertComputeTargetPlacement, now refuses a target with a workspace, non-null default folders or a working directory, and createSession, resumeSession (against the stored target too) and the merge in _ensureOrchestrationAndSend all use it. The merge's check for adding a target had a branch that could never run, since the overrides come from the same map it tested. It now refuses any target that differs from the stored one, which covers adding a target to a session whose stored config names none, unless the stored config could not be read for an already active orchestration. createSessionForAgent takes an optional computeTarget and passes it to createSession, which applies the same checks. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
releaseRemoteRuntime awaited the warm session's disconnect with no limit, and forgot the session's warm handle only after it, so a release whose disconnect was slow could hold its caller forever and then remove the handle a later turn had stored meanwhile. It now forgets the handle before anything is awaited and waits for the disconnect at most 5 s; past that the disconnect settles in the background. The bounded disconnect is the one _cancelAndDisconnect already used, now shared as _disconnectWithin. Bind and release run under the session's run-turn lock, and release stays safe without it. A model grant now records the binding it was made for. grantModel refuses, for a retry, when that binding is no longer the session's (released, or cleared by a shutdown while the open was in flight), and the request handler uses a grant only while its binding is the current one. An open that fails anywhere after the grant and before a warm session on the bound client is stored drops the grant, not only a failed native create or resume. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The remote runtime methods were safe only when callers passed their
optional arguments. A request handler made without a session id
trusted the session id the remote runtime reported, a release without
a token could end a later turn's binding, and a binding did not record
the compute target it was opened for, so it was admitted for any.
createRemoteModelRequestHandler and RemoteRuntimeHost.requestHandler
now need the session id, and RemoteRuntimeRequestHandler takes it as
its first, required argument: a request naming another session is
refused, one naming none is the bound session's. releaseRemoteRuntime
needs the token; a destroy ends a binding through RemoteRuntimeHost.end.
bindRemoteRuntime takes { targetId, resume? }, with targetId checked
against the opaque id pattern, and admit (and the runTurn gate) refuses
for good a binding opened for another target than the session's.
After the credentials are resolved, which may wait for a token, the
handler checks that the session's current grant is still the one it
checked the request against, and sends nothing when the binding was
released or a new turn granted meanwhile.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A remote session's model grant allowed any GET or POST under its provider's base path, so the worker's provider credential reached files, batches, stored completions and the like, and the whole host when the base URL had no path. checkModelRequest now allows only the endpoints in REMOTE_MODEL_ENDPOINTS: POST to chat/completions, responses, messages and messages/count_tokens, and GET to models, each optionally after v1/ for a base URL without a version path. The path check also refuses any double encoding (%25) and an encoded dot, slash or backslash left after one decoding, so %252e%252e, %252f and %255c no longer pass. Routing, hop-by-hop and cookie headers the remote runtime sets (host, forwarded, x-forwarded-*, x-real-ip, x-original-*, x-rewrite-url, x-http-method-override, via, connection, keep-alive, te, trailer, upgrade, proxy-*, cookie) are dropped before the request is sent; a header that carries a placeholder from the provider config stays for injectSecrets to check. Plain http is now accepted only for localhost, 127.0.0.0/8 and [::1], not for names below localhost. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ys by index
redactProviderSecrets checked the names of a remote provider config's
fields but copied the values of type, baseUrl, wireApi and
azure.apiVersion as they were, so an object or array under one of them
crossed to the remote runtime whole. Each must now be a string, or the
config is refused (REMOTE_RUNTIME_REFUSED). RemoteRuntimeHost.grantModel
returns { provider } alone instead of the rest of the resolved config.
REMOTE_PROCESS_HOST.selfPid is 0: a pid a remote runtime lists is never
this worker, so a remote shell whose pid equals the worker's counts as
running and its cancel is sent.
Compute target config arrays are read by index into a fresh array
without calling any method of the input, and a hole or accessor element
is refused. supportedStatePolicies must be a dense array, read the same
way, so a sparse list or an overridden every no longer passes.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
parseComputeTarget dropped any top-level key it did not know, so a misspelt settings block such as storeOwnd vanished without a word. It now refuses every key outside COMPUTE_TARGET_KEYS: id, kind, statePolicy, displayName, enabled, config and each state policy's settings key. compute-target.ts and compute-runtime.ts each had their own copy of the plain-object check. compute-target.ts now exports isPlainRecord as @internal and compute-runtime.ts uses it. The compute-runtime.ts header no longer names a model vendor's API style. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
createComputeRegistry only wrapped new ComputeRegistry and nothing in the SDK used it, so it is removed along with its export from index.ts. ComputeRegistry, the error types and the provider contract types stay exported. The registry tests build their registries with new ComputeRegistry. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A remote session's tool calls come from an untrusted host, but their handlers run on the worker. One table in remote-tool-policy.ts now says which PilotSwarm tools a remote session is never declared (the workspace tools, load_agent, the Workflow tools and the two tools that start a worker process) and which arguments are refused (write_artifact fromFile, read_artifact toFile, load_skill path and unload, spawn_agent workspace). SessionManager declares a remote session only the tools the policy allows and guards the handlers its native session is created with; ManagedSession guards every handler it registers for a turn. stripWorkerFolders also drops the default folders and blocks the workspace tools, and a remote session gets no Workflow context. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A Workflow's steps would run on the worker, and its tool grant would be built from the tool list the remote runtime reports. Until Workflows carry a placement, a session on a compute target is refused: captureWorkflowToolBinding and captureWorkflowWorkspace throw "Workflows are not available to a session on a compute target yet." (and the shared capture refusal for a spawn), before the runtime's tool list is read, and the turn's spawn_workflow, workflow_definition and update_workflow bridge answers with the same words. runTurn now names the placement once (onComputeTarget) for the snapshot lifecycle, default folders and the bridge. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A remote conversation is now created, never resumed, at turn 0 and at an epoch start, whatever the binding says the remote holds. A remote create or resume that fails becomes a retryable REMOTE_RUNTIME_UNAVAILABLE in fixed words, with the remote's error kept as its cause (RemoteRuntimeError takes a cause), so a "Session not found" from the remote never reaches the local recovery checks. runTurn never takes the lossy replay, the failure for missing state, the live-session recovery or the transcript reset for a session on a compute target: it fails the turn for a retry instead. A state reset of such a session only forgets its warm handle, with a bounded disconnect; it starts or leases no local client and leaves the session directory and store alone. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…rget The placement rule was tested only on its helper. This drives the spawnChildSession activity with a stubbed client: a child of a session on a compute target is created on that target with no worker folders, a workspace is refused before the child is created, and a local parent's child still takes its default folders and working directory. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
When the runtime failed to start, start() cleaned up by calling stop(), which disposed the compute providers and marked the worker as unable to start again. The cleanup of a failed start now tears down without disposing them; only a caller's stop() disposes providers. start() is split into building and starting the runtime so a test can fail the runtime-start step and retry. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The external workspace check read the session's creation config best effort, so a failed read looked like a session with no compute target and the workspace provider was called. On a worker with compute targets or providers, an unreadable placement is now refused for a retry before the provider is called. A worker without them goes on as before, as this check always did when its catalog reads failed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
requireBinding decided "refused for good" by whether a registry existed, so a worker with providers but no targets failed target turns for good, and with no registry a binding for any target was used. Now a worker with compute targets is the authority on them: a disabled or unknown target is refused for good. A worker with no targets refuses for a retry, bound or not, because another worker may have the target. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A create that names no target takes no advisory lock, so it could insert the session row with no creation config after a target create found no row, and the target create then wrote its target onto that row. A create that names a target now also reads whether its own transaction wrote the row (the row's xmin against the current transaction id) and treats a row written elsewhere as existing, so adding a target to it is refused. Creates that name no target run the same statements as before. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Past turn 0 and outside an epoch start, a binding with resume: false used to create an empty conversation without a word. Such a remote has lost the session's state, so the turn is now refused with a retryable REMOTE_RUNTIME_UNAVAILABLE before anything is opened, and the state policy can restore the remote and bind again. The contract is written on RemoteRuntimeBindOptions.resume, and the test that pinned the silent create now checks the refusal. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Turn 0 and an epoch start always create a new native session, even when the binding says the remote still holds one. The remote's old session was left in place, while a local reset deletes it first. The remote open now calls deleteSession on the bound client before it creates, best effort and bounded by the release deadline: a delete that fails, throws or hangs never stops or holds the create. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…te disconnect A shutdown clears the bindings and warm sessions without the session lock, so an open whose native create was still pending could later publish a warm handle that no binding owned. The open now checks, just before it publishes, that its binding token is still the session's; if not, it disconnects what it opened within the remote deadline and fails with a retryable REMOTE_RUNTIME_UNAVAILABLE. A stale remote handle in the next open, a destroy and an invalidation of a remote handle now wait for its disconnect no longer than the remote deadline, and a destroy ends the binding and its grant before it waits. Local sessions take the same paths as before. The release docstring now says what holds without the lock. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The image gate asks getModelVisionInfo for the session. For a session on a compute target with no declared vision, the lookup found the remote client outside the pool, resolved the default key, and started and leased a local Copilot runtime just to read its model list. A remote session's model always comes through a provider the worker brokers, so the lookup now answers it from the model's declared vision alone: a declared model gets its images, any other omits them with the usual note and event, as a local session on an undeclared BYOK model does. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A transport-loss result skipped the remote guard in runTurn and was rewritten to the connection-closed wording, which sends the orchestration into the retry that recovers a local runtime and, after three tries, records a lossy handoff and a lost-worker notice. For a session on a compute target, a returned transport loss now throws the same retryable REMOTE_RUNTIME_UNAVAILABLE as its other losses, and so does a turn that throws after its connection was lost; a remote refusal thrown then keeps its own kind. Local sessions are unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…send A remote runtime's request handler followed whichever grant the session held, so a handler made for one turn could use a later turn's grant, which matters for a provider that needs no credential. It now serves the binding of the first grant it uses and refuses any other binding's grant; a grant made again for the same binding, as on an open retried on it, is still that binding's. The grant records its binding token. The grant was re-checked only before the tool-catalog adaptation read the request body, so a release during that read still sent the request. ByokRequestCompatibility now has sendAdapted, whose beforeSend hook runs after the adaptation's last await with nothing awaited before the send, and the remote handler checks its grant there. The local handler passes no hook and behaves as before. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
RemoteRuntimeHost.bind checked only that the session had no binding, so one remote client could be bound to two sessions at once. A client routes tool calls, permission requests and hooks by the session id its remote reports, and the per-session handler guards only model requests, so one session's runtime could reach the other's handlers. The host now records each bound client and refuses a client bound to another session with a retryable REMOTE_RUNTIME_BOUND; a release, a destroy or a shutdown frees it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ries only exactly A routing, connection or cookie header was kept when its value held a credential placeholder, so a remote runtime could put one there with text of its own around it. Such a header is now dropped whatever it holds, and a provider config that defines one is refused when the grant is made, so no placeholder ever belongs in one. A placeholder was swapped wherever it appeared in a permitted header, keeping any text around it. Now the header must hold exactly the placeholder, or exactly "Bearer <placeholder>" in authorization. A model request may carry no query beyond the one its provider takes: none, or the api-version the provider config names, exactly. The base URL still carries none. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The grant fixed the provider's origin, path and endpoints but not the model, so a remote runtime could ask for any model the worker's key reaches. The grant now records the model name the worker resolved for the turn, the one the native session is created with (for a deployment-routed provider, the deployment's name), and the request handler refuses a request whose JSON body names another model, or none: every endpoint a remote runtime may POST to takes the model in its body. The body is read from a clone, after the binding pin and before the grant's last check at the send. A session that names no model gets no grant. Token usage is still taken from the runtime's own reports; a comment says so where it is read. Metering it on the worker is a follow-up. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A remote session was declared write_artifact with fromFile and read_artifact with toFile, which its handlers always refuse, and its prompt told it to use them. The remote tool policy now declares each tool it limits without the arguments it refuses, on a copy of the schema, so the tools local sessions share are untouched; the handler refusals stay. A remote session's prompt gets a short note after the base instructions: it runs on a remote host and passes files to artifacts as inline content. Local sessions are unchanged. spawn_agent stays declared: on the current orchestration it is refused only for a session whose lineage has an owner, through the tool capture; it creates a child on the same compute target for an ownerless lineage and with the deprecated tool_names form. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A session on a compute target is never declared the Workflow tools and its turn's bridge refuses them, but a person could still start one of its Workflow Definitions through the management client (and so the Web API and MCP), and the Workflow's steps would run on the worker. startSessionWorkflowDefinition, the start every path shares (a person's, the session's own tool's, a spawn state's), now reads the owning session's stored creation config and refuses a session that names a compute target, with the tool's words, before anything is read from or written to the Workflow store. The management client checks the config it already reads before its default-folders check, so a person gets the same answer either way. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
delete_agent and manage_agent_session delete a finished child or session directly, and the delete command for a session whose orchestration is retired does too. None of them runs the deleteSession activity, so a deleted session's compute provider was never told. Each now calls the existing best-effort release after its delete: bounded, it never throws, and it reads nothing on a worker without compute providers. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…nd the parsed body The worker checked a remote runtime's model request against the session's grant, but sent the runtime's original text. A body that named the model twice passed the check, which reads the last key, and went out with both, so a provider that reads the first key could serve another model on the worker's credential. The query was compared decoded but sent as the runtime wrote it. The handler now sends the body it checked, serialized again from the parsed object, so each key goes out once, as checked. The sent length is computed from that body. The request goes out with the grant's own query in canonical form, whatever encoding the runtime used. A duplicate key is not refused: plain JSON parsing cannot see it, so the body is made canonical instead. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The worker reads every POST body a remote runtime sends to check its model, with no limit, so one runtime could make it hold any amount of memory, for every session on the worker. The handler now counts the body's bytes as it reads them and refuses the request once they pass REMOTE_MODEL_REQUEST_MAX_BODY_BYTES: it reads no further, decodes nothing and sends nothing. The cap is 32 MiB. A model request carries images inline as base64, so it can be large, and the request limits model APIs publish are in the tens of megabytes; 32 MiB leaves room for several full-size images while the worker holds at most a few copies of one capped body per request. The handler is made without an options object, so the cap is a constant. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… value for a configured one The worker forwarded every header a remote runtime set except a short list of routing, connection and cookie headers. So a header that picks a model or deployment at a gateway, or names an account or project for billing, went out with the worker's credential. A provider-config header that held plain text instead of its placeholder was also passed through, so the runtime could replace a configured value. The handler now forwards only an allow-list: content-type, accept, user-agent, x-request-id, the messages API's version and beta headers, and the client libraries' telemetry headers (one name prefix). It also forwards the credential and provider-config headers of the session's grant, each of which must hold exactly its placeholder; any other value there refuses the request. Every other header is dropped silently. The routing, connection and cookie headers stay refused in a provider config and are never forwarded. The list was checked against the requests the bundled runtime sends to a recording server, for each provider type and wire format, with a key, a static token, no credential and a configured header. Besides the listed headers and the credential, it sends only two headers that tag who started the request and the kind of interaction. A configured provider does not need them, so they stay dropped and nothing was added to the list. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
No remote-handler test passed a tool-catalog policy, so nothing showed that the send-time grant check runs after the adaptation reads the body again, or that a regrouped body still names the session's model. The new test builds the handler with a policy that groups the tools. When the policy lookup releases the binding, nothing is sent. Without a release, the provider receives the grouped tools and the session's model. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A config stored on the worker with computeTarget: null (for example through setSessionConfig) made the worker treat the session as remote: its images skipped the local model catalog, a reset kept its local state, and its tools were refused to Workflows and children. The worker now checks for a target with != null, here and in the turn's spawn, tool-capture and workspace checks, so null behaves as absent. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… closed A turn result in the connection-closed words but without the transport-loss flag (the inactivity watchdog, or a session error) passed the remote guard, so the orchestration retried it as a local runtime's lost connection and ended in a lossy handoff. For a session on a compute target such a result now fails the turn with the retryable REMOTE_RUNTIME_UNAVAILABLE, in fixed words that do not match the connection-closed retry. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… late one The worker awaited a remote create or resume with no deadline while it held the session lock, so a remote that never answered blocked the session. The open now has a deadline (60 s by default, the same as a workflow tool session's setup and half of the session lock's longest wait). Past it the turn fails with the retryable REMOTE_RUNTIME_UNAVAILABLE, its model grant is dropped and the lock is released; a handle the open returns later is disconnected within the release deadline and never published. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…is unanswered Before a forced fresh remote conversation, the worker deletes the one the remote holds. A delete that timed out was still followed by the create, so a delete that ran late could remove the fresh conversation. A delete that does not answer within the release deadline now fails the turn with the retryable REMOTE_RUNTIME_UNAVAILABLE and no create is sent. A delete the remote refuses at once (for example, not found) still goes on to the create. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…the conversation The binding's resume field was optional, and an absent value meant resume after turn 0, so a state policy that left it out at a fresh start never had the remote's old conversation deleted. resume is now a required boolean in the internal binding type, and a binding without one is refused with REMOTE_RUNTIME_INVALID. Turn 0 and an epoch start behave as before. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
dropWarmSession awaited a remote runtime handle's disconnect with no deadline, so a hung remote held the caller, for example a next open that fails its policy or package check. A remote handle is now forgotten at once and its disconnect waited for no longer than the release deadline, as a release does. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
shutdown() listed each warm session's background shells, including those of a remote session, whose shells this worker never kills. A remote runtime that did not answer the list held every stop for up to the shutdown's task-list deadline. A remote session's shells are no longer listed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A stop() now starts one disposal of the compute providers and keeps its promise. A later or overlapping stop() awaits that promise and never calls dispose() again. A failed start's cleanup still keeps the providers, so the start can be retried. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…the stored config resumeSession took a stored creation config it could not read for one with no compute target, so resuming a session on a target with that target failed with a ComputeTargetError that looked permanent. It now skips the add/change check when the read fails, as resume treats its other catalog reads as best effort. The send still reads the stored config again before any start, refuses a changed or added target, and refuses to start a session whose stored config it cannot read. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…tore When the read-back after a create with a compute target finds the target missing, the client refused the create but left the row. A later resume and send from any client then started that session on a worker. The client now soft-deletes the row before it throws, as a best effort: a failed delete never hides the refusal, and a row that was there before the create (or may have been) is left alone. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The web client accepted computeTarget through the public client's types but never sent it, so the session ran on an ordinary worker. Its createSession, createSessionForAgent and resumeSession now refuse a non-null computeTarget with WEB_MODE_UNSUPPORTED before any Web API call, in the words of its other refused options. null or absent names no target and works as before. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…me the form that works In a session on a compute target whose lineage has an owner, the default spawn_agent call was offered but refused, because its grant needed a capture of the parent's tools. A named agent had no form that worked, and grant and tools were still declared. A spawn by such a session now takes the ceiling-only path the tool_names form already used: nothing of the parent is captured, and the child gets the parent's tool ceiling and is owned by the lineage's owner. A named agent is refused before it is read, in words that say to spawn a custom child; it stays declared because it works in an ownerless lineage. The remote declaration of spawn_agent leaves out grant and tools (its handler refuses them) and its descriptions name the form that works. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add computeTargets and computeProviders to the worker options in the configuration reference, with a short "Compute targets" section: what a target and a provider are, registerComputeProvider, the session's computeTarget option on createSession, createSessionForAgent and resumeSession, and a link to the design record. No state policy is implemented yet, so a worker refuses to start with an enabled target. List computeTarget among the createSession fields in the SDK app guide. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
waldemort-auto
Bot
force-pushed
the
waldemort/m1-pr1-compute-abstraction
branch
from
December 2, 2026 07:21
903ae7b to
5be6099
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Lets a session's agent runtime run outside the worker, on a compute target: a named kind of remote compute, such as a sandbox pool, that the deployment defines in the worker configuration. A session picks a target by id at creation and keeps it; the provider picks the sandbox for each turn.
The core rule: an untrusted remote runtime never sees worker credentials or worker files. The worker keeps the model keys and brokers every model request; the remote gets no worker folders, processes, MCP servers or Workflows.
This PR is the foundation. No state policy exists yet, so a worker refuses to start with an enabled target. PR 3 adds the first one.
Design record:
docs/proposals/remote-compute-targets.md. It is the first commit here and covers the whole stack. Please read it first.Stack
main)waldemort/m1-pr1-compute-abstraction)waldemort/m1-pr2-opaque-archive-store)What changes
ComputeTarget,ComputeProvider,computeTargets/computeProviders/registerComputeProvider()on the worker, andcomputeTargetoncreateSession,createSessionForAgentandresumeSession.compute-runtime.ts): the remote gets placeholders, not keys. Each request must match the turn's grant (origin, path, model endpoint, query, model) and allowed headers before the worker swaps in the real credential.remote-tool-policy.ts): no workspace, Workflow or infrastructure tools; no worker file paths; files go inline.configuration.mdandsdk-apps.md.Compatibility
Tests
New
compute-registry,compute-runtimeandcompute-integrationunit tests (91 in total). The same steps as PR checks pass on Linux and Node 24:Not in this PR
Session workspaces on a compute target (planned, design record section 12), usage metering in the broker, and the smaller follow-ups listed in section 12.