Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions apps/code/src/renderer/features/sessions/service/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ export class SessionService {
session.status = "error";
session.errorMessage =
"Authentication required. Please sign in to continue.";
if (initialPrompt?.length) {
session.initialPrompt = initialPrompt;
}
sessionStoreSetters.setSession(session);
return;
}
Expand Down Expand Up @@ -296,6 +299,9 @@ export class SessionService {
session.status = "error";
session.errorTitle = "Failed to connect";
session.errorMessage = message;
if (initialPrompt?.length) {
session.initialPrompt = initialPrompt;
}

if (latestRun?.log_url) {
try {
Expand Down Expand Up @@ -504,6 +510,9 @@ export class SessionService {
if (existing?.logUrl) {
session.logUrl = existing.logUrl;
}
if (existing?.initialPrompt?.length) {
session.initialPrompt = existing.initialPrompt;
}
sessionStoreSetters.setSession(session);
}

Expand Down Expand Up @@ -564,6 +573,13 @@ export class SessionService {
useSessionAdapterStore.getState().setAdapter(taskRun.id, adapter);
}

// Store the initial prompt on the session so retry/reset flows can
// re-send it if the session errors after this point (e.g. subscription
// error, agent crash, or prompt failure).
if (initialPrompt?.length) {
session.initialPrompt = initialPrompt;
}

sessionStoreSetters.setSession(session);
this.subscribeToChannel(taskRun.id);

Expand Down Expand Up @@ -1786,8 +1802,32 @@ export class SessionService {
* Retry connecting to the existing session (resume attempt using
* the sessionId from logs). Does NOT tear down — avoids the connect
* effect loop.
*
* If the session failed before any conversation started (has an
* initialPrompt saved from the original creation attempt), creates
* a fresh session and re-sends the prompt instead of reconnecting
* to an empty session.
*/
async clearSessionError(taskId: string, repoPath: string): Promise<void> {
const session = sessionStoreSetters.getSessionByTaskId(taskId);
if (session?.initialPrompt?.length) {
const { taskTitle, initialPrompt } = session;
await this.teardownSession(session.taskRunId);
const auth = this.getAuthCredentials();
if (!auth) {
throw new Error(
"Unable to reach server. Please check your connection.",
);
}
await this.createNewLocalSession(
taskId,
taskTitle,
repoPath,
auth,
initialPrompt,
);
return;
}
await this.reconnectInPlace(taskId, repoPath);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
ContentBlock,
SessionConfigOption,
SessionConfigSelectGroup,
SessionConfigSelectOption,
Expand Down Expand Up @@ -68,6 +69,8 @@ export interface AgentSession {
cloudOutput?: Record<string, unknown> | null;
/** Cloud task error message */
cloudErrorMessage?: string | null;
/** Initial prompt to re-send on retry if the first connection attempt failed */
initialPrompt?: ContentBlock[];
/** Cloud task branch */
cloudBranch?: string | null;
/** Number of session/prompt events to skip from polled logs (set during resume) */
Expand Down
Loading