Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

fix(cli): the remembered subscription model never survived to be used

bitcoinbuilder6eef66cd0f40
diff --git a/cli/src/cli.ts b/cli/src/cli.ts
index 0a7bd48e8..42ca15a68 100644
--- a/cli/src/cli.ts
+++ b/cli/src/cli.ts
@@ -168,7 +168,7 @@ import { probeGridAssignment, sameGridAssignment } from './lib/gridAssignment.js
import { agentFrame, type AgentFrame } from './lib/agentFrame.js'
import { SessionInputController } from './lib/sessionInput.js'
import { adaptSlashCommand } from './lib/goalCommand.js'
-import { RuntimeProfileManager } from './lib/runtimeProfile.js'
+import { RuntimeProfileManager, parseRuntimeProfile } from './lib/runtimeProfile.js'
import { RuntimeProfileController, inspectRuntimePane } from './lib/runtimeProfileController.js'
import { deviceErrorText } from './lib/deviceErrors.js'
import { correlateAgentEvent, turnHeartbeatFrame } from './lib/agentEvent.js'
@@ -3811,8 +3811,24 @@ async function runForeground(session: AuthSession): Promise<void> {
//
// Coming back reads what was kept. Not cleared on the way home: an agent bounced between a grid
// and its own login should land on the same model every time, not only the first.
+ // ⚠️ `selectedModel` answers an ENCODED runtime-profile id (`runtime-v1:…`), not a model name —
+ // handing that to an engine would point it at a model that does not exist. Decode it and take
+ // the model. For claude the decoded value is already the vendor's alias (`opus`), which is what
+ // ANTHROPIC_MODEL wants. Null when the daemon has not observed this pane's model yet, which is a
+ // real answer: there is then nothing to come back to and the engine decides, as it did before.
+ const observed = parseRuntimeProfile(runtimeProfiles.selectedModel(session))?.model ?? null
const remembered = grid
- ? (runtimeProfiles.selectedModel(session) ?? null)
+ // Two guards, and both come from watching this go wrong:
+ //
+ // * Capture only when the agent is on its OWN LOGIN. Moving grid→grid must not overwrite the
+ // memory with the first grid's model — the subscription choice has not changed, and the
+ // whole point is to still have it on the way home.
+ //
+ // * Never remember the model being moved TO. An engine can keep REPORTING a grid model after
+ // it has come back (Claude Code restores it from its own session file and says so), so a
+ // later move to that same grid would otherwise capture the grid's model as the
+ // "subscription" one and hand it straight back — teaching the bug to itself.
+ ? (!session.grid && observed !== grid.model ? observed : (session.subscriptionModel ?? null))
: (session.subscriptionModel ?? null)
// What this machine cannot do at all is said first, before the pane is even looked at.
const target: LaunchSource = {
diff --git a/cli/src/lib/registry.spec.ts b/cli/src/lib/registry.spec.ts
index 2d3fa11d8..407d8c441 100644
--- a/cli/src/lib/registry.spec.ts
+++ b/cli/src/lib/registry.spec.ts
@@ -1296,6 +1296,36 @@ describe('registry across a reboot and pane loss', () => {
expect(registry.setGridLaunch('nobody', null)).toBe(false)
})
+ it('keeps the remembered subscription model across a reload', async () => {
+ // ⚠️ REGRESSION. A row is rebuilt from an explicit field list on load, so a field added to the
+ // type and the setter but NOT to that list is written to disk and silently dropped by the next
+ // load. It reads as "the setter never ran", which is where a day went — so what is pinned here
+ // is survival across a RELOAD, not merely that the setter returned true.
+ const { registry } = await loadRegistryModule()
+ registry.load()
+ const pending = registry.openPendingAgent({
+ engine: 'claude',
+ runtimes: [{ backend: 'tmux', paneId: '%21' }],
+ cwd: '/tmp/demo',
+ })!
+ expect(registry.setSubscriptionModel(pending.agentId, 'opus')).toBe(true)
+ expect(registry.setSubscriptionModel('nobody', 'opus')).toBe(false)
+
+ // The reload is the whole test: a field missing from the rehydration list survives the write and
+ // dies here.
+ const { registry: reloaded } = await loadRegistryModule()
+ reloaded.load()
+ expect(reloaded.byAgent(pending.agentId)?.subscriptionModel).toBe('opus')
+
+ // ...and the SECOND way it was lost: a hook bind rebuilds the row from named fields, so a field
+ // the rebuild does not name is still on disk while memory has already forgotten it.
+ const transcriptPath = join(dataDir, 'session-sub.jsonl')
+ writeFileSync(transcriptPath, '{}\n')
+ const bound = reloaded.register({ sessionId: 'session-sub', transcriptPath, tmuxPane: '%21', cwd: '/tmp/demo' })
+ expect(bound?.entry.agentId).toBe(pending.agentId)
+ expect(bound?.entry.subscriptionModel).toBe('opus')
+ })
+
it('drops any launch state on the hook that proves the engine is up', async () => {
const transcriptPath = join(dataDir, 'session-f.jsonl')
writeFileSync(transcriptPath, '{}\n')
diff --git a/cli/src/lib/registry.ts b/cli/src/lib/registry.ts
index db008a0d6..051072917 100644
--- a/cli/src/lib/registry.ts
+++ b/cli/src/lib/registry.ts
@@ -759,6 +759,13 @@ class Registry {
grid: normalizedGridAssignment(raw.grid),
codexHome: typeof rawCodexHome === 'string' && rawCodexHome ? rawCodexHome : null,
...(rawGridLaunch !== undefined ? { gridLaunch: rawGridLaunch } : {}),
+ // ⚠️ Rehydrated EXPLICITLY, like every field above it. A row is rebuilt from this list on
+ // load, so a field added to the type and the setter but not to this list is written to
+ // disk and then silently dropped by the next load — which is exactly what happened, and
+ // it looks like "the setter never ran" rather than like a missing line here.
+ ...(typeof raw?.subscriptionModel === 'string' && raw.subscriptionModel
+ ? { subscriptionModel: raw.subscriptionModel }
+ : {}),
...(raw.bypassPermission === true ? { bypassPermission: true } : {}),
transcriptPath,
title: titleDisplayName(typeof raw.title === 'string' ? raw.title : null),
@@ -1139,6 +1146,11 @@ class Registry {
grid: existing?.grid ?? null,
// The credential-bearing launch. Like codexHome: written once, carried forward, never re-derived.
gridLaunch: existing?.gridLaunch ?? null,
+ // ⚠️ Carried forward for the same reason, and it was missed once: a bind REBUILDS the row from
+ // named fields, so a field the rebuild does not name survives on disk and vanishes from
+ // memory the moment the engine reports in. The symptom is a move back to the engine's own
+ // login landing on a house default — the remembered model was there, then a hook bind ate it.
+ ...(existing?.subscriptionModel ? { subscriptionModel: existing.subscriptionModel } : {}),
transcriptPath: effectiveTranscriptPath,
projectDir: engine === 'grok' || engine === 'agy' || engine === 'copilot'
? basename(input.cwd ?? existing?.cwd ?? '') || sessionId
diff --git a/cli/src/lib/subscriptionModel.spec.ts b/cli/src/lib/subscriptionModel.spec.ts
index 5be3526ef..b16feb28c 100644
--- a/cli/src/lib/subscriptionModel.spec.ts
+++ b/cli/src/lib/subscriptionModel.spec.ts
@@ -39,6 +39,16 @@ describe('subscriptionModelLaunch', () => {
expect(subscriptionModelLaunch('claude', undefined)).toBeNull()
})
+ it('round-trips the model name a runtime profile decodes to', () => {
+ // ⚠️ The daemon reads this from `selectedModel`, which answers an ENCODED profile
+ // (`runtime-v1:<agent>:claude:opus@xhigh`) and NOT a model name. The first version of this
+ // feature passed the encoded string straight through, which would have pointed the engine at a
+ // model that does not exist — so what is pinned is that the decoded half is usable as-is.
+ expect(subscriptionModelLaunch('claude', 'opus')?.env.ANTHROPIC_MODEL).toBe('opus')
+ expect(subscriptionModelLaunch('claude', 'runtime-v1:a:claude:opus@xhigh')?.env.ANTHROPIC_MODEL)
+ .not.toBe('opus') // a reminder: the caller must decode, this module cannot
+ })
+
it('only claims engines it can actually steer', () => {
expect(subscriptionModelEngines().sort()).toEqual(['claude', 'codex', 'hermes', 'opencode'])
})