Skip to content

Commit 7e6f3b0

Browse files
fix(code): address review feedback for /clear command
Remove inline import in commands.ts. Rewrite resetSession() to create a new task run via createNewLocalSession() instead of clearing in-memory logs, ensuring old messages don't reappear on app restart.
1 parent a0c1945 commit 7e6f3b0

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

apps/code/src/renderer/features/message-editor/commands.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { AvailableCommand } from "@agentclientprotocol/sdk";
2+
import { getSessionService } from "@features/sessions/service/service";
23
import { ANALYTICS_EVENTS, type FeedbackType } from "@shared/types/analytics";
34
import { track } from "@utils/analytics";
45
import { toast } from "@utils/toast";
@@ -59,9 +60,6 @@ const commands: CodeCommand[] = [
5960
toast.error("Cannot clear: no active session");
6061
return;
6162
}
62-
const { getSessionService } = await import(
63-
"@features/sessions/service/service"
64-
);
6563
await getSessionService().resetSession(ctx.taskId, ctx.repoPath);
6664
toast.success("Conversation cleared");
6765
},

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

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,11 +1747,23 @@ export class SessionService {
17471747

17481748
/**
17491749
* Start a fresh session for a task, abandoning the old conversation.
1750-
* Clears the backend sessionId so the next reconnect creates a new
1751-
* session instead of attempting to resume the stale one.
1750+
* Tears down the current session and creates a new task run so that
1751+
* S3 logs start clean — old messages won't reappear on restart.
17521752
*/
17531753
async resetSession(taskId: string, repoPath: string): Promise<void> {
1754-
await this.reconnectInPlace(taskId, repoPath, null, true);
1754+
const session = sessionStoreSetters.getSessionByTaskId(taskId);
1755+
if (!session) return;
1756+
1757+
const { taskTitle } = session;
1758+
1759+
await this.teardownSession(session.taskRunId);
1760+
1761+
const auth = this.getAuthCredentials();
1762+
if (!auth) {
1763+
throw new Error("Unable to reach server. Please check your connection.");
1764+
}
1765+
1766+
await this.createNewLocalSession(taskId, taskTitle, repoPath, auth);
17551767
}
17561768

17571769
/**
@@ -1768,7 +1780,6 @@ export class SessionService {
17681780
taskId: string,
17691781
repoPath: string,
17701782
overrideSessionId?: string | null,
1771-
clearHistory = false,
17721783
): Promise<void> {
17731784
const session = sessionStoreSetters.getSessionByTaskId(taskId);
17741785
if (!session) return;
@@ -1789,13 +1800,7 @@ export class SessionService {
17891800
throw new Error("Unable to reach server. Please check your connection.");
17901801
}
17911802

1792-
const prefetchedLogs = clearHistory
1793-
? {
1794-
rawEntries: [] as StoredLogEntry[],
1795-
sessionId: undefined,
1796-
adapter: undefined as Adapter | undefined,
1797-
}
1798-
: await this.fetchSessionLogs(logUrl, taskRunId);
1803+
const prefetchedLogs = await this.fetchSessionLogs(logUrl, taskRunId);
17991804

18001805
// Determine sessionId: undefined = use from logs, null = strip (fresh), string = use as-is
18011806
const sessionId =

0 commit comments

Comments
 (0)