@devries-cameron20 / t3code Mirror · read-only / commits / c1377176b1
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 23, 00:30 UTC

fix(composer): don't send attached threads to a machine that can't read them (#18310)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Nikita Maximilian Grimm committed Oct 19, 2026 at 23:16 UTC c1377176b1107dead2b4afe40cf423f0054449ca
5 files changed +130 -5
apps/web/src/components/ChatView.tsx
+41 -2
@@ -339,6 +339,7 @@ import {
339 type TerminalContextSelection,
340 } from "../lib/terminalContext";
341 import {
342 + collectInlineContextIds,
343 ensureInlineContextReferences,
344 removeInlineContextReference,
345 } from "../lib/composerContextReferences";
@@ -559,7 +560,10 @@ import {
560 supportsServerUpdateThreadContinuation,
561 } from "../versionSkew";
562 import { useAssetUrls } from "../assets/assetUrls";
562 -import { ATTACHMENT_ONLY_BOOTSTRAP_PROMPT } from "@t3tools/shared/composerContextReferences";
563 +import {
564 + ATTACHMENT_ONLY_BOOTSTRAP_PROMPT,
565 + threadContextsOutsideEnvironment,
566 +} from "@t3tools/shared/composerContextReferences";
567 import { recallableComposerPrompt } from "./chat/composerPromptHistory";
568 import { observeResize } from "~/lib/observeResize";
569
@@ -1226,6 +1230,15 @@ export default function ChatView(props: ChatViewProps) {
1230 const draft = store.getComposerDraft(composerDraftTarget);
1231 return (draft?.images.length ?? 0) > 0 || (draft?.files.length ?? 0) > 0;
1232 });
1233 + const referencedThreadContexts = useComposerDraftStore(
1234 + useShallow((store) => {
1235 + const draft = store.getComposerDraft(composerDraftTarget);
1236 + if (!draft?.threadContexts.length) return [];
1237 + // Linked prompts can replace text without pruning stored context records.
1238 + const referenced = new Set(collectInlineContextIds(draft.prompt));
1239 + return draft.threadContexts.filter((record) => referenced.has(record.contextId));
1240 + }),
1241 + );
1242 const composerHasNonPromptContent = useComposerDraftStore((store) => {
1243 const draft = store.getComposerDraft(composerDraftTarget);
1244 return draft ? composerDraftHasUserContent({ ...draft, prompt: "" }) : false;
@@ -3128,6 +3141,9 @@ export default function ChatView(props: ChatViewProps) {
3141 return (
3142 environment?.connection.phase === "connected" &&
3143 (loadBalancingSettings.loadBalancingWeights[candidate.environmentId] ?? 50) > 0 &&
3144 + referencedThreadContexts.every(
3145 + (record) => record.environmentId === candidate.environmentId,
3146 + ) &&
3147 providersByEnvironment
3148 .get(candidate.environmentId)
3149 ?.some(
@@ -6037,7 +6053,14 @@ export default function ChatView(props: ChatViewProps) {
6053 : "Choose a machine to continue",
6054 description: loadBalancing.pending
6055 ? "Resource checks are still running. You can choose a machine in the composer."
6040 - : "No eligible machine has available resources. Choose a machine in the composer to override.",
6056 + : referencedThreadContexts.length > 0 &&
6057 + !logicalProjectEnvironments.some((candidate) =>
6058 + referencedThreadContexts.every(
6059 + (record) => record.environmentId === candidate.environmentId,
6060 + ),
6061 + )
6062 + ? "No machine can read every attached thread. Choose a machine in the composer or remove the threads."
6063 + : "No eligible machine has available resources. Choose a machine in the composer to override.",
6064 });
6065 return;
6066 }
@@ -6122,6 +6145,22 @@ export default function ChatView(props: ChatViewProps) {
6145 previewAnnotationContextReference(directAnnotation.annotation),
6146 ])
6147 : promptRef.current;
6148 + const strandedThread = threadContextsOutsideEnvironment({
6149 + text: promptForSend,
6150 + records: composerThreadContexts,
6151 + environmentId,
6152 + })[0];
6153 + if (strandedThread) {
6154 + const owner = environmentById.get(strandedThread.environmentId)?.label ?? "its machine";
6155 + toastManager.add(
6156 + stackedThreadToast({
6157 + type: "warning",
6158 + title: "Attached thread is on another machine",
6159 + description: `This machine's agent can't read "${strandedThread.title}". Remove it, or switch back to ${owner} to send.`,
6160 + }),
6161 + );
6162 + return;
6163 + }
6164 if (queuedRunEdit.isEditing) {
6165 // Edit mode repurposes the composer: sending saves the queued message
6166 // in place instead of dispatching a new turn.
apps/web/src/components/ThreadContextChip.tsx
+9 -1
@@ -9,6 +9,7 @@ import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
9 export function ThreadContextChip(props: {
10 record: Pick<ThreadContextRecord, "environmentId" | "threadId" | "title">;
11 copyMarkdown?: string;
12 + unreadable?: boolean;
13 }) {
14 const { environmentId, threadId } = props.record;
15 const shell = useThreadShell({ environmentId, threadId });
@@ -19,6 +20,7 @@ export function ThreadContextChip(props: {
20 render={
21 <ContextChip
22 kind="thread"
23 + {...(props.unreadable ? { state: "invalid" as const } : {})}
24 render={<Link to="/$environmentId/$threadId" params={{ environmentId, threadId }} />}
25 aria-label={`Thread, ${title}`}
26 data-markdown-copy={props.copyMarkdown}
@@ -29,7 +31,13 @@ export function ThreadContextChip(props: {
31 </ContextChip>
32 }
33 />
32 - <TooltipPopup side="top">{shell ? "Open thread" : "Thread no longer available"}</TooltipPopup>
34 + <TooltipPopup side="top">
35 + {props.unreadable
36 + ? "On another machine, so this machine's agent can't read it. Remove it or switch back to send."
37 + : shell
38 + ? "Open thread"
39 + : "Thread no longer available"}
40 + </TooltipPopup>
41 </Tooltip>
42 );
43 }
apps/web/src/components/composerContextPresentation.tsx
+11 -1
@@ -323,6 +323,16 @@ function ComposerPreviewAnnotationDetails({
323 );
324 }
325
326 +function ComposerThreadContextChip(props: { record: ThreadContextRecord }) {
327 + const { environmentId } = use(ComposerContextActionsContext);
328 + return (
329 + <ThreadContextChip
330 + record={props.record}
331 + unreadable={environmentId !== null && props.record.environmentId !== environmentId}
332 + />
333 + );
334 +}
335 +
336 function UnresolvedContextChip(props: { label: string }) {
337 return (
338 <UnresolvedChip
@@ -432,7 +442,7 @@ const composerContextPresentationRegistry = createContextPresentationRegistry<
442 canRender: (entry) => entry.kind === "thread",
443 render: (entry, context) =>
444 entry.kind === "thread" ? (
435 - <ThreadContextChip record={entry.record} />
445 + <ComposerThreadContextChip record={entry.record} />
446 ) : (
447 <UnresolvedContextChip label={context.label} />
448 ),
packages/shared/src/composerContextReferences.test.ts
+49 -1
@@ -1,4 +1,9 @@
1 -import type { ComposerContextId, ComposerContextRecord } from "@t3tools/contracts";
1 +import {
2 + type ComposerContextId,
3 + type ComposerContextRecord,
4 + EnvironmentId,
5 + ThreadId,
6 +} from "@t3tools/contracts";
7 import { describe, expect, it } from "vite-plus/test";
8
9 import {
@@ -11,6 +16,7 @@ import {
16 projectComposerContextForProvider,
17 replaceComposerContextReferences,
18 sanitizeComposerContextLabel,
19 + threadContextsOutsideEnvironment,
20 toComposerContextId,
21 toKindScopedComposerContextId,
22 } from "./composerContextReferences.ts";
@@ -301,6 +307,48 @@ describe("provider projection", () => {
307 });
308 });
309
310 +describe("threadContextsOutsideEnvironment", () => {
311 + it("returns only referenced foreign threads, ignoring local and removed references", () => {
312 + const local = {
313 + version: 1 as const,
314 + kind: "thread" as const,
315 + contextId: ctx("thread_local"),
316 + label: "Local thread",
317 + environmentId: EnvironmentId.make("env-local"),
318 + threadId: ThreadId.make("local"),
319 + title: "Local thread",
320 + };
321 + const foreign = {
322 + ...local,
323 + contextId: ctx("thread_foreign"),
324 + environmentId: EnvironmentId.make("env-foreign"),
325 + threadId: ThreadId.make("foreign"),
326 + };
327 + const removed = {
328 + ...foreign,
329 + contextId: ctx("thread_removed"),
330 + threadId: ThreadId.make("removed"),
331 + };
332 + const records = [local, foreign, removed];
333 + const localReference = "[Local](t3-context://v1/thread/thread_local)";
334 +
335 + expect(
336 + threadContextsOutsideEnvironment({
337 + text: `${localReference} [Foreign](t3-context://v1/thread/thread_foreign)`,
338 + records,
339 + environmentId: local.environmentId,
340 + }),
341 + ).toEqual([foreign]);
342 + expect(
343 + threadContextsOutsideEnvironment({
344 + text: localReference,
345 + records,
346 + environmentId: local.environmentId,
347 + }),
348 + ).toEqual([]);
349 + });
350 +});
351 +
352 describe("toComposerContextId", () => {
353 it("keeps same-kind raw IDs distinct when one contains the namespace prefix", () => {
354 expect(toKindScopedComposerContextId("image", "x")).toBe("image_x");
packages/shared/src/composerContextReferences.ts
+20
@@ -4,7 +4,9 @@ import {
4 type ComposerContextKind,
5 type ComposerContextRecord,
6 type ElementContextDetails,
7 + type EnvironmentId,
8 type KnownComposerContextRecord,
9 + type ThreadContextRecord,
10 } from "@t3tools/contracts";
11
12 const CONTEXT_PROTOCOL = "t3-context:";
@@ -320,6 +322,24 @@ export function projectComposerContextForProvider(input: {
322 return `${body}\n\n<${CONTEXT_ENVELOPE_TAG} version="1">\n${entries.join("\n")}\n</${CONTEXT_ENVELOPE_TAG}>`;
323 }
324
325 +// Thread reads are environment-local even when a draft moves between machines.
326 +export function threadContextsOutsideEnvironment(input: {
327 + text: string;
328 + records: ReadonlyArray<ComposerContextRecord>;
329 + environmentId: EnvironmentId;
330 +}): ThreadContextRecord[] {
331 + const referenced = new Set(
332 + collectComposerContextReferences(input.text).map((occurrence) => occurrence.contextId),
333 + );
334 + return input.records.filter(
335 + (record): record is ThreadContextRecord =>
336 + record.kind === "thread" &&
337 + "threadId" in record &&
338 + referenced.has(record.contextId) &&
339 + record.environmentId !== input.environmentId,
340 + );
341 +}
342 +
343 export function remapComposerContextAttachments(
344 context: import("@t3tools/contracts").OrchestrationMessageContext | undefined,
345 before: ReadonlyArray<{ readonly id?: string | undefined }>,