Skip to content

feat(threads): thread_create starts a thread on another of the user's computers - #1290

Merged
bvsr365 merged 5 commits into
masterfrom
thread-create-on-another-computer
Nov 15, 2026
Merged

bvsr365 merged 5 commits into
masterfrom
thread-create-on-another-computer

Conversation

@bvsr365

@bvsr365 bvsr365 commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator

Problem

An agent can start a thread only on this computer. The only work it can start on another of the user's computers is a subagent. The agent threads design (#1161, §4.4) also lets an agent start a top-level thread on another computer, in that computer's copy of the same repository.

Change

  • thread_create takes computer (a name from list_computers), and optionally projectId, a project of that computer, to choose among several checkouts. Without computer nothing changes.
  • Local checks, read at every call (a retry and the passes that finish a launch included):
    • "Let agents work on your other devices" is on and that computer is turned on under it;
    • the caller is not a private thread, and was not itself started from another device (one computer deep);
    • the per-run cap (5) and the working-at-once cap (10);
    • the hop count when there is a first message;
    • a model that computer offers: instanceId and model together, or neither for that computer's default.
  • Project. projects.match must find exactly one strong match: a shared root commit and a shared remote. No strong match, or several, refuses with the candidates' ids and names, and projectId picks one of them. Nothing is cloned (Starting a thread on another computer drops the project when that computer doesn't have it #484).
  • Never unmarked. The launch starts only when that computer takes the agent mark (feat(bridge): an agent's calls to another computer are marked, and that computer treats them more strictly than a person's #1235) on every marked row. An older computer is refused with computer_outdated and gets no call that changes a thread.
  • The launch. The receipt (thread_create:<caller>:<key>, kind remote_thread_create, with the computer) and a remote_launches row are written in one transaction before any call. RemoteThreadLaunches then runs threads.create → threads.setModel → composer.options → threads.setPermissionMode → orchestrator.send:
  • One start sequence for both features. remoteThreadStart.ts now runs these steps for remote subagents and launched threads alike. Remote subagents keep their create and send keys; their model and mode writes now get keys too.
  • remote_launches (run database 21) is this computer's record that a thread here launched a thread there:
    • states starting, created, launched and abandoned;
    • what became of the first message: none, pending, sent, failed or uncertain;
    • indexed by launcher and by computer plus far thread id, for PR 9's read, wait, message and Stop.
  • The result is { threadId: "<node>:<id>", link, computer, title, permissionMode, model, runId?, firstMessage: "sent" | "failed" | "uncertain", firstMessageReason?, replayed }:
    • a thread that exists is returned even when its first message failed;
    • a retry with the same clientRequestId continues the same launch and never makes a second thread or sends twice;
    • a write that cannot be confirmed is uncertain, never done or failed. A create that is not confirmed answers status: "uncertain".
  • Unfinished launches. A launch the call did not finish (a lost link, a restart) is finished by the service's passes: at boot, when Bridge comes up, and every few seconds while one is open. One refused for good, or still open after a day, ends abandoned, and a thread already made for it there is archived with threads.settle.
  • The launcher's note is a thread chip (feat(threads): a thread an agent started says so, and the thread that started it links to it #1224) naming the qualified id and the computer, written once when the thread first exists there.
  • Refusals carry a code and the computer's name: computer_offline, computer_not_shared, computer_outdated, computer_not_allowed (here, or that computer's agent reach none), no_matching_project, several_matching_projects, plus private_thread, remote_from_remote, creation_limit and agent_hops_exceeded.
  • Docs. The tool description, the MCP instructions, docs/run-engine/SPEC.md §15.1 and the threat model ("Threads agents start on another computer").

How to review

Read the commits in order:

  1. refactor(subagents): remoteThreadStart.ts and RemoteSubagents.advanceStart now calling it. The only behaviour change for subagents is idempotency keys on setModel and setPermissionMode.

  2. feat(bridge): projects.match returns candidates when it has no single answer (possibleProjects in projectMatch.ts), and the port's projectCandidates.

  3. feat(threads): the core.

    • createOnComputer in appTools/thread.ts: argument checks and the per-run cap.
    • createRemoteThreadAsAgent, remoteProjectFor, remoteThreadResult and noteRemoteLaunch in OrchestratorService.ts: the local checks, the project, the receipt and row, the result.
    • RemoteThreadLaunches.ts: the launch state machine and its passes.
    • remoteLaunches.ts and migration 21.

    The risk is in RemoteThreadLaunches.advance: which failure ends a launch, which keeps the thread, and which leaves it for the next pass. A failure on orchestrator.send never abandons the thread. A transient failure before the thread exists leaves the launch starting. A refusal for good before setup is done abandons it and archives what was made.

  4. test(threads), then docs.

