@@ -922,6 +922,46 @@ describe("SessionService", () => {
922922 expect ( mockTrpcAgent . reconnect . mutate ) . toHaveBeenCalled ( ) ;
923923 } ) ;
924924
925+ it ( "creates fresh session when initialPrompt is set (prompt never delivered)" , async ( ) => {
926+ const service = getSessionService ( ) ;
927+ const mockSession = createMockSession ( {
928+ status : "error" ,
929+ initialPrompt : [ { type : "text" , text : "fix the bug" } ] ,
930+ } ) ;
931+ // First call returns the error session, subsequent calls return connected
932+ mockSessionStoreSetters . getSessionByTaskId
933+ . mockReturnValueOnce ( mockSession )
934+ . mockReturnValue (
935+ createMockSession ( {
936+ taskRunId : "new-run" ,
937+ status : "connected" ,
938+ } ) ,
939+ ) ;
940+ mockTrpcAgent . start . mutate . mockResolvedValue ( {
941+ channel : "agent-event:new-run" ,
942+ configOptions : [ ] ,
943+ } ) ;
944+ mockTrpcAgent . onSessionEvent . subscribe . mockReturnValue ( {
945+ unsubscribe : vi . fn ( ) ,
946+ } ) ;
947+ mockTrpcAgent . onPermissionRequest . subscribe . mockReturnValue ( {
948+ unsubscribe : vi . fn ( ) ,
949+ } ) ;
950+ mockTrpcAgent . prompt . mutate . mockResolvedValue ( { stopReason : "end_turn" } ) ;
951+ mockBuildAuthenticatedClient . mockReturnValue ( {
952+ createTaskRun : vi . fn ( ) . mockResolvedValue ( { id : "new-run" } ) ,
953+ appendTaskRunLog : vi . fn ( ) ,
954+ } ) ;
955+
956+ await service . clearSessionError ( "task-123" , "/repo" ) ;
957+
958+ // Should tear down old session and create a new one
959+ expect ( mockTrpcAgent . cancel . mutate ) . toHaveBeenCalledWith ( {
960+ sessionId : "run-123" ,
961+ } ) ;
962+ expect ( mockTrpcAgent . start . mutate ) . toHaveBeenCalled ( ) ;
963+ } ) ;
964+
925965 it ( "handles missing session gracefully" , async ( ) => {
926966 const service = getSessionService ( ) ;
927967 mockSessionStoreSetters . getSessionByTaskId . mockReturnValue ( undefined ) ;
0 commit comments