Skip to content

Linked environments: the thread relay and client pairing still keep a link the peer revoked #977

Closed

Description

@scuttletoby

Follow-up to #959 / #964.

What is left: #964 ends a link here once the peer turns its token away, but only for calls through PeerMcpClient (every agent tool call). Two other paths still only record the refusal, so the link keeps listing as reachable there:

  • Thread-stream relay: apps/server/src/peer/PeerThreadRelay.ts (around line 109) maps both 401 and 403 to a rejected read error ("Its link may have been revoked there; link it again.") and does not end the link. A user who only reads linked threads keeps seeing the link as live.
  • Client pairing: apps/server/src/peer/PeerClientPairing.ts (ask) turns every refusal of clientPairing, a 401 included, into unsupported("refused") and does not end the link.

Expected: both end the link the same way PeerMcpClient now does (fork/peerLinkRevoke.ts):

  1. Only a 401 can end a link. A 403 (linked_environments_off, not_a_link_session, a browser origin) must not.
  2. A single 401 is not proof. End the link only when a fresh MCP session started right after it is refused with 401 too, because an older peer answers 401 for its own storage errors as well. Since fix(server): a link the peer revoked ends here too #964 a current peer answers 503 for those, on /mcp and on the linked-thread routes.
  3. Use PeerLinks.recordRevoked with the linked_at the refused request resolved, so a link made again since is kept.

Also to weigh: a different machine answering at the link's stored address as the same environmentId (a reused address on the LAN or tailnet, say) can answer 401 and end the link. resolve already sends that address the token, so this adds little, and a new pairing code recovers. Still, the fix should not make it easier. For example, keep the fresh-session check above, which that machine would also have to refuse.

Test: for the relay and for client pairing, the box revokes the link, then a stream read (or a pairing request) ends the link here and the link lists as expired. A 403 and a single 401 followed by an accepted fresh session leave the link reachable.

🤖 Generated with Claude Code

Activity

  1. scuttletoby commented on Nov 22, 2026

    @scuttletoby
    OwnerAuthor

    Minor follow-ups from the round-2 lenses on #964 (both safe to merge): code #964 (comment), state #964 (comment)

    • apps/server/src/fork/peerLinkRevoke.ts:17 keeps its own copy of the protocol version string from PeerMcpClient.ts:26; pass it in through makeRefusals' inputs (no new seam line).
    • peerLinkRevoke.ts:111: a 403 on the second session start gives a generic "HTTP 403" message instead of the "Linked environments turned off" one (link is kept, text only).
    • PeerMcpClient.ts:176-179: the old 401 branches can no longer be reached (upstream code; leave unless the seam count allows).
    • peer/linkThreadHttp.ts:74: a store failure at the 30 s recheck of an open thread stream now ends the stream with an error instead of cleanly (relay reconnects; only a log error).
    • Older peer with a longer outage: an older peer still answers 401 for its own storage errors and can end a good link if the outage outlasts the 2-3 back-to-back checks (peerLinkRevoke.ts:84, no wait between them). Consider a short wait between them.
    • PeerMcpClient.ts:250: if the fresh session is accepted but the retried call gets 401 again, the message says "revoked there; link it again" although the link still works.

    🤖 Generated with Claude Code

  2. added 3 commits that reference this issue on Nov 22, 2026
  3. added 4 commits that reference this issue on Nov 28, 2026
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