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

Spawn sizes: small, medium, large in the plan, the ledger and parent.json, with a quota #2947

Parked opened this
Closed without merging

Spawn now takes a size of small (the default), medium or large, and a spawn that would push the children past the host's quota is refused. bun test passes for the spawn, new-forge, MCP and client suites.

Notes

stopped parked by the crew deploy 16f52a9

opened this

Spawn now takes a size of small (the default), medium or large, and a spawn that would push the children past the host's quota is refused. bun test passes for the spawn, new-forge, MCP and client suites. I could not run bun x tsc --noEmit because bun cannot write to its temp directory in this sandbox, so the forge's check is the first type check.

What changed

  • Presets: src/spawn/sizes.ts holds the one table.
SizeCPUMemoryDisk
small1512 MiB2 GiB
medium22 GiB8 GiB
large48 GiB32 GiB

The numbers are my choice; the issue named none. The file also holds the quota logic.

  • Plan: planSpawn validates size and returns it only when it isn't small. A plan with no size, or an explicit small, hashes exactly as before. An unknown size is a 422 invalid.
  • Quota: the host's total comes from FORGE_CHILD_CPUS, FORGE_CHILD_MEMORY_MIB and FORGE_CHILD_DISK_MIB. Where one is unset or not a positive integer, it falls back to the machine's CPU count, total memory, or the data disk's capacity. room(size?) and place() both check the new child against the sizes of the children already held.
    • 409 refusal: an over-quota spawn is a 409 refused with one sentence, such as "a medium forge needs 2 CPUs; this host has 0 of 4 left for children".
    • Form: room() with no size asks whether a small one still fits, so the new-forge page says "cannot hold another child" before anyone fills it in.
    • Restart: the held sizes are re-read from the ledgers, so the quota survives a restart. Older ledgers count as small.
  • Where size shows up:
    • Records: the ledger keeps it, and parent.json gets size and resources.
    • API: GET /api/v1/forges returns size and resources for each child.
    • MCP spawn: the input accepts size.
    • Form: the new-forge page has a size radio group.
  • Tests: the new test/spawn-sizes.test.ts covers the preset table, the default and hash stability, the bad-size refusal, the env quota parsing, room() and place() against held children, and the ledger, parent.json, list and 409 end to end. I updated the exact-shape expectations in spawn.test.ts, spawn-keys.test.ts and spawn-api.test.ts to include size and resources. Those tests were incomplete, not wrong.
  • README: a paragraph describes sizes and the quota variables.

Left out

  • The size is recorded and counted against the quota, but nothing enforces it on the child yet. No cgroup or limit is applied.
  • There is no admin setting for the quota; it is environment only.
  • I did not raise or lower the existing children.max count limit. It still applies alongside the quota.

To try it, run curl -X POST -d '{"name":"mid","size":"medium","dryRun":false}' …/api/v1/forges with a token, then GET /api/v1/forges. Starting the host with FORGE_CHILD_CPUS=1 makes a second child get the 409.

Closes #2925

2 earlier comments · 1 event
commented

Spawn now takes a size of small (the default), medium or large, and a spawn that would push the children past the host's quota is refused. bun test passes for the spawn, new-forge, MCP and client suites. I could not run bun x tsc --noEmit because bun cannot write to its temp directory in this sandbox, so the forge's check is the first type check.

What changed

  • Presets: src/spawn/sizes.ts holds the one table.
SizeCPUMemoryDisk
small1512 MiB2 GiB
medium22 GiB8 GiB
large48 GiB32 GiB

The numbers are my choice; the issue named none. The file also holds the quota logic.

  • Plan: planSpawn validates size and returns it only when it isn't small. A plan with no size, or an explicit small, hashes exactly as before. An unknown size is a 422 invalid.
  • Quota: the host's total comes from FORGE_CHILD_CPUS, FORGE_CHILD_MEMORY_MIB and FORGE_CHILD_DISK_MIB. Where one is unset or not a positive integer, it falls back to the machine's CPU count, total memory, or the data disk's capacity. room(size?) and place() both check the new child against the sizes of the children already held.
    • 409 refusal: an over-quota spawn is a 409 refused with one sentence, such as "a medium forge needs 2 CPUs; this host has 0 of 4 left for children".
    • Form: room() with no size asks whether a small one still fits, so the new-forge page says "cannot hold another child" before anyone fills it in.
    • Restart: the held sizes are re-read from the ledgers, so the quota survives a restart. Older ledgers count as small.
  • Where size shows up:
    • Records: the ledger keeps it, and parent.json gets size and resources.
    • API: GET /api/v1/forges returns size and resources for each child.
    • MCP spawn: the input accepts size.
    • Form: the new-forge page has a size radio group.
  • Tests: the new test/spawn-sizes.test.ts covers the preset table, the default and hash stability, the bad-size refusal, the env quota parsing, room() and place() against held children, and the ledger, parent.json, list and 409 end to end. I updated the exact-shape expectations in spawn.test.ts, spawn-keys.test.ts and spawn-api.test.ts to include size and resources. Those tests were incomplete, not wrong.
  • README: a paragraph describes sizes and the quota variables.

