The best way to control Claude Code, Codex and more from any computer or phone
fix(server): t3_thread_read names the thread a pasted link points to (#38301)
Julius Marminge committed
Nov 17, 2026 at 12:03 UTC
de7b5e05f6a95573f65c923727fe84542a5b86e9
2 files changed
+62
-8
apps/server/src/mcp/OrchestratorMcpService.test.ts
+25
@@ -30,6 +30,7 @@ import {
30
type ServerProvider,
31
} from "@t3tools/contracts";
32
import { checkpointWorkspace } from "@t3tools/provider-testing/replayWorkspace";
33
+import { formatThreadLink, hostedThreadLink } from "@t3tools/shared/threadLinks";
34
import * as DateTime from "effect/DateTime";
35
import * as Deferred from "effect/Deferred";
36
import * as Duration from "effect/Duration";
@@ -4634,6 +4635,30 @@ describe("OrchestratorMcpService thread lookup", () => {
4635
}),
4636
);
4637
4638
+ it.effect("points a pasted thread link at the thread it names", () =>
4639
+ Effect.gen(function* () {
4640
+ const delegated = liveThreadShell(ThreadId.make("thread:delegated-task:command%3Amcp%3Aabc"));
4641
+ const ref = { environmentId: client.environmentId, threadId: delegated.id };
4642
+ const sent = yield* Ref.make(0);
4643
+ yield* Effect.gen(function* () {
4644
+ const mcp = yield* OrchestratorMcpService.OrchestratorMcpService;
4645
+ for (const link of [
4646
+ `t3-thread://v2/${ref.environmentId}/${ref.threadId}`,
4647
+ formatThreadLink(ref, "Delegated task"),
4648
+ hostedThreadLink(ref),
4649
+ ]) {
4650
+ const read = yield* mcp
4651
+ .readThread(client, { threadId: ThreadId.make(link) })
4652
+ .pipe(Effect.flip);
4653
+ assert.equal(read.code, "thread_not_found");
4654
+ assert.include(read.message, `\`${delegated.id}\``);
4655
+ assert.include(read.message, "is a thread link");
4656
+ assert.notInclude(read.message, "no longer available");
4657
+ }
4658
+ }).pipe(Effect.provide(service([delegated], sent)));
4659
+ }),
4660
+ );
4661
+
4662
it.effect("keeps the plain message for an id that matches nothing", () =>
4663
Effect.gen(function* () {
4664
const { read, send, wait } = yield* failuresFor([]);
apps/server/src/mcp/threadAccess.ts
+37
-8
@@ -4,6 +4,7 @@ import type {
4
} from "../orchestration-v2/ProjectionStore.ts";
5
import {
6
CommandId,
7
+ type EnvironmentId,
8
OrchestratorMcpFailure,
9
type ProjectId,
10
type ProviderInstanceId,
@@ -12,6 +13,12 @@ import {
13
ThreadId,
14
type OrchestrationV2ThreadShell,
15
} from "@t3tools/contracts";
16
+import {
17
+ hasThreadLinks,
18
+ parseThreadLinkHref,
19
+ threadLinkCandidates,
20
+ threadLinkRefs,
21
+} from "@t3tools/shared/threadLinks";
22
import * as SecureRandom from "effect/crypto/SecureRandom";
23
import * as Effect from "effect/Effect";
24
@@ -32,8 +39,22 @@ const suggestedThreadId = (threadId: ThreadId) => {
39
return encoded === rest ? null : ThreadId.make(`${delegatedTaskPrefix}${encoded}`);
40
};
41
42
+// A pasted link (bare, Markdown, or hosted) names its thread; only this environment's can be read here.
43
+const candidateThreadIds = (threadId: ThreadId, environmentId: EnvironmentId) => {
44
+ if (!hasThreadLinks(threadId)) {
45
+ const suggested = suggestedThreadId(threadId);
46
+ return suggested === null ? [] : [suggested];
47
+ }
48
+ const link = parseThreadLinkHref(threadId);
49
+ const refs =
50
+ link === null
51
+ ? threadLinkRefs(threadId, environmentId)
52
+ : threadLinkCandidates(link, environmentId);
53
+ return refs.filter((ref) => ref.environmentId === environmentId).map((ref) => ref.threadId);
54
+};
55
+
56
/**
36
- * Agents paste bare uuids for `mcp:<uuid>` threads and unencoded delegated-task ids.
57
+ * Agents paste bare uuids for `mcp:<uuid>` threads, unencoded delegated-task ids, and thread links.
58
* The id is never rewritten, so permission checks keyed on it still hold; the miss
59
* only names a live thread the caller could read by its full id. Ids from another
60
* machine miss here too. The link hint is static: listing links probes peers.
@@ -44,13 +65,21 @@ export const threadNotFound = Effect.fn("OrchestratorMcpService.threadNotFound")
65
threadId: ThreadId,
66
message: string,
67
) {
47
- const suggested = suggestedThreadId(threadId);
48
- const shell =
49
- suggested === null
50
- ? null
51
- : yield* threads.getThreadShell(suggested).pipe(Effect.orElseSucceed(() => null));
52
- const mcpHint =
53
- shell === null || shell.deletedAt !== null ? "" : ` Did you mean \`${suggested}\`?`;
68
+ let suggested: ThreadId | null = null;
69
+ for (const candidate of candidateThreadIds(threadId, scope.environmentId)) {
70
+ const shell = yield* threads.getThreadShell(candidate).pipe(Effect.orElseSucceed(() => null));
71
+ if (shell !== null && shell.deletedAt === null) {
72
+ suggested = candidate;
73
+ break;
74
+ }
75
+ }
76
+ if (suggested !== null && hasThreadLinks(threadId)) {
77
+ return yield* new OrchestratorMcpFailure({
78
+ code: "thread_not_found",
79
+ message: `\`${threadId}\` is a thread link, not a thread id. Pass \`${suggested}\` instead.`,
80
+ });
81
+ }
82
+ const mcpHint = suggested === null ? "" : ` Did you mean \`${suggested}\`?`;
83
const caller =
84
scope.thread === undefined
85
? null