Verification

Tier 5 (daemon protocol, persistence and a migration, permissions across computers). Tested commit: d26e30c810a3cec2783ef3137d6be3a8ae271ad8 (tests ran on 0959c7a65, the same tree before its commit emails were rewritten for the push), on origin/master aeb4b30e1.

  • npx vitest run tests/net/bridge/routed/threadCreateRemote.test.ts: two real daemons over Bridge, with only the owner's turn stood in for. The agent calls thread_create through the app-tool registry over the caller orchestrator's real host. It checks:
    • the thread there is in the matching project, records startedFrom.agent, has no createdByThreadId, and is held to the launcher's Auto narrowed to the device limit (Auto-accept edits);
    • the first message runs there with source mcp, sentByAgent, the sender in agent.from and the narrowed mode;
    • the launch row and the launcher's chip note name the qualified id;
    • a retry with the same request id returns the same thread, sends nothing again and writes no second note; the same key with other arguments is refused;
    • Full access is used when both computers allow it;
    • a first message refused there (agent_daily_budget) returns the thread with firstMessage: "failed", and a retry makes no second thread;
    • a launch cut after threads.create (composer.options fails offline) returns the thread with firstMessage: "uncertain". A new RemoteThreadLaunches, reading only the run database as after a restart, finishes it on the same thread and sends the message once. The agent's retry then reads sent;
    • each refusal, with nothing made there:
      • offline;
      • not allowed here (switch off, computer not turned on) and there (agent reach none);
      • outdated: threads.create advertised one version below the mark, giving computer_outdated;
      • not shared: Works on threads off on that computer;
      • no matching project;
      • several checkouts, with candidates, and projectId choosing one;
      • notify with computer.
  • tests/net/bridge/routed/remoteSubagents.test.ts, tests/run/remoteSubagents.test.ts and tests/run/remoteSubagentEngine.test.ts: remote subagents through the shared sequence, unchanged.
  • tests/net/bridge/hub/matchProject.test.ts: two clones that cannot be told apart now come back as weak candidates instead of an empty answer. This test asserted the old empty answer and is updated for the new one.
  • Also run: agentMark, threadCreateTools, threadCreateDaemon, contractVersions (run database 21), mergedLists, ids, table, agentAccessSettings, projectAgentInstructions, renderer/agentLaunchedThread. All 15 files together: 184 tests passed. threadCreateDaemon.test.ts alone: 29 passed. In an earlier run beside a typecheck, four of its cases failed with errors I did not keep; they did not come back alone or in the full run. They share the fixture's fixed 10-second wait, so a timeout under load is the likely cause.
  • npm run typecheck: clean.
  • Not checked: two real computers on different versions (the older computer is simulated by lowering the advertised row version); a real provider turn there; the chip as drawn in a window for a thread on another computer (the chip's states come from feat(threads): a thread an agent started says so, and the thread that started it links to it #1224 and are not changed here).

Notes

  • Beyond the brief:
  • Known gap: the "10 launched threads working at once" cap counts this thread's working local launches and its launches on other computers that are not finished yet. It cannot see whether a thread there is still working until PR 9 reads those threads.
  • Run database contract 20 → 21 (remote_launches).
  • Needs review by the other teammate before merging: it changes what agents may do on other computers.

Refs #1160

🤖 Generated with Claude Code

bvsr365 and others added 5 commits November 16, 2026 00:22
…dule remote subagents and launched threads share

create, setModel, composer.options, setPermissionMode and send now run from runRemoteThreadStart. Every
write has its own idempotency key from the start's key; the mode's key names the mode, which is narrowed
afresh each time. Remote subagents keep their create and send keys and behave as before.

Refs #1160

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…itory when it has no single answer

Refs #1160

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… computers

thread_create takes computer (and a project id of that computer to choose among checkouts). The local
checks run first, then the launch is recorded with its receipt in a new remote_launches table (run
database 21) and RemoteThreadLaunches runs the shared start sequence, every write marked as the agent's.
A retry with the same clientRequestId continues the same launch; one a restart cut off is finished by
later passes, or archived there with threads.settle. The launcher gets a thread chip note.

Refs #1160

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refs #1160

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…puter

Refs #1160

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant