Skip to content

The agent that grows with you

fix(tui): a deferred pick's repeated confirmation is reported, and a busy pick says next turn

Tekniumd4468242de33
diff --git a/ui-tui/src/__tests__/canonicalSessionControls.test.ts b/ui-tui/src/__tests__/canonicalSessionControls.test.ts
index 02e7cd913e3..c1da44d5fce 100644
--- a/ui-tui/src/__tests__/canonicalSessionControls.test.ts
+++ b/ui-tui/src/__tests__/canonicalSessionControls.test.ts
@@ -232,3 +232,17 @@ it('a /compress that removes nothing prints main\'s "No changes" report without
expect(ctx.transcript.setHistoryItems).not.toHaveBeenCalled()
expect(request.mock.calls.filter(([method]) => method === 'session.resume')).toHaveLength(1)
})
+
+it('a pick deferred by a running turn says it applies from the next turn', async () => {
+ const { ctx, request, slash } = harness()
+
+ request.mockImplementation(async (method: string) =>
+ method === 'session.mutate'
+ ? { model: 'picked', operation: 'model', status: 'deferred', execution_generation: 4 }
+ : { session_id: 'owner', revision: 8, execution_generation: 4, info })
+
+ slash('/model picked --tui-session')
+ await vi.waitFor(() => expect(ctx.transcript.sys).toHaveBeenCalled())
+ expect(ctx.transcript.sys.mock.calls[0][0]).toContain('applies next turn')
+ expect(getUiState().info?.model).toBe('old')
+})
diff --git a/ui-tui/src/__tests__/createGatewayEventHandler.deferredPick.test.ts b/ui-tui/src/__tests__/createGatewayEventHandler.deferredPick.test.ts
index 1844d1c67c7..cb7524c52b4 100644
--- a/ui-tui/src/__tests__/createGatewayEventHandler.deferredPick.test.ts
+++ b/ui-tui/src/__tests__/createGatewayEventHandler.deferredPick.test.ts
@@ -48,4 +48,23 @@ describe('a model pick made during a turn that did not apply at the boundary', (
await vi.waitFor(() => expect(context.gateway.gw.request).toHaveBeenCalledTimes(2))
expect(context.gateway.gw.request.mock.calls.at(-1)[1]).toMatchObject({ operation: 'model', payload: { confirm: 'owner-token', model: 'guarded' } })
})
+
+ it('a confirmation refused again (a queued turn moved the session) is reported, not dropped', async () => {
+ patchUiState({ info: { model: 'frozen' } as any, sid: 'sess-1' })
+ const sys = vi.fn()
+ const context = ctx(sys)
+ context.gateway.gw.request = vi.fn(async (method: string) =>
+ method === 'session.resume'
+ ? { execution_generation: 2, revision: 4 }
+ : { confirm: 'fresh-token', confirm_message: 'Still costly', operation: 'model', session_id: 'sess-1',
+ status: 'confirmation_required', target_model: 'guarded' })
+
+ createGatewayEventHandler(context)({ payload: { confirm: 'old-token', operation: 'model', payload: { model: 'guarded' },
+ session_id: 'sess-1', status: 'confirmation_required', target_model: 'guarded' }, session_id: 'sess-1', type: 'session.updated' } as any)
+
+ getOverlayState().confirm?.onConfirm()
+ await vi.waitFor(() => expect(sys).toHaveBeenCalled())
+ expect(sys.mock.calls[0][0]).toContain('run /model again')
+ expect(getUiState().info?.model).toBe('frozen')
+ })
})
diff --git a/ui-tui/src/app/createGatewayEventHandler.ts b/ui-tui/src/app/createGatewayEventHandler.ts
index 47c60f7735b..3aa772fded4 100644
--- a/ui-tui/src/app/createGatewayEventHandler.ts
+++ b/ui-tui/src/app/createGatewayEventHandler.ts
@@ -623,8 +623,15 @@ function applyDeferredPickOutcome(
danger: true,
detail: (update.confirm_message as string | undefined) || t('slashCmd.session.model.expensiveDetail'),
onConfirm: () =>
- void mutateCanonicalSession(gw, sid, 'model', arg, undefined, update.confirm as string).catch((error: unknown) =>
- sys(`error: ${error instanceof Error ? error.message : String(error)}`)
+ void mutateCanonicalSession(gw, sid, 'model', arg, undefined, update.confirm as string).then(
+ mutation => {
+ // Refused again (a queued turn or another pick moved the session first): say so once,
+ // never re-ask in a loop.
+ if (mutation?.result.status === 'confirmation_required') {
+ sys(t('slashCmd.session.model.confirmStale'))
+ }
+ },
+ (error: unknown) => sys(`error: ${error instanceof Error ? error.message : String(error)}`)
),
title: t('slashCmd.session.model.confirmTitle', String(update.target_model ?? pick.model ?? ''))
}
diff --git a/ui-tui/src/app/slash/canonicalSessionControls.ts b/ui-tui/src/app/slash/canonicalSessionControls.ts
index f3568dcd4fc..054f50af245 100644
--- a/ui-tui/src/app/slash/canonicalSessionControls.ts
+++ b/ui-tui/src/app/slash/canonicalSessionControls.ts
@@ -237,6 +237,14 @@ function applyModelResult(result: CanonicalControlResult, ctx: SlashRunCtx) {
throw new Error(t('session.main.invalidModelSwitchResponse'))
}
+ if (result.status === 'deferred') {
+ // A turn is running: the owner keeps the pick for the next turn, and session.info repaints the
+ // model when it lands (or a refusal / confirmation follows on session.updated).
+ ctx.transcript.sys(t('slashCmd.session.model.switchedDeferred', result.model))
+
+ return
+ }
+
patchUiState(state => ({
...state,
info: {