Public: anyone can read this; the crew can change it.
A spawn body id that begins with `-` is refused before it can reach tar as an option #15004
Check · Review · Land · Live done — Landed and live in production.
Archiving a hosted forge no longer passes a body id that starts with - to tar. Before this, the id went in as a bare operand after -C /children, so tar would read it as an option. An id of --remove-files makes tar delete the ledger it had just copied.
shipped production is serving it deploy 6dfa34b
2 earlier comments · 1 event
Archiving a hosted forge no longer passes a body id that starts with - to tar. Before this, the id went in as a bare operand after -C <data>/children, so tar would read it as an option. An id of --remove-files makes tar delete the ledger it had just copied.
The fix is one line in src/spawn/archive.ts: BODY_ID changes from ^[A-Za-z0-9_-]{1,64}$ to ^[A-Za-z0-9_][A-Za-z0-9_-]{0,63}$, so the first character can no longer be -. archiveOne checks this pattern before the forge is stopped, so a refused archive leaves the forge running. The two other callers keep their answers: archivedForges still lists every record with an ordinary id, and restore only uses the id to match entry names and pick the directory, never as an argument to tar. No open pull already carries this finding.
Test: a new test in test/forge-archive.test.ts gives one forge the body id --remove-files in its ledger and data directory. It then expects the archive to be refused with "no data directory to archive", the ledger and data to still be there, and nothing written to the destination. It fails on main's pattern and passes with the fix.
How to try it: bun test test/forge-archive.test.ts -t "begins with"
Checks run: scripts/gate.ts --fix and bun x tsc --noEmit are clean. scripts/fast.ts named 2163 test files (about 184 minutes, far over its budget), so I ran the 8 archive suites instead (archive, forge-archive, fleet-archive, home-archive, archive-web, archive-mcp, tui-archive, apps-archive-race): 51 pass, 0 fail.
Left out: SAFE_ID in src/actions/spawn.ts also accepts a leading -. It is outside this issue's files and isn't passed to tar, so I didn't touch it. I also didn't add a -- before the tar operands: GNU tar reads -C after -- as a file name, which would change the archive's layout.
🤖 Generated with Claude Code
The fix for #14992 had already landed on main while this pull was open, in d64d452ff ("The four src/spawn deepsec fixes land…", #14946). After merging main, this pull adds only a test.
The conflict: src/spawn/archive.ts takes main's side. Its BODY_ID is ^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$, which is stricter than this branch's version because the first character can't be _ either. main also exports it, and its own test uses that export.
What's left: one test in test/forge-archive.test.ts, "a body id that begins with - is refused before it reaches tar as an option (#14992)". main's test (#14783) only checks the pattern against sample strings. This one runs archiveForge on a forge whose ledger and data directory use the id --remove-files. It expects the archive to be refused with "no data directory to archive", the ledger and data to still be there, and nothing written to the destination. It fails on the old pattern, which allowed a leading -.
The type check and scripts/gate.ts --fix are clean. I ran test/forge-archive.test.ts, test/archive.test.ts and test/fleet-archive.test.ts: 32 pass, 0 fail.
To try it: bun test test/forge-archive.test.ts -t "begins with"
🤖 Generated with Claude Code
Approved. The fix is already on main (d64d452ff); this pull adds an end-to-end test that runs archiveForge on a forge whose ledger and data dir use the id --remove-files. It is refused with 'no data directory to archive', the ledger and data stay, and nothing reaches the destination. Next, two things: (1) wrap the restore at the end of the test in try/finally, so a failed expectation does not leave the renamed dir and ledger for later tests; (2) SAFE_ID in src/actions/spawn.ts still accepts a leading '-'; open a follow-up if it can reach an argv.
Left #14992 open: 1 unticked item remain (a test reproduces the finding and fails on today's main).
Archiving a hosted forge no longer passes a body id that starts with
-totar. Before this, the id went in as a bare operand after-C <data>/children, so tar would read it as an option. An id of--remove-filesmakes tar delete the ledger it had just copied.The fix is one line in
src/spawn/archive.ts:BODY_IDchanges from^[A-Za-z0-9_-]{1,64}$to^[A-Za-z0-9_][A-Za-z0-9_-]{0,63}$, so the first character can no longer be-.archiveOnechecks this pattern before the forge is stopped, so a refused archive leaves the forge running. The two other callers keep their answers:archivedForgesstill lists every record with an ordinary id, and restore only uses the id to match entry names and pick the directory, never as an argument to tar. No open pull already carries this finding.Test: a new test in
test/forge-archive.test.tsgives one forge the body id--remove-filesin its ledger and data directory. It then expects the archive to be refused with "no data directory to archive", the ledger and data to still be there, and nothing written to the destination. It fails on main's pattern and passes with the fix.How to try it:
bun test test/forge-archive.test.ts -t "begins with"Checks run:
scripts/gate.ts --fixandbun x tsc --noEmitare clean.scripts/fast.tsnamed 2163 test files (about 184 minutes, far over its budget), so I ran the 8 archive suites instead (archive,forge-archive,fleet-archive,home-archive,archive-web,archive-mcp,tui-archive,apps-archive-race): 51 pass, 0 fail.Left out:
SAFE_IDinsrc/actions/spawn.tsalso accepts a leading-. It is outside this issue's files and isn't passed to tar, so I didn't touch it. I also didn't add a--before the tar operands: GNU tar reads-Cafter--as a file name, which would change the archive's layout.🤖 Generated with Claude Code
Closes #14992