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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

mason/forge:mason/13776-a-funded-child-whose-parent-door-is-unre → main 3 commits fork

  • Merged. mason/13776-a-funded-child-whose-parent-door-is-unre was merged into main as 17e9bbb.

Review

Sign in to review this change.
3 files changed +28 −2
src/crew/runner.ts +5
@@ -2467,5 +2467,10 @@ export function credentialEnv(picked: Pick, dataDir?: string): Record<string, st
24672467 // forge's account too.
24682468 const lent = (picked.kind === "env" || picked.kind === "none") && dataDir !== undefined ? fundedEnv(dataDir) : undefined;
24692469 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 }
24702475 return ownEnv();
24712476 }
test/child-credit.test.ts +13
@@ -231,6 +231,19 @@ describe("a parent funds a child's crew", () => {
231231 expect(env).toEqual({ ANTHROPIC_BASE_URL: parentLocal(door.port), ANTHROPIC_API_KEY: f.token });
232232 expect(JSON.stringify(env)).not.toContain(PARENT_KEY);
233233
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
234247 // An org's grant (picked "none") reaches the same lent door (#10991).
235248 expect(credentialEnv({ kind: "none" }, childDir)).toEqual(env);
236249
test/crew-one-shot.test.ts +10 −2
@@ -10,6 +10,7 @@ import { turnBudget } from "../src/crew/model_access.ts";
1010 import { setModelGrant } from "../src/core/model_grant.ts";
1111 import { createUser } from "../src/core/users.ts";
1212 import { configureConversation } from "../src/crew/conversation.ts";
13 import { parentLocal } from "../src/spawn/beat-door.ts";
1314 import { ONE_SHOT_USD, oneShot } from "../src/crew/one_shot.ts";
1415
1516 let dir = "", app: ReturnType<typeof createApp>, admin = "", member = "";
@@ -62,8 +63,15 @@ describe("oneShot", () => {
6263 expect(turnBudget(app, { kind: "none" }, member, 1, new Date())).toEqual({ ok: false, refusal: "no_account", said: expect.any(String) });
6364 writeFileSync(join(dir, "parent.json"), JSON.stringify({ credit: { token: "bearer-token-1", capUsd: 1, spentUsd: 0.5 } }));
6465 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 }
6775 });
6876 test("the answer comes back, the budget is the smallest cap, and the cost is booked", async () => {
6977 on(0.03);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs