Skip to content

feat(server): delegate work across linked environments - #290

Merged
lukemaj merged 4 commits into
mainfrom
feat/164-peer-links
Oct 14, 2026
Merged

lukemaj merged 4 commits into
mainfrom
feat/164-peer-links

Conversation

@lukemaj

@lukemaj lukemaj commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

What changed: A planner on one machine can delegate_task to a linked machine (bestia, rocky, cavallo), track and cancel it, and is woken by its result; links are made headlessly with a pairing code and never expire, but stay revocable.
Why: Thread tools only saw the local server, and outside-MCP sign-in hard-expired after 30 days with no refresh and no delegate_task or wake-up.
So what: After Sol and Grok review this exact head and CI is green, the agent merges; deploy rides the staging/restart rule, then the agent links the machines over SSH and proves a real cross-machine delegation.

Refs #164 (stays open until the real cross-machine proof after deploy).

How

Ports upstream's unmerged peer-link stack as an upstream-sourced fork feature peer-links (drop our copy when upstream merges):

Fork hooks (stay ours):

  1. Permanent link session: McpOAuth.approve passes permanent = pairing-code decision && peer-link client through PendingCode to issueMcpClientSession; TTL to REUSABLE_DEV_SESSION_EXPIRES_AT (apps/server/src/peer/permanentSession.ts). Browser approvals keep 30 days. t3 auth session revoke cuts a link off.
  2. Prism on the target: the persisted, replayed launch omits modelSelection unless target.model is set, and carries prismRole ?? delegatedPrismRole(role), lane, workspaceStrategy and the raw task.
  3. Recovery-aware wait: waitForThread follows a Prism recovery successor of the waited run at the initial read, the event stream and the timeout read (one budget; pending recovery returns timedOut: true); the follower reads the reply of the run that finished.

Links table: fork module with upstream's exact peer_environment_links DDL (CREATE TABLE IF NOT EXISTS), no migration 061, pinned by a PRAGMA table_info test. No web/mobile changes, no version bump.

Design: council and three reviewed revisions on #164; revision 3 approved by Sol (gpt-6.1-sol) and Grok (grok-4.7).

Proof

223 focused tests pass at this head (peer, recovery wait, permanent session, CLI, schema, launch, delegation, completion delivery, orchestrator toolkit), server and contracts typecheck, targeted lint, scripts/fork-check.sh. Commands and results: #164 (comment). Real cross-machine proof follows deploy.

Elon record

  • Requirements and who asked: cross-machine delegate/track/wake with headless one-time setup and no periodic renewal (user, 2026-10-14); port now on current main without waiting for Absorb upstream main through 8d11fe1261 #166 or upstream merge (user, 2026-10-14); role, lane, Prism, target-side workspace (user, 2026-10-07).
  • Deleted: outside-MCP OAuth per caller, SSH environments as transport, Connections UI/import/handoff layers, migration 061, follower re-pin, exposure runbook, global MCP TTL change.
  • Bottleneck: adapting the stack across the 124-commit gap.
  • Checked myself: pushed head cac69e6a, the permanence predicate in McpOAuth.approve, live reachability of all three servers over Tailscale HTTPS.

Built by GPT-6.1-Sol (Codex) in T3 Code; coordinated by Claude Opus 5.5 (Claude Code).

🤖 Generated with Claude Code

@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:XXL labels Oct 14, 2026
@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅
Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅
Codex Live turn WebSocket decoded 20.9 KiB 20.9 KiB 0 B (0.0%) 29.3 KiB ✅
Codex Live turn messages 2 2 0 (0.0%) 8 ✅
Claude Total thread wire 5.0 KiB 5.0 KiB +24 B (+0.5%) 6.8 KiB ✅
Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB +24 B (+2.0%) 2.0 KiB ✅
Claude Live turn WebSocket decoded 21.2 KiB 21.2 KiB +41 B (+0.2%) 29.3 KiB ✅
Claude Live turn messages 1 2 +1 (+100.0%) 8 ✅

Baseline: 8f939c2 · PR result: 060b86a · Source CI: success

Scenario and decoded snapshot size

10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

  • Codex decoded thread snapshot: 108.5 KiB
  • Claude decoded thread snapshot: 108.8 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

@lukemaj

lukemaj commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

Independent review (Sol, gpt-6.1-sol, high) at cac69e6a315bb40c5c0888c8add42c0ed5edecb5: failure (relayed unchanged by the coordinator)

  1. Blocking, P1: accepted launch replay depends on fresh Prism availability. apps/server/src/mcp/toolkits/project/handlers.ts:156 calls prism.resolve before reaching the launch service's receipt lookup. If B accepts a launch, A loses its response, and B's eligible models subsequently exhaust their quota, become disabled, or disappear, replay returns provider_unavailable or model_unavailable despite the existing accepted child. A's follower retries indefinitely while that condition persists, without attaching the child or delivering its completed result. Pending cancellation also cannot recover the child's identity to stop it.

    Fix: provide a receipt-first replay path for an already accepted keyed launch, returning its persisted thread/run without fresh Prism selection. Retain authentication, grant identity, link-origin fencing and applicable mode checks. Add a regression that loses the response, changes the destination catalog or headroom, restarts the source, and verifies attachment, result delivery and cancellation without another launch. Current restart tests use an unchanged catalog and mock the destination launch service, so they miss this interaction.

No additional blocking findings in the inspected diff.

Coordinator adjudication: accepted; the call order is verified at handlers.ts:153-166 (Prism resolve precedes ThreadMessageIntake.launchThread, which owns the receipt lookup).

VERDICT: failure

@lukemaj

lukemaj commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

Independent review (Grok, grok-4.7, high) at cac69e6a315bb40c5c0888c8add42c0ed5edecb5: success (relayed by the coordinator; full text in thread review-290-grok-cac69e6a)

No blocking or non-blocking findings. Checked: port matches bfef035876 on peer modules, linkOrigin.ts, delegatedTaskModes.ts, peerLink.ts, with drift limited to the three approved hooks and fork base adaptations; no migration 061, forkPeerLinksSchema uses upstream DDL with a PRAGMA table_info pin; node scripts/fork-features.mjs check reports 35 features OK; permanence only for pairing-code && peerLink, browser approval stays 30 days, revoke immediate, pairing codes not logged; stored launch omits modelSelection unless target.model and carries prismRole/lane/workspaceStrategy; waitForThread delegates to waitForRecovery with per-run finalization, successor following, pending -> timedOut: true; follower reads waited.runId; record-first commits before any network call, attach needs no live parent, unsent cancel never sends, replaced link refused, first result wins. Tests were read, not re-run.

Note: this verdict does not cover Sol's blocking finding (replay through Prism before receipt lookup, comment above); the fix will be a new head and both reviews rerun on it.

VERDICT: success

Port the server peer-link stack from pingdotgg/t3code #16653, #16654, #16655, #16684, #16695 and #16719 at d79fdd537ca222fc43fb41c1496466da77ee3449. Adopt record-first recovery from Lenoridev/t3code bfef03587650a920878d9e65c5c61431c80ad55b (#17051).

Keep permanent pairing-code link sessions, persisted target Prism selection and recovery-aware thread waits in fork modules. Add focused two-server, clock, restart and schema proof for #164.
@lukemaj

lukemaj commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

Independent review (Sol, gpt-6.1-sol, high) at 8e0c71810aa448acdc6e50b60e73d45b4844e054: success (relayed unchanged by the coordinator)

Blocking findings: none. Non-blocking findings: none.

The previous finding is closed:

  • ThreadLaunchService.ts:251 reads the receipt before admission. Replay requires an accepted thread.create, matching thread and project identities, matching link-origin session, and permissible modes. With an initial message, it also requires its accepted dispatch receipt and matching persisted run. Missing receipts take the normal Prism/admission path.
  • mcp/toolkits/project/handlers.ts:137 places Prism selection and attachment claims inside that fresh-launch path. Reusing an accepted key returns the existing launch; it cannot create another thread or run while bypassing admission.
  • Authentication, caller capability checks, grant-generation identity, and mode resolution remain ahead of replay. Replacement links remain refused.

The four regressions at RemoteDelegation.test.ts:1025 exercise lost responses and source restart with real destination receipts, launch service, and thread state, covering catalog disappearance and exhausted headroom, result delivery or pending cancellation, exactly one persisted thread/run/message, and rejection of fresh admission. Range-diff: both earlier commits unchanged, only the intended fix added. Executed RemoteDelegation.test.ts and ThreadLaunchService.test.ts: 89 passed. Scope excludes live cross-machine proof.

VERDICT: success

@lukemaj

lukemaj commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

Independent review (Grok, grok-4.7, high) at 8e0c71810aa448acdc6e50b60e73d45b4844e054: success (relayed by the coordinator; full text in thread review-290-grok-8e0c7181)

No blocking or non-blocking findings. Sol's finding is closed: t3_thread_launch calls ThreadLaunchService.replayOrLaunch before Prism (handlers.ts:136-174); prism.resolve runs only inside the admission callback; lookup reuses the existing readReceipt (no second receipt store). An accepted thread.create returns the persisted thread and run; a missing receipt falls through to admission; a mismatched receipt fails closed (status/type, thread, project, link-origin session, broader modes, non-matching initial-message dispatch) (ThreadLaunchService.ts:251-299). Authentication, mode caps, grant identity (PeerMcpClient.ts:151-159) and expectedLinkIdentity stay ahead of replay; command id mcp:launch:<request namespace>:<clientRequestId> prevents cross-session or cross-key hits. Range-diff: earlier commits patch-identical, only the fix added. node scripts/fork-features.mjs check: 35 features OK. Regressions (unit + four peer cases with a real destination launch service) passed.

VERDICT: success

@lukemaj

lukemaj commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

Independent review (Sol, gpt-6.1-sol, medium) at 060b86a82e0401b3064a02322512b7b28ac435fc: success (relayed unchanged)

No blocking findings.

  • 8e0c7181..060b86a8 contains exactly one commit, three files, and five insertions, with no other changes.
  • The environment-links case assigns label and breaks, resolving the missing assignment. Its "Listed/list linked environments" wording matches the tool presentation and neighboring list summaries, including failed or unfinished calls.
  • Feature-map edits correctly assign t3ToolSummary.ts to peer-links and add its upstream-edit allowlist entry. node scripts/fork-features.mjs check passed: OK (35 features).
  • git diff --check passed; the worktree remains clean.

Optional tests were not run (the presentation test lives at packages/client-runtime/src/work-log/presentation.test.ts; CI covers it).

VERDICT: success

@lukemaj

lukemaj commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

Independent review (Grok, grok-4.7, medium) at 060b86a82e0401b3064a02322512b7b28ac435fc: success (relayed by the coordinator)

Only change since 8e0c71810a: three files, five lines (the environment-links case, t3ToolSummary.ts in the peer-links upstream list and scripts/fork-upstream-edits.txt). node scripts/fork-features.mjs check OK. The new case matches neighbours (phrase("Listed", "list", ...), same shape as project-list/worktree-list); summarizeT3ToolCalls now covers all 57 T3McpToolSummaryAction members, closing the TS2454 hole. No other consumer needs a case: summaryActionPriority has a default (treated like environment-read); no mobile switch on the union.

VERDICT: success

@lukemaj
lukemaj merged commit 9b49575 into main Oct 14, 2026
29 checks passed
@lukemaj
lukemaj deleted the feat/164-peer-links branch October 14, 2026 12:52
lukemaj added a commit that referenced this pull request Oct 14, 2026
…Rs at it (#296)

* docs(map): cross-machine control cites PR #290; network routes become a part

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

* docs(agents): PRs keep docs/map.md current for the parts they touch

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

* docs(agents): only kept or new map parts cite the PR

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

* docs(agents): context and removed map parts take no PR ref

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

* docs(agents): only a PR that ships a part's work cites itself on the map

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
lukemaj added a commit that referenced this pull request Oct 14, 2026
Replay merged Chromeria #290 while retaining native launch, provider admission,
restart continuation and fork recovery behavior. This is an incomplete
absorption checkpoint; combined proof and delivery are still pending.

(cherry picked from commit 9b49575)
lukemaj added a commit that referenced this pull request Oct 29, 2026
Replay merged Chromeria #290 while retaining native launch, provider admission,
restart continuation and fork recovery behavior. This is an incomplete
absorption checkpoint; combined proof and delivery are still pending.

(cherry picked from commit 9b49575)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant