Skip to content

fix(ui): /model + /preset update active model so the next card pill is fresh#385

Merged
esengine merged 1 commit into
mainfrom
fix/372-model-badge-stale
May 7, 2026
Merged

fix(ui): /model + /preset update active model so the next card pill is fresh#385
esengine merged 1 commit into
mainfrom
fix/372-model-badge-stale

Conversation

@esengine

@esengine esengine commented May 7, 2026

Copy link
Copy Markdown
Owner

Closes #372.

Why

state.session.model is set once in initialState() and never mutated. /model <id>, /preset {auto,flash,pro} only route through loop.configure({ model }) — they never feed the agent store. So the next streaming.start / reasoning.start / "thinking · X" card snapshots the launch-time model id, regardless of which model actually answered the turn.

Repro:

  1. Start session on flash (or default).
  2. /model deepseek-v4-pro.
  3. Send a new message.
  4. Streaming card pill still reads flash.

What changes

  • src/cli/ui/state/events.ts — new typed event:

    const sessionModelChange = z.object({
      type: z.literal("session.model.change"),
      model: z.string().min(1),
    });
  • src/cli/ui/state/reducer.ts — handles session.model.change. Returns the same state when the id is unchanged so React.memo'd consumers don't re-render needlessly.

  • src/cli/ui/slash/handlers/model.ts/model and /preset {auto,flash,pro} dispatch the event after loop.configure(...). ctx.dispatch is already plumbed via agentStore.dispatch in App.tsx (existing wire — used by other handlers).

Cards already opened keep their captured model — that snapshot at streaming.start / reasoning.start is intentional so mid-turn auto-escalation doesn't relabel completed reasoning. Fresh cards opened after the switch render the new id.

Tests

tests/ui-reducer.test.ts — 3 new cases:

  • session.model.change updates state.session.model and the next streaming card snapshots it
  • no-op (referential identity) when id unchanged
  • existing card opened on the prior model is NOT relabeled (preserves the existing snapshot guarantee)

Test plan

  • npm run verify — 133 files / 2141 passed / 1 skipped (was 2138, +3 new)
  • Manual: chat /model deepseek-v4-pro → send a message → next assistant card pill reads pro
  • Manual: /preset flash/preset pro → next card pill matches the active preset
  • Manual: pre-existing assistant card from before the switch still shows the model that produced it (no retroactive relabel)

…s fresh (#372)

`state.session.model` was set once in `initialState()` and never
mutated. `/model <id>` and `/preset {auto,flash,pro}` only routed
through `loop.configure({ model })`, never into the agent store —
so the next `streaming.start` / `reasoning.start` / "thinking · X"
card snapshotted the launch-time model id, even when the model that
actually answered the turn was different.

Add a typed `session.model.change` event the model handlers dispatch
through `ctx.dispatch`. Reducer mutates `state.session.model` (with
referential identity preserved when the id is unchanged) and the
existing snapshot logic in `makeReasoningCard` / `makeStreamingCard`
picks up the new value automatically. Cards already opened keep
their captured model — that snapshot is intentional so mid-turn
escalation doesn't relabel completed reasoning.
@esengine esengine merged commit 3c24c0f into main May 7, 2026
3 checks passed
@esengine esengine deleted the fix/372-model-badge-stale branch May 7, 2026 14:04
@esengine esengine mentioned this pull request May 7, 2026
6 tasks
ChasLui pushed a commit to ChasLui/DeepSeek-Reasonix that referenced this pull request May 23, 2026
…s fresh (esengine#372) (esengine#385)

`state.session.model` was set once in `initialState()` and never
mutated. `/model <id>` and `/preset {auto,flash,pro}` only routed
through `loop.configure({ model })`, never into the agent store —
so the next `streaming.start` / `reasoning.start` / "thinking · X"
card snapshotted the launch-time model id, even when the model that
actually answered the turn was different.

Add a typed `session.model.change` event the model handlers dispatch
through `ctx.dispatch`. Reducer mutates `state.session.model` (with
referential identity preserved when the id is unchanged) and the
existing snapshot logic in `makeReasoningCard` / `makeStreamingCard`
picks up the new value automatically. Cards already opened keep
their captured model — that snapshot is intentional so mid-turn
escalation doesn't relabel completed reasoning.
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.

Model badge on assistant card still shows flash after switching to pro

1 participant