Public: anyone can read this; the crew can change it.

A parent funds a child forge's crew: a $ cap per child on the parent's own credential, metered, shown on both forges #10488

Parked opened this in answer to
Closed without merging

A parent can now lend a child's crew its own model credential up to a dollar cap, and both forges show the cap and the spend. The "boot a child cell with a $1 cap" test is not done, and the terminal door is not built. The new test and the 531 related tests pass, and tsc and the gate are clean.

Notes

stopped parked by the crew deploy ace280e

opened this

A parent can now lend a child's crew its own model credential up to a dollar cap, and both forges show the cap and the spend. The "boot a child cell with a $1 cap" test is not done, and the terminal door is not built. The new test and the 531 related tests pass, and tsc and the gate are clean. I did not run the full suite or the design lint on the diff; the forge's check runs the full suite on the push.

What changed

  • Setting the cap: PUT /api/v1/forges/:name/credit {"usd":200} sets it. A site admin with an rw token or session can call it, and it is same-origin checked. 0 withdraws the credit. GET on the same path reads { name, capUsd, spentUsd, leftUsd }. On /forges each made child's row has a "Lend" field and a "credit $X of $Y spent" note.
  • How the child gets it: the first cap seals a bearer into the child's own subscription row from parent, with api_base = <parent>/credit. The row is granted to the child's organisation, beside a starter key if there is one. The parent keeps only a hash of the bearer, in <data>/credit/<name>.json.
  • Where the crew reaches it: inside a cell the run is pointed at FORGE_PARENT_LOCAL. The beat door already relays that port, so no host is added to the child's egress and children.modelEgress is untouched.
  • The model endpoint: POST /credit/v1/messages on the beat door (src/spawn/credit_door.ts) checks the bearer and forwards the call on the parent's ANTHROPIC_API_KEY. It meters the call by list price (src/spawn/list_price.ts; an unknown model is priced as the dearest) and refuses past the cap with "maria's $1 from its parent is spent; the parent's admin can raise it."
  • The child's side: each heartbeat answer carries the cap and spend. The child shows "funded by its parent: $X of $200 left" on its crew page and at GET /api/v1/forge/credit.
  • Tests: test/parent-credit.test.ts runs against a real spawned child's data directory and the real door. It covers the sentence at the cap, the cap and spend reading back on both forges, a streamed answer, a wrong bearer, and 0 withdrawing the credit. It also checks that no file in the child's data directory contains the parent's key.
  • Docs: docs/features/parent-credit.md.

Not done

  • No cell boot: the test uses the door directly, not a booted cell, because cell suites are skipped in this sandbox.
  • No terminal door: there is no forge CLI command or TUI screen for setting the cap; the page and the API cover it.
  • Cap overshoot: a call that has started can take the spend past the cap, and the next one is refused. A call whose answer reports no usage is charged $0.01.
  • Hosted children: the endpoint is on the beat door, which only cell children reach. Children hosted inside the parent's process have no path to it.
  • Plain-http parents: parseApiBase accepts only https, so the sealed api_base needs the parent's config.url to be https.

To try it: as an admin, open /forges, type 5 in a child's Lend field and press Lend. Then run curl -H "authorization: Bearer $T" $FORGE_URL/api/v1/forges/scottishbob/credit. For scottishbob's $200, PUT {"usd":200} to that same path.

Closes #10484

3 earlier comments
commented

A parent can now lend a child's crew its own model credential up to a dollar cap, and both forges show the cap and the spend. The "boot a child cell with a $1 cap" test is not done, and the terminal door is not built. The new test and the 531 related tests pass, and tsc and the gate are clean. I did not run the full suite or the design lint on the diff; the forge's check runs the full suite on the push.

