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
1 change: 1 addition & 0 deletions docs/net/threat-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ After the launch, `thread_read`, `thread_wait`, `thread_send`, `thread_steer` an
- **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.
- **Settle watches.** `notify` on `thread_send` to such a thread, or on `thread_create` with `computer`, makes a watch that follows the run there with the same unmarked reads the launcher's own `thread_wait` would make (`runs.wait`, `runs.get`, `runs.list`, `queue.list`), one loop per watch, backing off while the computer does not answer; there is no new routed row and nothing there knows a watch exists. A computer that refuses this device, stops sharing or is too old ends the watch with one notice, and the 24-hour expiry bounds it otherwise.
- **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.
Expand Down
5 changes: 3 additions & 2 deletions docs/run-engine/SPEC.md

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions src/mms/orchestrator/OrchestratorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,8 @@ export class OrchestratorService extends EventEmitter {
this.remoteLaunches?.start()
// Stops kept while Bridge was off are sent now.
this.remoteThreads?.start()
// Settle watches on threads there that waited to try again try now.
this.settleNotices?.remoteReachable()
}
}

Expand Down Expand Up @@ -1958,6 +1960,8 @@ export class OrchestratorService extends EventEmitter {
private questionRouterOff: (() => void) | null = null
/** The settle notice (`notify`): the watches of messages agents sent, followed on this computer (SPEC §15.1). */
private settleNotices: SettleNotices | undefined
/** The first wait of a settle watch on another computer after a round that did not reach it (tests shorten it). */
private remoteWatchRetryMs: number | undefined
/** Pending retries of a queue item's row release (`releaseQueuedRows`); a shutdown clears them. */
private readonly releaseRetries = new Set<ReturnType<typeof setTimeout>>()
/** Background repairs of unfinished agent queue commands tried so far, per thread. */
Expand Down Expand Up @@ -2901,6 +2905,18 @@ export class OrchestratorService extends EventEmitter {
isSubagent: (threadId) => engine.delegations.getLineage(threadId)?.relationship === 'subagent',
inPlan: (threadId) => this.lastChatModeOf(threadId) === 'plan',
deliver: (threadId, notice, held) => this.queueSettleNotice(threadId, notice, held),
// A thread this computer's agent launched on another computer is followed there through routed reads (issue #1160).
remote: {
reads: () => this.remoteThreads,
launched: (node, remoteThreadId) => {
const record = engine.remoteLaunches.getByRemoteThread(node, remoteThreadId)
return record ? { computer: record.computerName, title: record.title } : undefined
},
denial: (node, computer) => this.remoteThreadDenial(node, computer),
// What `remoteAgentMark` carried for a message of that run: its own count plus one.
sentHops: (runId) => (engine.getRun(runId)?.outcome?.agentHops ?? 0) + 1,
...(this.remoteWatchRetryMs !== undefined ? { retryMs: this.remoteWatchRetryMs, needsInputRecheckMs: this.remoteWatchRetryMs } : {})
},
delivered: (threadId, item) => {
if (queueHasSettleNotice(queueOf(threadId), item)) return true
try {
Expand Down
17 changes: 14 additions & 3 deletions src/mms/orchestrator/RemoteLaunchedThreads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,11 @@ export function remoteReachRefusal(error: unknown, computer: string, what: strin
case 'route_unreachable':
case 'bridge_off':
return new RemoteThreadRefusal('computer_offline', `${computer} is offline, so ${what} did not reach it.`, computer)
case 'computer_forbidden':
return new RemoteThreadRefusal('computer_not_shared', `${computer} does not share its threads with this computer (${message}), so ${what} did not reach it.`, computer)
case 'computer_forbidden': {
// Why it refused (it blocked this device, turned sharing off), for a settle notice that says so.
const reason = error instanceof DomainRpcError && isRecord(error.details) && typeof error.details.reason === 'string' ? error.details.reason : undefined
return new RemoteThreadRefusal('computer_not_shared', `${computer} does not share its threads with this computer (${message}), so ${what} did not reach it.`, computer, reason ? { reason } : undefined)
}
case 'computer_outdated':
return new RemoteThreadRefusal('computer_outdated', `Update Mousse on ${computer}: it is too old for ${what} from an agent on this computer.`, computer)
case 'agent_reach':
Expand Down Expand Up @@ -240,7 +243,7 @@ export class RemoteLaunchedThreads {
return localized(qualifyRoutedResult(method, value, { node, ...(self ? { self } : {}) }), self)
}

private async read(target: RemoteTarget, method: string, params: Record<string, unknown>, what: string, signal?: AbortSignal): Promise<{ value: unknown; versions: Record<string, number> | undefined }> {
private async read(target: Pick<RemoteTarget, 'node' | 'computer' | 'remoteThreadId'>, method: string, params: Record<string, unknown>, what: string, signal?: AbortSignal): Promise<{ value: unknown; versions: Record<string, number> | undefined }> {
try {
const { result, versions } = await this.call(target, method, { threadId: target.remoteThreadId, ...params }, { what, ...(signal ? { signal } : {}) })
return { value: this.named(target.node, method, result), versions }
Expand All @@ -249,6 +252,14 @@ export class RemoteLaunchedThreads {
}
}

/**
* One read of the thread there, named as this computer names things; a failure is the refusal that says why. The
* settle notice's follower finds a watched message with it (`runs.list`, `runs.get`, `queue.list`).
*/
async readThread(target: Pick<RemoteTarget, 'node' | 'computer' | 'remoteThreadId'>, method: string, params: Record<string, unknown>, what: string, signal?: AbortSignal): Promise<unknown> {
return (await this.read(target, method, params, what, signal)).value
}

// ------------------------------------------------------------------ reading

/** `thread_read` view `events`: one page of the run events there, `limit` at most (the tool's own page). */
Expand Down
Loading
Loading