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(grid): the Model Manager needs a grid that knows --no-wake; typed --json refusals; stale comments (#1322)

Kelvin5ef007a56617
diff --git a/cli/src/lib/gridEnvelope.spec.ts b/cli/src/lib/gridEnvelope.spec.ts
new file mode 100644
index 000000000..7859a4d91
--- /dev/null
+++ b/cli/src/lib/gridEnvelope.spec.ts
@@ -0,0 +1,58 @@
+/**
+ * `grid --json`'s refusal envelope, read off a stderr it shares with everything else `grid` writes. Each
+ * envelope below is built as the contract's `CliErrorEnvelope` (`gridProtocol.ts`, grid-protocol `cli-error`),
+ * so an envelope the contract reshapes fails `tsc` here as well as where it is read.
+ */
+import { describe, expect, it } from 'vitest'
+import { gridEnvelopes } from './gridEnvelope.js'
+import { GRID_ASLEEP_CODE, type CliErrorEnvelope } from './gridProtocol.js'
+
+const line = (error: CliErrorEnvelope['error']): string => JSON.stringify({ error } satisfies CliErrorEnvelope)
+
+describe('gridEnvelopes', () => {
+ it('reads the code a program compares and the sentence a person is shown, among the lines beside them', () => {
+ const asleep = line({ code: GRID_ASLEEP_CODE, message: 'Grid team is asleep: this grid is resting', status: 503 })
+ const stderr = `${asleep}\nGrid team is asleep: this grid is resting\n`
+
+ expect(gridEnvelopes(stderr)).toEqual([{ code: GRID_ASLEEP_CODE, message: 'Grid team is asleep: this grid is resting' }])
+ })
+
+ it('keeps every envelope, in the order written', () => {
+ const first = line({ code: null, message: 'first', status: null })
+ const second = line({ code: 'second_code', message: 'second', status: 400 })
+
+ expect(gridEnvelopes(`warning: something\n${first}\n${second}\n`)).toEqual([
+ { code: null, message: 'first' },
+ { code: 'second_code', message: 'second' },
+ ])
+ })
+
+ it('reads a code that is not a string, and a sentence with nothing displayable left, as none', () => {
+ const odd = JSON.stringify({ error: { code: 7, message: ' \n\t ', status: 400 } })
+ const bare = JSON.stringify({ error: {} })
+
+ expect(gridEnvelopes(`${odd}\n${bare}\n`)).toEqual([{ code: null, message: null }, { code: null, message: null }])
+ })
+
+ it('leaves the code exactly as sent, and makes the sentence safe for a screen and bounded', () => {
+ const noisy = `one\u001b[2Jtwo‮three${'x'.repeat(700)}`
+ const [read] = gridEnvelopes(line({ code: ' grid_asleep ', message: noisy, status: 503 }))
+
+ expect(read?.code).toBe(' grid_asleep ')
+ expect(read?.message?.startsWith('one [2Jtwo three')).toBe(true)
+ expect(Array.from(read?.message ?? '')).toHaveLength(600)
+ expect(read?.message?.endsWith('…')).toBe(true)
+ })
+
+ it('skips what is not an envelope: plain text, broken JSON, an array, an error that is not an object', () => {
+ const stderr = [
+ 'grid: error: unrecognized arguments: --no-wake',
+ '{"error": {"code": "grid_asleep"',
+ '[{"error": {"code": "grid_asleep"}}]',
+ JSON.stringify({ error: 'grid_asleep' }),
+ JSON.stringify({ detail: 'asleep', code: GRID_ASLEEP_CODE }),
+ ].join('\n')
+
+ expect(gridEnvelopes(stderr)).toEqual([])
+ })
+})
diff --git a/cli/src/lib/gridEnvelope.ts b/cli/src/lib/gridEnvelope.ts
index 972960cf4..e40f6129b 100644
--- a/cli/src/lib/gridEnvelope.ts
+++ b/cli/src/lib/gridEnvelope.ts
@@ -1,11 +1,17 @@
/**
- * The refusal envelope `grid --json` writes on stderr beside its plain sentence, one JSON line:
- * `{"error": {"code", "message", "status"}}` (autonomous-grid `cli/json_error.py`). Grid reads compare
- * its `code` (`gridReader.ts`); the sign-in hand-off shows its `message` (`gridHandoff.ts`). ⚠️ That
- * message is a subprocess's text on a person's screen, so control characters become spaces and it is
- * bounded; the `code` is compared, never shown, and is left exactly as sent.
+ * The refusal envelope `grid --json` writes on stderr beside its plain sentence, one JSON line: the
+ * contract's `CliErrorEnvelope` (`gridProtocol.ts`, grid-protocol `cli-error`), whose names are read here
+ * through it. Grid reads compare its `code` (`gridReader.ts`); the sign-in hand-off shows its `message`
+ * (`gridHandoff.ts`). ⚠️ That message is a subprocess's text on a person's screen, so control characters
+ * become spaces and it is bounded; the `code` is compared, never shown, and is left exactly as sent.
*/
-export interface GridEnvelope { code: string | null; message: string | null }
+import type { CliErrorEnvelope } from './gridProtocol.js'
+import type { Unchecked } from './gridUnchecked.js'
+
+type CliError = CliErrorEnvelope['error']
+
+/** One envelope as read: its `code`, and its `message` once displayable — null when none was left. */
+export interface GridEnvelope { code: CliError['code']; message: CliError['message'] | null }
/** Fits `grid`'s rendering of a control-plane refusal (request line ~70 + ≤400 chars of reply). */
const MAX_MESSAGE_CHARS = 600
@@ -27,7 +33,10 @@ export function gridEnvelopes(stderr: string): GridEnvelope[] {
return stderr.split('\n').flatMap((line) => {
let parsed: unknown
try { parsed = line.trim().startsWith('{') ? JSON.parse(line.trim()) : null } catch { return [] }
- const error = isObject(parsed) && isObject(parsed.error) ? parsed.error : null
- return error ? [{ code: typeof error.code === 'string' ? error.code : null, message: displayable(error.message) }] : []
+ if (!isObject(parsed)) return []
+ const envelope: Unchecked<CliErrorEnvelope> = parsed
+ if (!isObject(envelope.error)) return []
+ const error: Unchecked<CliError> = envelope.error
+ return [{ code: typeof error.code === 'string' ? error.code : null, message: displayable(error.message) }]
})
}
diff --git a/cli/src/lib/gridExec.ts b/cli/src/lib/gridExec.ts
index 3e335da87..96f9bee6a 100644
--- a/cli/src/lib/gridExec.ts
+++ b/cli/src/lib/gridExec.ts
@@ -34,6 +34,11 @@ export { GRID_BINARY, GRID_NO_UPDATE_CHECK_VAR, gridAvailable, gridBinaryPath, g
* `3286163`, 2026-09-04). An older binary answers argparse's exit 2, which the hand-off already
* reads as OUTDATED; this constant is what lets every OTHER call say so in one sentence instead of
* each one rediscovering it.
+ *
+ * Two arguments are newer, deliberately without raising it: `mcp config --json` (0.3.42,
+ * `gridMcpUrl.ts`) and `--no-wake` (0.3.49, `gridReader.readViaCli`). Each is an extra that reads an
+ * older `grid`'s exit 2 as "no web tools" or "no read", and never retries without the flag; raising
+ * the floor would instead refuse the harness grid itself to a `grid` that can sign in and serve.
*/
export const GRID_VERSION_FLOOR = '0.3.36'
diff --git a/cli/src/lib/gridLaunch.spec.ts b/cli/src/lib/gridLaunch.spec.ts
index 769f45e9a..f74b76b42 100644
--- a/cli/src/lib/gridLaunch.spec.ts
+++ b/cli/src/lib/gridLaunch.spec.ts
@@ -779,9 +779,9 @@ describe('web tools (grid ADR 0041)', () => {
it("takes Claude Code's built-in web tools away on every grid launch, web tools or not", () => {
// `WebSearch` is an Anthropic SERVER tool (`web_search_20250305`) that no grid runs, and
- // `WebFetch` summarises through a haiku call on the same base URL, which the relay answers
- // `503 no_providers_available`. Both are dead on a grid, with or without a replacement, and a
- // model offered a dead tool reaches for it first.
+ // `WebFetch` summarises through a haiku call on the same base URL, which the relay refuses
+ // (`404 model_not_found`, or `503 no_providers_available` on a grid with no engine yet). Both are
+ // dead on a grid, with or without a replacement, and a model offered a dead tool reaches for it first.
for (const override of [OVERRIDE, WITH_MODEL, WITH_MCP]) {
expect(launchOf('claude', override).args).toContain('--disallowedTools=WebSearch,WebFetch')
}
diff --git a/cli/src/lib/gridPicture.ts b/cli/src/lib/gridPicture.ts
index 96486f58b..2d26af688 100644
--- a/cli/src/lib/gridPicture.ts
+++ b/cli/src/lib/gridPicture.ts
@@ -38,7 +38,10 @@ const MIN_ABSENT_READS = 2
* [MIN_ABSENT_READS] answers, not [GRID_MODEL_RETENTION_MS]. Without this, a model stopped on another
* computer stayed in this one's Shared with you for over two minutes, offered and failing (only the
* computer that stopped it knows at once: `provenStopped`). Three awake memos (15s each), so one slow look
- * between them still counts as the grid answering throughout.
+ * between them still counts as the grid answering throughout. A master's respawn or takeover is no wake
+ * either: the overview lists nodes by their last heartbeat in the grid's database, inside the node TTL, so a
+ * new master's first answer lists what the old one's last did; the seconds of 502/503 between them read as
+ * unknown, after which the full [GRID_MODEL_RETENTION_MS] applies.
*/
const AWAKE_CONTINUITY_MS = 45_000
diff --git a/cli/src/lib/gridReader.ts b/cli/src/lib/gridReader.ts
index b30d43c19..98c28d3f6 100644
--- a/cli/src/lib/gridReader.ts
+++ b/cli/src/lib/gridReader.ts
@@ -32,6 +32,7 @@ import {
type GridOverview, type LastKnown as WireLastKnown, type LastKnownNode, type NodeModelCapability,
type OverviewModel, type OverviewNode, type ProviderDiscovery,
} from './gridProtocol.js'
+import type { Unchecked } from './gridUnchecked.js'
/** The owner status of a grid the platform's reaper slept (grid-apis `grid_sleep_state.ASLEEP`), as
* `grid info --json` passes it through. Only the grid's owner sees a status at all. */
@@ -90,10 +91,6 @@ export type GridRead =
| { kind: 'unreachable' }
type Json = Record<string, unknown>
-/** An object off the wire: the contract's key names — so a renamed field fails `tsc` here — with every value
- * still unchecked. The generated types keep an index signature (a newer server may add keys), which would
- * erase the names from `keyof`, so the declared keys are picked out first. */
-type Unchecked<T> = { [K in keyof T as string extends K ? never : number extends K ? never : K]?: unknown }
const isObject = (value: unknown): value is Json => !!value && typeof value === 'object' && !Array.isArray(value)
const text = (value: unknown): string =>
typeof value === 'string' ? value.replace(/[\u0000-\u001f\u007f]/g, ' ').trim().slice(0, MAX_TEXT) : ''
diff --git a/cli/src/lib/gridUnchecked.ts b/cli/src/lib/gridUnchecked.ts
new file mode 100644
index 000000000..7eae9e49d
--- /dev/null
+++ b/cli/src/lib/gridUnchecked.ts
@@ -0,0 +1,6 @@
+/**
+ * An object off the wire: the contract's key names (`gridProtocol.ts`) — so a renamed field fails `tsc` where
+ * it is read — with every value still unchecked. The generated types keep an index signature (a newer server
+ * may add keys), which would erase the names from `keyof`, so the declared keys are picked out first.
+ */
+export type Unchecked<T> = { [K in keyof T as string extends K ? never : number extends K ? never : K]?: unknown }
diff --git a/cli/src/lib/gridWebMcp.ts b/cli/src/lib/gridWebMcp.ts
index e1b6ffb6f..9e852bb42 100644
--- a/cli/src/lib/gridWebMcp.ts
+++ b/cli/src/lib/gridWebMcp.ts
@@ -108,10 +108,11 @@ export function mcpServersConfig(mcpUrl: string, keyVar: string): string {
* wire, `_reject_server_tools` in `shared/agent/cli_seat.py`) and the pane prints `API Error: 400
* Unsupported tool type: web_search_20250305`.
* * `WebFetch` DOES fetch the page from this machine — and then summarises it through a haiku call
- * on the SAME base URL. The grid's relay serves only the models its nodes run and answers any
- * other name `503 no_providers_available` (grid-src `private_server/relay.py`; only the reserved
- * `auto` is routed), so the fetch succeeds and the tool still fails. An earlier version of this
- * comment left `WebFetch` enabled on the belief that a local fetch made it safe; it does not.
+ * on the SAME base URL. The grid's relay serves only the models its nodes run (only the reserved
+ * `auto` is routed), and refuses a name none of its engines ever served at once with `404
+ * model_not_found` (grid-protocol 0.1.1 `ModelNotFound`; a grid that has never had an engine says
+ * `503 no_providers_available`), so the fetch succeeds and the tool still fails. An earlier version
+ * of this comment left `WebFetch` enabled on the belief that a local fetch made it safe; it does not.
*
* The cost is not the failed calls: a model offered a familiar dead tool reaches for it FIRST, spends
* turns on the refusal, and only then finds `mcp__harness__web_search`, the search the grid actually
diff --git a/store/agents/autonomous-grid/VERSIONS b/store/agents/autonomous-grid/VERSIONS
index 54b751c75..fd01dbd26 100644
--- a/store/agents/autonomous-grid/VERSIONS
+++ b/store/agents/autonomous-grid/VERSIONS
@@ -1,4 +1,7 @@
-# Runtime floor matches Harness's managed Grid runtime. Fallback installs this exact upstream.
-GRID_MIN_VERSION="0.3.47"
+# Runtime floor: the oldest public Grid whose argparse takes every argument this package passes. That is
+# --no-wake (0.3.49), which every automatic read of a remote grid carries: an older Grid refuses them all.
+# Never above Harness's managed Grid pin, which setup would then refuse.
+# Fallback installs this exact upstream: the commit Grid 0.3.49 was released from (tag v0.3.49).
+GRID_MIN_VERSION="0.3.49"
UPSTREAM_REPO="https://github.com/autonomous-ai/autonomous-grid.git"
-UPSTREAM_COMMIT="0b8d0e34109735ffd73aadf7288120451cc436fc"
+UPSTREAM_COMMIT="9fd7045a25efd0ac002213481b010ed339f3d99c"
diff --git a/store/agents/autonomous-grid/skills/grid-operations/SKILL.md b/store/agents/autonomous-grid/skills/grid-operations/SKILL.md
index f5287868c..e53d40052 100644
--- a/store/agents/autonomous-grid/skills/grid-operations/SKILL.md
+++ b/store/agents/autonomous-grid/skills/grid-operations/SKILL.md
@@ -213,8 +213,8 @@ sets `enable_thinking:false` at startup — needed, because a zero budget alone
every token thinking [run]. `--thinking on` enables it; either applies only to a new start.
**6. Prove it answers — once, bounded.** A successful `join` means *starting*, not ready. First wait
-for the relay to list it (a call before that answers `No providers available for this model`, which
-is "not yet", not "broken"):
+for the relay to list it (a call before that answers `No providers available for this model`, or
+`model_not_found` on a grid that has served other models, which is "not yet", not "broken"):
# engine on this computer: its own checks first, then the relay
"$GRID_FLEET" verify --at http://127.0.0.1:PORT/v1 --model MODEL_ALIAS --kind llama.cpp --grid GRID --alias MODEL_ALIAS
@@ -299,8 +299,8 @@ Say what failed and stop; translate every message, never repeat a raw line that
then `"$GRID_FLEET" init`, then the step again. Never `grid login`: it is a second sign-in. Only
`harness grid setup` saying this computer is not signed in to Harness is theirs: `harness login`,
the only command ever theirs.
- - **`No providers available for this model`** right after a join → not registered yet; wait as
- step 6 says.
+ - **`No providers available for this model`** right after a join, or `model_not_found` (404) on a
+ grid that has served other models → not registered yet; wait as step 6 says.
- **`exceeds the available context size`** (an agent may show it as a garbled "expected array
`choices`") → served with too small a window: leave, and join again with the longest context
that fits (step 5) — never under 64K.
diff --git a/store/agents/autonomous-grid/test/nowake.test.mjs b/store/agents/autonomous-grid/test/nowake.test.mjs
index 359926d10..08de7ec34 100644
--- a/store/agents/autonomous-grid/test/nowake.test.mjs
+++ b/store/agents/autonomous-grid/test/nowake.test.mjs
@@ -3,9 +3,10 @@
// the last reading on screen, and a hidden page stops listening.
import test from 'node:test';
import assert from 'node:assert/strict';
-import { mkdtemp, readFile, rm } from 'node:fs/promises';
+import { cp, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
+import { execFile } from 'node:child_process';
import { tmpdir } from 'node:os';
-import { join } from 'node:path';
+import { dirname, join } from 'node:path';
import { runInNewContext } from 'node:vm';
import { atomicJson, gridJson, PACKAGE, stateDir } from '../lib/fleet.mjs';
import { assemble, createCollector } from '../lib/telemetry.mjs';
@@ -176,3 +177,40 @@ test('a fresh workspace probes with --no-wake and takes a sleeping own grid as a
const probes=calls.filter(c=>c[1]==='engines');
assert.ok(probes.length>0);for(const probe of probes)assert.ok(probe.includes('--no-wake'),probe.join(' '));
});
+
+/** A package script run as the person's agent runs it, against one fake `grid`, and its exit status. */
+const script=(file,args,grid,dir,root=PACKAGE)=>new Promise(done=>execFile(file,args,{cwd:root,env:{...process.env,
+ PATH:`${dirname(process.execPath)}:${process.env.PATH}`,HARNESS_GRID_BIN:grid,ADAPTER_RUNTIME_DIR:join(dir,'runtime')}},
+ (error,stdout,stderr)=>done({code:error?error.code:0,out:`${stdout}${stderr}`})));
+
+// setup.sh asks for Node >= 22 first (harness_node 22, the package's engines), on the Node running this test.
+const belowSetupNode=Number(process.versions.node.split('.')[0])<22&&`setup.sh needs Node >= 22; this run is on ${process.versions.node}`;
+
+test('setup and doctor take the first grid that knows --no-wake as the floor, and nothing older',{skip:belowSetupNode},async t=>{
+ const dir=await temporary(t),log=join(dir,'calls.json');
+ const old=await fakeGrid(dir,'grid-0.3.48',{verbs:{version:{stdout:'grid 0.3.48\n'}}},log);
+ const first=await fakeGrid(dir,'grid-0.3.49',{verbs:{version:{stdout:'grid 0.3.49\n'}}},log);
+ // Every automatic read of a remote grid carries NO_WAKE, so a grid that refuses it can never be read.
+ const refused=await script('bash',['toolchain/setup.sh'],old,dir);
+ assert.equal(refused.code,1,refused.out);assert.match(refused.out,/miss Grid >= 0\.3\.49\b/);
+ const doctored=await script(process.execPath,['toolchain/fleet.mjs','doctor'],old,dir);
+ assert.equal(doctored.code,1,doctored.out);assert.match(doctored.out,/Grid >= 0\.3\.49 is required/);
+ // The positive control: the same scripts, one release on, pass.
+ const ok=await script('bash',['toolchain/setup.sh'],first,dir);
+ assert.equal(ok.code,0,ok.out);assert.match(ok.out,/^ok {3}grid 0\.3\.49$/m);
+ const healthy=await script(process.execPath,['toolchain/fleet.mjs','doctor'],first,dir);
+ assert.equal(healthy.code,0,healthy.out);assert.match(healthy.out,/^ok {3}Grid 0\.3\.49$/m);
+});
+
+test('doctor reads the floor however the shell would, and says so when VERSIONS names none',async t=>{
+ const dir=await temporary(t),log=join(dir,'calls.json'),root=join(dir,'package');
+ const grid=await fakeGrid(dir,'grid-0.3.49',{verbs:{version:{stdout:'grid 0.3.49\n'}}},log);
+ for(const part of ['lib','toolchain'])await cp(join(PACKAGE,part),join(root,part),{recursive:true});
+ // Unquoted is the same value to setup.sh, which sources the file.
+ await writeFile(join(root,'VERSIONS'),'GRID_MIN_VERSION=0.3.50\n');
+ const above=await script(process.execPath,['toolchain/fleet.mjs','doctor'],grid,dir,root);
+ assert.equal(above.code,1,above.out);assert.match(above.out,/Grid >= 0\.3\.50 is required/);
+ await writeFile(join(root,'VERSIONS'),'GRID_MIN=0.3.49\n');
+ const none=await script(process.execPath,['toolchain/fleet.mjs','doctor'],grid,dir,root);
+ assert.equal(none.code,1,none.out);assert.match(none.out,/VERSIONS names no GRID_MIN_VERSION/);assert.doesNotMatch(none.out,/TypeError|null/);
+});
diff --git a/store/agents/autonomous-grid/toolchain/fleet.mjs b/store/agents/autonomous-grid/toolchain/fleet.mjs
index b727c988f..861babc91 100644
--- a/store/agents/autonomous-grid/toolchain/fleet.mjs
+++ b/store/agents/autonomous-grid/toolchain/fleet.mjs
@@ -1,7 +1,7 @@
#!/usr/bin/env node
import { createLog, verifyEngine, verifyModel, verifyRelay, relayOnlyRefusal } from '../lib/verify.mjs';
import { join, resolve } from 'node:path';
-import { atomicJson, DEFAULT_CONFIG, execute, gridJson, harnessNameFor, nameJoin, readConfig, runTracked } from '../lib/fleet.mjs';
+import { atomicJson, DEFAULT_CONFIG, execute, gridJson, harnessNameFor, nameJoin, PACKAGE, readConfig, runTracked } from '../lib/fleet.mjs';
import { createCollector } from '../lib/telemetry.mjs';
import { discoverMachines } from '../lib/harness.mjs';
import { inventory, machineState, summarize } from '../lib/inventory.mjs';
@@ -38,10 +38,15 @@ try {
if(args.length && !(args.length===1 && args[0]==='--json')) throw new Error('Use: fleet status [--json]');
console.log(JSON.stringify(await readStatus(workspace),null,2));
} else if (command === 'doctor') {
+ // The floor setup.sh holds Grid to, read from VERSIONS so the two cannot disagree — quoted or not, as the
+ // shell that sources it would take it.
+ const { readFile } = await import('node:fs/promises');
+ const floor = (await readFile(join(PACKAGE, 'VERSIONS'), 'utf8')).match(/^GRID_MIN_VERSION=(["']?)(\d+\.\d+\.\d+)\1\s*$/m)?.[2];
+ if (!floor) throw new Error(`${join(PACKAGE, 'VERSIONS')} names no GRID_MIN_VERSION="X.Y.Z", so the Grid floor is unknown. Reinstall this package.`);
const result = await execute({ transport: 'local' }, ['version']);
const version = result.stdout.match(/\d+\.\d+\.\d+/)?.[0];
- const [a=0,b=0,c=0] = (version || '').split('.').map(Number);
- if (!result.ok || !(a > 0 || b > 3 || (b === 3 && c >= 47))) throw new Error('Grid >= 0.3.47 is required. Run toolchain/setup.sh or update the selected Harness runtime.');
+ const [a=0,b=0,c=0] = (version || '').split('.').map(Number), [x,y,z] = floor.split('.').map(Number);
+ if (!result.ok || !(a > x || (a === x && (b > y || (b === y && c >= z))))) throw new Error(`Grid >= ${floor} is required. Run toolchain/setup.sh or update the selected Harness runtime.`);
console.log(`ok Grid ${version}\nok Node ${process.versions.node}\nok local fleet viewer\ninfo Paired Harness machines use encrypted connections; SSH targets use existing keys`);
} else if (command === 'discover') {
if (args.length && (args.length !== 1 || args[0] !== '--add')) throw new Error('Use: fleet discover [--add]');