Skip to content

fix(tui): keep the current session across logout and provider removal - #3129

Open
liruifengv wants to merge 3 commits into
mainfrom
fix/logout-keeps-session
Open

fix(tui): keep the current session across logout and provider removal#3129
liruifengv wants to merge 3 commits into
mainfrom
fix/logout-keeps-session

Conversation

@liruifengv

Copy link
Copy Markdown
Collaborator

Related Issue

Internal fix reported from the field (no tracking issue): a user's session appeared to lose its task after logout → re-login; investigation traced it to the logout flow closing the session. See Problem below.

Problem

Logging out of the provider the current session is using (via /logout, or deleting it in the provider manager) silently closed the session: the session id was reset, the goal box disappeared, and the next login started a brand-new empty session. The previous session stayed intact on disk, but nothing told the user it existed or how to get back (/resume), so in-flight work (goals, context) looked lost.

Sessions are not tied to an account elsewhere in the product — /model already switches providers freely mid-session — so closing the session on logout has no consistency justification; it is just historical behavior from the original provider-picker rework.

What changed

  • /logout of the active provider no longer closes the session; it only clears the model display and shows a warning: Logged out from X. Current model is unavailable — /login or /model to continue.
  • The provider manager's delete paths now mirror /logout (and no longer wipe session state unconditionally when removing the OAuth provider while it is not the active one).
  • Removed the now-unused clearActiveSessionAfterLogout controller method.
  • Safety of the kept session: sending a message with the dangling model fails cleanly with LLM not set, send "/login" to login (both engines); an active goal merely pauses (Paused after model configuration error). Re-login heals the session through the existing session.setModel() path, so logout → login now preserves the conversation end to end.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: the issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

Logging out of (or removing) the provider used by the current session
closed the session and reset the session id, so a subsequent login
started a fresh empty session and the previous one appeared lost.

Keep the session open: only the model display is cleared, and the next
turn fails with model.not_configured until the user logs in again or
picks another model. Re-login heals the session via setModel.
@changeset-bot

changeset-bot Bot commented Aug 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c74db87

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Aug 20, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@c74db87
npx https://pkg.pr.new/@moonshot-ai/kimi-code@c74db87

commit: c74db87

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a9ead16ea6

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread apps/kimi-code/src/tui/commands/auth.ts
Logging out with the session retained zeroes the footer's context
counters, and re-login with the same model alias is a setModel no-op,
so nothing restored them: the footer stayed at zero and the
cache-expiry hint misjudged the next prompt. Call syncRuntimeState
after setModel in the existing-session branch of
activateModelAfterLogin so contextTokens/contextUsage recover even on
a no-op model change.
@liruifengv

Copy link
Copy Markdown
Collaborator Author

@codex

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 11d229657c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread apps/kimi-code/src/tui/commands/auth.ts
A provider logout that retains the session zeroes the footer's context
counters, but performModelSwitch only mapped model/thinking from
session.getStatus() and the v2 model-change event only republishes the
model and its context limit — so healing the session via /model (the
recovery hinted by the logout warning) left contextTokens/contextUsage
at zero. Republish the counters from the live status on switch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant