Repository navigation
Description
Problem
Upstream's linked environments (Labs beta, in v0.1.7) let agents on one machine use T3 tools on another: thread tools, queues, projects, scheduled tasks, pull-request tools and delegate_task, 38 tools plus delegate_task. A link is a synchronous call to the other machine's /mcp, so it only works towards a machine that can be reached.
In the corporate setup (an always-on work VM, and a laptop behind a firewall that refuses every inbound connection, reaching the VM over Zscaler Private Access), the laptop can link to the VM but the VM can never link to the laptop. Adopting upstream's link features as shipped would leave every one of them one-way there. That's a gap that depends on how the two devices connect, which is a downgrade from J5's peering today, where poll mode makes everything J5 offers work both ways. Hiding the features instead would withhold upstream's work.
Alternatives considered and set aside:
- Holding upstream's tools on the polling rail. Every held tool's result would need a "pending" variant on result types upstream owns. Reads would need snapshots, and control calls (interrupt, steer, answering approvals) would need to be tied to their target and expire.
- T3 Connect. Upstream's hosted Connect can't be used: one account per server, and J5 points at none of upstream's infrastructure. Running J5's own (Should J5 run its own T3 Connect? #725) is operations work on the scale of v3, and
cloudflaredconnects out on port 7844 rather than through the corporate network, which security teams commonly flag. - Polling as a give-back. Upstream declined a poll mode for the first version of links (pingdotgg/t3code#16655 reply).
Proposal: a reverse route
The laptop opens a connection to the VM over ordinary HTTPS, through ZPA, and keeps it open. The VM exposes that connection on its own loopback address, such as 127.0.0.1:<port>, so anything on the VM that calls that address is talking to the laptop. Upstream's link from the VM to the laptop uses that address. Upstream accepts plain http on loopback (peerOrigin in apps/server/src/peer/PeerLinks.ts) and checks that the answer reports the laptop's environment id.
Upstream's link tools then work both ways and synchronously, with no edit to upstream's code. J5's direct mode can use the same route. It's what Connect does, with your own reachable server in Cloudflare's place.
Evidence that it will hold: the J5 web app on the laptop already keeps a WebSocket to the VM's J5 open through ZPA all day, and Zscaler's client signs in silently through Jamf SSO, so redialling never waits on the person.
Design questions
- The line says which machine it carries. The VM needs to know which laptop is on which loopback address. The laptop stating its environment id when it opens the line is enough. Forgery and impersonation aren't design considerations on J5's closed, trusted network (Jackson, 2026-11-07), so the line needs no sign-in of its own beyond what reaching the VM already requires.
- Only the VM uses the route. The address stays on the VM's own loopback. Reaching the laptop from a phone through the VM is out of scope.
- Poll mode's storage stays. A sleeping laptop has no line, and J5 messages still need holding until it wakes.
- A distinct failure code when the machine can't be reached, and a notice when the line comes back. Upstream turns an unreachable machine into a generic
orchestration_error(PeerForwarding.ts). Keep a distinct code (such aspeer_unreachable), record which thread hit it with which tools, and send each such thread one platform notice when the line is back. The agent decides whether to retry; no automatic retry, and no instruction to end its turn. This needs a small hook in upstream's forwarding, which would be a FORK.md entry. J5's cross-machinej5_spawn_agentfails with the same code when the line is down.- A delegated task already running when the line drops. Upstream's follower (
RemoteDelegation.ts) treats every failure as retryable exceptcapability_denied,thread_not_found,run_not_foundand aninvalid_requestfor a forgotten link, and backs off from 2 seconds up to 5 minutes. A new code is outside that list, so the follower keeps retrying; the new code must not reuse one of those four. - Where the hook sits. On
PeerForwarding.call, which carries agents' tool calls and the launch step ofdelegate_task, not onreadThreadandwaitForThread, which the follower uses. A launch that fails gets the notice; a follower's retries don't produce one. - No notice for a delegate's parent. The parent isn't waiting on a call; the task's completion wakes it. The follower's own retry is enough, at the cost of up to 5 minutes after the line returns before it notices.
- A delegated task already running when the line drops. Upstream's follower (
- No nginx changes. The route is a WebSocket on a path the VM's J5 already serves, so the existing nginx block forwards it. Keepalives every few seconds, like the web app's (it treats 15 s of silence as unresponsive,
PING_TIMEOUT), keep it inside nginx's and ZPA's idle timeouts; poll mode's 25-second held requests already pass the same block. nginx's 1 MB body limit covers request bodies, not WebSocket messages. The VM-side hop to127.0.0.1:<port>never touches nginx. - Docs. The October poll-mode session listed "relay, tunnel and client forwarding" as out of scope. The peering definition's rule that "a relay or tunnel is never a required part of it" still holds, because the route is optional.
Line test
Skipped (Jackson, 2026-11-10). With keepalives on the web app's rhythm, ZPA's idle timeout no longer matters: the web app's WebSocket already survives all day through ZPA and nginx. The two things the test would still have shown are measured on the real route during the live test instead:
- a 5 MB message from the laptop to the VM over the WebSocket, through ZPA;
- how fast the line comes back after sleep and network changes.
The test script stays in https://github.com/Jacksondr5/j5-line-test (private) if a question comes up later.
Related
#725 (J5's own Connect), #772 (v0.1.7 advance: linked environments), #399 (poll mode).
Drafted with Claude Opus 5.5.
Activity
Jacksondr5 commentedon Nov 7, 2026
Sequencing (Jackson, 2026-11-07): cross-machine work starts after the upstream v0.1.7 merge. This issue comes first, then #956 (
j5_spawn_agenton another J5 machine, which needs this for the VM-to-laptop direction) and the remote persona delegate, then #953 (Crews across machines). The line test can run any time; its results tune this design and don't gate it.docs(j5): a polling server holds a line, so links reach a server that…
Jacksondr5 commentedon Nov 17, 2026
Implementation plan (2026-11-16, council approved: Claude Opus 9/10, GPT Sol 9/10)
The definition merged in #1075:
docs/j5/product/cross-device.md("A line to a server that cannot be reached", AC13, AC29–AC35) and divergence D46 indocs/j5/product/upstream.md.How a call reaches the laptop: no ports, one WebSocket
Upstream's
PeerLinksandPeerMcpClientget theirHttpClientfrom the combined layer inapps/server/src/server.ts(around lines 832–836). That's the server's onlyPeerLinks, and it serves Settings and agents' link requests. J5 gives that layer a routingHttpClient:NodeHttpClientwith a custom Nodehttp.Agent(keepAlive: false) whosecreateConnectionreturns a stream carried over the line.redirect: "manual"still applies. The Node client never follows redirects.The CLI's
j5 environment linkandlistbuild their ownPeerLinksin a separate process that holds no line. They can't reach a line address, and that's not supported here: #1004's link flow covers it.A line address is
http://127.77.x.y:1, a reserved loopback host per poller, taken from the store peer record's row id. The port is one nothing listens on, so a request that ever missed the routing client would be refused. Upstream accepts plain http to127.x(isLocalLoopbackHost). An address released and later reused just reads as "didn't answer", becauseresolvechecks the environment id before sending a token (PeerLinks.ts:588–597).The line is one WebSocket, opened by the laptop, carrying many HTTP connections as raw bytes. Node writes and parses all the HTTP at both ends:
open(id),data(id, bytes),end(id)(end of data in one direction, sent after any queued data) andreset(id)(destroys only that connection), plusping/pong.Socketfromrequest.upgrade. Each connection is a NodeDuplexwith no-opsetKeepAlive,setNoDelay,setTimeout,refandunref.createConnectionsendsopen(id)and returns the Duplex synchronously, or fails at once when no line is up. Duplex_writesends a frame and calls back without waiting.open(id), the line client connects to its own server's actual listen address (127.0.0.1 only when the server binds every interface) and copies bytes both ways, carrying errors and resets across.Buffering is bounded, without per-connection flow control:
wssocket: while the bytes passed tows.sendand not yet confirmed by its callbacks exceed 1 MB, every local connection is paused, and they resume as the callbacks bring that count back under 1 MB.wshas no drain event, so the count is the mechanism.The line's life:
PeerPoller's per-peer loop: when a poll succeeds and no line is up, it dials. That inherits the poller's backoff and its stop. A 401 on the upgrade stops the line until the poll loop stops or restarts, as a 401 on a poll stops polling (PeerPoller.ts:287).pingevery 10 seconds in the line's scope, and any inbound frame counts as life. Either side drops the line after 30 seconds without one.SessionStore.awaitInvalidation, which already covers revocation, expiry and peer removal, asServerBrowserStream.ts:207does.linecapability. A poller opens a line only to a storing server that advertises it.Layer 1: the line
J5_PEER_API_PATHS.line. It authenticates likepoll(AuthA2APeerScope) and serves only a peer recorded here with link modestore.server.ts(FORK.md case).Layer 2: D46
peer_unreachabletoOrchestratorMcpFailure's codes (packages/contracts/src/orchestratorMcp.ts) (FORK.md case).PeerMcpClient(FORK.md case): theunreachablebranch offromLinkError("did not answer"), and theHttpClientErrorcatch ("stopped answering", which includes a body cut mid-read). Add upstream fix(server): linked calls fail fast when a peer stalls the MCP handshake pingdotgg/t3code#28876'sTimeoutErrorbranch at the next advance. Refusal codes are unchanged. The follower'sisFinaldoesn't list the new code, so it keeps retrying.McpToolAccess.routed, where a routed tool goes to another machine under its own name (McpToolAccess.ts:417) (FORK.md case).delegate_taskhandler (agentDelegation.ts), which recordsdelegate_taskfor anypeer_unreachableon a delegate aimed at another machine, including its project lookup.PeerForwardingandRemoteDelegationstay untouched, so the follower andtask_cancel/task_statuson a remote task record nothing, by construction.PeerMcpClient.ts,McpToolAccess.tsandserver.ts. D46's "Consequences" paragraph is corrected to match.Tests
PeerPollRoundTrip.test.ts. Upstream's link describes the poller through the line address, links with the real OAuth registration, decision and token exchange, and calls/mcprepeatedly, including error responses.PeerMcpClienttests: no answer, and a dropped connection, both givingpeer_unreachable.delegate_taskfailure produces a notice namingdelegate_task.Live test
A Sol 6.1 tester Peer Agent runs two J5 test servers (
setup-agent-live-test.ts --peer) in poll mode, with Haiku or Luna turns:SIGSTOPand thenSIGCONTto the laptop server's captured PID, mid-delegate. The follower should keep retrying, and another agent's launch should fail withpeer_unreachable. After the redial, the notice should arrive.Then Jackson tries it on ZPA with a nightly build.
Before the build: Jackson confirms that the VM's nginx passes WebSocket upgrades on
/api/paths, not only on/ws.Left out on purpose
Jacksondr5 commentedon Nov 17, 2026
Built and merged in #1077 (the line) and #1078 (
peer_unreachableand the back-in-reach notice), squashed as 37acd6c. The live test passed on every flow it exercised; a re-test after the prompt-redial fix measured 1.04 s from wake to notice (26 s before). Still to verify by hand on the real ZPA setup with a nightly: link the VM to the laptop, delegate from the VM, sleep and wake the laptop during a held task, and check the task finishes and the notice arrives.Jacksondr5 commentedon Nov 19, 2026
Hand test on the real VM ↔ laptop setup (2026-11-19)
Three tests, all run from an agent on the VM against the linked laptop. Machine names, IDs and addresses are replaced with placeholders.
1.
delegate_taskfrom VM to laptop, with no disconnect: ✅ passedt3_environment_linkslisted the laptop asreachable.t3_project_listwith itsenvironmentIdreturned the laptop's projects.Run "hostname", then "sleep 240", then "date". Reply with both outputs.toclaude-haiku-5-5in a project on the laptop, inasyncmode.[completed]notice woke the VM thread on its own (no polling). It carried the laptop's hostname and adatetaken after the sleep.childThreadId: null, andremoteChild.threadIdwas still themcp:launch:<hash>placeholder. It stayed that way in the completion. Reading the remote thread by that ID did work later.2. Same delegate, with the laptop disconnected while the task ran:⚠️ task failed, but the line behaved correctly
The laptop timeline, read with
t3_thread_readon the remote thread:hostname; sleep 240; dateENOTFOUND) because the laptop had no network; it kept retryingfailed:API Error: Can't reach the API server — check your internet or DNS (ENOTFOUND)[failed]notice reached the VM thread unprompted.task_statusagreed:status: failed,workState: result_available, with the error as the summary.3.
t3_project_listagainst the laptop about every 13 s, with a disconnect in the middle: ✅ errors are cleanpeer_unreachablepeer_unreachable(links:status: unreachable, samelastError)peer_unreachablepeer_unreachablestatus: reachable)The error:
{"_tag":"OrchestratorMcpFailure","code":"peer_unreachable","message":"<laptop> did not answer at http://<loopback-line-address>."}What worked:
lastErroragreed with the call errors.t3_thread_list/task_statusor retrying with the sameclientRequestId.Suggested follow-ups
peer_unreachablemessage readable. "did not answer at http://127.x.x.x:N" shows the local line endpoint, which tells the user nothing. Something like "<laptop>is offline or its line is down (last seen HH:MM:SS)" would be clearer.lastError. After reconnect, the link showsstatus: reachablebut still carries the oldlastError. Clear it when the peer answers again, or add a timestamp to it.childThreadIdstaysnullandremoteChild.threadIdstays themcp:launch:placeholder through completion. Confirm that's intended.Jacksondr5 commentedon Nov 20, 2026
Hand test verdict: passed
The run above covers what this issue still needed on the real ZPA setup.
peer_unreachable: while the laptop was offline, each call from the VM to it failed straight away with that code.Test 2's delegate died because the laptop couldn't reach the Claude API with wifi off. That's how upstream's provider behaves, not a fault in the line.
On the suggested follow-ups:
lastErrorafter reconnect: upstream's link status. No change in J5.childThreadIdand themcp:launch:placeholder: upstream's launch handler. Reading the thread by that ID works.Claude Opus 5.5