@@ -56,6 +56,7 @@ import { useEnvironmentScope } from "~/state/session";
5656import { threadEnvironment } from "../../state/threads" ;
5757import { vcsEnvironment } from "../../state/vcs" ;
5858import { useChildThreadInputs , readThreadShell , waitForThreadShell } from "../../state/entities" ;
59+ import { serverEnvironment } from "../../state/server" ;
5960import { environmentShell } from "../../state/shell" ;
6061import { ThreadStatusLine } from "./ThreadStatusLine" ;
6162import { formatRelativeTimeLabel } from "../../timestampFormat" ;
@@ -455,14 +456,20 @@ export function useThreadLifecycle(input: ThreadLifecycleInput) {
455456 } ;
456457 const handleStopBackgroundWorkStable = useStableCallback ( handleStopBackgroundWork ) ;
457458 const openRelatedThreadGenerationRef = useRef ( 0 ) ;
458- const onOpenRelatedThread = async ( threadId : ThreadId ) => {
459+ // A task delegated to a linked environment opens there; the default is this thread's own.
460+ const onOpenRelatedThread = async (
461+ threadId : ThreadId ,
462+ threadEnvironmentId : EnvironmentId = environmentId ,
463+ ) => {
459464 const generation = ++ openRelatedThreadGenerationRef . current ;
460- const threadRef = scopeThreadRef ( environmentId , threadId ) ;
465+ const threadRef = scopeThreadRef ( threadEnvironmentId , threadId ) ;
461466 const isEnvironmentLive = ( ) =>
462- appAtomRegistry . get ( environmentShell . stateValueAtom ( environmentId ) ) . status === "live" ;
467+ appAtomRegistry . get ( environmentShell . stateValueAtom ( threadEnvironmentId ) ) . status === "live" ;
463468 // The shell can leave idle subagent children out, so absence is not deletion there: the
464469 // route decides from the thread's own detail.
465- const shellOmitsChildren = serverConfig ?. shellThreadFamilies === true ;
470+ const shellOmitsChildren =
471+ appAtomRegistry . get ( serverEnvironment . configValueAtom ( threadEnvironmentId ) )
472+ ?. shellThreadFamilies === true ;
466473 // A just-launched child can reach this timeline before its shell syncs.
467474 if ( ! shellOmitsChildren && isEnvironmentLive ( ) && readThreadShell ( threadRef ) === null ) {
468475 const location = router . latestLocation ;
0 commit comments