Skip to content

Commit e31844d

Browse files
fix: carry an explicit keyless-Zen pick to an agent without its own model
An agent with no stored pick inherits the most recent one through `fallbackModel()`, whose recents loop skipped a keyless-Zen entry without checking this launch's explicit picks. The loop and the shared Zen repair helper now both honor that record, so Tab to another agent keeps a deliberate Zen choice. New test covers it. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_016x3nbZU5Vb6HnSTqE7vELm
1 parent 51c6a8a commit e31844d

2 files changed

Lines changed: 34 additions & 9 deletions

File tree

‎packages/tui/src/context/local.tsx‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,14 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
610610
})
611611
// altimate_change end
612612

613+
// altimate_change start — models explicitly picked during this launch (`--model`, picker,
614+
// cycle, favorite). A stale keyless-Zen selection is repaired to Base only when it is not one
615+
// of these, so switching conversations or agents cannot reroute a deliberate choice. See R8
616+
// for restarts. Declared before `fallbackModel`, which reads it as soon as it is created.
617+
const [explicitPicks, setExplicitPicks] = createStore<Record<string, true>>({})
618+
const pickKey = (model: { providerID: string; modelID: string }) => `${model.providerID}/${model.modelID}`
619+
// altimate_change end
620+
613621
const fallbackModel = createMemo(() => { // altimate_change
614622
const explicit = explicitFallbackModel() // altimate_change — declared above
615623
if (explicit) return explicit // altimate_change
@@ -644,7 +652,7 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
644652
if (!isModelValid(item)) continue
645653
if (baseAvailable) {
646654
const provider = sync.data.provider.find((candidate) => candidate.id === item.providerID)
647-
if (provider && isPublicZenProvider(provider)) continue
655+
if (provider && isPublicZenProvider(provider) && !explicitPicks[pickKey(item)]) continue
648656
}
649657
return item
650658
}
@@ -680,16 +688,11 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
680688
// `--model`/config `model` (see `explicitFallbackModel` above `fallbackModel()`). Each
681689
// candidate is checked in the SAME priority order this memo used before; only the two
682690
// implicit branches route through `substituteStaleZen`.
683-
// Models explicitly picked during this launch (`--model`, picker, cycle, favorite). A stale
684-
// keyless-Zen selection is repaired to Base only when it is not one of these, so switching
685-
// conversations and back cannot reroute a deliberate choice. See R8 for restarts.
686-
const [explicitPicks, setExplicitPicks] = createStore<Record<string, true>>({})
687-
const pickKey = (model: { providerID: string; modelID: string }) => `${model.providerID}/${model.modelID}`
688691

689692
function substituteStaleZen(model: { providerID: string; modelID: string } | undefined) {
690693
if (!model) return model
691694
const provider = sync.data.provider.find((candidate) => candidate.id === model.providerID)
692-
if (provider && isPublicZenProvider(provider) && isModelValid(ALTIMATE_BASE_MODEL)) {
695+
if (provider && isPublicZenProvider(provider) && isModelValid(ALTIMATE_BASE_MODEL) && !explicitPicks[pickKey(model)]) {
693696
return { ...ALTIMATE_BASE_MODEL }
694697
}
695698
return model
@@ -700,7 +703,7 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
700703

701704
const persistedAgentPick = a ? modelStore.model[a.name] : undefined
702705
if (persistedAgentPick && isModelValid(persistedAgentPick))
703-
return explicitPicks[pickKey(persistedAgentPick)] ? persistedAgentPick : substituteStaleZen(persistedAgentPick)
706+
return substituteStaleZen(persistedAgentPick)
704707

705708
const agentConfiguredModel = a?.model
706709
if (agentConfiguredModel && isModelValid(agentConfiguredModel)) return agentConfiguredModel

‎packages/tui/test/context/stale-zen-cycle.test.tsx‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ async function mount(agentModel?: { providerID: string; modelID: string }) {
104104
if (url.pathname === "/config/providers") return json({ providers, default: {} })
105105
if (url.pathname === "/provider")
106106
return json({ all: providers, default: {}, connected: ["opencode", "altimate-free", "anthropic"] })
107-
if (url.pathname === "/agent") return json([agent])
107+
if (url.pathname === "/agent") return json([agent, { ...agent, name: "plan" }])
108108
if (url.pathname === "/project/proj_test/directories") return json([])
109109
return undefined
110110
})
@@ -242,3 +242,25 @@ test("an explicit keyless-Zen pick survives switching conversations and back", a
242242
}
243243
})
244244

245+
test("an explicit keyless-Zen pick carries to another agent without its own model", async () => {
246+
const originalStateHome = process.env.OPENCODE_TEST_STATE_HOME
247+
await using isolatedState = await tmpdir()
248+
process.env.OPENCODE_TEST_STATE_HOME = isolatedState.path
249+
const { local, cleanup } = await mount()
250+
try {
251+
await waitUntil(() => local.model.ready)
252+
local.model.set({ ...STALE_ZEN }, { recent: true })
253+
await waitUntil(() => local.model.current()?.providerID === STALE_ZEN.providerID)
254+
const from = local.agent.current()?.name
255+
local.agent.move(1)
256+
await waitUntil(() => local.agent.current()?.name !== from)
257+
// The other agent has no pick of its own, so it inherits the most recent one: the Zen choice.
258+
await Bun.sleep(100)
259+
expect(local.model.current()).toMatchObject(STALE_ZEN)
260+
} finally {
261+
await cleanup()
262+
if (originalStateHome === undefined) delete process.env.OPENCODE_TEST_STATE_HOME
263+
else process.env.OPENCODE_TEST_STATE_HOME = originalStateHome
264+
}
265+
})
266+

0 commit comments

Comments
 (0)