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.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(project-settings): timed-out launch-info fetch retries + agents nothing-to-gate pin
enes9a72e21fb153
diff --git a/src/core/project-launch-info-handlers.ts b/src/core/project-launch-info-handlers.tsindex d6a537325..6dce93f57 100644--- a/src/core/project-launch-info-handlers.ts+++ b/src/core/project-launch-info-handlers.ts@@ -39,6 +39,9 @@ export function registerProjectLaunchInfoHandlers(const info = workspaceStore.projectTargetInfo(projectId)const sharedDoc: ProjectSettingsDoc = snap.shared ?? {}const resolved = resolveProjectSettings(snap.local, snap.shared ?? undefined)+ // A cwd-less inline canvas falls to `localTrustKey('')` — inert by construction: such a+ // project has no shared document to have, so `sharedDoc` is always `{}` and every family's+ // `projectTrustContent` already returns null before this key is ever consulted.const key = info?.ssh? sshTrustKey({ server: info.ssh.server, remoteCwd: info.ssh.remoteCwd }): localTrustKey(info?.cwd ?? '')diff --git a/src/core/workspace-store.settings.test.ts b/src/core/workspace-store.settings.test.tsindex d6a794b5d..a3d35ab04 100644--- a/src/core/workspace-store.settings.test.ts+++ b/src/core/workspace-store.settings.test.ts@@ -406,6 +406,22 @@ describe('project-settings:launch-info', () => {expect(await fake.handlers['project-settings:launch-info']('nope')).toBeNull()})+ it('reports trusted.agents true when the SHARED doc has no launchCmd/env, even with a local agents overlay', async () => {+ const store = new WorkspaceStore()+ const trust = new ProjectTrustStore()+ registerProjectLaunchInfoHandlers(fake, store, trust)+ await store.save(ws([project({ cwd: projRoot })]))+ // A shared doc exists but never sets anything in the `agents` family — nothing executable to+ // gate — while this machine's own local overlay picks a launchCmd of its own (never gated: a+ // value the user typed locally is their own instruction, not hostile shared input).+ await store.writeProjectSettings('p1', { terminal: { shell: '/bin/zsh' } })+ await store.updateLocalProjectSettings('p1', { agents: { launchCmd: 'npm run dev' } })++ const info = (await fake.handlers['project-settings:launch-info']('p1')) as ProjectLaunchInfo+ expect(info.resolved.agents.launchCmd).toEqual({ value: 'npm run dev', source: 'local' })+ expect(info.trusted.agents).toBe(true)+ })+it('a shared change invalidates the OLD approval — trusted flips back to false', async () => {const store = new WorkspaceStore()const trust = new ProjectTrustStore()diff --git a/src/renderer/state/projectLaunchInfo.test.ts b/src/renderer/state/projectLaunchInfo.test.tsindex 2a75a2919..aa5713f88 100644--- a/src/renderer/state/projectLaunchInfo.test.ts+++ b/src/renderer/state/projectLaunchInfo.test.ts@@ -94,6 +94,35 @@ describe('ensureProjectLaunchInfo', () => {await vi.advanceTimersByTimeAsync(0)expect(projectLaunchInfoNow('p1')).toEqual(INFO)})++ // The wire call this project's first fetch is waiting on may NEVER answer at all — a dropped+ // Server Edition WS-RPC request neither times out nor rejects (permissionMode.ts's+ // `CAPS_WAIT_MS` doc). Without clearing the in-flight entry on timeout, every later `ensure`+ // for this project would just rejoin that exhausted promise and no fresh wire call would ever+ // be issued again.+ it('a timed-out fetch is retried on the NEXT ensure, and its late answer cannot clobber the retry', async () => {+ vi.useFakeTimers()+ let resolveStale!: (v: ProjectLaunchInfo | null) => void+ const staleInfo: ProjectLaunchInfo = { ...INFO, trusted: { agents: false, shell: true } }+ const freshInfo: ProjectLaunchInfo = { ...INFO, trusted: { agents: true, shell: true } }+ // Gated — never answers on its own until `resolveStale` is called.+ const fn = mockLaunchInfo(() => new Promise((r) => (resolveStale = r)))++ const first = ensureProjectLaunchInfo('p1')+ await vi.advanceTimersByTimeAsync(3000)+ await first // gave up waiting++ fn.mockImplementation(() => Promise.resolve(freshInfo))+ await ensureProjectLaunchInfo('p1') // must issue a SECOND wire call, not rejoin the first+ expect(fn).toHaveBeenCalledTimes(2)+ expect(projectLaunchInfoNow('p1')).toEqual(freshInfo)++ // The abandoned first fetch finally answers — its write must be discarded, never overwrite+ // the retry's fresher result (the generation guard).+ resolveStale(staleInfo)+ await vi.advanceTimersByTimeAsync(0)+ expect(projectLaunchInfoNow('p1')).toEqual(freshInfo)+ })})describe('invalidateProjectLaunchInfo', () => {diff --git a/src/renderer/state/projectLaunchInfo.ts b/src/renderer/state/projectLaunchInfo.tsindex f59c6d38e..215493d6d 100644--- a/src/renderer/state/projectLaunchInfo.ts+++ b/src/renderer/state/projectLaunchInfo.ts@@ -10,12 +10,22 @@ import type { ProjectLaunchInfo } from '@shared/project-settings'* for its own memo.** `cache`/`generation` are BOTH keyed by projectId so one project's invalidate never disturbs- * another's warm entry. `generation` exists solely to keep an ABANDONED fetch from clobbering a- * fresher one: `invalidateProjectLaunchInfo` bumps it and drops the in-flight entry so the next- * `ensure` starts a real new request, but the OLD request (already in flight) is not cancelled —- * only silenced. Its `.then` still runs and checks the generation before writing, so a slow answer- * from before the invalidate can never overwrite what a later fetch (or the invalidate itself)- * already settled on.+ * another's warm entry. `generation` is claimed FRESH by every fetch this module actually issues+ * (not merely bumped by `invalidate`): a write is honored only while its own claimed value is still+ * the current one. This closes two distinct ways an abandoned fetch can otherwise clobber a fresher+ * answer:+ * - `invalidateProjectLaunchInfo` bumps it directly and drops the in-flight entry, so an in-flight+ * fetch that predates the invalidate is superseded even if nothing ever re-`ensure`s.+ * - the ENSURE_WAIT_MS timeout (below) drops the in-flight entry WITHOUT touching the generation —+ * on its own, a fetch that never settles (a dropped Server Edition WS-RPC request neither times+ * out nor rejects — see permissionMode.ts's `CAPS_WAIT_MS` doc) would otherwise leave `inFlight`+ * pointing at an exhausted promise forever, so every later `ensure` for that project just+ * rejoins it and NO fresh wire call is ever made again. Dropping the entry lets the next `ensure`+ * issue a real new fetch, which claims its OWN generation — so if the original fetch finally+ * answers after that, its stale generation no longer matches and its write is silently dropped,+ * exactly like the invalidate case.+ * Neither path cancels the abandoned fetch (there is nothing to cancel it with) — only its write is+ * ever silenced, never the promise itself.*/const cache = new Map<string, { info: ProjectLaunchInfo | null; fetchedAt: number }>()const inFlight = new Map<string, Promise<void>>()@@ -29,6 +39,16 @@ function currentGeneration(projectId: string): number {return generation.get(projectId) ?? 0}+/** Claims and returns a generation strictly newer than whatever the project is currently at —+ * called once per fetch actually issued (never on a joined in-flight call), so two fetches for the+ * same project always hold distinguishable values regardless of which one (invalidate, timeout, or+ * a plain re-ensure) triggered the reissue. */+function claimGeneration(projectId: string): number {+ const next = currentGeneration(projectId) + 1+ generation.set(projectId, next)+ return next+}+/** The last-known answer, synchronously — null when nothing has been fetched yet (or the project* was never warmed, or the fetch itself found no shared executable content to gate at all: a* caller reading null must treat it as "no override behavior", i.e. fail open, exactly like an@@ -40,29 +60,45 @@ export function projectLaunchInfoNow(projectId: string): ProjectLaunchInfo | nul/*** Kick off (or join) the launch-info fetch for one project. Never rejects, and never takes longer* than `ENSURE_WAIT_MS` — on timeout the promise resolves with whatever is cached (possibly- * nothing), and a late answer still lands in `cache` for the NEXT read. Memoized per project: a- * second caller while one is already in flight joins the same promise rather than firing a second- * request.+ * nothing), and a late answer still lands in `cache` for the NEXT read PROVIDED nothing fresher+ * has claimed the project's generation since (see the module doc). Memoized per project: a second+ * caller while one is already in flight joins the same promise rather than firing a second request;+ * once a fetch's own in-flight entry is cleared (settled, or timed out), the NEXT caller always+ * issues a brand new wire call — a project is never left permanently cold by one dropped request.*/export function ensureProjectLaunchInfo(projectId: string): Promise<void> {const existing = inFlight.get(projectId)if (existing) return existing- const gen = currentGeneration(projectId)+ const gen = claimGeneration(projectId)const fetch = Promise.resolve().then(() => window.nodeTerminal.projectSettings.launchInfo(projectId)).then((info) => {- // A bump since this fetch started means `invalidateProjectLaunchInfo` (and likely a fresher- // `ensure`) ran while we were in flight — never let a stale answer land over it.+ // A newer claim since this fetch started means it was superseded (an invalidate, or this+ // very fetch having already been abandoned by a timeout and reissued) — never let a stale+ // answer land over whatever a fresher fetch already wrote.if (currentGeneration(projectId) === gen) cache.set(projectId, { info, fetchedAt: Date.now() })}).catch(() => {// Fail open: leave whatever is cached (possibly nothing) alone.})- const timeout = new Promise<void>((resolve) => setTimeout(resolve, ENSURE_WAIT_MS))- const bounded = Promise.race([fetch, timeout])- // Own in-flight entry cleared only by the request that owns it — an abandoned (invalidated)- // fetch's `finally` must not delete a NEWER fetch's entry out from under it.++ // `bounded` is referenced inside the timeout callback before its own declaration below — safe+ // because the callback only runs asynchronously, well after `bounded` is assigned.+ let bounded!: Promise<void>+ const timeout = new Promise<void>((resolve) => {+ setTimeout(() => {+ // The wire call may simply never answer (see the module doc). Clear OUR OWN in-flight entry+ // — guarded on identity, since a fetch that already finished (and cleared itself in the+ // `finally` below) may have already been superseded by a newer `ensure` by the time this+ // timer fires, and that newer entry must not be touched.+ if (inFlight.get(projectId) === bounded) inFlight.delete(projectId)+ resolve()+ }, ENSURE_WAIT_MS)+ })+ bounded = Promise.race([fetch, timeout])+ // Same identity guard as the timeout branch: a fetch that answers after ITS OWN timeout already+ // cleared (and possibly a newer fetch is now in flight) must not delete that newer entry.fetch.finally(() => {if (inFlight.get(projectId) === bounded) inFlight.delete(projectId)})