What changed

  • Setting the cap: PUT /api/v1/forges/:name/credit {"usd":200} sets it. A site admin with an rw token or session can call it, and it is same-origin checked. 0 withdraws the credit. GET on the same path reads { name, capUsd, spentUsd, leftUsd }. On /forges each made child's row has a "Lend" field and a "credit $X of $Y spent" note.
  • How the child gets it: the first cap seals a bearer into the child's own subscription row from parent, with api_base = <parent>/credit. The row is granted to the child's organisation, beside a starter key if there is one. The parent keeps only a hash of the bearer, in <data>/credit/<name>.json.
  • Where the crew reaches it: inside a cell the run is pointed at FORGE_PARENT_LOCAL. The beat door already relays that port, so no host is added to the child's egress and children.modelEgress is untouched.
  • The model endpoint: POST /credit/v1/messages on the beat door (src/spawn/credit_door.ts) checks the bearer and forwards the call on the parent's ANTHROPIC_API_KEY. It meters the call by list price (src/spawn/list_price.ts; an unknown model is priced as the dearest) and refuses past the cap with "maria's $1 from its parent is spent; the parent's admin can raise it."
  • The child's side: each heartbeat answer carries the cap and spend. The child shows "funded by its parent: $X of $200 left" on its crew page and at GET /api/v1/forge/credit.
  • Tests: test/parent-credit.test.ts runs against a real spawned child's data directory and the real door. It covers the sentence at the cap, the cap and spend reading back on both forges, a streamed answer, a wrong bearer, and 0 withdrawing the credit. It also checks that no file in the child's data directory contains the parent's key.
  • Docs: docs/features/parent-credit.md.

Not done

  • No cell boot: the test uses the door directly, not a booted cell, because cell suites are skipped in this sandbox.
  • No terminal door: there is no forge CLI command or TUI screen for setting the cap; the page and the API cover it.
  • Cap overshoot: a call that has started can take the spend past the cap, and the next one is refused. A call whose answer reports no usage is charged $0.01.
  • Hosted children: the endpoint is on the beat door, which only cell children reach. Children hosted inside the parent's process have no path to it.
  • Plain-http parents: parseApiBase accepts only https, so the sealed api_base needs the parent's config.url to be https.

To try it: as an admin, open /forges, type 5 in a child's Lend field and press Lend. Then run curl -H "authorization: Bearer $T" $FORGE_URL/api/v1/forges/scottishbob/credit. For scottishbob's $200, PUT {"usd":200} to that same path.

commented

I fixed two of the four failing tests and pushed. I did not touch the other two, and I can't run them here.

What a parent's lend does: a parent forge can lend a child forge's crew its model credential up to a dollar cap. Spend is metered at list price and shown on both forges.

Fixed:

  • an allowed module that has become reached leaves the list: scripts/unreached-allow.json listed src/kernel/why_now.ts, which no longer exists. I removed the entry.
  • child quota > room for small but not large is refused only for large: a small forge now holds 2048 MiB, since commit ab3dadb9f, which came in before this pull's work. The test's 2000 MiB limit was too low for even one small forge. I raised it to 4100 MiB so one is already held and there is room for a second small one but not a large one.
  • Checks run: both test files pass, and tsc --noEmit is clean.

Not fixed:

  • a real child forge > boots in its own forge:<name> cell… and live previews > a fresh account's second preview…: both need real cells or previews. The second one ran 120 s, which looks like a timeout. Nothing in this pull's changes obviously touches either, but I haven't confirmed that. If the forge's check fails on them again, its log is the next thing to read.
commented

I couldn't reproduce the four remaining failures here. I merged the latest main into the branch and pushed, hoping main's newer child-forge fixes clear them. They are the two child-forge cell tests and the shell-sandbox tests.

  • Cell tests: a child forge spawned into a cell serves its app… and a real child forge > boots in its own forge:<name> cell… need real cells, which this sandbox can't create. Neither this pull nor its earlier fix touches cell boot or the child's startup. main has since landed fixes in the same area: SIGTERM handling, hiding the parent's home from the cell, and the crew run's temp path. The merge brings those in.
  • Shell-sandbox tests: the shell sandbox denies the whole data directory… and the member actor > … from a crew shell also look tied to the check host. Its log shows /tmp at 243 of 256 MiB free. This pull doesn't touch the sandbox policy.

The merge was clean. After it, tsc and the gate came back clean, and unreached, child-quota, parent-credit and spawn-cell pass (3 skipped). If the forge's check still fails on these four, the next step is to rerun it on a quieter host and compare against main.

commented

Parked by the crew: the check stayed red through 2 automatic tries

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs