@@ -339,6 +339,7 @@ import {
339339 type TerminalContextSelection ,
340340} from "../lib/terminalContext" ;
341341import {
342+ collectInlineContextIds ,
342343 ensureInlineContextReferences ,
343344 removeInlineContextReference ,
344345} from "../lib/composerContextReferences" ;
@@ -559,7 +560,10 @@ import {
559560 supportsServerUpdateThreadContinuation ,
560561} from "../versionSkew" ;
561562import { 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" ;
563567import { recallableComposerPrompt } from "./chat/composerPromptHistory" ;
564568import { observeResize } from "~/lib/observeResize" ;
565569
@@ -1226,6 +1230,15 @@ export default function ChatView(props: ChatViewProps) {
12261230 const draft = store . getComposerDraft ( composerDraftTarget ) ;
12271231 return ( draft ?. images . length ?? 0 ) > 0 || ( draft ?. files . length ?? 0 ) > 0 ;
12281232 } ) ;
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+ ) ;
12291242 const composerHasNonPromptContent = useComposerDraftStore ( ( store ) => {
12301243 const draft = store . getComposerDraft ( composerDraftTarget ) ;
12311244 return draft ? composerDraftHasUserContent ( { ...draft , prompt : "" } ) : false ;
@@ -3128,6 +3141,9 @@ export default function ChatView(props: ChatViewProps) {
31283141 return (
31293142 environment ?. connection . phase === "connected" &&
31303143 ( loadBalancingSettings . loadBalancingWeights [ candidate . environmentId ] ?? 50 ) > 0 &&
3144+ referencedThreadContexts . every (
3145+ ( record ) => record . environmentId === candidate . environmentId ,
3146+ ) &&
31313147 providersByEnvironment
31323148 . get ( candidate . environmentId )
31333149 ?. some (
@@ -6037,7 +6053,14 @@ export default function ChatView(props: ChatViewProps) {
60376053 : "Choose a machine to continue" ,
60386054 description : loadBalancing . pending
60396055 ? "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." ,
60416064 } ) ;
60426065 return ;
60436066 }
@@ -6122,6 +6145,22 @@ export default function ChatView(props: ChatViewProps) {
61226145 previewAnnotationContextReference ( directAnnotation . annotation ) ,
61236146 ] )
61246147 : 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+ }
61256164 if ( queuedRunEdit . isEditing ) {
61266165 // Edit mode repurposes the composer: sending saves the queued message
61276166 // in place instead of dispatching a new turn.
0 commit comments