Public: anyone can read this; the crew can change it.
A cell names the release it runs #16425
Check · Review · Land · Live done — Landed and live in production.
sold/cell-stamp → main 0 commits 2 threads · 2 unresolved
2 files
changed +56
−2
src/spawn/cell.ts +18 −2
| @@ -69,6 +69,7 @@ export const ownsBody = (bodyId: string): boolean => bodyId.startsWith(CELL_PREF | ||
| 69 | 69 | // directly. |
| 70 | 70 | export { crewAtWork, nextRunDue } from "./child_runs.ts"; |
| 71 | 71 | import { childCrewAtWork, closeChildDb } from "./child_db.ts"; |
| 72 | import { running, UNSTAMPED, type Running } from "../kernel/version.ts"; | |
| 72 | 73 | |
| 73 | 74 | /** |
| 74 | 75 | * How long a child forge told to go has to drain and mark its start clean |
| @@ -226,7 +227,7 @@ export function cellSpecFor(input: { | ||
| 226 | 227 | * its cgroup's directory (when the kernel holds the caps) let it read its own |
| 227 | 228 | * use against its size (`selfUse`, `spawn/usage.ts`; #10853). |
| 228 | 229 | */ |
| 229 | export function cellEnv(input: { port: number; dataDir: string; url: string; parentPort?: number; size?: Size; cgroupDir?: string; claude?: string }): Record<string, string> { | |
| 230 | export function cellEnv(input: { port: number; dataDir: string; url: string; parentPort?: number; size?: Size; cgroupDir?: string; claude?: string; stamp?: Stamp }): Record<string, string> { | |
| 230 | 231 | const env = childEnv({ |
| 231 | 232 | PORT: String(input.port), |
| 232 | 233 | FORGE_HOST: "127.0.0.1", |
| @@ -241,12 +242,27 @@ export function cellEnv(input: { port: number; dataDir: string; url: string; par | ||
| 241 | 242 | // Which Claude Code its crew runs: the parent's own choice, a path and not |
| 242 | 243 | // a secret, so a test can put a stand-in in the cell (#12001). |
| 243 | 244 | ...(input.claude === undefined || input.claude === "" ? {} : { FORGE_AGENT_RUNNER: input.claude }), |
| 245 | // Which release it runs, so its health, MCP initialize and the parent can say so (an unstamped | |
| 246 | // cell answered "dev" and left serverInfo.version out, which left every cell's Talk toolless). | |
| 247 | ...(input.stamp?.version === undefined ? {} : { FORGE_VERSION: input.stamp.version }), | |
| 248 | ...(input.stamp?.commit === undefined ? {} : { FORGE_COMMIT: input.stamp.commit }), | |
| 244 | 249 | }); |
| 245 | 250 | delete env["USER"]; |
| 246 | 251 | delete env["LOGNAME"]; |
| 247 | 252 | return env; |
| 248 | 253 | } |
| 249 | 254 | |
| 255 | /** The release a cell runs: the parent's own stamp on the parent's code; the commit alone on its own code. */ | |
| 256 | export interface Stamp { | |
| 257 | readonly version?: string; | |
| 258 | readonly commit?: string; | |
| 259 | } | |
| 260 | ||
| 261 | export function stampFor(source: Pick<CodeSource, "kind" | "commit">, parent: Running = running()): Stamp { | |
| 262 | if (source.kind === "parent") return { ...(parent.version === UNSTAMPED ? {} : { version: parent.version }), ...(parent.commit === null ? {} : { commit: parent.commit }) }; | |
| 263 | return source.commit === undefined || source.commit === "" ? {} : { commit: source.commit }; | |
| 264 | } | |
| 265 | ||
| 250 | 266 | /** |
outdated
stampFor is the logic that decides what a cell announces, and the tests only reach it by calling it directly. Add cases for last-good, an own source with an empty commit, and a parent with only one of version or commit. Add one test that the spawned env carries the stamp, so that dropping |
||
| 251 | 267 | * What a child is started with: `cellEnv`, plus the parent's runner (`FORGE_AGENT_RUNNER`, or the |
| 252 | 268 | * older `FORGE_CLAUDE`) when it has one. The child's crew reads it (`main.ts`), so a parent run |
| @@ -548,7 +564,7 @@ export function makeRegistry(parent: App, launcher?: Launcher): CellChildren { | ||
| 548 | 564 | const command = childCommand(process.execPath, source.main); |
| 549 | 565 | const { proc, unfollow } = spawnInCell(cell, command, { |
| 550 | 566 | cwd: dirname(source.main), |
| 551 | env: childEnvFor({ port, dataDir: dir, url, parentPort, size: input.size, ...(cell.cgroupDir === undefined ? {} : { cgroupDir: cell.cgroupDir }) }), | |
| 567 | env: childEnvFor({ port, dataDir: dir, url, parentPort, size: input.size, stamp: stampFor(source), ...(cell.cgroupDir === undefined ? {} : { cgroupDir: cell.cgroupDir }) }), | |
| 552 | 568 | }, log); |
| 553 | 569 | const exited = proc.exited.then((code) => { |
| 554 | 570 | unfollow(); |
test/cell-stamp.test.ts added +38
| @@ -0,0 +1,38 @@ | ||
| 1 | import { expect, test } from "bun:test"; | |
| 2 | import { cellEnv, stampFor } from "../src/spawn/cell.ts"; | |
| 3 | ||
| 4 | // The f2f cells (2026-11-25) answered version "dev" with no commit: unstamped, their MCP initialize | |
| 5 | // left serverInfo.version out and Talk on every cell had no tools. A cell names the release it runs. | |
| 6 | const parent = { version: "0.7.661", commit: "a".repeat(40) }; | |
| 7 | ||
| 8 | test("a cell on the parent's code carries the parent's version and commit", () => { | |
| 9 | const env = cellEnv({ port: 1, dataDir: "/d", url: "https://c.example", stamp: stampFor({ kind: "parent" }, parent) }); | |
| 10 | expect(env.FORGE_VERSION).toBe("0.7.661"); | |
| 11 | expect(env.FORGE_COMMIT).toBe("a".repeat(40)); | |
| 12 | }); | |
| 13 | ||
| 14 | test("a cell on its own code carries that commit and no version it does not run", () => { | |
| 15 | const env = cellEnv({ port: 1, dataDir: "/d", url: "https://c.example", stamp: stampFor({ kind: "own", commit: "b".repeat(40) }, parent) }); | |
| 16 | expect(env.FORGE_COMMIT).toBe("b".repeat(40)); | |
| 17 | expect(env.FORGE_VERSION).toBeUndefined(); | |
| 18 | }); | |
| 19 | ||
| 20 | test("an unstamped parent stamps nothing rather than a false release", () => { | |
| 21 | const env = cellEnv({ port: 1, dataDir: "/d", url: "https://c.example", stamp: stampFor({ kind: "parent" }, { version: "dev", commit: null }) }); | |
| 22 | expect(env.FORGE_VERSION).toBeUndefined(); | |
| 23 | expect(env.FORGE_COMMIT).toBeUndefined(); | |
| 24 | }); | |
| 25 | ||
| 26 | test("a cell on its last good code carries that commit, like its own", () => { | |
| 27 | expect(stampFor({ kind: "last-good", commit: "c".repeat(40) }, parent)).toEqual({ commit: "c".repeat(40) }); | |
| 28 | }); | |
| 29 | ||
| 30 | test("own code with no recorded commit stamps nothing", () => { | |
| 31 | expect(stampFor({ kind: "own", commit: "" }, parent)).toEqual({}); | |
| 32 | expect(stampFor({ kind: "own" }, parent)).toEqual({}); | |
| 33 | }); | |
| 34 | ||
| 35 | test("a parent stamped with only a version, or only a commit, passes only what it has", () => { | |
| 36 | expect(stampFor({ kind: "parent" }, { version: "0.7.661", commit: null })).toEqual({ version: "0.7.661" }); | |
| 37 | expect(stampFor({ kind: "parent" }, { version: "dev", commit: "d".repeat(40) })).toEqual({ commit: "d".repeat(40) }); | |
| 38 | }); |
new above
offline
This block lands between childEnvFor's doc comment (the lines just above, about the runner the child's crew reads) and childEnvFor itself. The original comment is now orphaned and describes Stamp. Move Stamp and stampFor above that comment or below childEnvFor.