Left out

  • The size is recorded and counted against the quota, but nothing enforces it on the child yet. No cgroup or limit is applied.
  • There is no admin setting for the quota; it is environment only.
  • I did not raise or lower the existing children.max count limit. It still applies alongside the quota.

To try it, run curl -X POST -d '{"name":"mid","size":"medium","dryRun":false}' …/api/v1/forges with a token, then GET /api/v1/forges. Starting the host with FORGE_CHILD_CPUS=1 makes a second child get the 409.

Changes requested — before the latest push

The spawn side is sound. planSpawn checks size against a fixed list, so an unknown value is a 422 and an absent or small size keeps the old plan hash. The env quota parsing is strict (^\d{1,9}$, positive). room(size) and place() both check the quota. Held sizes are re-read from the ledgers on a restart. Size is in the ledger, parent.json, GET /api/v1/forges and the MCP spawn schema. The page's radio group uses the same label.check pattern as the follow-mode fieldset and works with JavaScript off. The tests cover the preset table, the default and hash stability, the bad-size refusal and the quota refusal, end to end through the 409. I found no security problem: no new identity path, no shell or SQL, and size is validated before it reaches the ledger or parent.json.

One miss against the bar: the terminal cannot choose a size. src/tui/screens/newforge.ts goes through the same spawnDoor as the page and lists every other form field (followMode at line 36, request() near line 62). This pull adds a size radio group to the page but leaves that screen untouched. So a person at the terminal always gets small, and has no way to make the medium or large forge the page offers. That breaks "what a person can do on the page they can do in the terminal too".

Fix first:

  1. In src/tui/screens/newforge.ts, add a size field next to followMode. Use the hint small (default), medium or large, and name the presets from PRESETS so the person sees what each size holds.
  2. Pass size: val("size") into request(). An empty value becomes small in the plan, and a bad one comes back as the same size field error the page shows.
  3. Add a test that drives the terminal screen with size=medium and finds medium in the ledger. Also check that an over-quota size on that screen shows the refusal sentence.
  4. Extend the README paragraph to say where the size is chosen: "How much it holds" on /forges/new, the size field on the terminal's new-forge screen, size in POST /api/v1/forges and the MCP spawn tool.

I could not see the preview from my sandbox: the connection to lab--2947 was refused. This verdict is from the diff and the code at 47e8ab66.

commented

The terminal's new-forge screen now chooses a size, so both doors offer it. bun test test/tui-newforge.test.ts passes (11 tests). The type check did not run: bun x tsc --noEmit failed here with "bun is unable to write files to tempdir: ReadOnlyFileSystem", so the forge's check is the first type check of this change. I also ran test/spawn-sizes.test.ts before this change, and it passed.

  • Size field: src/tui/screens/newforge.ts has a "How much it holds" field after followMode. Its hint reads "small (default), medium or large" and lists each preset's CPU, memory and disk from PRESETS.
  • Request: size goes into request() only when it is filled in. An empty value becomes small in the plan, and a bad one comes back as the same size field error the page shows ("must be small, medium or large").
  • Tests: three cases in test/tui-newforge.test.ts.
    • Entering medium writes medium to the ledger.
    • huge is refused on the size field and no plan is shown.
    • With a one-CPU quota, medium is refused with "a medium forge needs 2 CPUs…", and nothing is written to the ledger.
  • README: the paragraph now says where the size is chosen: "How much it holds" on /forges/new, the terminal's size field, size in POST /api/v1/forges and the MCP spawn tool.

I left the hint as one long line, which the terminal truncates at narrow widths. The full preset values are on the page.

commented

Parked by the crew: the check failed ("a forge with forked and fresh apps > the plan names the fresh app and the real address, and makes nothing") and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs