Skip to content

Reverse route: let the VM reach a laptop that can't be reached, over a line the laptop opens #951

Closed

Description

@Jacksondr5

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 cloudflared connects 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

  1. 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.
  2. 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.
  3. Poll mode's storage stays. A sleeping laptop has no line, and J5 messages still need holding until it wakes.
  4. 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 as peer_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-machine j5_spawn_agent fails 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 except capability_denied, thread_not_found, run_not_found and an invalid_request for 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 of delegate_task, not on readThread and waitForThread, 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.
  5. 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 to 127.0.0.1:<port> never touches nginx.
  6. 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

  1. Jacksondr5 commented on Nov 7, 2026

    @Jacksondr5
    OwnerAuthor

    Sequencing (Jackson, 2026-11-07): cross-machine work starts after the upstream v0.1.7 merge. This issue comes first, then #956 (j5_spawn_agent on 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.

  2. Jacksondr5 commented on Nov 17, 2026

    @Jacksondr5
    OwnerAuthor

    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 in docs/j5/product/upstream.md.

    How a call reaches the laptop: no ports, one WebSocket

    Upstream's PeerLinks and PeerMcpClient get their HttpClient from the combined layer in apps/server/src/server.ts (around lines 832–836). That's the server's only PeerLinks, and it serves Settings and agents' link requests. J5 gives that layer a routing HttpClient:

    • A request for a line address uses Effect's NodeHttpClient with a custom Node http.Agent (keepAlive: false) whose createConnection returns a stream carried over the line.
    • Every other request runs on the ordinary fetch client, in the caller's context, so upstream's redirect: "manual" still applies. The Node client never follows redirects.

    The CLI's j5 environment link and list build their own PeerLinks in 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 to 127.x (isLocalLoopbackHost). An address released and later reused just reads as "didn't answer", because resolve checks 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:

    • Frames: open(id), data(id, bytes), end(id) (end of data in one direction, sent after any queued data) and reset(id) (destroys only that connection), plus ping / pong.
    • VM side. A demultiplexer on the route's Effect Socket from request.upgrade. Each connection is a Node Duplex with no-op setKeepAlive, setNoDelay, setTimeout, ref and unref. createConnection sends open(id) and returns the Duplex synchronously, or fails at once when no line is up. Duplex _write sends a frame and calls back without waiting.
    • Laptop side. On 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:

    • On the laptop, which sends the large answers over a real ws socket: while the bytes passed to ws.send and 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. ws has no drain event, so the count is the mechanism.
    • On the VM, the demultiplexer pulls frames continuously and never pauses the line, because Effect's reader pauses the whole socket. Each connection's unread bytes are capped at 32 MB; a connection over the cap is reset, so the call fails visibly. What the VM sends is small tool requests.
    • Data for an unknown or reset id is dropped.

    The line's life:

    • The line opens within 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).
    • Each side sends ping every 10 seconds in the line's scope, and any inbound frame counts as life. Either side drops the line after 30 seconds without one.
    • Each line gets a random id. When a line drops or is replaced, every connection it carried is reset, and nothing from it can attach to the replacement. A close handler acts only if its line is still current.
    • On the VM, the route races the line against SessionStore.awaitInvalidation, which already covers revocation, expiry and peer removal, as ServerBrowserStream.ts:207 does.
    • The hello gains a line capability. A poller opens a line only to a storing server that advertises it.

    Layer 1: the line

    1. The peer route J5_PEER_API_PATHS.line. It authenticates like poll (AuthA2APeerScope) and serves only a peer recorded here with link mode store.
    2. The VM demultiplexer and Duplex, and the laptop's line client inside the poll loop.
    3. The line address per store peer. The contract gains the address only.
    4. Wiring in server.ts (FORK.md case).

    Layer 2: D46

    1. Add peer_unreachable to OrchestratorMcpFailure's codes (packages/contracts/src/orchestratorMcp.ts) (FORK.md case).
    2. Classify in PeerMcpClient (FORK.md case): the unreachable branch of fromLinkError ("did not answer"), and the HttpClientError catch ("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's TimeoutError branch at the next advance. Refusal codes are unchanged. The follower's isFinal doesn't list the new code, so it keeps retrying.
    3. Record the tool the agent called.
      • In McpToolAccess.routed, where a routed tool goes to another machine under its own name (McpToolAccess.ts:417) (FORK.md case).
      • In J5's own delegate_task handler (agentDelegation.ts), which records delegate_task for any peer_unreachable on a delegate aimed at another machine, including its project lookup.
      • PeerForwarding and RemoteDelegation stay untouched, so the follower and task_cancel/task_status on a remote task record nothing, by construction.
    4. The rows are held in memory, and only for calls to a store peer (one with a line address): AC35 covers only servers that hold a line, and a row for any other peer would never be notified. Each holds the thread, the tool, when it was called, and the id of the line that was current when the call started (or none). Recording and notifying are serialized per peer:
      • When line L comes up: every row for that peer whose line isn't L is sent as one notice per thread naming every call, and those rows are removed.
      • When a row is recorded while a line is up that isn't the row's line, it's sent at once. In-flight calls are reset when a line drops, before any redial, so this is rare. A thread could then get a second notice, which is accepted rather than adding machinery to wait for outstanding calls.
      • Archived threads are skipped. Removing the peer clears its rows. A restart of the VM forgets pending notices, since that restart has already interrupted those threads, so there's no table and no restart test.
    5. Four FORK.md cases in all: contracts, PeerMcpClient.ts, McpToolAccess.ts and server.ts. D46's "Consequences" paragraph is corrected to match.

    Tests

    • Layer 1:
      • The framing.
      • A 5 MB answer sent at the same time as a small request and pings, with both progressing.
      • A response cut after its headers.
      • Aborting a request mid-open and mid-wait.
      • When a line drops, every connection resets. A replacement doesn't inherit the old line's connections or close events.
      • Invalidating the session closes the line, and a 401 stops the dialler.
      • A test with two servers, in the style of 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 /mcp repeatedly, including error responses.
    • Layer 2:
      • Rows in the existing PeerMcpClient tests: no answer, and a dropped connection, both giving peer_unreachable.
      • The follower keeps retrying on that real classification.
      • A remote delegate_task failure produces a notice naming delegate_task.
      • Notice rules: one notice for rows from before the line came up; a row recorded on the same line waits for the next line; a row recorded after replacement is sent at once; archived threads; peer removal.

    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:

    1. Link the VM to the laptop at the line address through Settings' link dialog or an agent's link request, not the CLI.
    2. Delegate work to the laptop from the VM.
    3. Read a 5 MB thread through the line.
    4. Simulate sleep by sending SIGSTOP and then SIGCONT to the laptop server's captured PID, mid-delegate. The follower should keep retrying, and another agent's launch should fail with peer_unreachable. After the redial, the notice should arrive.
    5. Log the time to open each connection and the time to redial.

    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

    • Reusing connections.
    • Per-connection flow control.
    • Cancelling the laptop's work when the VM gives up.
    • Redialling at once when a sleep is detected.
    • Durable notice rows.
    • Aggregating late failures into the same notice.
    • Routing the CLI.
    • The line's up state in the contract (One link flow: connect two machines once, for messages and actions #1004).
    • Forgery hardening.
  3. Jacksondr5 commented on Nov 17, 2026

    @Jacksondr5
    OwnerAuthor

    Built and merged in #1077 (the line) and #1078 (peer_unreachable and 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.

  4. Jacksondr5 commented on Nov 19, 2026

    @Jacksondr5
    OwnerAuthor

    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_task from VM to laptop, with no disconnect: ✅ passed

    • t3_environment_links listed the laptop as reachable. t3_project_list with its environmentId returned the laptop's projects.
    • I delegated Run "hostname", then "sleep 240", then "date". Reply with both outputs. to claude-haiku-5-5 in a project on the laptop, in async mode.
    • The [completed] notice woke the VM thread on its own (no polling). It carried the laptop's hostname and a date taken after the sleep.
    • One thing to check: the launch result had childThreadId: null, and remoteChild.threadId was still the mcp: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_read on the remote thread:

    Time (UTC) Event
    22:57:09 Run started
    22:57:13 Agent ran hostname; sleep 240; date
    23:01:13 Command finished; output was captured in the thread
    23:01–23:04 Agent's next Claude API call failed (ENOTFOUND) because the laptop had no network; it kept retrying
    23:04:12 Run marked failed: API Error: Can't reach the API server — check your internet or DNS (ENOTFOUND)
    • The [failed] notice reached the VM thread unprompted. task_status agreed: status: failed, workState: result_available, with the error as the summary.
    • The command output was not lost. It's in the remote thread's activity and can be read from the VM, but it isn't in the final summary.
    • Nothing resumed or retried after reconnect. The run stayed failed even though the real work had finished.
    • The error looks the same as an Anthropic API outage. Nothing says the remote machine was the one that lost its network.
    • This test didn't exercise the case that matters most for the line: the line breaking while the remote agent stays healthy. The laptop's own agent died first. A better repeat would cut only the J5 connection (stop J5 on the laptop, or block the line) and leave internet up.
    • I couldn't tell whether the notice was sent at 23:04 or held until reconnect, because the notice has no timestamp.

    3. t3_project_list against the laptop about every 13 s, with a disconnect in the middle: ✅ errors are clean

    # Time (UTC) Result
    1 23:11:43 Succeeded
    2 23:11:59 peer_unreachable
    3 23:12:12 peer_unreachable (links: status: unreachable, same lastError)
    4 23:12:25 peer_unreachable
    5 23:12:38 peer_unreachable
    — before 23:12:51 "Linked environment reachable again" notice arrived
    6 23:12:51 Succeeded (links: status: reachable)
    7 23:13:04 Succeeded
    8 23:13:18 Succeeded

    The error:

    {"_tag":"OrchestratorMcpFailure","code":"peer_unreachable","message":"<laptop> did not answer at http://<loopback-line-address>."}

    What worked:

    • Each call failed at once with a stable code. There were no hangs or long timeouts.
    • The link status and lastError agreed with the call errors.
    • The back-in-reach notice arrived unprompted. It listed every unanswered call with an exact timestamp and warned they may have run there. It said nothing was retried, and pointed to t3_thread_list / task_status or retrying with the same clientRequestId.

    Suggested follow-ups

    1. Make the peer_unreachable message 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.
    2. Stale lastError. After reconnect, the link shows status: reachable but still carries the old lastError. Clear it when the peer answers again, or add a timestamp to it.
    3. Add timestamps to the reconnect notice. It lists the failed calls but not when the peer came back, so the outage length can't be worked out from it.
    4. Remote child IDs. childThreadId stays null and remoteChild.threadId stays the mcp:launch: placeholder through completion. Confirm that's intended.
    5. Failed run after finished work. In test 2 the task finished its real work and then failed on the final API call. It may be worth at least putting the last tool output in the failure summary. Another option is a retry-on-reconnect for provider network errors.
    6. Re-test line-only loss. The remaining hand check from the comment above (sleep/wake during a held task, with the agent healthy) still needs a run where only the line drops.
  5. Jacksondr5 commented on Nov 20, 2026

    @Jacksondr5
    OwnerAuthor

    Hand test verdict: passed

    The run above covers what this issue still needed on the real ZPA setup.

    • The line: after wifi came back, the laptop reopened its line to the VM through ZPA without any help.
    • peer_unreachable: while the laptop was offline, each call from the VM to it failed straight away with that code.
    • The notice: about 13 s after the laptop came back, the thread got one "reachable again" notice listing every unanswered call. The next calls succeeded.
    • Delegates: a delegate's follower held through the outage and reported the outcome once the laptop could be reached again.

    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:

    1. The message that shows the line address: added to One link flow: connect two machines once, for messages and actions #1004, which owns the wording agents read about links.
    2. lastError after reconnect: upstream's link status. No change in J5.
    3. When the laptop came back: the notice arrives at that moment, so its own time in the thread answers this. No change.
    4. childThreadId and the mcp:launch: placeholder: upstream's launch handler. Reading the thread by that ID works.
    5. A run that fails after its work finished: upstream's provider retries. No change.
    6. Losing only the line: the line behaves the same whatever the laptop's agent is doing, and test 3 covers that case.

    Claude Opus 5.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions