Public: anyone can read this; the crew can change it.
A funded child whose parent door is unreachable falls back silently to its own environment and its run is never counted #13777
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/13776-a-funded-child-whose-parent-door-is-unre → main 3 commits fork
3 files
changed +28
−2
src/crew/runner.ts +5
| @@ -2467,5 +2467,10 @@ export function credentialEnv(picked: Pick, dataDir?: string): Record<string, st | ||
| 2467 | 2467 | // forge's account too. |
| 2468 | 2468 | const lent = (picked.kind === "env" || picked.kind === "none") && dataDir !== undefined ? fundedEnv(dataDir) : undefined; |
| 2469 | 2469 | if (lent !== undefined) return lent; |
| 2470 | // Funded but the door is unreachable (FORGE_PARENT_LOCAL unset or invalid): falling back to the | |
| 2471 | // forge's own credential would spend off the host's counter (#13776). Refuse the run instead. | |
| 2472 | if ((picked.kind === "env" || picked.kind === "none") && dataDir !== undefined && fundingOf(dataDir) !== undefined) { | |
| 2473 | throw new Error("this forge is funded by its parent, but the parent's door (FORGE_PARENT_LOCAL) is unreachable: run refused"); | |
| 2474 | } | |
| 2470 | 2475 | return ownEnv(); |
| 2471 | 2476 | } |
test/child-credit.test.ts +13
| @@ -231,6 +231,19 @@ describe("a parent funds a child's crew", () => { | ||
| 231 | 231 | expect(env).toEqual({ ANTHROPIC_BASE_URL: parentLocal(door.port), ANTHROPIC_API_KEY: f.token }); |
| 232 | 232 | expect(JSON.stringify(env)).not.toContain(PARENT_KEY); |
| 233 | 233 | |
| 234 | // Funded but the door unreachable: refuse, never fall back to the forge's own credential | |
| 235 | // (#13776). | |
| 236 | const saved = process.env["FORGE_PARENT_LOCAL"]; | |
| 237 | try { | |
| 238 | delete process.env["FORGE_PARENT_LOCAL"]; | |
| 239 | expect(() => credentialEnv({ kind: "env" }, childDir)).toThrow(/unreachable/); | |
| 240 | process.env["FORGE_PARENT_LOCAL"] = "http://evil.test"; | |
| 241 | expect(() => credentialEnv({ kind: "none" }, childDir)).toThrow(/unreachable/); | |
| 242 | } finally { | |
| 243 | if (saved === undefined) delete process.env["FORGE_PARENT_LOCAL"]; | |
| 244 | else process.env["FORGE_PARENT_LOCAL"] = saved; | |
| 245 | } | |
| 246 | ||
| 234 | 247 | // An org's grant (picked "none") reaches the same lent door (#10991). |
| 235 | 248 | expect(credentialEnv({ kind: "none" }, childDir)).toEqual(env); |
| 236 | 249 |
test/crew-one-shot.test.ts +10 −2
| @@ -10,6 +10,7 @@ import { turnBudget } from "../src/crew/model_access.ts"; | ||
| 10 | 10 | import { setModelGrant } from "../src/core/model_grant.ts"; |
| 11 | 11 | import { createUser } from "../src/core/users.ts"; |
| 12 | 12 | import { configureConversation } from "../src/crew/conversation.ts"; |
| 13 | import { parentLocal } from "../src/spawn/beat-door.ts"; | |
| 13 | 14 | import { ONE_SHOT_USD, oneShot } from "../src/crew/one_shot.ts"; |
| 14 | 15 | |
| 15 | 16 | let dir = "", app: ReturnType<typeof createApp>, admin = "", member = ""; |
| @@ -62,8 +63,15 @@ describe("oneShot", () => { | ||
| 62 | 63 | expect(turnBudget(app, { kind: "none" }, member, 1, new Date())).toEqual({ ok: false, refusal: "no_account", said: expect.any(String) }); |
| 63 | 64 | writeFileSync(join(dir, "parent.json"), JSON.stringify({ credit: { token: "bearer-token-1", capUsd: 1, spentUsd: 0.5 } })); |
| 64 | 65 | expect(turnBudget(app, { kind: "none" }, member, 1, new Date())).toEqual({ ok: true, budget: 0.5 }); |
| 65 | expect(await oneShot(app, member, "s", "p")).toEqual({ ok: true, value: "{}" }); | |
| 66 | rmSync(join(dir, "parent.json")); | |
| 66 | const door = process.env["FORGE_PARENT_LOCAL"]; | |
| 67 | process.env["FORGE_PARENT_LOCAL"] = parentLocal(4000); | |
| 68 | try { | |
| 69 | expect(await oneShot(app, member, "s", "p")).toEqual({ ok: true, value: "{}" }); | |
| 70 | } finally { | |
| 71 | if (door === undefined) delete process.env["FORGE_PARENT_LOCAL"]; | |
| 72 | else process.env["FORGE_PARENT_LOCAL"] = door; | |
| 73 | rmSync(join(dir, "parent.json")); | |
| 74 | } | |
| 67 | 75 | }); |
| 68 | 76 | test("the answer comes back, the budget is the smallest cap, and the cost is booked", async () => { |
| 69 | 77 | on(0.03); |
new above
offline