Skip to content

Commit 51e3d13

Browse files
committed
fixes
1 parent e631c3c commit 51e3d13

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
@@ -360,28 +360,14 @@ export class SessionService {
360360
taskId,
361361
taskRunId,
362362
});
363-
try {
364-
await this.recreateSession(
365-
taskRunId,
366-
taskId,
367-
taskTitle,
368-
repoPath,
369-
auth,
370-
);
371-
} catch (recreateError) {
372-
log.error("Failed to recreate session after null reconnect", {
373-
taskId,
374-
error:
375-
recreateError instanceof Error
376-
? recreateError.message
377-
: String(recreateError),
378-
});
379-
this.setErrorSession(
380-
taskId,
381-
taskRunId,
382-
"Failed to start a new session. Please try again.",
383-
);
384-
}
363+
await this.recreateOrError(
364+
taskRunId,
365+
taskId,
366+
taskTitle,
367+
repoPath,
368+
auth,
369+
"Failed to start a new session. Please try again.",
370+
);
385371
}
386372
} catch (error) {
387373
const errorMessage =
@@ -390,28 +376,14 @@ export class SessionService {
390376
taskId,
391377
error: errorMessage,
392378
});
393-
try {
394-
await this.recreateSession(
395-
taskRunId,
396-
taskId,
397-
taskTitle,
398-
repoPath,
399-
auth,
400-
);
401-
} catch (recreateError) {
402-
log.error("Failed to recreate session after reconnect error", {
403-
taskId,
404-
error:
405-
recreateError instanceof Error
406-
? recreateError.message
407-
: String(recreateError),
408-
});
409-
this.setErrorSession(
410-
taskId,
411-
taskRunId,
412-
errorMessage || "Failed to reconnect. Please try again.",
413-
);
414-
}
379+
await this.recreateOrError(
380+
taskRunId,
381+
taskId,
382+
taskTitle,
383+
repoPath,
384+
auth,
385+
errorMessage || "Failed to reconnect. Please try again.",
386+
);
415387
}
416388
}
417389

@@ -431,12 +403,35 @@ export class SessionService {
431403
removePersistedConfigOptions(taskRunId);
432404
}
433405

406+
private async recreateOrError(
407+
taskRunId: string,
408+
taskId: string,
409+
taskTitle: string,
410+
repoPath: string,
411+
auth: AuthCredentials,
412+
fallbackMessage: string,
413+
): Promise<void> {
414+
try {
415+
await this.recreateSession(taskRunId, taskId, taskTitle, repoPath, auth);
416+
} catch (recreateError) {
417+
log.error("Failed to recreate session", {
418+
taskId,
419+
error:
420+
recreateError instanceof Error
421+
? recreateError.message
422+
: String(recreateError),
423+
});
424+
this.setErrorSession(taskId, taskRunId, taskTitle, fallbackMessage);
425+
}
426+
}
427+
434428
private setErrorSession(
435429
taskId: string,
436430
taskRunId: string,
431+
taskTitle: string,
437432
errorMessage: string,
438433
): void {
439-
const session = this.createBaseSession(taskRunId, taskId, "");
434+
const session = this.createBaseSession(taskRunId, taskId, taskTitle);
440435
session.status = "error";
441436
session.errorMessage = errorMessage;
442437
sessionStoreSetters.setSession(session);

0 commit comments

Comments
 (0)