From 3cb24eb230d049f7ee47f85e4002e8362451c4bd Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 22 Nov 2026 01:51:09 -0800 Subject: [PATCH 1/3] fix(server): unlinking an environment ends its session on the other machine Forgetting a linked environment deleted the link and its token here but left the session it had opened on the other machine valid for up to 30 days. Each relink added another, so a machine linked and unlinked repeatedly kept a pile of live credentials in its Sharing & access. The MCP OAuth server now serves RFC 7009 token revocation at /oauth/mcp/revoke (advertised as revocation_endpoint). It ends only the MCP client session the presented token belongs to and answers 200 for anything else. Unlink forgets the link here first, then asks the peer to revoke, bounded by the probe timeout. A peer that is offline or on an older version keeps the session until it expires or is revoked there, and the CLI says so. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/auth/EnvironmentAuth.ts | 19 +++++++++ apps/server/src/auth/McpOAuth.test.ts | 17 ++++++++ apps/server/src/auth/McpOAuth.ts | 1 + apps/server/src/auth/mcpOAuthHttp.ts | 13 ++++++ apps/server/src/cli/environment.ts | 14 ++++--- .../src/mcp/toolkits/orchestrator/handlers.ts | 2 +- .../src/mcp/toolkits/orchestrator/tools.ts | 2 +- apps/server/src/peer/PeerLinks.test.ts | 6 ++- apps/server/src/peer/PeerLinks.ts | 42 ++++++++++++++++--- .../src/provider/agentContextBudget.json | 2 +- apps/server/src/ws.ts | 2 +- .../settings/LinkedEnvironmentsSettings.tsx | 2 +- apps/web/src/i18n/translations/de.json | 2 +- apps/web/src/i18n/translations/en.json | 2 +- apps/web/src/i18n/translations/es.json | 2 +- apps/web/src/i18n/translations/fr.json | 2 +- apps/web/src/i18n/translations/ja.json | 2 +- apps/web/src/i18n/translations/ko.json | 2 +- apps/web/src/i18n/translations/pt-BR.json | 2 +- apps/web/src/i18n/translations/ru.json | 2 +- apps/web/src/i18n/translations/sv.json | 2 +- apps/web/src/i18n/translations/zh.json | 2 +- docs/user/remote-access.md | 5 ++- packages/contracts/src/auth.ts | 9 ++++ packages/contracts/src/environmentHttp.ts | 7 ++++ 25 files changed, 135 insertions(+), 28 deletions(-) diff --git a/apps/server/src/auth/EnvironmentAuth.ts b/apps/server/src/auth/EnvironmentAuth.ts index 202ca25310d13..90ed438f1b02f 100644 --- a/apps/server/src/auth/EnvironmentAuth.ts +++ b/apps/server/src/auth/EnvironmentAuth.ts @@ -635,6 +635,10 @@ export class EnvironmentAuth extends Context.Service< readonly authenticateMcpClient: ( request: HttpServerRequest.HttpServerRequest, ) => Effect.Effect; + /** Ends the MCP client session `token` belongs to. False when it is no live MCP client token. */ + readonly revokeMcpClientToken: ( + token: string, + ) => Effect.Effect; readonly issueMcpClientSession: (input: { readonly label: string; readonly access: AuthMcpClientAccess; @@ -1637,6 +1641,20 @@ export const make = Effect.gen(function* () { ); }; + const revokeMcpClientToken: EnvironmentAuth["Service"]["revokeMcpClientToken"] = Effect.fn( + "EnvironmentAuth.revokeMcpClientToken", + )(function* (token) { + const session = yield* sessions.verify(token).pipe(Effect.option); + if ( + Option.isNone(session) || + session.value.subject !== MCP_CLIENT_SUBJECT || + session.value.method !== "bearer-access-token" + ) { + return false; + } + return yield* revokeSession(session.value.sessionId); + }); + const issueMcpClientSession: EnvironmentAuth["Service"]["issueMcpClientSession"] = (input) => sessions .issue({ @@ -1719,6 +1737,7 @@ export const make = Effect.gen(function* () { issueWebSocketTicket, issueStartupPairingUrl, authenticateMcpClient, + revokeMcpClientToken, issueMcpClientSession, consumeMcpApprovalCode, }); diff --git a/apps/server/src/auth/McpOAuth.test.ts b/apps/server/src/auth/McpOAuth.test.ts index d72a716673e66..f66d0b1c6e81c 100644 --- a/apps/server/src/auth/McpOAuth.test.ts +++ b/apps/server/src/auth/McpOAuth.test.ts @@ -209,6 +209,7 @@ it.effect("derives discovery metadata from the origin the client reached", () => authorization_endpoint: `${ORIGIN}/oauth/mcp/authorize`, token_endpoint: `${ORIGIN}/oauth/mcp/token`, registration_endpoint: `${ORIGIN}/oauth/mcp/register`, + revocation_endpoint: `${ORIGIN}/oauth/mcp/revoke`, code_challenge_methods_supported: ["S256"], }); }), @@ -396,6 +397,22 @@ it.live("signs in with a pairing code and issues a token only /mcp accepts", () }), ); expect(ticket.status).toBe(401); + + // Revocation ends only an MCP client's own session; any other token is answered alike and kept. + const owner = yield* auth.exchangeBootstrapCredentialForAccessToken( + (yield* auth.issuePairingCredential()).credential, + undefined, + { deviceType: "desktop" }, + ); + const bearer = (token: string) => + HttpServerRequest.fromWeb(at("/api", { headers: { authorization: `Bearer ${token}` } })); + for (const other of ["not-a-token", owner.access_token]) { + expect((yield* handler(at("/oauth/mcp/revoke", form({ token: other })))).status).toBe(200); + } + yield* auth.authenticateHttpRequest(bearer(owner.access_token)); + const revoked = yield* handler(at("/oauth/mcp/revoke", form({ token: token.access_token }))); + expect(revoked.status).toBe(200); + yield* auth.authenticateMcpClient(bearer(token.access_token)).pipe(Effect.flip); }), ), ); diff --git a/apps/server/src/auth/McpOAuth.ts b/apps/server/src/auth/McpOAuth.ts index 9ab0bfe1c176a..e63c600ae1b2d 100644 --- a/apps/server/src/auth/McpOAuth.ts +++ b/apps/server/src/auth/McpOAuth.ts @@ -97,6 +97,7 @@ export const authorizationServerMetadata = ( authorization_endpoint: `${urls.issuer}/oauth/mcp/authorize`, token_endpoint: `${urls.issuer}/oauth/mcp/token`, registration_endpoint: `${urls.issuer}/oauth/mcp/register`, + revocation_endpoint: `${urls.issuer}/oauth/mcp/revoke`, response_types_supported: ["code"], grant_types_supported: ["authorization_code"], code_challenge_methods_supported: ["S256"], diff --git a/apps/server/src/auth/mcpOAuthHttp.ts b/apps/server/src/auth/mcpOAuthHttp.ts index 6e10362000adf..c9ffde0ecda99 100644 --- a/apps/server/src/auth/mcpOAuthHttp.ts +++ b/apps/server/src/auth/mcpOAuthHttp.ts @@ -9,6 +9,7 @@ import { } from "@t3tools/contracts"; import * as Effect from "effect/Effect"; import * as Option from "effect/Option"; +import * as Redacted from "effect/Redacted"; import * as Result from "effect/Result"; import * as Schema from "effect/Schema"; import { HttpServerRequest, HttpServerResponse } from "effect/http"; @@ -20,6 +21,7 @@ import { DEFAULT_HOSTED_APP_URL } from "@t3tools/shared/connectAuth"; import * as CloudLink from "../cloud/CloudLink.ts"; import { agentApprovalAppUrlConfig } from "../cloud/publicConfig.ts"; import * as ServerEnvironment from "../environment/ServerEnvironment.ts"; +import * as EnvironmentAuth from "./EnvironmentAuth.ts"; import * as McpOAuth from "./McpOAuth.ts"; import { renderErrorPage } from "./mcpOAuthHtml.ts"; @@ -75,6 +77,7 @@ export const layer = HttpApiBuilder.group( "mcpOAuth", Effect.fnUntraced(function* (handlers) { const oauth = yield* McpOAuth.McpOAuth; + const environmentAuth = yield* EnvironmentAuth.EnvironmentAuth; const cloudLink = yield* CloudLink.CloudLink; const serverEnvironment = yield* ServerEnvironment.ServerEnvironmentIdentity; const hostedAppUrl = yield* agentApprovalAppUrlConfig.pipe( @@ -205,6 +208,16 @@ export const layer = HttpApiBuilder.group( yield* noStore; return yield* oauth.exchangeCode({ request, urls: yield* requestUrls, token: payload }); }), + ) + .handle("revoke", ({ payload }) => + Effect.gen(function* () { + yield* noStore; + // RFC 7009 §2.2: an unknown or already revoked token gets the same 200 as a revoked one. + if (payload.token === undefined) return; + yield* environmentAuth + .revokeMcpClientToken(Redacted.value(payload.token)) + .pipe(Effect.orDie); + }), ); }), ); diff --git a/apps/server/src/cli/environment.ts b/apps/server/src/cli/environment.ts index 8c6d2ab78c041..9243d0340eabf 100644 --- a/apps/server/src/cli/environment.ts +++ b/apps/server/src/cli/environment.ts @@ -293,16 +293,20 @@ const environmentUnlinkCommand = Command.make("unlink", { ), }).pipe( Command.withDescription( - "Forget a linked environment here. Revoke it in that environment's Sharing & access to end its session there too.", + "Forget a linked environment here, and end its session there when that environment answers.", ), Command.withHandler((flags) => runWithPeerLinks(flags, (links) => Effect.gen(function* () { - const removed = yield* links.unlink(EnvironmentId.make(flags.environmentId)); + const { removed, endedThere } = yield* links.unlink( + EnvironmentId.make(flags.environmentId), + ); yield* Console.log( - removed - ? `Forgot ${flags.environmentId}. Revoke it in that environment's Sharing & access to end its session there.\n` - : `No linked environment ${flags.environmentId}.\n`, + !removed + ? `No linked environment ${flags.environmentId}.\n` + : endedThere + ? `Forgot ${flags.environmentId} and ended its session there.\n` + : `Forgot ${flags.environmentId}. It did not answer, so revoke it in that environment's Sharing & access to end its session there.\n`, ); }), ), diff --git a/apps/server/src/mcp/toolkits/orchestrator/handlers.ts b/apps/server/src/mcp/toolkits/orchestrator/handlers.ts index d90a118be468e..40965e7284034 100644 --- a/apps/server/src/mcp/toolkits/orchestrator/handlers.ts +++ b/apps/server/src/mcp/toolkits/orchestrator/handlers.ts @@ -218,7 +218,7 @@ const handlers = { t3_environment_unlink: McpToolAccess.writesEnvironment(({ environmentId }) => Effect.gen(function* () { const links = yield* PeerLinks.PeerLinks; - const removed = yield* links + const { removed } = yield* links .unlink(environmentId) .pipe( Effect.mapError( diff --git a/apps/server/src/mcp/toolkits/orchestrator/tools.ts b/apps/server/src/mcp/toolkits/orchestrator/tools.ts index b2866bb0babc5..f617b61fabaa3 100644 --- a/apps/server/src/mcp/toolkits/orchestrator/tools.ts +++ b/apps/server/src/mcp/toolkits/orchestrator/tools.ts @@ -350,7 +350,7 @@ const EnvironmentLinkTool = Tool.make("t3_environment_link", { const EnvironmentUnlinkTool = Tool.make("t3_environment_unlink", { description: - "Forget a linked environment. That machine's Connections list its session until revoked there.", + "Forget a linked environment. Its session on that machine ends too when the machine answers.", parameters: OrchestratorMcpEnvironmentUnlinkInput, success: OrchestratorMcpEnvironmentUnlinkResult, failure: OrchestratorMcpFailure, diff --git a/apps/server/src/peer/PeerLinks.test.ts b/apps/server/src/peer/PeerLinks.test.ts index 0b1f4f716474c..d009725bbbaf5 100644 --- a/apps/server/src/peer/PeerLinks.test.ts +++ b/apps/server/src/peer/PeerLinks.test.ts @@ -157,7 +157,7 @@ it.effect("routes peer reads to readers and sees uncommitted link updates", () = expect((yield* links.list)[0]?.label).toBe("Uncommitted box"); }), ); - expect(yield* links.unlink(box.environmentId)).toBe(true); + expect(yield* links.unlink(box.environmentId)).toEqual({ removed: true, endedThere: false }); expect(yield* links.list).toEqual([]); }), ); @@ -206,6 +206,10 @@ it.effect("links with a pairing code, and the peer holds its agents to the limit // A refusal keeps the peer's reason. const notFound = yield* probe(a, undefined, "refuse").pipe(Effect.flip); expect(notFound).toMatchObject({ code: "thread_not_found", message: "No such thread." }); + + // Unlinking ends the session on B too, instead of leaving a live credential behind. + expect(yield* a.links.unlink(box.environmentId)).toEqual({ removed: true, endedThere: true }); + expect(yield* linkedSessions(b)).toEqual([]); }), ).pipe(Effect.provide(NodeHttpServer.layerTest)), ); diff --git a/apps/server/src/peer/PeerLinks.ts b/apps/server/src/peer/PeerLinks.ts index 5325e5745c5d7..a3a1d4a56089c 100644 --- a/apps/server/src/peer/PeerLinks.ts +++ b/apps/server/src/peer/PeerLinks.ts @@ -116,8 +116,10 @@ export class PeerLinks extends Context.Service< readonly get: ( environmentId: EnvironmentId, ) => Effect.Effect, PeerLinkError>; - /** Forgets the link here. The peer still lists the session until it is revoked there. */ - readonly unlink: (environmentId: EnvironmentId) => Effect.Effect; + /** Forgets the link here, then asks the peer to end the link's session. */ + readonly unlink: ( + environmentId: EnvironmentId, + ) => Effect.Effect<{ readonly removed: boolean; readonly endedThere: boolean }, PeerLinkError>; /** An address that answers as the linked peer, with its token, ready to call. */ readonly resolve: ( environmentId: EnvironmentId, @@ -665,16 +667,46 @@ const make = Effect.gen(function* () { ), ); + /** Best effort: a peer that is gone or too old to revoke lets its session expire instead. */ + const revokeAtPeer = Effect.fn("PeerLinks.revokeAtPeer")( + function* (urlsJson: string, token: string) { + const urls = yield* decodeUrls(urlsJson); + // A race over no addresses never settles. + if (urls.length === 0) return false; + yield* Effect.raceAll( + urls.map((url) => + clientFor(url).pipe( + Effect.flatMap((client) => + client.mcpOAuth.revoke({ payload: { token: Redacted.make(token) } }), + ), + Effect.timeout(probeTimeout(url)), + ), + ), + ); + return true; + }, + Effect.catchCause((cause) => + Effect.logDebug("The unlinked peer did not revoke the link's session", { cause }).pipe( + Effect.as(false), + ), + ), + ); + const unlink: PeerLinks["Service"]["unlink"] = Effect.fn("PeerLinks.unlink")( function* (environmentId) { - const deleted = yield* sql<{ secret_name: string }>` + const deleted = yield* sql<{ secret_name: string; urls_json: string }>` DELETE FROM peer_environment_links WHERE environment_id = ${environmentId} - RETURNING secret_name + RETURNING secret_name, urls_json `.pipe(Effect.catch(failStorage)); + let endedThere = false; for (const row of deleted) { + const token = yield* secrets.get(row.secret_name).pipe(Effect.catch(failStorage)); yield* secrets.remove(row.secret_name).pipe(Effect.catch(failStorage)); + if (Option.isSome(token)) { + endedThere = yield* revokeAtPeer(row.urls_json, new TextDecoder().decode(token.value)); + } } - return deleted.length > 0; + return { removed: deleted.length > 0, endedThere }; }, ); diff --git a/apps/server/src/provider/agentContextBudget.json b/apps/server/src/provider/agentContextBudget.json index 222f23b6b02d9..4d4286111477f 100644 --- a/apps/server/src/provider/agentContextBudget.json +++ b/apps/server/src/provider/agentContextBudget.json @@ -1,5 +1,5 @@ { "claudeSystemAppendBytes": 6245, "codexAdditionalContextBytes": 7639, - "mcpToolListJsonBytes": 59170 + "mcpToolListJsonBytes": 59168 } diff --git a/apps/server/src/ws.ts b/apps/server/src/ws.ts index d1db4372ab871..3faa98aae062a 100644 --- a/apps/server/src/ws.ts +++ b/apps/server/src/ws.ts @@ -2735,7 +2735,7 @@ export const layerWsRpc = ( peerLinks.names.pipe(Effect.map((links) => ({ links }))), [WS_METHODS.peerLinksLink]: (input) => peerLinks.link(input), [WS_METHODS.peerLinksUnlink]: ({ environmentId }) => - peerLinks.unlink(environmentId).pipe(Effect.map((removed) => ({ removed }))), + peerLinks.unlink(environmentId).pipe(Effect.map(({ removed }) => ({ removed }))), [WS_METHODS.peerLinksSubscribeThread]: (input) => peerThreadRelay.subscribe(input), [WS_METHODS.peerLinksThreadHistoryPage]: (input) => Effect.annotateCurrentSpan({ "orchestration_v2.thread_id": input.threadId }).pipe( diff --git a/apps/web/src/components/settings/LinkedEnvironmentsSettings.tsx b/apps/web/src/components/settings/LinkedEnvironmentsSettings.tsx index 954c0e1c4ee3c..47d85c4f1883f 100644 --- a/apps/web/src/components/settings/LinkedEnvironmentsSettings.tsx +++ b/apps/web/src/components/settings/LinkedEnvironmentsSettings.tsx @@ -659,7 +659,7 @@ export function useForgetPeerLink(environmentId: EnvironmentId, link: PeerLinkSu const forget = async () => { const confirmed = await (requestConfirmDialog( gt( - "Forget {label}? Agents here stop working there. Revoke \"T3 Code · …\" in {label}''s Sharing & access to end the session there too.", + "Forget {label}? Agents here stop working there, and their session on {label} ends too if it answers.", { label: link.label }, ), { variant: "destructive" }, diff --git a/apps/web/src/i18n/translations/de.json b/apps/web/src/i18n/translations/de.json index 0db2fb8989ce2..3d03318d0b090 100644 --- a/apps/web/src/i18n/translations/de.json +++ b/apps/web/src/i18n/translations/de.json @@ -8928,7 +8928,7 @@ "fb71127e5746a6bc": "Unter „Freigabe & Zugriff“ dort oder mit t3 pair", "1e3fee7084791773": "Auch {target} zurück mit {source} verknüpfen", "ea34a190b0bd804c": "Agenten auf {target} können dann auch auf {source} arbeiten.", - "ad5ed0ce61b966eb": "{label} vergessen? Agenten von hier arbeiten dort nicht mehr. Widerrufe „T3 Code · …“ unter „Freigabe & Zugriff“ auf {label}, um die Sitzung auch dort zu beenden.", + "974f8c65e8b5f492": "{label} vergessen? Agenten hier arbeiten dort nicht mehr, und ihre Sitzung auf {label} endet ebenfalls, wenn es antwortet.", "81c9796bf61b306a": "Verknüpfung konnte nicht vergessen werden", "130e51beb6cf5aad": "Umgebung verknüpfen", "122c3e355699e69d": "Agenten hier können dort dann Threads starten, ihnen Nachrichten senden und auf sie warten. Sie erscheint unter „Autorisierte Clients“ in „Freigabe & Zugriff“ dieser Umgebung und kann dort widerrufen werden.", diff --git a/apps/web/src/i18n/translations/en.json b/apps/web/src/i18n/translations/en.json index 3aa61a18f6b2b..2ea0a3e1e6955 100644 --- a/apps/web/src/i18n/translations/en.json +++ b/apps/web/src/i18n/translations/en.json @@ -8936,7 +8936,7 @@ "fb71127e5746a6bc": "From Sharing & access there, or t3 pair", "1e3fee7084791773": "Also link {target} back to {source}", "ea34a190b0bd804c": "Agents on {target} can then work on {source} too.", - "ad5ed0ce61b966eb": "Forget {label}? Agents here stop working there. Revoke \"T3 Code · …\" in {label}''s Sharing & access to end the session there too.", + "974f8c65e8b5f492": "Forget {label}? Agents here stop working there, and their session on {label} ends too if it answers.", "81c9796bf61b306a": "Could not forget the link", "130e51beb6cf5aad": "Link an environment", "122c3e355699e69d": "Agents here can then launch, message and wait on threads there. It appears under Authorized clients in that environment's Sharing & access, where it can be revoked.", diff --git a/apps/web/src/i18n/translations/es.json b/apps/web/src/i18n/translations/es.json index 60ddca69b570f..f9e018da1bf74 100644 --- a/apps/web/src/i18n/translations/es.json +++ b/apps/web/src/i18n/translations/es.json @@ -8926,7 +8926,7 @@ "fb71127e5746a6bc": "Desde Compartir y acceso allí, o t3 pair", "1e3fee7084791773": "Vincular también {target} de vuelta a {source}", "ea34a190b0bd804c": "Los agentes de {target} podrán trabajar también en {source}.", - "ad5ed0ce61b966eb": "¿Olvidar {label}? Los agentes de aquí dejarán de trabajar allí. Revoca \"T3 Code · …\" en Compartir y acceso de {label} para cerrar también la sesión allí.", + "974f8c65e8b5f492": "¿Olvidar {label}? Los agentes de aquí dejan de trabajar allí, y su sesión en {label} también termina si responde.", "81c9796bf61b306a": "No se pudo olvidar el vínculo", "130e51beb6cf5aad": "Vincular un entorno", "122c3e355699e69d": "Así los agentes de aquí podrán iniciar hilos allí, enviarles mensajes y esperarlos. Aparece en Clientes autorizados, en Compartir y acceso de ese entorno, donde se puede revocar.", diff --git a/apps/web/src/i18n/translations/fr.json b/apps/web/src/i18n/translations/fr.json index fdcba31a1032f..3d53686b0ca5f 100644 --- a/apps/web/src/i18n/translations/fr.json +++ b/apps/web/src/i18n/translations/fr.json @@ -8928,7 +8928,7 @@ "fb71127e5746a6bc": "Depuis Partage et accès sur cette machine, ou t3 pair", "1e3fee7084791773": "Associer aussi {target} en retour à {source}", "ea34a190b0bd804c": "Les agents de {target} pourront alors aussi travailler sur {source}.", - "ad5ed0ce61b966eb": "Oublier {label} ? Les agents d’ici cessent d’y travailler. Révoquez « T3 Code · … » dans Partage et accès sur {label} pour y fermer aussi la session.", + "974f8c65e8b5f492": "Oublier {label} ? Les agents d’ici cessent d’y travailler, et leur session sur {label} prend fin aussi s’il répond.", "81c9796bf61b306a": "Impossible d’oublier l’association", "130e51beb6cf5aad": "Associer un environnement", "122c3e355699e69d": "Les agents d’ici pourront alors lancer des fils là-bas, leur envoyer des messages et les attendre. L’association apparaît sous Clients autorisés dans Partage et accès de cet environnement, où elle peut être révoquée.", diff --git a/apps/web/src/i18n/translations/ja.json b/apps/web/src/i18n/translations/ja.json index 13379225ecf26..72ccefe022d54 100644 --- a/apps/web/src/i18n/translations/ja.json +++ b/apps/web/src/i18n/translations/ja.json @@ -8884,7 +8884,7 @@ "fb71127e5746a6bc": "リンク先の「共有とアクセス」、または t3 pair から", "1e3fee7084791773": "{target} から {source} へも逆方向にリンクする", "ea34a190b0bd804c": "{target} のエージェントも {source} で作業できるようになります。", - "ad5ed0ce61b966eb": "{label} を削除しますか?ここのエージェントはそこで作業できなくなります。そこでのセッションも終了するには、{label} の「共有とアクセス」で \"T3 Code · …\" を取り消してください。", + "974f8c65e8b5f492": "{label} を削除しますか?ここのエージェントはそこで作業できなくなり、{label} が応答すればそこでのセッションも終了します。", "81c9796bf61b306a": "リンクを削除できませんでした", "130e51beb6cf5aad": "環境をリンク", "122c3e355699e69d": "これで、ここのエージェントがそこでスレッドを起動し、メッセージを送り、完了を待てるようになります。リンクはその環境の「共有とアクセス」の「承認済みクライアント」に表示され、そこで取り消せます。", diff --git a/apps/web/src/i18n/translations/ko.json b/apps/web/src/i18n/translations/ko.json index cc8261d7681ff..4d15e37e1c8c3 100644 --- a/apps/web/src/i18n/translations/ko.json +++ b/apps/web/src/i18n/translations/ko.json @@ -8887,7 +8887,7 @@ "fb71127e5746a6bc": "그곳의 공유 및 액세스 또는 t3 pair에서", "1e3fee7084791773": "{target}에서 {source}(으)로도 반대 방향 연결", "ea34a190b0bd804c": "그러면 {target}의 에이전트도 {source}에서 작업할 수 있습니다.", - "ad5ed0ce61b966eb": "{label}을(를) 삭제할까요? 이곳의 에이전트가 그곳에서 더 이상 작업하지 않습니다. 그곳의 세션도 끝내려면 {label}의 공유 및 액세스에서 \"T3 Code · …\"를 취소하세요.", + "974f8c65e8b5f492": "{label}을(를) 잊을까요? 여기의 에이전트는 그곳에서 더 이상 작업하지 않으며, {label}이(가) 응답하면 그곳의 세션도 종료됩니다.", "81c9796bf61b306a": "링크를 삭제할 수 없습니다", "130e51beb6cf5aad": "환경 연결", "122c3e355699e69d": "그러면 이곳의 에이전트가 그곳에서 스레드를 시작하고, 메시지를 보내고, 기다릴 수 있습니다. 해당 환경의 공유 및 액세스에서 승인된 클라이언트에 표시되며 그곳에서 취소할 수 있습니다.", diff --git a/apps/web/src/i18n/translations/pt-BR.json b/apps/web/src/i18n/translations/pt-BR.json index a9ce3832a0b9f..165420de811b4 100644 --- a/apps/web/src/i18n/translations/pt-BR.json +++ b/apps/web/src/i18n/translations/pt-BR.json @@ -8927,7 +8927,7 @@ "fb71127e5746a6bc": "Em Compartilhamento e acesso de lá, ou t3 pair", "1e3fee7084791773": "Vincular também {target} de volta a {source}", "ea34a190b0bd804c": "Os agentes de {target} poderão trabalhar também em {source}.", - "ad5ed0ce61b966eb": "Esquecer {label}? Os agentes daqui deixam de funcionar lá. Revogue \"T3 Code · …\" em Compartilhamento e acesso de {label} para encerrar a sessão lá também.", + "974f8c65e8b5f492": "Esquecer {label}? Os agentes daqui param de trabalhar lá, e a sessão deles em {label} também termina se ele responder.", "81c9796bf61b306a": "Não foi possível esquecer o vínculo", "130e51beb6cf5aad": "Vincular um ambiente", "122c3e355699e69d": "Os agentes daqui poderão então iniciar threads lá, enviar mensagens e aguardá-las. Ele aparece em Clientes autorizados em Compartilhamento e acesso daquele ambiente, onde pode ser revogado.", diff --git a/apps/web/src/i18n/translations/ru.json b/apps/web/src/i18n/translations/ru.json index ee0fe30aa4f39..c918c402789f2 100644 --- a/apps/web/src/i18n/translations/ru.json +++ b/apps/web/src/i18n/translations/ru.json @@ -8928,7 +8928,7 @@ "fb71127e5746a6bc": "Из раздела «Общий доступ» там или через t3 pair", "1e3fee7084791773": "Также привязать {target} в ответ к {source}", "ea34a190b0bd804c": "Тогда агенты на {target} смогут работать и на {source}.", - "ad5ed0ce61b966eb": "Забыть {label}? Агенты отсюда перестанут там работать. Чтобы завершить сеанс и там, отзовите «T3 Code · …» в разделе «Общий доступ» на {label}.", + "974f8c65e8b5f492": "Забыть {label}? Агенты отсюда перестанут там работать, а их сеанс на {label} тоже завершится, если он ответит.", "81c9796bf61b306a": "Не удалось забыть привязку", "130e51beb6cf5aad": "Привязать окружение", "122c3e355699e69d": "После этого агенты отсюда смогут запускать треды там, писать в них и ждать их. Связь появится в разделе «Авторизованные клиенты» в «Общем доступе» того окружения, где её можно отозвать.", diff --git a/apps/web/src/i18n/translations/sv.json b/apps/web/src/i18n/translations/sv.json index fb02753220b14..0b1331a1f8d7a 100644 --- a/apps/web/src/i18n/translations/sv.json +++ b/apps/web/src/i18n/translations/sv.json @@ -8934,7 +8934,7 @@ "fb71127e5746a6bc": "Från Delning och åtkomst där, eller t3 pair", "1e3fee7084791773": "Länka även {target} tillbaka till {source}", "ea34a190b0bd804c": "Agenter på {target} kan då också arbeta på {source}.", - "ad5ed0ce61b966eb": "Glöm {label}? Agenter här slutar arbeta där. Återkalla ”T3 Code · …” under Delning och åtkomst på {label} för att avsluta sessionen där också.", + "974f8c65e8b5f492": "Glöm {label}? Agenter här slutar arbeta där, och deras session på {label} avslutas också om den svarar.", "81c9796bf61b306a": "Kunde inte glömma länken", "130e51beb6cf5aad": "Länka en miljö", "122c3e355699e69d": "Agenter här kan sedan starta, skicka meddelanden till och vänta på trådar där. Den visas under Auktoriserade klienter i miljöns Delning och åtkomst, där den kan återkallas.", diff --git a/apps/web/src/i18n/translations/zh.json b/apps/web/src/i18n/translations/zh.json index 04044302284b7..88c50d111ae83 100644 --- a/apps/web/src/i18n/translations/zh.json +++ b/apps/web/src/i18n/translations/zh.json @@ -8944,7 +8944,7 @@ "fb71127e5746a6bc": "从远端“共享与访问”页面或 t3 pair 获取", "1e3fee7084791773": "同时将 {target} 反向关联到 {source}", "ea34a190b0bd804c": "之后 {target} 上的智能体也能在 {source} 上工作。", - "ad5ed0ce61b966eb": "忘记 {label}?此处的智能体将停止在那里工作。在 {label} 的“共享与访问”中撤销“T3 Code · …”,以同时结束那里的连接。", + "974f8c65e8b5f492": "忘记 {label}?此处的代理将不再在那里工作;如果 {label} 有响应,它们在那里的会话也会结束。", "81c9796bf61b306a": "无法移除关联", "130e51beb6cf5aad": "关联环境", "122c3e355699e69d": "这里的智能体随后就能在该环境中启动会话、发送消息并等待结果。此连接将显示在该环境“共享与访问”的“已授权客户端”中,可在那里撤销。", diff --git a/docs/user/remote-access.md b/docs/user/remote-access.md index 99255db9ac8cb..72d199791a476 100644 --- a/docs/user/remote-access.md +++ b/docs/user/remote-access.md @@ -468,8 +468,9 @@ an address you trust: the code is sent there. machine's own threads, projects or settings, and they skip its project setup scripts. - The link shows up in that machine's **Settings → Sharing & access** like any - outside agent. Revoke it there to end it. **Forget** on this machine only - removes it here. + outside agent, and can be revoked there. **Forget** on this machine also ends + it there when that machine answers; a machine that is offline or on an older + T3 Code keeps listing it until it expires or you revoke it there. - A link stays valid while agents use it. One unused for 30 days expires, as does one to a machine on an older T3 Code after 30 days; link again with a new pairing code. diff --git a/packages/contracts/src/auth.ts b/packages/contracts/src/auth.ts index 826ffeb6b258e..5a630a6b7abe9 100644 --- a/packages/contracts/src/auth.ts +++ b/packages/contracts/src/auth.ts @@ -554,6 +554,8 @@ export const AuthMcpAuthorizationServerMetadata = Schema.Struct({ authorization_endpoint: Schema.String, token_endpoint: Schema.String, registration_endpoint: Schema.String, + // Older environments do not serve one. + revocation_endpoint: Schema.optionalKey(Schema.String), response_types_supported: Schema.Array(Schema.Literal("code")), grant_types_supported: Schema.Array(Schema.Literal("authorization_code")), code_challenge_methods_supported: Schema.Array(Schema.Literal("S256")), @@ -670,6 +672,13 @@ export const AuthMcpTokenRequest = Schema.Struct({ }).pipe(HttpApiSchema.asFormUrlEncoded()); export type AuthMcpTokenRequest = typeof AuthMcpTokenRequest.Type; +/** RFC 7009: the holder of an access token ends its session. */ +export const AuthMcpRevokeRequest = Schema.Struct({ + token: Schema.optionalKey(Schema.RedactedFromValue(Schema.String)), + token_type_hint: Schema.optionalKey(Schema.String), +}).pipe(HttpApiSchema.asFormUrlEncoded()); +export type AuthMcpRevokeRequest = typeof AuthMcpRevokeRequest.Type; + export const AuthMcpTokenResult = Schema.Struct({ access_token: Schema.String, token_type: Schema.Literal("Bearer"), diff --git a/packages/contracts/src/environmentHttp.ts b/packages/contracts/src/environmentHttp.ts index 9b5cd9a0cb5c1..2a6c0dc43d50c 100644 --- a/packages/contracts/src/environmentHttp.ts +++ b/packages/contracts/src/environmentHttp.ts @@ -25,6 +25,7 @@ import { AuthMcpRegisteredClient, AuthMcpRegistrationError, AuthMcpTokenError, + AuthMcpRevokeRequest, AuthMcpTokenRequest, AuthMcpTokenResult, AuthPairingCredentialResult, @@ -725,6 +726,12 @@ class EnvironmentMcpOAuthHttpApi extends HttpApiGroup.make("mcpOAuth") success: AuthMcpTokenResult, error: AuthMcpTokenError, }), + ) + .add( + HttpApiEndpoint.post("revoke", "/oauth/mcp/revoke", { + payload: AuthMcpRevokeRequest, + success: HttpApiSchema.Empty(200), + }), ) {} const EnvironmentOrchestrationThreadSnapshotParams = Schema.Struct({ From 0689ff8caf99acefea8142d365bf80eea7e601a8 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 22 Nov 2026 11:17:16 -0800 Subject: [PATCH 2/3] fix: tell web and agents when the unlinked environment kept its session Co-Authored-By: Claude Opus 5.5 --- .../src/mcp/toolkits/orchestrator/handlers.ts | 4 ++-- apps/server/src/ws.ts | 3 +-- .../settings/LinkedEnvironmentsSettings.tsx | 13 ++++++++++++- apps/web/src/i18n/translations/de.json | 2 ++ apps/web/src/i18n/translations/en.json | 2 ++ apps/web/src/i18n/translations/es.json | 2 ++ apps/web/src/i18n/translations/fr.json | 2 ++ apps/web/src/i18n/translations/ja.json | 2 ++ apps/web/src/i18n/translations/ko.json | 2 ++ apps/web/src/i18n/translations/pt-BR.json | 2 ++ apps/web/src/i18n/translations/ru.json | 2 ++ apps/web/src/i18n/translations/sv.json | 2 ++ apps/web/src/i18n/translations/zh.json | 2 ++ packages/contracts/src/orchestratorMcp.ts | 1 + packages/contracts/src/peerLink.ts | 6 +++++- 15 files changed, 41 insertions(+), 6 deletions(-) diff --git a/apps/server/src/mcp/toolkits/orchestrator/handlers.ts b/apps/server/src/mcp/toolkits/orchestrator/handlers.ts index 40965e7284034..57932ac21a619 100644 --- a/apps/server/src/mcp/toolkits/orchestrator/handlers.ts +++ b/apps/server/src/mcp/toolkits/orchestrator/handlers.ts @@ -218,7 +218,7 @@ const handlers = { t3_environment_unlink: McpToolAccess.writesEnvironment(({ environmentId }) => Effect.gen(function* () { const links = yield* PeerLinks.PeerLinks; - const { removed } = yield* links + const result = yield* links .unlink(environmentId) .pipe( Effect.mapError( @@ -226,7 +226,7 @@ const handlers = { new OrchestratorMcpFailure({ code: "orchestration_error", message: error.message }), ), ); - return { environmentId, removed }; + return { environmentId, ...result }; }), ), t3_thread_interrupt: McpToolAccess.writesThreads( diff --git a/apps/server/src/ws.ts b/apps/server/src/ws.ts index 3faa98aae062a..b5faaaa16f97c 100644 --- a/apps/server/src/ws.ts +++ b/apps/server/src/ws.ts @@ -2734,8 +2734,7 @@ export const layerWsRpc = ( [WS_METHODS.peerLinksNames]: (_input) => peerLinks.names.pipe(Effect.map((links) => ({ links }))), [WS_METHODS.peerLinksLink]: (input) => peerLinks.link(input), - [WS_METHODS.peerLinksUnlink]: ({ environmentId }) => - peerLinks.unlink(environmentId).pipe(Effect.map(({ removed }) => ({ removed }))), + [WS_METHODS.peerLinksUnlink]: ({ environmentId }) => peerLinks.unlink(environmentId), [WS_METHODS.peerLinksSubscribeThread]: (input) => peerThreadRelay.subscribe(input), [WS_METHODS.peerLinksThreadHistoryPage]: (input) => Effect.annotateCurrentSpan({ "orchestration_v2.thread_id": input.threadId }).pipe( diff --git a/apps/web/src/components/settings/LinkedEnvironmentsSettings.tsx b/apps/web/src/components/settings/LinkedEnvironmentsSettings.tsx index 47d85c4f1883f..5ab6debec7255 100644 --- a/apps/web/src/components/settings/LinkedEnvironmentsSettings.tsx +++ b/apps/web/src/components/settings/LinkedEnvironmentsSettings.tsx @@ -668,7 +668,18 @@ export function useForgetPeerLink(environmentId: EnvironmentId, link: PeerLinkSu setBusy(true); const result = await unlink({ environmentId, input: { environmentId: link.environmentId } }); setBusy(false); - if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) { + if (result._tag === "Success") { + if (result.value.removed && result.value.endedThere !== true) { + toastManager.add({ + type: "warning", + title: gt("{label} did not answer", { label: link.label }), + description: gt( + "Revoke \"T3 Code · …\" in {label}''s Sharing & access to end the session there too.", + { label: link.label }, + ), + }); + } + } else if (!isAtomCommandInterrupted(result)) { failureToast(gt("Could not forget the link"), String(squashAtomCommandFailure(result))); } }; diff --git a/apps/web/src/i18n/translations/de.json b/apps/web/src/i18n/translations/de.json index 3d03318d0b090..c9aebc46cd49d 100644 --- a/apps/web/src/i18n/translations/de.json +++ b/apps/web/src/i18n/translations/de.json @@ -8929,6 +8929,8 @@ "1e3fee7084791773": "Auch {target} zurück mit {source} verknüpfen", "ea34a190b0bd804c": "Agenten auf {target} können dann auch auf {source} arbeiten.", "974f8c65e8b5f492": "{label} vergessen? Agenten hier arbeiten dort nicht mehr, und ihre Sitzung auf {label} endet ebenfalls, wenn es antwortet.", + "6cf9e3083b15614f": "{label} hat nicht geantwortet", + "34ccbdf619b83be3": "Widerrufe „T3 Code · …“ unter „Freigabe & Zugriff“ auf {label}, um die Sitzung auch dort zu beenden.", "81c9796bf61b306a": "Verknüpfung konnte nicht vergessen werden", "130e51beb6cf5aad": "Umgebung verknüpfen", "122c3e355699e69d": "Agenten hier können dort dann Threads starten, ihnen Nachrichten senden und auf sie warten. Sie erscheint unter „Autorisierte Clients“ in „Freigabe & Zugriff“ dieser Umgebung und kann dort widerrufen werden.", diff --git a/apps/web/src/i18n/translations/en.json b/apps/web/src/i18n/translations/en.json index 2ea0a3e1e6955..0808df7eab79b 100644 --- a/apps/web/src/i18n/translations/en.json +++ b/apps/web/src/i18n/translations/en.json @@ -8937,6 +8937,8 @@ "1e3fee7084791773": "Also link {target} back to {source}", "ea34a190b0bd804c": "Agents on {target} can then work on {source} too.", "974f8c65e8b5f492": "Forget {label}? Agents here stop working there, and their session on {label} ends too if it answers.", + "6cf9e3083b15614f": "{label} did not answer", + "34ccbdf619b83be3": "Revoke \"T3 Code · …\" in {label}''s Sharing & access to end the session there too.", "81c9796bf61b306a": "Could not forget the link", "130e51beb6cf5aad": "Link an environment", "122c3e355699e69d": "Agents here can then launch, message and wait on threads there. It appears under Authorized clients in that environment's Sharing & access, where it can be revoked.", diff --git a/apps/web/src/i18n/translations/es.json b/apps/web/src/i18n/translations/es.json index f9e018da1bf74..88f660710fce2 100644 --- a/apps/web/src/i18n/translations/es.json +++ b/apps/web/src/i18n/translations/es.json @@ -8927,6 +8927,8 @@ "1e3fee7084791773": "Vincular también {target} de vuelta a {source}", "ea34a190b0bd804c": "Los agentes de {target} podrán trabajar también en {source}.", "974f8c65e8b5f492": "¿Olvidar {label}? Los agentes de aquí dejan de trabajar allí, y su sesión en {label} también termina si responde.", + "6cf9e3083b15614f": "{label} no respondió", + "34ccbdf619b83be3": "Revoca \"T3 Code · …\" en Compartir y acceso de {label} para cerrar también la sesión allí.", "81c9796bf61b306a": "No se pudo olvidar el vínculo", "130e51beb6cf5aad": "Vincular un entorno", "122c3e355699e69d": "Así los agentes de aquí podrán iniciar hilos allí, enviarles mensajes y esperarlos. Aparece en Clientes autorizados, en Compartir y acceso de ese entorno, donde se puede revocar.", diff --git a/apps/web/src/i18n/translations/fr.json b/apps/web/src/i18n/translations/fr.json index 3d53686b0ca5f..114dd21e96fd4 100644 --- a/apps/web/src/i18n/translations/fr.json +++ b/apps/web/src/i18n/translations/fr.json @@ -8929,6 +8929,8 @@ "1e3fee7084791773": "Associer aussi {target} en retour à {source}", "ea34a190b0bd804c": "Les agents de {target} pourront alors aussi travailler sur {source}.", "974f8c65e8b5f492": "Oublier {label} ? Les agents d’ici cessent d’y travailler, et leur session sur {label} prend fin aussi s’il répond.", + "6cf9e3083b15614f": "{label} n’a pas répondu", + "34ccbdf619b83be3": "Révoquez « T3 Code · … » dans Partage et accès sur {label} pour y fermer aussi la session.", "81c9796bf61b306a": "Impossible d’oublier l’association", "130e51beb6cf5aad": "Associer un environnement", "122c3e355699e69d": "Les agents d’ici pourront alors lancer des fils là-bas, leur envoyer des messages et les attendre. L’association apparaît sous Clients autorisés dans Partage et accès de cet environnement, où elle peut être révoquée.", diff --git a/apps/web/src/i18n/translations/ja.json b/apps/web/src/i18n/translations/ja.json index 72ccefe022d54..e207333046ee3 100644 --- a/apps/web/src/i18n/translations/ja.json +++ b/apps/web/src/i18n/translations/ja.json @@ -8885,6 +8885,8 @@ "1e3fee7084791773": "{target} から {source} へも逆方向にリンクする", "ea34a190b0bd804c": "{target} のエージェントも {source} で作業できるようになります。", "974f8c65e8b5f492": "{label} を削除しますか?ここのエージェントはそこで作業できなくなり、{label} が応答すればそこでのセッションも終了します。", + "6cf9e3083b15614f": "{label} が応答しませんでした", + "34ccbdf619b83be3": "そこでのセッションも終了するには、{label} の「共有とアクセス」で \"T3 Code · …\" を取り消してください。", "81c9796bf61b306a": "リンクを削除できませんでした", "130e51beb6cf5aad": "環境をリンク", "122c3e355699e69d": "これで、ここのエージェントがそこでスレッドを起動し、メッセージを送り、完了を待てるようになります。リンクはその環境の「共有とアクセス」の「承認済みクライアント」に表示され、そこで取り消せます。", diff --git a/apps/web/src/i18n/translations/ko.json b/apps/web/src/i18n/translations/ko.json index 4d15e37e1c8c3..d0c34a39635f7 100644 --- a/apps/web/src/i18n/translations/ko.json +++ b/apps/web/src/i18n/translations/ko.json @@ -8888,6 +8888,8 @@ "1e3fee7084791773": "{target}에서 {source}(으)로도 반대 방향 연결", "ea34a190b0bd804c": "그러면 {target}의 에이전트도 {source}에서 작업할 수 있습니다.", "974f8c65e8b5f492": "{label}을(를) 잊을까요? 여기의 에이전트는 그곳에서 더 이상 작업하지 않으며, {label}이(가) 응답하면 그곳의 세션도 종료됩니다.", + "6cf9e3083b15614f": "{label}이(가) 응답하지 않았습니다", + "34ccbdf619b83be3": "그곳의 세션도 끝내려면 {label}의 공유 및 액세스에서 \"T3 Code · …\"를 취소하세요.", "81c9796bf61b306a": "링크를 삭제할 수 없습니다", "130e51beb6cf5aad": "환경 연결", "122c3e355699e69d": "그러면 이곳의 에이전트가 그곳에서 스레드를 시작하고, 메시지를 보내고, 기다릴 수 있습니다. 해당 환경의 공유 및 액세스에서 승인된 클라이언트에 표시되며 그곳에서 취소할 수 있습니다.", diff --git a/apps/web/src/i18n/translations/pt-BR.json b/apps/web/src/i18n/translations/pt-BR.json index 165420de811b4..d32f4d0a45121 100644 --- a/apps/web/src/i18n/translations/pt-BR.json +++ b/apps/web/src/i18n/translations/pt-BR.json @@ -8928,6 +8928,8 @@ "1e3fee7084791773": "Vincular também {target} de volta a {source}", "ea34a190b0bd804c": "Os agentes de {target} poderão trabalhar também em {source}.", "974f8c65e8b5f492": "Esquecer {label}? Os agentes daqui param de trabalhar lá, e a sessão deles em {label} também termina se ele responder.", + "6cf9e3083b15614f": "{label} não respondeu", + "34ccbdf619b83be3": "Revogue \"T3 Code · …\" em Compartilhamento e acesso de {label} para encerrar a sessão lá também.", "81c9796bf61b306a": "Não foi possível esquecer o vínculo", "130e51beb6cf5aad": "Vincular um ambiente", "122c3e355699e69d": "Os agentes daqui poderão então iniciar threads lá, enviar mensagens e aguardá-las. Ele aparece em Clientes autorizados em Compartilhamento e acesso daquele ambiente, onde pode ser revogado.", diff --git a/apps/web/src/i18n/translations/ru.json b/apps/web/src/i18n/translations/ru.json index c918c402789f2..c000355e83081 100644 --- a/apps/web/src/i18n/translations/ru.json +++ b/apps/web/src/i18n/translations/ru.json @@ -8929,6 +8929,8 @@ "1e3fee7084791773": "Также привязать {target} в ответ к {source}", "ea34a190b0bd804c": "Тогда агенты на {target} смогут работать и на {source}.", "974f8c65e8b5f492": "Забыть {label}? Агенты отсюда перестанут там работать, а их сеанс на {label} тоже завершится, если он ответит.", + "6cf9e3083b15614f": "{label} не ответил", + "34ccbdf619b83be3": "Чтобы завершить сеанс и там, отзовите «T3 Code · …» в разделе «Общий доступ» на {label}.", "81c9796bf61b306a": "Не удалось забыть привязку", "130e51beb6cf5aad": "Привязать окружение", "122c3e355699e69d": "После этого агенты отсюда смогут запускать треды там, писать в них и ждать их. Связь появится в разделе «Авторизованные клиенты» в «Общем доступе» того окружения, где её можно отозвать.", diff --git a/apps/web/src/i18n/translations/sv.json b/apps/web/src/i18n/translations/sv.json index 0b1331a1f8d7a..a9bfc4cecbe7e 100644 --- a/apps/web/src/i18n/translations/sv.json +++ b/apps/web/src/i18n/translations/sv.json @@ -8935,6 +8935,8 @@ "1e3fee7084791773": "Länka även {target} tillbaka till {source}", "ea34a190b0bd804c": "Agenter på {target} kan då också arbeta på {source}.", "974f8c65e8b5f492": "Glöm {label}? Agenter här slutar arbeta där, och deras session på {label} avslutas också om den svarar.", + "6cf9e3083b15614f": "{label} svarade inte", + "34ccbdf619b83be3": "Återkalla ”T3 Code · …” under Delning och åtkomst på {label} för att avsluta sessionen där också.", "81c9796bf61b306a": "Kunde inte glömma länken", "130e51beb6cf5aad": "Länka en miljö", "122c3e355699e69d": "Agenter här kan sedan starta, skicka meddelanden till och vänta på trådar där. Den visas under Auktoriserade klienter i miljöns Delning och åtkomst, där den kan återkallas.", diff --git a/apps/web/src/i18n/translations/zh.json b/apps/web/src/i18n/translations/zh.json index 88c50d111ae83..2169040ad1c51 100644 --- a/apps/web/src/i18n/translations/zh.json +++ b/apps/web/src/i18n/translations/zh.json @@ -8945,6 +8945,8 @@ "1e3fee7084791773": "同时将 {target} 反向关联到 {source}", "ea34a190b0bd804c": "之后 {target} 上的智能体也能在 {source} 上工作。", "974f8c65e8b5f492": "忘记 {label}?此处的代理将不再在那里工作;如果 {label} 有响应,它们在那里的会话也会结束。", + "6cf9e3083b15614f": "{label} 没有响应", + "34ccbdf619b83be3": "在 {label} 的“共享与访问”中撤销“T3 Code · …”,以同时结束那里的连接。", "81c9796bf61b306a": "无法移除关联", "130e51beb6cf5aad": "关联环境", "122c3e355699e69d": "这里的智能体随后就能在该环境中启动会话、发送消息并等待结果。此连接将显示在该环境“共享与访问”的“已授权客户端”中,可在那里撤销。", diff --git a/packages/contracts/src/orchestratorMcp.ts b/packages/contracts/src/orchestratorMcp.ts index f84d003ed12e3..49595364ad786 100644 --- a/packages/contracts/src/orchestratorMcp.ts +++ b/packages/contracts/src/orchestratorMcp.ts @@ -965,6 +965,7 @@ export type OrchestratorMcpEnvironmentUnlinkInput = export const OrchestratorMcpEnvironmentUnlinkResult = Schema.Struct({ environmentId: EnvironmentId, removed: Schema.Boolean, + endedThere: Schema.Boolean, }); export type OrchestratorMcpEnvironmentUnlinkResult = typeof OrchestratorMcpEnvironmentUnlinkResult.Type; diff --git a/packages/contracts/src/peerLink.ts b/packages/contracts/src/peerLink.ts index 6f33686b4b37b..3ff0fe93228d8 100644 --- a/packages/contracts/src/peerLink.ts +++ b/packages/contracts/src/peerLink.ts @@ -63,7 +63,11 @@ export type PeerLinkCreateInput = typeof PeerLinkCreateInput.Type; export const PeerLinkRemoveInput = Schema.Struct({ environmentId: EnvironmentId }); export type PeerLinkRemoveInput = typeof PeerLinkRemoveInput.Type; -export const PeerLinkRemoveResult = Schema.Struct({ removed: Schema.Boolean }); +export const PeerLinkRemoveResult = Schema.Struct({ + removed: Schema.Boolean, + // Whether the peer ended the link's session. Older servers never ask it to. + endedThere: Schema.optionalKey(Schema.Boolean), +}); export type PeerLinkRemoveResult = typeof PeerLinkRemoveResult.Type; /** Why linking or calling a peer failed, in words a user can act on. */ From 0f16fba25d487eb248810a427531a83171437eab Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 22 Nov 2026 11:38:44 -0800 Subject: [PATCH 3/3] fix(server): only the linked peer receives the token when unlinking Co-Authored-By: Claude Opus 5.5 --- apps/server/src/auth/EnvironmentAuth.ts | 6 ++++- apps/server/src/peer/PeerLinks.test.ts | 10 +++++++++ apps/server/src/peer/PeerLinks.ts | 29 ++++++++++++++++++++----- docs/user/remote-access.md | 5 +++-- 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/apps/server/src/auth/EnvironmentAuth.ts b/apps/server/src/auth/EnvironmentAuth.ts index 90ed438f1b02f..977840617d04c 100644 --- a/apps/server/src/auth/EnvironmentAuth.ts +++ b/apps/server/src/auth/EnvironmentAuth.ts @@ -1644,7 +1644,11 @@ export const make = Effect.gen(function* () { const revokeMcpClientToken: EnvironmentAuth["Service"]["revokeMcpClientToken"] = Effect.fn( "EnvironmentAuth.revokeMcpClientToken", )(function* (token) { - const session = yield* sessions.verify(token).pipe(Effect.option); + const session = yield* sessions.verify(token).pipe( + Effect.asSome, + Effect.catchIf(SessionStore.isSessionCredentialInvalidError, () => Effect.succeedNone), + Effect.mapError((cause) => new ServerAuthSessionCredentialValidationError({ cause })), + ); if ( Option.isNone(session) || session.value.subject !== MCP_CLIENT_SUBJECT || diff --git a/apps/server/src/peer/PeerLinks.test.ts b/apps/server/src/peer/PeerLinks.test.ts index d009725bbbaf5..8f1d6cc381d63 100644 --- a/apps/server/src/peer/PeerLinks.test.ts +++ b/apps/server/src/peer/PeerLinks.test.ts @@ -210,6 +210,16 @@ it.effect("links with a pairing code, and the peer holds its agents to the limit // Unlinking ends the session on B too, instead of leaving a live credential behind. expect(yield* a.links.unlink(box.environmentId)).toEqual({ removed: true, endedThere: true }); expect(yield* linkedSessions(b)).toEqual([]); + + // An address that now answers as another environment never receives the token. + const other = yield* serveApart(descriptorOf("environment-other", "Other")); + const relink = yield* b.auth.issuePairingCredential({ access: "auto", purpose: "peer-link" }); + yield* a.links.link({ url: b.url, pairingCode: relink.credential, access: "auto" }); + yield* a.sql`UPDATE peer_environment_links SET urls_json = ${JSON.stringify([other.url])}`; + expect(yield* a.links.unlink(box.environmentId)).toEqual({ + removed: true, + endedThere: false, + }); }), ).pipe(Effect.provide(NodeHttpServer.layerTest)), ); diff --git a/apps/server/src/peer/PeerLinks.ts b/apps/server/src/peer/PeerLinks.ts index a3a1d4a56089c..859266c469c70 100644 --- a/apps/server/src/peer/PeerLinks.ts +++ b/apps/server/src/peer/PeerLinks.ts @@ -669,17 +669,21 @@ const make = Effect.gen(function* () { /** Best effort: a peer that is gone or too old to revoke lets its session expire instead. */ const revokeAtPeer = Effect.fn("PeerLinks.revokeAtPeer")( - function* (urlsJson: string, token: string) { + function* (environmentId: EnvironmentId, urlsJson: string, token: string) { const urls = yield* decodeUrls(urlsJson); // A race over no addresses never settles. if (urls.length === 0) return false; yield* Effect.raceAll( urls.map((url) => - clientFor(url).pipe( + // An address can change hands after linking; only the linked peer may see the token. + answersAs(url, environmentId).pipe( + Effect.flatMap(Effect.fromOption), + Effect.andThen(clientFor(url)), Effect.flatMap((client) => - client.mcpOAuth.revoke({ payload: { token: Redacted.make(token) } }), + client.mcpOAuth + .revoke({ payload: { token: Redacted.make(token) } }) + .pipe(Effect.timeout(probeTimeout(url))), ), - Effect.timeout(probeTimeout(url)), ), ), ); @@ -700,10 +704,23 @@ const make = Effect.gen(function* () { `.pipe(Effect.catch(failStorage)); let endedThere = false; for (const row of deleted) { - const token = yield* secrets.get(row.secret_name).pipe(Effect.catch(failStorage)); + // Unreadable only skips the revocation; the secret is still removed below. + const token = yield* secrets + .get(row.secret_name) + .pipe( + Effect.catch((cause) => + Effect.logWarning("Could not read the unlinked peer's token", { cause }).pipe( + Effect.as(Option.none()), + ), + ), + ); yield* secrets.remove(row.secret_name).pipe(Effect.catch(failStorage)); if (Option.isSome(token)) { - endedThere = yield* revokeAtPeer(row.urls_json, new TextDecoder().decode(token.value)); + endedThere = yield* revokeAtPeer( + environmentId, + row.urls_json, + new TextDecoder().decode(token.value), + ); } } return { removed: deleted.length > 0, endedThere }; diff --git a/docs/user/remote-access.md b/docs/user/remote-access.md index 72d199791a476..051445f03eb07 100644 --- a/docs/user/remote-access.md +++ b/docs/user/remote-access.md @@ -469,8 +469,9 @@ an address you trust: the code is sent there. scripts. - The link shows up in that machine's **Settings → Sharing & access** like any outside agent, and can be revoked there. **Forget** on this machine also ends - it there when that machine answers; a machine that is offline or on an older - T3 Code keeps listing it until it expires or you revoke it there. + it there when that machine confirms it. If it can't, such as when it is + offline or on an older T3 Code, Forget says so; revoke it in that machine's + Sharing & access. - A link stays valid while agents use it. One unused for 30 days expires, as does one to a machine on an older T3 Code after 30 days; link again with a new pairing code.