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
9 changes: 9 additions & 0 deletions docs/net/threat-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,15 @@ An agent can also start a top-level thread on another of the user's computers (`
- The mode is the launcher's own (its thread's mode and its run's), narrowed by that computer to the limit it set for this one; no fixed mode caps it, as for remote subagents. The owner holds the thread to that mode from its first write and records the launching agent (`startedFrom.agent`).
- The launch is recorded here before any call (`remote_launches` in the run database, beside the `thread_create` receipt), and every write has its own idempotency key from the launch's key, so a lost link, a retry or a restart reaches the same execution there and never makes a second thread or sends the first message twice. A write that is not confirmed is reported as uncertain, never as done or failed.

After the launch, `thread_read`, `thread_wait`, `thread_send`, `thread_steer` and `thread_interrupt` take the thread's qualified id (`src/mms/orchestrator/RemoteLaunchedThreads.ts`):

- **Only threads launched from here.** A qualified id is reachable only when `remote_launches` records it as launched by the calling thread or a thread of its lineage, and not from a private thread; any other is refused (`not_launched_here`) before anything is sent, so an agent cannot use a launched thread's id to read or change another thread there. The switch and the ticked computer are read again at every call (`computer_not_allowed`), except for a Stop: an agent may always stop work it started. `approval_respond` refuses a qualified id: an approval there waits for a person there.
- **Reads** are the routed read rows a window uses (`runs.events`, `thread.messages`, `runs.get`, `runs.list`, `queue.list`, `orchestrator.pendingQuestions`), unmarked, and follow the device's ordinary read access there. They ask for the tool's page, not whole transcripts: `thread.messages` (version 3) takes `index`, `textOffset` and `textMax`, and the owner builds the same rows its own agents get, each text cut to the tool's limit and the page to 64 KB, so a large transcript does not cross and large reads keep sharing the two slots per computer with the windows. Every id in a result is named the way this computer names it before a tool sees it: the owner's threads qualified, this computer's own plain, and an agent sender (`origin.from`) by its thread on its own computer, so no id of another computer resolves to a thread here.
- **Waiting** is one new read row, `runs.wait`: the owner waits at most 40 s on its own run events and answers when the run ends or waits on a person (`needs_input`); the caller gives it a 50 s deadline, under the minute an MCP client waits. A thread with a run preparing or a message in its queue is never answered idle. An owner without the row is asked `runs.get` every 4 s instead.
- **Messages, steers and Stops** are the marked `orchestrator.send`, `orchestrator.steer` and `orchestrator.abort` above, keyed by the caller's request key, so the owner's limits, envelope and reach apply exactly as for a launch's first message. A send whose link drops after it reached the computer is reported uncertain and not sent again by the caller.
- **A person's Stop** of the launcher (and its deletion or expiry) sends a marked Stop for every thread it launched. A Stop that cannot be delivered is kept in its `remote_launches` row (run database 22), survives a restart, is sent when that computer answers, and is given up after a day; until then the launcher's transcript says the other run may still be going. The owner stops only runs this computer's agents started and leaves a thread a person took over. A later message from this computer to that thread supersedes a Stop still waiting, so it cannot end newer work. Nothing there is deleted.
- **Reachability.** Every call first reaches the computer (its row versions) with a 10 s deadline of its own, then runs with its own deadline. A call that did not reach it is tried once more about a second later; only then is the computer called offline. A refusal names which reason it was (`computer_offline`, `computer_not_shared`, `computer_outdated`, `computer_not_allowed`, `remote_thread_gone`) with the computer's name, from that computer's answer to this call, never from the device list's online flag.

#### Calls marked as an agent's (issue #1160)

Seven routed rows take a key `agent: { thread, run, title, hops, mode }`: `threads.create`, `threads.setModel`, `threads.setPermissionMode`, `orchestrator.send`, `orchestrator.steer`, `queue.enqueue` and `orchestrator.abort` (`ROUTED_AGENT_KEY` in `src/shared/bridge/routed.ts`). Remote subagents and threads agents start on another computer send it.
Expand Down
4 changes: 3 additions & 1 deletion docs/run-engine/SPEC.md

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/mms/MmsProfileServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,8 @@ export class MmsProfileServices {
runInProgress: (threadId) => this.lifecycleOwnedTasks(threadId).some((task) => this.orchestrator.isTurnActive(task.taskId) || this.runEngine.getActiveRun(task.taskId) !== null),
stop: async (threadId) => { await this.orchestrator.stopThread(threadId, 'expired', { clearQueue: true }) },
quiesce: (threadId) => {
// What the expired threads launched on other computers is stopped there; nothing there is deleted.
this.orchestrator.stopRemoteLaunches(this.lifecycleOwnedTasks(threadId).map((task) => task.taskId), 'expired')
// A question waiting for an answer and an open terminal are not a run: they end at expiry.
for (const task of this.lifecycleOwnedTasks(threadId)) {
this.questions.dismissAllForThread(task.taskId, 'thread_deleted')
Expand Down Expand Up @@ -1817,6 +1819,9 @@ export class MmsProfileServices {
}

private async stopRunsForDelete(threadIds: readonly string[]): Promise<void> {
// What the deleted threads launched on other computers is stopped there, whether or not they run now; nothing there
// is deleted.
this.orchestrator.stopRemoteLaunches(threadIds, 'deleted')
const running = (): string[] => this.runningForDelete(threadIds)
const stopping = running()
if (!stopping.length) return
Expand Down
3 changes: 2 additions & 1 deletion src/mms/bridge/BridgeProfileService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,8 @@ export class BridgeProfileService {
services,
client: this.router.client,
computers: () => (this.router.enabled() ? this.router.pairedComputers() : undefined),
online: (node) => this.router.isOnline(node)
online: (node) => this.router.isOnline(node),
self: () => rt.identity.self()?.node
})
services.orchestrator.setRemoteComputers(computersPort)
this.disposers.add(() => services.orchestrator.setRemoteComputers(undefined))
Expand Down
8 changes: 8 additions & 0 deletions src/mms/bridge/routed/RoutedClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NetError, newId, type NodeId, type RpcId } from '../../../shared/net'
import {
ROUTED_LARGE_READS,
ROUTED_RUN_WAIT_DEADLINE_MS,
ROUTED_LARGE_READS_PER_CALLER,
ROUTED_METHODS,
ROUTED_DROPPABLE_KEYS,
Expand Down Expand Up @@ -92,6 +93,8 @@ const SEQUENCED_DEADLINE_MS = 15_000
const deadlineOf = (method: string): number =>
ROUTED_METHODS[method]?.sequenced
? SEQUENCED_DEADLINE_MS
: method === 'runs.wait'
? ROUTED_RUN_WAIT_DEADLINE_MS
: LONG_METHODS.has(method)
? LONG_DEADLINE_MS
: DEFAULT_DEADLINE_MS
Expand Down Expand Up @@ -176,6 +179,11 @@ export class RoutedClient {
return this.guard(node, session, computer, () => this.versions(node, session))
}

/** The name a person knows `node` by. */
nameOf(node: NodeId): string {
return this.deps.computer(node).name
}

/** Runs one routed row on `node` and returns its result, or throws what the person should see. */
async call(
node: NodeId,
Expand Down
14 changes: 14 additions & 0 deletions src/mms/bridge/routed/remoteComputers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ROUTED_AGENT_METHODS } from '../../../shared/bridge/routed'
import type { MmsProfileServices } from '../../MmsProfileServices'
import type { RemoteComputer, RemoteComputersPort } from '../../protocol/remoteComputersPort'
import { repositoryIdentitiesFor } from '../remote/repositoryIdentity'
import { DomainRpcError } from '../../protocol/domainRegistry'
import type { RoutedClient } from './RoutedClient'

const isRecord = (value: unknown): value is Record<string, unknown> => !!value && typeof value === 'object' && !Array.isArray(value)
Expand All @@ -18,11 +19,24 @@ export function remoteComputersPort(options: {
client: RoutedClient
computers: () => Array<{ node: NodeId; name: string }> | undefined
online: (node: NodeId) => boolean
self?: () => string | undefined
}): RemoteComputersPort {
const { services, client } = options
return {
computers: (): RemoteComputer[] | undefined =>
options.computers()?.map(({ node, name }) => ({ node, name, online: options.online(node) })),
self: () => options.self?.(),
versions: async (node, signal) => {
const asked = client.versionsOrRefusal(node as NodeId)
if (!signal) return asked
// The connect deadline: a handshake that stalls fails here, whatever the call's own deadline is.
return new Promise((resolve, reject) => {
const give = (): void => reject(new DomainRpcError('computer_offline', `${client.nameOf(node as NodeId)} did not answer in time, so it is taken as offline.`))
if (signal.aborted) return give()
signal.addEventListener('abort', give, { once: true })
asked.then(resolve, reject).finally(() => signal.removeEventListener('abort', give))
})
},
call: (node, method, params, callOptions) => client.call(node as NodeId, method, params, callOptions),
takesAgentMark: async (node) => {
const versions = await client.versionsOrRefusal(node as NodeId)
Expand Down
Loading
Loading