@@ -202,6 +202,9 @@ export class SessionService {
202202 session . status = "error" ;
203203 session . errorMessage =
204204 "Authentication required. Please sign in to continue." ;
205+ if ( initialPrompt ?. length ) {
206+ session . initialPrompt = initialPrompt ;
207+ }
205208 sessionStoreSetters . setSession ( session ) ;
206209 return ;
207210 }
@@ -296,6 +299,9 @@ export class SessionService {
296299 session . status = "error" ;
297300 session . errorTitle = "Failed to connect" ;
298301 session . errorMessage = message ;
302+ if ( initialPrompt ?. length ) {
303+ session . initialPrompt = initialPrompt ;
304+ }
299305
300306 if ( latestRun ?. log_url ) {
301307 try {
@@ -504,6 +510,9 @@ export class SessionService {
504510 if ( existing ?. logUrl ) {
505511 session . logUrl = existing . logUrl ;
506512 }
513+ if ( existing ?. initialPrompt ?. length ) {
514+ session . initialPrompt = existing . initialPrompt ;
515+ }
507516 sessionStoreSetters . setSession ( session ) ;
508517 }
509518
@@ -564,6 +573,13 @@ export class SessionService {
564573 useSessionAdapterStore . getState ( ) . setAdapter ( taskRun . id , adapter ) ;
565574 }
566575
576+ // Store the initial prompt on the session so retry/reset flows can
577+ // re-send it if the session errors after this point (e.g. subscription
578+ // error, agent crash, or prompt failure).
579+ if ( initialPrompt ?. length ) {
580+ session . initialPrompt = initialPrompt ;
581+ }
582+
567583 sessionStoreSetters . setSession ( session ) ;
568584 this . subscribeToChannel ( taskRun . id ) ;
569585
@@ -1786,8 +1802,32 @@ export class SessionService {
17861802 * Retry connecting to the existing session (resume attempt using
17871803 * the sessionId from logs). Does NOT tear down — avoids the connect
17881804 * effect loop.
1805+ *
1806+ * If the session failed before any conversation started (has an
1807+ * initialPrompt saved from the original creation attempt), creates
1808+ * a fresh session and re-sends the prompt instead of reconnecting
1809+ * to an empty session.
17891810 */
17901811 async clearSessionError ( taskId : string , repoPath : string ) : Promise < void > {
1812+ const session = sessionStoreSetters . getSessionByTaskId ( taskId ) ;
1813+ if ( session ?. initialPrompt ?. length ) {
1814+ const { taskTitle, initialPrompt } = session ;
1815+ await this . teardownSession ( session . taskRunId ) ;
1816+ const auth = this . getAuthCredentials ( ) ;
1817+ if ( ! auth ) {
1818+ throw new Error (
1819+ "Unable to reach server. Please check your connection." ,
1820+ ) ;
1821+ }
1822+ await this . createNewLocalSession (
1823+ taskId ,
1824+ taskTitle ,
1825+ repoPath ,
1826+ auth ,
1827+ initialPrompt ,
1828+ ) ;
1829+ return ;
1830+ }
17911831 await this . reconnectInPlace ( taskId , repoPath ) ;
17921832 }
17931833
0 commit comments