Skip to content

fix(desktop): keep model runtime state per session#43702

Merged
OutThisLife merged 6 commits into
mainfrom
salvage/desktop-model-runtime-per-session
Jun 10, 2026
Merged

fix(desktop): keep model runtime state per session#43702
OutThisLife merged 6 commits into
mainfrom
salvage/desktop-model-runtime-per-session

Conversation

@OutThisLife

Copy link
Copy Markdown
Collaborator

Salvages and supersedes #40163 (by @pinguarmy / 郝鹏宇). Cherry-picked onto current main with authorship preserved; all review feedback from that thread was already addressed by the author's latest commits, verified here against a clean rebase.

Summary

  • Keep Desktop cached-session runtime state in sync with the active chat's model/provider/reasoning/fast/yolo fields.
  • Restore persisted model/provider/reasoning/service-tier runtime when resuming stored sessions, instead of inheriting the latest global model from another chat.
  • Persist live model/reasoning/fast changes back to the session row so future resumes keep the chat's latest runtime.
  • Persist/restore custom endpoint base_url + api_mode in model_config on resume (raw api_key deliberately not stored in the session DB).
  • Include provider in session.info and emit session.info after reasoning/fast/model changes.
  • Add shared formatting for the footer/model label and expose reasoning/fast state in the model menu.

Root cause

Desktop had three stale-state paths:

  1. The renderer cached one set of footer atoms globally, so switching sessions could keep showing another chat's runtime state.
  2. session.resume rebuilt the backend agent from current global config rather than the stored session row, so an older chat whose DB row said gpt-5.4 + high reasoning could resume as the latest global gpt-5.5 + medium reasoning.
  3. Live runtime changes made inside a session (model switch, reasoning effort, fast/service tier) were emitted to the current frontend but not consistently persisted for the next resume.

Review feedback addressed (from #40163)

  • _apply_model_switch keeps the two-arg _restart_slash_worker(sid, session) and adds _persist_live_session_runtime(session).
  • use-session-state-cache.ts adds the per-session runtime setters alongside the sameMessageList(...) reference-equality guard, not in place of it.
  • Live-runtime persistence collapsed to a single update_session_meta(..., model) DB write (update_session_model only as a legacy fallback).
  • Custom endpoint base_url/api_mode persisted/restored in model_config.
  • session["model_override"] repopulated after a DB-restored resume so a later /new rebuilds from the same restored source of truth.

Test plan

  • scripts/run_tests.sh tests/test_tui_gateway_server.py → 255 passed, 1 failed. The failure (test_browser_manage_connect_default_local_reports_launch_hint) reproduces identically on clean main in this local macOS env (a Chromium browser is installed, so the "not found" hint never fires) and is unrelated to this diff.
  • npm run typecheck --workspace apps/desktop → passed.
  • apps/desktop vitest: use-model-controls.test.tsx, model-status-label.test.ts, store/session.test.ts → 24 passed.

Closes #40163.

郝鹏宇 added 5 commits June 10, 2026 13:05
(cherry picked from commit f72ee87d99ee38cb7b5badeb9a8af869bb92073a)
(cherry picked from commit d91942ebd4671ff857b5c8526dbf133f04782ecb)
(cherry picked from commit 32b3793418257617b8da57e26151f079c2620d00)
(cherry picked from commit c58467779436dcef44a80ad55b52664752dc0837)
@github-actions

github-actions Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

🔎 Lint report: salvage/desktop-model-runtime-per-session vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 10705 on HEAD, 10703 on base (🆕 +2)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 5600 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

The salvaged commits on this branch preserve @pinguarmy's authorship
(郝鹏宇 / peterhao@Peters-MacBook-Air.local). Add the mapping so the
check-attribution CI gate resolves the email to the GitHub username.
@OutThisLife OutThisLife enabled auto-merge (squash) June 10, 2026 18:15
@OutThisLife OutThisLife merged commit 6de3963 into main Jun 10, 2026
27 checks passed
@OutThisLife OutThisLife deleted the salvage/desktop-model-runtime-per-session branch June 10, 2026 18:16
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