Skip to content

feat(cli): squirrel audit --urls-file batch mode #1231 - #2058

Merged
nc9 merged 9 commits into
mainfrom
boat/batch-audit-1231
Nov 18, 2026
Merged

nc9 merged 9 commits into
mainfrom
boat/batch-audit-1231

Conversation

@nc9

@nc9 nc9 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Batch mode for squirrel audit (PR A of the #1231 spec): squirrel audit --urls-file urls.txt --out-dir reports/ [--concurrency N] [--retry-failed] [--restart] [--url-timeout S] [--max-urls N] [--allow-private-hosts].

Closes #1231 for the local-audit scope. Signed-in batches (credit estimate, --yes, --max-credits, ephemeral default) and the retention notices are the spec's PR B and are NOT in this PR: a signed-in batch is refused with a message unless --offline.

Design: each URL runs as a child squirrel audit (same binary). The child writes a small hidden --batch-record file (audit status, reason code, score, pages, final URL) from the one exit point of the audit; the orchestrator adds exit code, signal and timings and is the only writer of results.jsonl. A child that dies with no record is crashed. --concurrency with --urls-file is the batch pool, not the crawl worker pool (documented).

Acceptance criteria

  • audits every URL, one report each plus JSONL: executeBatch > audits every URL...; real run: 4 local sites + 1 dead port, 5 report files and results.jsonl
  • kill and re-run does not redo completed URLs: a re-run does not redo completed URLs..., interrupting the batch then re-running...
  • failures recorded with reason, batch continues, exit code: a failing URL is recorded... (exit 6), unreachable exit 5 in the real run
  • --concurrency respected: never more than --concurrency children...; real run at --concurrency 4 completed without lock errors. The 10-concurrent-audit storage criterion rests on Concurrent squirrel audit processes fail with 'SQLite database is busy (locked)' #1226 (closed); I ran 4, not 10, against real children
  • docs and completions: docs/cli/audit.mdx (flags, results schema, exit code 6, retention recipe), completion.ts bash/zsh/fish, make validate passes
  • Concurrent squirrel audit processes fail with 'SQLite database is busy (locked)' #1226 prerequisite: closed
  • child process and record vocabulary, crashed without a record: a child killed by a signal with no record is crashed; timeout: a child past --url-timeout...
  • exit codes 0/1/2/6 (and 130): tests above plus exit 2 only when --fail-on tripped...
  • untrusted file: parser tests (existing) plus partial counts as success; rejected lines..., private hosts are rejected unless allowed, hashed report names
  • [~] same-project exclusion (two URLs of one project never overlap), lock file (a live lock...), SIGINT/SIGTERM forwarding with exit 130 (interrupting... via the stop signal; no real-signal test)
  • signed-in batches: deferred to PR B (refused unless --offline)
  • -o, --resume, --project-name, --summary rejected: checked by hand for -o and URL plus --urls-file; no automated test for the other three

Gates (apps/cli)

format:check, lint, typecheck clean. bun test batch/run, batch/manifest, batch/urls-file, self/completion: 191 pass; audit-options and three audit wiring tests: 70 pass. make validate in docs/: pass.

Agent skill: needs a short batch section (private skills issue to file).

CodeQL js/file-system-race fix (head fe9fb26)

The batch lock no longer decides anything on a path that can change between check and use:

  • Fresh lock: created with O_EXCL (unchanged).
  • On EEXIST the holder is read through one descriptor (openSync + fstatSync + readFileSync(fd)). Live or other-host holder: refused with the existing message.
  • Stale holder: the taker first creates (O_EXCL) a claim file .batch.lock.takeover-<sha256 of the stale bytes>. Under the claim it re-reads the lock (must still be the same stale bytes), writes the new lock to an O_EXCL temp ${path}.${pid}.${random}, renameSyncs it over the lock atomically, then re-reads and confirms our pid + nonce before proceeding.
  • Release deletes the lock only while it still holds our nonce.

Why the claim file: rename-then-confirm alone does not exclude racers. In the new race test (8 child processes on one stale lock) all of them won without it, because each renamed and confirmed before the next renamed. With the claim, exactly one wins.

Tests: apps/cli/tests/batch/lock.test.ts (fresh acquire, refusal while held, other-host lock, unreadable lock, stale takeover with no temp debris, claimed takeover refused, release leaves someone else's lock, 8 racers exactly one wins).
Residual: a process killed between creating the claim and removing it leaves the claim, and later runs refuse with a message naming the file to delete.

Comment thread apps/cli/src/batch/run.ts Fixed
Comment thread apps/cli/src/batch/run.ts Fixed
Comment thread apps/cli/src/batch/run.ts Fixed
@nc9
nc9 force-pushed the boat/batch-audit-1231 branch from 96f786f to 7572f13 Compare November 16, 2026 12:00
Comment thread apps/cli/src/batch/run.ts Fixed
Comment thread apps/cli/src/batch/run.ts Fixed
@nc9
nc9 force-pushed the boat/batch-audit-1231 branch from 3f87803 to fe9fb26 Compare November 16, 2026 19:41
@nc9
nc9 force-pushed the boat/batch-audit-1231 branch 2 times, most recently from 722d8b6 to 8a60316 Compare November 17, 2026 13:42
@nc9
nc9 marked this pull request as ready for review November 17, 2026 19:18
@nc9
nc9 force-pushed the boat/batch-audit-1231 branch 3 times, most recently from 8b5e1c4 to 52ef57f Compare November 18, 2026 01:10
nc9 added 9 commits November 18, 2026 15:43
Clears CodeQL js/file-system-race on the batch lock. A fresh lock is created
with O_EXCL. A stale lock is taken over only by whoever first creates (O_EXCL)
a claim file named after the stale lock's content; under the claim the lock is
re-read through one descriptor and must still hold the same stale bytes, then
an O_EXCL temp file is renamed over it and the lock is confirmed by our pid
and nonce. Release deletes the lock only while it still holds our nonce.

Signed-off-by: Nik Cubrilovic <[email protected]>
…second signal #1231

planBatch reruns a crashed/interrupted URL as the next attempt, like skipped-budget, so the re-run that the Ctrl-C message asks for does it. The second SIGINT/SIGTERM no longer exits with children running and running lines left behind: it kills the children so each gets its interrupted record and the lock is released; a third exits. SIGHUP is handled like SIGINT, and a child that died of SIGINT is recorded interrupted.

Signed-off-by: Nik Cubrilovic <[email protected]>
Children got the user's raw offline tokens (--offline=false, --offline
false, --no-offline). The orchestrator now drops every raw offline form
and passes --offline only when the parent resolved it true. The guard
tests now also cover repeated flags (citty parses them as an array, which
is refused) and check that no child is spawned.

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the boat/batch-audit-1231 branch from 52ef57f to 0b0c147 Compare November 18, 2026 04:43
@nc9
nc9 merged commit e3deada into main Nov 18, 2026
16 checks passed
@nc9
nc9 deleted the boat/batch-audit-1231 branch November 18, 2026 04:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Batch mode for squirrel audit: --urls-file with concurrency, resume and per-URL failure records

2 participants