From 6686898179f403cfb5cdd50485275a8b7a3203d6 Mon Sep 17 00:00:00 2001 From: Purv Kabaria Date: Fri, 10 Jul 2026 21:24:24 +0530 Subject: [PATCH 1/2] fix(cli): resume selected session in `cn ls` instead of the latest `loadSession()` always loaded the most recently modified session file and ignored the session the user picked in the `cn ls` TUI. The `ls` command already communicates the selection by setting `CONTINUE_CLI_TEST_SESSION_ID` (the same env var `SessionManager` uses to pin the current session id), but `loadSession()` never consulted it, so `--resume` always reopened the latest session. Honor that env var first when set, falling back to the most-recent session when it is absent or the id can't be loaded. Plain `cn --resume` behavior is unchanged. Fixes #12927 Co-Authored-By: Claude Opus 4.8 --- extensions/cli/src/session.test.ts | 25 +++++++++++++++++++++++++ extensions/cli/src/session.ts | 12 ++++++++++++ 2 files changed, 37 insertions(+) diff --git a/extensions/cli/src/session.test.ts b/extensions/cli/src/session.test.ts index 51bb6456645..b0b13b99193 100644 --- a/extensions/cli/src/session.test.ts +++ b/extensions/cli/src/session.test.ts @@ -357,6 +357,31 @@ describe("SessionManager", () => { expect(result).toEqual(mockSession); expect(getCurrentSession()).toEqual(mockSession); }); + + it("should load the selected session when CONTINUE_CLI_TEST_SESSION_ID is set", () => { + const selectedSession: Session = { + sessionId: "selected-session-id", + title: "Selected Session", + workspaceDirectory: "/test/workspace", + history: [], + }; + mockHistoryManager.load.mockReturnValue(selectedSession); + process.env.CONTINUE_CLI_TEST_SESSION_ID = "selected-session-id"; + + try { + const result = loadSession(); + + expect(result).toEqual(selectedSession); + // It must resolve the session by id, not by most-recent mtime + expect(mockHistoryManager.load).toHaveBeenCalledWith( + "selected-session-id", + ); + expect(mockFs.readdirSync).not.toHaveBeenCalled(); + expect(getCurrentSession()).toEqual(selectedSession); + } finally { + delete process.env.CONTINUE_CLI_TEST_SESSION_ID; + } + }); }); describe("clearSession", () => { diff --git a/extensions/cli/src/session.ts b/extensions/cli/src/session.ts index 45f765a08ae..d793f3ce3f8 100644 --- a/extensions/cli/src/session.ts +++ b/extensions/cli/src/session.ts @@ -300,6 +300,18 @@ export function saveSession(): void { */ export function loadSession(): Session | null { try { + // If a specific session has been selected (e.g. via `cn ls`), resume that + // one instead of the most recent. The selection is communicated through the + // same env var that SessionManager uses to pin the current session id. + const selectedSessionId = process.env.CONTINUE_CLI_TEST_SESSION_ID; + if (selectedSessionId) { + const selectedSession = loadSessionById(selectedSessionId); + if (selectedSession) { + SessionManager.getInstance().setSession(selectedSession); + return selectedSession; + } + } + // For resume, we need to find the most recent session const sessionDir = getSessionDir(); if (!fs.existsSync(sessionDir)) { From e68f1bbfad052a6c003afadf98fa76285ec824a1 Mon Sep 17 00:00:00 2001 From: Purv Kabaria Date: Sat, 11 Jul 2026 01:41:46 +0530 Subject: [PATCH 2/2] chore: retrigger CI Empty commit to retrigger CI after infra hangs/flakes on the previous run (macOS test-matrix job hung, JetBrains Autocomplete test fails identically on main, Windows VSIX post-build cleanup was cancelled).