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.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
fix(grid): a probe that could not look is not a probe that found nothing
bubu-dudu97e61a2761fd
diff --git a/cli/src/lib/gridAssignment.spec.ts b/cli/src/lib/gridAssignment.spec.tsindex be17d79bf..26b380003 100644--- a/cli/src/lib/gridAssignment.spec.ts+++ b/cli/src/lib/gridAssignment.spec.ts@@ -2,7 +2,7 @@ import { afterEach, describe, expect, it } from 'vitest'import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'import { tmpdir } from 'node:os'import { join } from 'node:path'-import { assignmentMatches, classifyGridAssignment, readOpencodeGridAssignment, readPiGridAssignment } from './gridAssignment.js'+import { assignmentMatches, classifyGridAssignment, probeGridAssignment, readOpencodeGridAssignment, readPiGridAssignment } from './gridAssignment.js'import { buildGridEngineLaunch, gridCapableEngines, type GridLaunchOverride } from './gridLaunch.js'import { clearProcessEnvCache, parsePsEnviron } from './processEnv.js'@@ -250,3 +250,30 @@ describe('readOpencodeGridAssignment', () => {await expect(readOpencodeGridAssignment({})).resolves.toBeNull()})})++describe('a failed read is not a finding', () => {+ // The flicker this pins: the app's grid pill swapped between an agent's model and "own login" for+ // the length of every turn. Each probe whose `ps` did not answer in time reported "on no grid",+ // the registry wrote that over a known-good assignment, and the next successful probe put it back.+ //+ // The distinction is the fix, not the failure rate. A read can fail for reasons this code will+ // never enumerate — a busy machine, a 2s timeout, a process caught mid-exec — and none of them are+ // evidence about where an agent is pointed.+ const DEAD_PID = 2 ** 31 - 1++ it('answers undefined when the environment cannot be read at all', async () => {+ clearProcessEnvCache()+ await expect(probeGridAssignment(+ { pid: DEAD_PID, executable: 'opencode', startMarker: 'Mon Jan 1 00:00:00 2035' },+ 'opencode',+ )).resolves.toBeUndefined()+ })++ it('is distinguishable from a read that found no grid', () => {+ // Same call shape, opposite meaning: this one looked and there was nothing.+ expect(classifyGridAssignment('claude', { PATH: '/usr/bin' })).toBeNull()+ // `null == undefined` is true, so only a strict check tells these apart — which is exactly what+ // `openProcessAgent` and `updateProcessIdentity` do.+ expect(classifyGridAssignment('claude', { PATH: '/usr/bin' })).not.toBeUndefined()+ })+})diff --git a/cli/src/lib/gridAssignment.ts b/cli/src/lib/gridAssignment.tsindex 24102db3d..9bd63d78f 100644--- a/cli/src/lib/gridAssignment.ts+++ b/cli/src/lib/gridAssignment.ts@@ -180,18 +180,29 @@ export async function readOpencodeGridAssignment(/*** Read one live engine process's grid.*- * Null covers both "not on a grid" and "could not look", deliberately: the caller renders an agent- * whose assignment is unknown the same as one with none, which at worst offers a move that turns out- * to be a no-op. The opposite error — claiming an agent is already on the right grid when nobody- * checked — would leave it quietly running somewhere else.+ * **Three answers, not two.** `null` is a finding — this process was read and is on no grid.+ * `undefined` is the absence of one: the environment could not be read at all, so there is nothing to+ * report. They were the same value until the app's grid pill was seen flickering between an agent's+ * model and "own login" for the length of every turn: each failed read overwrote a known-good+ * assignment with "on no grid", and the next successful one put it back.+ *+ * The reads that fail are ordinary — `ps eww` carries a 2s timeout and a discovery sweep runs one per+ * agent while the machine is busy answering. Which of them fails does not matter, and chasing that+ * was the wrong instinct: what matters is that failing to look must not erase what was already seen.+ * A process's environment cannot change under it (see `processEnv.ts`), so an earlier successful read+ * of THIS process stays true.+ *+ * `gateway` in the same registry has worked this way all along — `undefined` there means "the probe+ * failed" and leaves the stored value alone. Both `openProcessAgent` and `updateProcessIdentity`+ * already guard on `!== undefined`; the grid simply never used it.*/export async function probeGridAssignment(identity: ProcessIdentity,engine: AgentEngine,args = '',-): Promise<GridAssignment | null> {+): Promise<GridAssignment | null | undefined> {const processEnv = await readProcessEnv(identity)- if (!processEnv) return null+ if (!processEnv) return undefined// The two engines whose provider lives in a file this daemon wrote, rather than in a variable.if (engine === 'pi') return await readPiGridAssignment(processEnv, args)if (engine === 'opencode') return await readOpencodeGridAssignment(processEnv)diff --git a/cli/src/lib/tmuxAgentDiscovery.ts b/cli/src/lib/tmuxAgentDiscovery.tsindex 1da406c38..88d6d5459 100644--- a/cli/src/lib/tmuxAgentDiscovery.ts+++ b/cli/src/lib/tmuxAgentDiscovery.ts@@ -48,8 +48,9 @@ export interface DiscoveredTmuxAgent {*/gateway?: 'ori' | null/**- * The grid this pane's engine is actually talking to, read off the same environment. null = a normal- * vendor login, or the read failed; see `gridAssignment.ts` for why those share an answer.+ * The grid this pane's engine is actually talking to, read off the same environment. `null` = read,+ * and on no grid. `undefined` = could not be read, which must NOT overwrite a stored assignment —+ * see `probeGridAssignment`.*/grid?: GridAssignment | null}