fix(cli): resume selected session in cn ls instead of the latest#12974
Open
Purv-Kabaria wants to merge 2 commits into
Open
fix(cli): resume selected session in cn ls instead of the latest#12974Purv-Kabaria wants to merge 2 commits into
cn ls instead of the latest#12974Purv-Kabaria wants to merge 2 commits into
Conversation
`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 continuedev#12927 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #12927.
cn lslets you pick a past session from the TUI, but resuming always reopened the most recent session regardless of which one you selected.Root cause is in
extensions/cli/src/session.ts.loadSession()sorts the session files by mtime and unconditionally loadsfiles[0]:The
cn lsflow (commands/ls.ts) already communicates the chosen session by settingCONTINUE_CLI_TEST_SESSION_ID— the same env varSessionManager.getCurrentSession()uses to pin the current session id — before callingchat({ resume: true }). ButloadSession()never read that var, so the selection was silently dropped and--resumealways fell back to the latest session.This PR makes
loadSession()honorCONTINUE_CLI_TEST_SESSION_IDfirst (loading that session by id via the existingloadSessionById()), falling back to the most-recent session when the var is absent or the id can't be loaded. Plaincn --resumeis unchanged.The fix is intentionally minimal — one guard at the top of
loadSession(), no signature or caller changes.Checklist
Tests
Added a unit test in
extensions/cli/src/session.test.tsunderloadSession:should load the selected session when CONTINUE_CLI_TEST_SESSION_ID is set— sets the env var and assertsloadSession()resolves the session by id (historyManager.loadcalled with the selected id), does not fall back to scanning the directory by mtime (readdirSyncnot called), and sets it as the current session.I verified the test fails on
main(without the fix) and passes with it. ExistingloadSessiontests (including "should load the most recent session" for the no-selection path) still pass — fullsession.test.tsis green (32/32).I have read the CLA Document and I hereby sign the CLA