@@ -15,6 +15,7 @@ import {ScreenScaffold} from "@/components/ScreenScaffold"
1515import { StatusTag } from "@/components/StatusTag"
1616
1717import { useBindProjectContext } from "../context/useBindProjectContext"
18+ import { pendingTasksAtom } from "../home/pendingTask"
1819import { AppShell } from "../nav/AppShell"
1920import { useLivenessPoll } from "../sessions/useLivenessPoll"
2021
@@ -34,6 +35,7 @@ import {useAgentEntity} from "./useAgentEntity"
3435import { useAgentVisibilityRecheck } from "./useAgentVisibilityRecheck"
3536import { useApprovalActions } from "./useApprovalActions"
3637import { useChatAccess } from "./useChatAccess"
38+ import { useLeaveHeldTask } from "./useLeaveHeldTask"
3739import { useReferenceToolDisplays } from "./useReferenceToolDisplays"
3840import { useSessionTranscript } from "./useSessionTranscript"
3941import { useSessionWatch } from "./useSessionWatch"
@@ -74,6 +76,11 @@ export const ChatScreen = ({
7476 if ( isSessionFresh ( sessionId ) ) return
7577 void prefetchRecords ( sessionId ) . catch ( ( ) => undefined )
7678 } , [ boundProjectId , prefetchRecords , projectId , sessionId ] )
79+ useLeaveHeldTask ( sessionId , projectId )
80+ // A session the server does not list yet names its agent only in the route, and the rail's
81+ // link does not carry it. A first message waiting here names it too.
82+ const taskAgentId = useAtomValue ( pendingTasksAtom ) [ sessionId ] ?. agentId
83+ const routeAgentId = agentId ?? taskAgentId
7784 const {
7885 entityId : latestEntityId ,
7986 agentId : resolvedAgentId ,
@@ -83,11 +90,11 @@ export const ChatScreen = ({
8390 agentHidden : entityAgentHidden ,
8491 retry,
8592 retrying,
86- } = useAgentEntity ( sessionId , projectId , agentId )
93+ } = useAgentEntity ( sessionId , projectId , routeAgentId )
8794 const access = useChatAccess ( {
8895 sessionId,
8996 projectId,
90- routeAgentId : agentId ,
97+ routeAgentId,
9198 agentHidden : entityAgentHidden ,
9299 } )
93100 // An agent made private while this screen is open: the session row read says so (one
0 commit comments