nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] In-app /resume changes the model label but keeps the old client, so replies come from the previous model

Open diyaavirmani opened this issue 1 month ago • 2 comments

Description

/resume inside a running session switches the provider and model labels to the resumed session's values, but keeps the current LLM client. The next turns are served by the model you were already using, while the UI, the saved session and /stats all record them under the resumed session's provider and model.

For example: you're on a local model, then /resume a session you ran on a paid API model. Every reply is labelled with the paid model, but it actually comes from the local one. The session file and the usage stats say the paid model served it, so token and cost numbers are filed under the wrong model. The opposite direction is worse: you think you're on the cheap model while the expensive one keeps answering.

Starting with nanocoder --resume <id> works correctly. Only the in-app /resume (and the session picker) is affected.

Environment

  • OS: macOS (Darwin 25.6.0, x86_64)
  • Node version: 22.23.3
  • Nanocoder version: main at ef4e79ec, and v1.31.0
  • Provider: two local OpenAI-compatible test servers with scripted responses (provA / model-a and provB / model-b)
  • Model: n/a (scripted)

Steps to Reproduce

  1. Configure two providers, provA (model-a) and provB (model-b), each pointing at its own server. Each server always answers "answer served by provider A" or "answer served by provider B".
  2. Have a saved session that was run on provB / model-b.
  3. Start the TUI on the other provider: nanocoder --provider provA --model model-a.
  4. Run /resume <that session id> and wait for "Resumed session".
  5. Send a message.

Expected Behavior

Resuming restores the session's provider and model: it creates a matching client, or warns if that provider is no longer available. At the very least, the label, the saved session and the usage stats should match the model that actually answered.

Actual Behavior

in-app /resume --resume at startup (control)
requests received by the provider A server 1 (model-a) 1 (model-a)
requests received by the provider B server 0 0
label on the new reply model-b: "answer served by provider A" model-a: "answer served by provider A"
saved session provider/model provB/model-b provA/model-a
/stats ledger provB/model-b: 1 prompt, 15 tokens provA/model-a: 1 prompt, 15 tokens

The control starts on provA too, but its labels, saved session and stats stay consistent with the model that answered.

Same result on main ef4e79ec and on v1.31.0. I drove the real TUI through a pseudo-terminal.

Logs/Screenshots

What I think is going on:

  • applySession sets the labels with setCurrentProvider(session.provider) and setCurrentModel(session.model) (source/hooks/useAppHandlers.tsx:572-573), but never creates a client for them.
  • A normal model or provider switch creates the client: createLLMClient(...), then setClient(newClient) (source/hooks/useModeHandlers.tsx:141-159).
  • The next turn goes through the unchanged client (source/hooks/chat-handler/conversation/conversation-loop.tsx:398), while usage is priced and labelled with currentModel, which is now the resumed label (conversation-loop.tsx:604-610). Autosave and the stats ledger then save that label too.

Additional Context

Proposed fix (happy to adjust): when the resumed session's provider or model differs from the current one, have applySession go through the same switch logic as /model and /provider (create the client, then set the client, provider and provider config). If the provider isn't configured any more, keep the current client and labels and show a warning. Pulling the switch logic out of useModeHandlers into one shared function would keep the two paths from drifting apart again.

For tests: resuming a session from another provider creates a client for that provider, resuming one with an unavailable provider keeps the current client and labels and warns, and resuming a session on the same provider and model doesn't create a new client.

  • [x] I have searched existing issues to ensure this is not a duplicate
  • [x] I can reproduce this issue consistently
  • [x] This issue occurs with the latest version of nanocoder

@addyCooks could you take a look when you have a moment? I'd like to work on this one, so please assign it to me if that works for you.

diyaavirmani avatar Oct 19 '26 22:10 diyaavirmani

Hey, I'd like to take this one. Could you assign it to me?

Here's what I found: applySession in useAppHandlers.tsx only sets the provider and model labels and never touches the client. Startup --resume only looks right because init creates the client after applySession runs and overwrites the labels.

My plan is to have the in-app paths (/resume <id> and the session picker) call handleModelSelect(session.provider, session.model, true) before applying the session, the same programmatic switch the mode toggle already uses. If the provider isn't configured anymore, handleModelSelect already shows its "not available" error, and the labels stay on the model that's actually answering. I'd leave the startup path alone so it doesn't race client init.

I've got this working locally with tests, so I can open a PR as soon as you're good with it.

Devehab avatar Oct 23 '26 03:10 Devehab

Thanks @diyaavirmani, applySession sets the provider/model labels but never switches the client, so replies come from the old model but get labelled and saved as the resumed one. Assigning it to you since you asked first.

Suggestion: call the existing programmatic switch (handleModelSelect with isProgrammatic = true) from /resume and the session picker. It already covers a new provider, a new model on the same provider, and the "provider not available" case. Startup --resume looks fine, so I'd leave it alone.

@Devehab, thanks for offering. This one was claimed first, but I'm happy to assign you to another issue.

addyCooks avatar Oct 27 '26 05:10 addyCooks