@devries-cameron20 / t3code Mirror · read-only / commits / 3f3a1bf419
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 18:15 UTC

fix(server): reject pairing with an incompatible server protocol (#23789)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 23, 2026 at 20:19 UTC 3f3a1bf419f07b4dcbb3be9f9fbb4ed54055ee4f
2 files changed +63 -2
apps/server/src/cli/pair.test.ts
+40 -2
@@ -5,12 +5,14 @@ import * as NodeOS from "node:os";
5 import * as NodePath from "node:path";
6
7 import * as NodeServices from "@effect/platform-node/NodeServices";
8 -import { AuthStandardClientScopes } from "@t3tools/contracts";
8 +import { AuthStandardClientScopes, ORCHESTRATION_PROTOCOL_VERSION } from "@t3tools/contracts";
9 import * as NetService from "@t3tools/shared/Net";
10 import * as HostProcess from "@t3tools/shared/HostProcess";
11 import { assert, describe, expect, it } from "@effect/vitest";
12 +import * as Cause from "effect/Cause";
13 import * as ConfigProvider from "effect/ConfigProvider";
14 import * as Effect from "effect/Effect";
15 +import * as Exit from "effect/Exit";
16 import * as Layer from "effect/Layer";
17 import * as Sink from "effect/Sink";
18 import * as Stream from "effect/Stream";
@@ -89,19 +91,21 @@ const testDescriptor = {
91 label: "pair-test",
92 platform: { os: "linux", arch: "x64" },
93 serverVersion: "0.0.1",
94 + orchestrationProtocolVersion: ORCHESTRATION_PROTOCOL_VERSION,
95 capabilities: { repositoryIdentity: true },
96 };
97
98 const withDescriptorServer = <A, E, R>(
99 run: (origin: string) => Effect.Effect<A, E, R>,
100 host = "127.0.0.1",
101 + descriptor: object = testDescriptor,
102 ) =>
103 Effect.acquireUseRelease(
104 Effect.callback<NodeHttp.Server>((resume) => {
105 const server = NodeHttp.createServer((request, response) => {
106 if (request.url === "/.well-known/t3/environment") {
107 response.writeHead(200, { "content-type": "application/json" });
104 - response.end(JSON.stringify(testDescriptor));
108 + response.end(JSON.stringify(descriptor));
109 return;
110 }
111 response.writeHead(404);
@@ -328,6 +332,40 @@ describe("t3 pair", () => {
332 ).pipe(Effect.provide(NodeServices.layer)),
333 );
334
335 + // regression: #15492 an older CLI minted into a V1 database the protocol 2
336 + // server never reads, so pairing must refuse before opening the database.
337 + it.effect("rejects a server on another protocol before opening its database", () =>
338 + withDescriptorServer(
339 + (origin) =>
340 + Effect.gen(function* () {
341 + const baseDir = NodeFS.mkdtempSync(
342 + NodePath.join(NodeOS.tmpdir(), "t3-pair-protocol-test-"),
343 + );
344 + yield* persistServerRuntimeState({
345 + path: NodePath.join(baseDir, "userdata", "server-runtime.json"),
346 + state: yield* makePersistedServerRuntimeState({
347 + config: { host: "127.0.0.1", devUrl: undefined },
348 + port: Number(new URL(origin).port),
349 + }),
350 + });
351 +
352 + const exit = yield* provideCliTestLayers(
353 + runCli(["pair", "--base-dir", baseDir]).pipe(Effect.exit),
354 + );
355 +
356 + assert.deepEqual(NodeFS.readdirSync(NodePath.join(baseDir, "userdata")), [
357 + "server-runtime.json",
358 + ]);
359 + assert.isTrue(Exit.isFailure(exit));
360 + if (Exit.isFailure(exit)) {
361 + assert.include(String(Cause.squash(exit.cause)), "t3@0.0.45 pair");
362 + }
363 + }),
364 + "127.0.0.1",
365 + { ...testDescriptor, serverVersion: "0.0.45", orchestrationProtocolVersion: 1 },
366 + ).pipe(Effect.provide(NodeServices.layer)),
367 + );
368 +
369 // Without the capability `tailscale serve` blocks on an enablement URL, so
370 // pairing must stop at status instead of spawning it.
371 it.effect("explains a tailnet without HTTPS serve instead of running tailscale serve", () =>
apps/server/src/cli/pair.ts
+23
@@ -2,6 +2,7 @@ import {
2 type AuthEnvironmentScope,
3 AuthStandardClientScopes,
4 ExecutionEnvironmentDescriptor,
5 + ORCHESTRATION_PROTOCOL_VERSION,
6 PortSchema,
7 } from "@t3tools/contracts";
8 import { resolveWorktreeT3Home } from "@t3tools/shared/devHome";
@@ -77,6 +78,18 @@ export class NoRunningServerError extends Schema.TaggedError<NoRunningServerErro
78 }
79 }
80
81 +export class IncompatibleServerProtocolError extends Schema.TaggedError<IncompatibleServerProtocolError>()(
82 + "IncompatibleServerProtocolError",
83 + { serverVersion: Schema.String, serverProtocolVersion: Schema.Number },
84 +) {
85 + override get message(): string {
86 + return [
87 + `The running T3 Code server (${this.serverVersion}) speaks orchestration protocol ${String(this.serverProtocolVersion)}, but this CLI speaks protocol ${String(ORCHESTRATION_PROTOCOL_VERSION)}.`,
88 + `Pair with the matching CLI instead: \`npx t3@${this.serverVersion} pair\`.`,
89 + ].join("\n");
90 + }
91 +}
92 +
93 export class TailscaleUnavailableError extends Schema.TaggedError<TailscaleUnavailableError>()(
94 "TailscaleUnavailableError",
95 { cause: Schema.Defect() },
@@ -493,6 +506,16 @@ export const pairCommand = Command.make("pair", {
506 const logLevel = Option.getOrElse(cliLogLevel, () => "Warn" as const);
507
508 const target = yield* discoverPairTarget(Option.getOrUndefined(flags.baseDir));
509 + // Each protocol keeps auth in its own database, so a token minted here
510 + // for another protocol's server would never be accepted by it. Refuse
511 + // before any local layer opens (and migrates) that database.
512 + const serverProtocolVersion = target.descriptor.orchestrationProtocolVersion ?? 1;
513 + if (serverProtocolVersion !== ORCHESTRATION_PROTOCOL_VERSION) {
514 + return yield* new IncompatibleServerProtocolError({
515 + serverVersion: target.descriptor.serverVersion,
516 + serverProtocolVersion,
517 + });
518 + }
519
520 const notes: Array<string> = [];
521 let pairingBaseUrl: string;