Skip to content

Commit c7cc194

Browse files
committed
fixes
1 parent c5cdfdf commit c7cc194

File tree

2 files changed

+45
-46
lines changed

2 files changed

+45
-46
lines changed

apps/twig/src/renderer/features/sessions/service/service.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ describe("SessionService", () => {
753753
});
754754

755755
describe("clearSessionError", () => {
756-
it("cancels agent and removes session", async () => {
756+
it("cancels agent and tears down session fully", async () => {
757757
const service = getSessionService();
758758
const mockSession = createMockSession({ status: "error" });
759759
mockSessionStoreSetters.getSessionByTaskId.mockReturnValue(mockSession);
@@ -766,6 +766,10 @@ describe("SessionService", () => {
766766
expect(mockSessionStoreSetters.removeSession).toHaveBeenCalledWith(
767767
"run-123",
768768
);
769+
expect(mockAdapterFns.removeAdapter).toHaveBeenCalledWith("run-123");
770+
expect(
771+
mockSessionConfigStore.removePersistedConfigOptions,
772+
).toHaveBeenCalledWith("run-123");
769773
});
770774

771775
it("handles missing session gracefully", async () => {

apps/twig/src/renderer/features/sessions/service/service.ts

Lines changed: 40 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -366,28 +366,14 @@ export class SessionService {
366366
taskId,
367367
taskRunId,
368368
});
369-
try {
370-
await this.recreateSession(
371-
taskRunId,
372-
taskId,
373-
taskTitle,
374-
repoPath,
375-
auth,
376-
);
377-
} catch (recreateError) {
378-
log.error("Failed to recreate session after null reconnect", {
379-
taskId,
380-
error:
381-
recreateError instanceof Error
382-
? recreateError.message
383-
: String(recreateError),
384-
});
385-
this.setErrorSession(
386-
taskId,
387-
taskRunId,
388-
"Failed to start a new session. Please try again.",
389-
);
390-
}
369+
await this.recreateOrError(
370+
taskRunId,
371+
taskId,
372+
taskTitle,
373+
repoPath,
374+
auth,
375+
"Failed to start a new session. Please try again.",
376+
);
391377
}
392378
} catch (error) {
393379
const errorMessage =
@@ -396,28 +382,14 @@ export class SessionService {
396382
taskId,
397383
error: errorMessage,
398384
});
399-
try {
400-
await this.recreateSession(
401-
taskRunId,
402-
taskId,
403-
taskTitle,
404-
repoPath,
405-
auth,
406-
);
407-
} catch (recreateError) {
408-
log.error("Failed to recreate session after reconnect error", {
409-
taskId,
410-
error:
411-
recreateError instanceof Error
412-
? recreateError.message
413-
: String(recreateError),
414-
});
415-
this.setErrorSession(
416-
taskId,
417-
taskRunId,
418-
errorMessage || "Failed to reconnect. Please try again.",
419-
);
420-
}
385+
await this.recreateOrError(
386+
taskRunId,
387+
taskId,
388+
taskTitle,
389+
repoPath,
390+
auth,
391+
errorMessage || "Failed to reconnect. Please try again.",
392+
);
421393
}
422394
}
423395

@@ -437,12 +409,35 @@ export class SessionService {
437409
removePersistedConfigOptions(taskRunId);
438410
}
439411

412+
private async recreateOrError(
413+
taskRunId: string,
414+
taskId: string,
415+
taskTitle: string,
416+
repoPath: string,
417+
auth: AuthCredentials,
418+
fallbackMessage: string,
419+
): Promise<void> {
420+
try {
421+
await this.recreateSession(taskRunId, taskId, taskTitle, repoPath, auth);
422+
} catch (recreateError) {
423+
log.error("Failed to recreate session", {
424+
taskId,
425+
error:
426+
recreateError instanceof Error
427+
? recreateError.message
428+
: String(recreateError),
429+
});
430+
this.setErrorSession(taskId, taskRunId, taskTitle, fallbackMessage);
431+
}
432+
}
433+
440434
private setErrorSession(
441435
taskId: string,
442436
taskRunId: string,
437+
taskTitle: string,
443438
errorMessage: string,
444439
): void {
445-
const session = this.createBaseSession(taskRunId, taskId, "");
440+
const session = this.createBaseSession(taskRunId, taskId, taskTitle);
446441
session.status = "error";
447442
session.errorMessage = errorMessage;
448443
sessionStoreSetters.setSession(session);

0 commit comments

Comments
 (0)