Skip to content

The agent that grows with you

fix(dashboard): badge follows the PTY runtime model, not config, during fallback (#54509)

Austin Pickettaa30e02d860f
diff --git a/web/src/components/ChatSidebar.test.tsx b/web/src/components/ChatSidebar.test.tsx
index c2016ab9c46..d93f295b277 100644
--- a/web/src/components/ChatSidebar.test.tsx
+++ b/web/src/components/ChatSidebar.test.tsx
@@ -184,6 +184,77 @@ describe('ChatSidebar event socket', () => {
expect(reloadMocks.maybeReloadForLoopbackWsAuthFailure).toHaveBeenCalledWith(4401)
})
+ /** The PTY-side events socket of the chat tab, opened and ready. */
+ async function openedFeedSocket() {
+ await vi.waitFor(() => expect(FakeWebSocket.instances).toHaveLength(1))
+ const socket = FakeWebSocket.instances[FakeWebSocket.instances.length - 1]
+ await act(async () => {
+ socket.emit('open', {})
+ })
+ return socket
+ }
+
+ function feedEvent(payload: Record<string, unknown>) {
+ return {
+ data: JSON.stringify({
+ jsonrpc: '2.0',
+ method: 'event',
+ params: { type: 'session.info', payload }
+ })
+ }
+ }
+
+ it('shows the PTY runtime model after a fallback swap (#54509)', async () => {
+ apiMocks.getModelInfo.mockResolvedValue({
+ capabilities: { supports_reasoning: false },
+ model: 'configured-primary'
+ })
+
+ const { ChatSidebar } = await import('./ChatSidebar')
+ await render(<ChatSidebar channel="chat-1" />)
+
+ // The badge seeds from config (/api/model/info): the configured primary.
+ await vi.waitFor(() =>
+ expect(container.textContent).toContain('configured-primary')
+ )
+
+ // End-of-turn `session.info` from the PTY chat session: a provider
+ // fallback replaced the configured primary mid-turn, so the agent's
+ // runtime model is the one that actually answered. The badge must
+ // follow the runtime identity over config.yaml.
+ const socket = await openedFeedSocket()
+ await act(async () => {
+ socket.emit(
+ 'message',
+ feedEvent({ model: 'runtime-fallback', provider: 'fallback-provider' })
+ )
+ })
+
+ expect(container.textContent).toContain('runtime-fallback')
+ expect(container.textContent).not.toContain('configured-primary')
+ })
+
+ it('keeps showing the configured model until the PTY reports a runtime one', async () => {
+ apiMocks.getModelInfo.mockResolvedValue({
+ capabilities: { supports_reasoning: false },
+ model: 'configured-primary'
+ })
+
+ const { ChatSidebar } = await import('./ChatSidebar')
+ await render(<ChatSidebar channel="chat-1" />)
+ await openedFeedSocket()
+
+ // A session.info without a usable model (e.g. a title-only update)
+ // must not blank the badge: config stays the source until the PTY
+ // chat session reports its runtime identity.
+ const socket = FakeWebSocket.instances[FakeWebSocket.instances.length - 1]
+ await act(async () => {
+ socket.emit('message', feedEvent({ title: 'Some session title' }))
+ })
+
+ expect(container.textContent).toContain('configured-primary')
+ })
+
it("ignores the synchronous sidecar state replay", async () => {
const { ChatSidebar } = await import("./ChatSidebar");
diff --git a/web/src/components/ChatSidebar.tsx b/web/src/components/ChatSidebar.tsx
index b4069ecf4d5..94071b4e783 100644
--- a/web/src/components/ChatSidebar.tsx
+++ b/web/src/components/ChatSidebar.tsx
@@ -7,10 +7,13 @@
* 1. **JSON-RPC sidecar** (`GatewayClient` → /api/ws) — a lightweight
* session used only for connection state (the "live" badge) and
* credential warnings. Independent of the PTY pane's session by
- * design. The model badge does NOT come from here: it reads the
- * effective config model over REST (`/api/model/info`), and the model
- * picker writes config over REST (`/api/model/set`) then offers a
- * dashboard reload so the running chat adopts the new model.
+ * design. The model badge does NOT come from here: it prefers the
+ * PTY chat session's runtime identity (`session.info` over the events
+ * feed — the model actually answering, which changes when a provider
+ * fallback replaces the configured primary mid-turn, #54509), falls
+ * back to the effective config model over REST (`/api/model/info`),
+ * and the model picker writes config over REST (`/api/model/set`)
+ * then offers a dashboard reload so the running chat adopts it.
*
* 2. **Event subscriber** (/api/events?channel=…) — passive, receives
* every dispatcher emit from the PTY-side `tui_gateway.entry` that
@@ -95,6 +98,15 @@ const STATE_TONE: Record<ConnectionState, 'secondary' | 'warning' | 'success' |
error: 'destructive'
}
+/** The runtime model a `session.info` payload reports, or undefined when it
+ * carries none (title-only updates) — config stays the badge's source then.
+ * `session.info` is surface-specific on the wire, so narrow defensively. */
+function sessionInfoModel(payload: unknown): string | undefined {
+ if (!payload || typeof payload !== 'object') return undefined
+ const model = (payload as { model?: unknown }).model
+ return typeof model === 'string' && model.trim() ? model : undefined
+}
+
interface ChatSidebarProps {
channel: string
/** Chat profile from the dashboard switcher / URL scope. */
@@ -146,14 +158,23 @@ export function ChatSidebar({
const [info, setInfo] = useState<SessionInfo>({})
const [modelOpen, setModelOpen] = useState(false)
const [error, setError] = useState<string | null>(null)
- // The badge shows config.yaml's main model (`model.default`) via
- // `/api/model/info` — the same value the Models page writes and a new chat
- // session boots from. We deliberately don't use the sidecar's `session.info`
- // model: that's a one-time snapshot of the throwaway sidecar agent taken when
- // its session is created, and it never updates when the model is changed
- // elsewhere, so the badge would go stale. Pass the chat profile explicitly so
- // this card stays scoped to the PTY even if the global dashboard switcher
- // changes while the chat is open.
+ // Runtime model identity of the PTY chat session, from its `session.info`
+ // broadcasts over the events feed. This is the model actually answering —
+ // when a provider fallback replaces the configured primary mid-turn
+ // (#54509), the end-of-turn `session.info` reports the fallback model, and
+ // the badge must follow it rather than attribute the response to the
+ // configured model that failed.
+ const [runtimeModel, setRuntimeModel] = useState('')
+ // The config fallback for the badge: config.yaml's main model
+ // (`model.default`) via `/api/model/info` — the same value the Models page
+ // writes and a new chat session boots from, shown until the PTY session
+ // has broadcast a runtime identity. We deliberately don't use the
+ // SIDECAR's `session.info` model: that's a one-time snapshot of the
+ // throwaway sidecar agent taken when its session is created, and it never
+ // updates when the model is changed elsewhere, so the badge would go
+ // stale. Pass the chat profile explicitly so this card stays scoped to
+ // the PTY even if the global dashboard switcher changes while the chat
+ // is open.
const [effectiveModel, setEffectiveModel] = useState('')
// Whether the effective model supports reasoning effort — gates the
// ReasoningPicker. Read from the same `/api/model/info` capabilities the
@@ -198,6 +219,9 @@ export function ChatSidebar({
if (prevScopeKey.current === scopeKey) return
prevScopeKey.current = scopeKey
setError(null)
+ // Fresh PTY child on the new scope: its runtime identity is unknown until
+ // its first `session.info` broadcast, so drop the previous chat's model.
+ setRuntimeModel('')
// Fresh scope, fresh sidecar redial budget (#95951).
sidecarRedialAttemptRef.current = 0
sidecarGaveUpRef.current = false
@@ -459,6 +483,14 @@ export function ChatSidebar({
if (title !== undefined) {
onSessionTitleChange?.(title)
}
+ // Runtime identity of the PTY chat session — the model actually
+ // answering, which a provider fallback can swap mid-turn (#54509).
+ // The gateway re-emits `session.info` at every turn end (and on model
+ // switches), so this stays current without any new plumbing.
+ const model = sessionInfoModel(ev.payload)
+ if (model !== undefined) {
+ setRuntimeModel(model)
+ }
})
const offNewSession = feed.on('dashboard.new_session_requested', () => {
onDashboardNewSessionRequest?.()
@@ -497,9 +529,12 @@ export function ChatSidebar({
setVersion(v => v + 1)
}, [])
- // The picker writes config.yaml over REST and reloads — it doesn't ride the
- // sidecar gateway session, so it's available whenever the sidebar is mounted.
- const modelName = effectiveModel || info.model || '—'
+ // Runtime-first (#54509): the PTY session's `session.info` reports the
+ // model that is actually answering, so a provider-fallback swap shows the
+ // fallback model, not the configured primary that failed. Config remains
+ // the fallback until the PTY has broadcast a runtime identity (fresh chat,
+ // events feed still connecting).
+ const modelName = runtimeModel || effectiveModel || info.model || '—'
const modelLabel = modelName.split('/').slice(-1)[0] ?? '—'
const credential = credentialWarning(info.credential_warning)
const banner = error ?? credential?.message ?? null