Skip to content

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

Description

@nc9

Problem

Everyone who audits many sites (agencies, researchers, CI over a portfolio) ends up writing their own runner around squirrel audit <url>. Each runner reinvents the same things, and several of the hard parts are not safe to do from outside the CLI: parallelism against the shared local stores (see the concurrent-audit lock issue), resuming after a crash or reboot, recording per-URL failures (unreachable, off-site seed redirect, timeout) next to the reports instead of in scrollback, and deciding retention for the shared content store and keep_audits when hundreds of audits run (the 1 GB default cap and keep_audits = 3 are tuned for one site, not a corpus).

Proposal

A documented batch mode, for example squirrel audit --urls-file urls.txt --out-dir reports/ [--concurrency N]:

  • reads one URL per line (comments and blanks ignored);
  • runs up to N audits at once with a safe default;
  • writes one report per URL into the directory with a stable file name;
  • appends one record per URL to a results file (JSONL: url, status, exit reason, score, duration, error text);
  • resumes: a re-run skips URLs that already have a completed record and retries failed ones on request (--retry-failed);
  • prints a one-line notice when retention or the content-store cap retires or evicts data during the run, and the docs include a "batch and corpus use" recipe for [storage] keep_audits and content_store_max_bytes (env SQUIRREL_CONTENT_STORE_MAX_BYTES).

Acceptance Criteria

  • squirrel audit --urls-file <file> audits every listed URL and writes one report each plus a JSONL results file with a per-URL status and error.
  • Killing the process and re-running with the same arguments does not redo completed URLs.
  • A URL that fails (unreachable, refused, timeout) is recorded with its reason and does not stop the batch; the exit code says whether any URL failed.
  • --concurrency N is respected and 10 concurrent audits complete without storage lock errors.
  • docs/cli/audit.mdx documents the flag, the results file schema and a batch retention recipe; completion.ts lists the new flags.
  • Prerequisite: Concurrent squirrel audit processes fail with 'SQLite database is busy (locked)' #1226 (concurrent audits and the shared stores) is fixed first; batch mode is not enabled above --concurrency 1 before it.
  • Each URL runs as a child squirrel audit process and the manifest record (v, url, key, status, reason, exitCode, attempt, timings, report, score, pages, finalUrl, error, notes) uses the audit status vocabulary (completed, partial, blocked, unreachable, redirected, failed) plus timeout, crashed, rejected, skipped-budget; a child that dies without a record is recorded as crashed.
  • Batch exit code: 0 all completed or partial, 1 the batch could not run, 2 only --fail-on tripped, 6 at least one URL failed (new, documented in the exit-code table).
  • The urls-file is treated as untrusted: only http and https, no userinfo, size and length caps, non-public hosts rejected unless --allow-private-hosts, report file names derived from a hash of the URL.
  • Two URLs of the same project never run at once; a lock file stops two batches on one out-dir; SIGTERM is forwarded to children and the next run resumes.
  • Signed-in batches are ephemeral by default, estimate their worst-case credits up front, require --yes and honour --max-credits.
  • --urls-file rejects -o, --resume, --project-name and --summary with a clear message.

Activity

  1. added
    enhancement
    size: L
    on Oct 28, 2026
  2. added theissue type on Oct 28, 2026
  3. nc9 commented on Oct 30, 2026

    @nc9
    ContributorAuthor

    Spec: batch mode (squirrel audit --urls-file)

    Status: proposal for review, no code yet. The acceptance criteria in the issue stand; the spec adds the pieces they do not name (exit codes, the status vocabulary, the child protocol, security of the input file, credits) and a few corrections. Where it differs from the issue, the issue body is updated below.

    1. Surface

    squirrel audit --urls-file urls.txt --out-dir reports/ [--concurrency N] [--retry-failed] [--restart]
    
    • --urls-file replaces the positional URL (giving both is an error). One URL per line; blank lines and # comments ignored; - reads stdin. Optional per-line overrides are out of scope (a corpus with different settings per site is several batches).
    • --out-dir is required. -o/--output is rejected with --urls-file (one file per URL), -f/--format applies to every report (default json, because the consumer is a machine).
    • Every other audit flag is passed through to each audit unchanged (--max-pages, -C, --max-duration, --offline, --passive, --fail-on, --rule-include, --header, config). Flags that make no sense per batch are rejected: --resume (it means "resume an interrupted crawl", batch resume is automatic and described below), --project-name, --summary.
    • Naming. squirrel audit stays the surface: the command-scoping rule puts project-scoped commands at top level and a batch is many audits. A separate squirrel batch was considered and rejected: it would duplicate the whole audit flag set.
    • Batch-only flags: --concurrency N (default min(4, max(1, floor(cores / 2))), max 16), --retry-failed, --restart (ignore and replace the results file), --url-timeout <seconds> (hard wall-clock kill per URL, default max-duration * 1.5 + 60 when --max-duration is set, else none), --max-urls N (default 100000), --allow-private-hosts, --max-credits N (signed-in runs, section 9), --keep-data (section 8).

    2. Architecture: an orchestrator that runs squirrel audit children

    Run each URL as a child process of the same binary (process.execPath with the audit arguments), not as an in-process pool.

    Why not in-process: the audit command is written as a process. It sets process.exitCode, installs signal handlers, writes progress to the terminal, holds process-global singletons (the content store and link cache handles, the logger, the retained-store lease) and assumes one run's memory (a 30 to 100 page audit is hundreds of MB; a memory-hungry or wedged audit would take the batch down). A child gets crash isolation, a real exit code per URL, a kill switch for a wedged crawl, and the exact behaviour a user sees running squirrel audit by hand. The cost is one process start per URL (tens of milliseconds, negligible next to a crawl) and SQLite contention between children, which is the next section.

    Child protocol. The orchestrator passes a hidden --batch-record <file> to each child. On exit the child writes one JSON record there (status, reason code, score, pages, duration, retention notes, final URL, report path). The orchestrator reads it, adds the child's exit code and signal, and appends to the manifest. A child that dies before writing (OOM kill, SIGKILL, crash) has no record: the orchestrator records crashed with the signal. No stdout/stderr scraping: the retention and eviction notices from the issue ("one-line notice when retention or the content-store cap retires data") travel in the record's notes and the orchestrator prints them once per occurrence.

    3. Hard prerequisite: #1226

    The children share ~/.squirrel/content-store.db and the link cache. #1226 (concurrent audits fail with SQLite database is busy) is open and is the same defect the batch would hit on its first run at --concurrency 4. Batch mode must not ship before #1226's criteria hold (busy timeout first, BEGIN IMMEDIATE for contending writes, an error naming the file and the wait). The batch's own test is that issue's repro at 10 and the criterion "10 concurrent audits complete without storage lock errors". Until then the default --concurrency would have to be 1, which defeats the feature, so the order is #1226, then batch.

    Two URLs of the same registrable project (same project name, so the same project.db) must not run at once: the crawl lease (#946) exists per project, but two children contending for it just wastes a run. The scheduler keeps a set of active project names and defers a URL whose project is busy (it is picked up when the other finishes). Different hosts of one site audited as separate URLs are not special-cased beyond that.

    4. The manifest (results.jsonl) and statuses

    <out-dir>/results.jsonl, append-only, one JSON object per line, written only by the orchestrator (one writer, O_APPEND, one write per record so lines never interleave). Record:

    {
      "v": 1,
      "url": "https://example.com/",
      "key": "example.com-3fa9c1",
      "status": "completed",
      "reason": null,
      "exitCode": 0,
      "attempt": 1,
      "startedAt": "2026-10-30T10:00:00.000Z",
      "finishedAt": "2026-10-30T10:01:12.000Z",
      "durationMs": 72000,
      "report": "example.com-3fa9c1.json",
      "score": 87,
      "pages": 30,
      "finalUrl": null,
      "error": null,
      "notes": []
    }

    Exit codes of the child are the single-audit codes (0 success including partial, 1 error, 2 --fail-on tripped, 3 blocked, 4 redirected, 5 unreachable), so the table in docs/cli/audit.mdx stays the one source.

    5. Resume, retry, restart

    • Default is to resume: on start the orchestrator reads results.jsonl, takes the last record per key, and skips keys whose status is terminal-success (completed, partial). Killing the process and re-running with the same arguments therefore does not redo completed URLs (criterion 2). A truncated last line (killed mid-write) is ignored.
    • Failed keys (failed, blocked, unreachable, redirected, timeout, crashed) are skipped by default and re-run with --retry-failed, which also bumps attempt. rejected keys are never retried (the input is wrong); skipped-budget keys run on the next invocation. A changed --max-pages or level does not invalidate completed records (it is the operator's call: --restart).
    • --restart renames the old file to results.<timestamp>.jsonl and starts over.
    • A lock file <out-dir>/.batch.lock (pid, host, start time; stale when the pid is gone on this host) stops two orchestrators on one out-dir. This is the batch counterpart of the crawl lease.
    • The urls-file is re-read on resume; URLs removed from it are not touched, new ones run. A key appearing twice in the file runs once.

    6. Failures do not stop the batch; exit codes of the batch

    A failing URL is recorded and the batch continues. Batch exit code:

    Code Meaning
    0 Every URL ended completed or partial and no --fail-on gate tripped
    1 The batch itself could not run: bad arguments, unreadable file, out-dir not writable, lock held, prerequisite store failure
    2 No URL failed, but at least one --fail-on gate tripped (child exit 2)
    6 At least one URL ended failed, blocked, unreachable, redirected, timeout, crashed, rejected or skipped-budget (takes precedence over 2)

    6 is new and needs adding to the exit-code table and to docs; --retry-failed re-runs exactly what produced it. A final summary on stderr (counts per status, report and manifest paths) is printed in every case; with -f json nothing goes to stdout.

    7. Concurrency, memory and politeness

    • The scheduler is a fixed pool of --concurrency children with the per-project deferral from section 3. The default (at most 4, at most half the cores) is conservative on a laptop: a surface audit is a few hundred MB and spends CPU on rules. Docs give a sizing table and the memory rule of thumb.
    • --concurrency is per machine. Politeness per target is unchanged because each audit already rate-limits to its own host; two different sites share nothing. A list that contains many URLs on one host (different paths) is the case to warn about: the scheduler serialises by project name, so they run one after another.
    • Backpressure is not in v1. The orchestrator reads available memory once and prints a warning if concurrency * 600 MB exceeds it.
    • SIGINT/SIGTERM to the orchestrator forwards SIGTERM to children, waits their grace period (the audit's own shutdown writes a partial report), records them as crashed-with-signal only if they do not exit, and exits 130. Records written so far make the next run a resume.

    8. Retention and the shared stores (the "corpus recipe")

    The defaults (content store 1 GB LRU, keep_audits = 3 per project) are tuned for one site. For a batch:

    • Each child inherits [storage] from the config, plus the SQUIRREL_CONTENT_STORE_MAX_BYTES environment variable. The docs carry the recipe the issue asks for: keep_audits = 1 (or 0 for report-only corpora: nothing to resume or diff from), content_store_max_bytes sized to the corpus when later analysis needs stored HTML, and that the content store is the only copy of fetched HTML (it is evicted, and scripts are never stored unless --store-scripts).
    • --keep-data documents the opposite: by default a batch run sets keep_audits to 1 for its children unless the config sets it, so hundreds of one-off sites do not leave hundreds of three-audit projects in ~/.squirrel. This is a default for batch only and is printed in the preamble.
    • Optionally --isolated-home runs the children with HOME=<out-dir>/.home so a corpus does not mix with the user's real projects and can be deleted with the out-dir. Off by default because users want squirrel report <domain> to work afterwards.
    • The orchestrator prints one line per notice a child reports that retention or eviction retired data ("Retired 1 older audit ...", the content-store eviction notice), deduplicated, as the issue requests.

    9. Cloud, credits and publishing

    A signed-in squirrel audit registers a website per domain, auto-publishes and spends credits. For a 500-URL batch that is 500 dashboard sites and a bill. So batch defaults differ and are stated up front:

    • Batch runs are ephemeral by default (the --ephemeral behaviour of #3649: cloud features, no dashboard website, no schedule, no publish) unless --publish is given.
    • Before the first child starts, a signed-in batch computes the worst case (N x (50 + 2 x max_pages) credits, with the page cap and link-check reserve) from the same estimate the single audit prints, compares it to the balance, and refuses to continue without --yes. --max-credits N caps total spend: the scheduler stops starting new children once the running estimate plus in-flight caps would pass it, and records the rest as skipped-budget (not retried by default). Per-audit [cloud] max_credits_per_audit still applies to each child.
    • --offline batches are fully local and need none of this.
    • A fully hosted batch (the cloud crawls, the machine only submits) is a different feature: see Cloud rendering still fetches the target from the user's machine (parallel local GET, local fallback on block, robots/sitemaps/scripts/assets local); cloud mode should never touch the site from the user's IP #1285; this spec does not depend on it.

    10. Security of the urls-file

    The file is untrusted (shared lists, scraped data, a corpus from a third party).

    • Only http: and https: URLs. file:, javascript:, data:, ftp: and the rest are rejected with a reason. Userinfo (user:pass@host) is rejected (a credential in a list is a leak waiting to be logged).
    • Line length 2048, file size 64 MB, URL count --max-urls (default 100000): a larger file is an error before any request is made. Control characters and invalid UTF-8 are rejected per line. Leading and trailing whitespace is trimmed; a missing scheme gets https:// the way the single audit does it.
    • Non-public hosts (loopback, RFC1918, link-local, metadata, .local, .internal) are rejected unless --allow-private-hosts, using the same classifier the audit's cloud preflight uses (nonPublicHostLabel). The single audit allows localhost on purpose; a batch fed from a list should not scan an internal network by default. Every child also keeps the audit's own egress guard per hop, so a public name that redirects to a private address is still refused (Start URL redirects (bit.ly etc.): resolve the chain and audit the destination, with consent for cross-domain (--follow-redirect / prompt); today it scores the shortener #1281).
    • Redirects to another site: children run with the single-audit behaviour, so a cross-domain start URL ends redirected (exit 4) unless the batch is given --follow-redirect, and the manifest records the final URL.
    • Output safety: report names come from the hash, the manifest is data. The out-dir is created with mode 0700 when new.

    11. Documentation, completions, skill

    docs/cli/audit.mdx (flags, the record schema, exit code 6, the batch retention recipe, sizing), docs/guides/ batch and corpus recipe, completion.ts for the new flags, --help. The agent skill needs a short section (agents do run batches): a private issue labelled skills is filed with the first PR. A squirrel audit JSON report gains no field; the record carries what a batch needs.

    12. Test plan

    • Input parsing: comments, blanks, stdin, CRLF, duplicates, schemes, userinfo, private hosts, oversized lines and files, invalid UTF-8.
    • Manifest: record schema, one writer under concurrency, truncated last line, running successor logic.
    • Resume: kill the orchestrator mid-batch (SIGKILL), re-run, assert completed keys are not re-run (the criterion), --retry-failed bumps attempt, --restart rotates the file, lock file stale detection.
    • Failure handling with a local fixture site per case: unreachable (5), blocked (3), redirected (4), failed (1), timeout kill, crash (child killed -9), --fail-on (2), and the batch exit code precedence.
    • Concurrency: 10 children against 10 fixture sites, repeated, with Concurrent squirrel audit processes fail with 'SQLite database is busy (locked)' #1226 fixed: no lock error; per-project deferral for two URLs on one host; scheduler never exceeds --concurrency.
    • Credits: estimate refusal without --yes, --max-credits stops scheduling (stub API).
    • Retention notices surfaced once; defaults applied and printed.
    • Signals: SIGTERM forwarded, exit 130, next run resumes.

    13. Phases and PR split

    1. Prerequisite: Concurrent squirrel audit processes fail with 'SQLite database is busy (locked)' #1226 (separate PR, already filed).
    2. PR A (size L, public only): urls-file parsing and validation, orchestrator, child record protocol, results.jsonl, resume/restart/lock, concurrency, exit codes including 6, docs, completions, tests. Local audits only; signed-in runs refuse with a message until PR B.
    3. PR B: credits (estimate, --yes, --max-credits, ephemeral default), retention defaults and notices, sizing warning.
    4. PR C: squirrel audit --urls-file --status (summarise a manifest: counts, failures, slowest) and --isolated-home. Optional.

    The batch exit code 6 and the redirected/unreachable statuses depend on #1282 (merged), #1297 and #1324 (open): the orchestrator only reads child exit codes and the record, so it can land before them and the vocabulary grows as they merge.

    Acceptance criteria (additions)

    The issue body keeps its five criteria and gains the following.

  4. nc9 commented on Oct 30, 2026

    @nc9
    ContributorAuthor

    Review of the spec above against the current code and the open work, with the decisions it leaves to the maintainer. Recommendation: build it as written, in the three-PR split.

    What is settled by the spec: child squirrel audit processes under one orchestrator (the audit command owns process globals, signals and the content store handle, so an in-process pool is the wrong cut), results.jsonl with one writer and running records for crash detection, hashed report keys, resume by default with --retry-failed and --restart, batch exit code 6, per-project deferral for the one-project-one-db constraint, urls-file treated as untrusted.

    Interplay worth stating in the docs: --max-duration is per URL, not per batch, so a 500-URL batch with --max-duration 60 can run for hours; --url-timeout defaults to max-duration * 1.5 + 60 as the hard kill. --ephemeral is the batch default for signed-in runs, so no dashboard sites are created unless --publish is passed.

    Decisions needed before PR A:

    1. Ship order: wait for Concurrent squirrel audit processes fail with 'SQLite database is busy (locked)' #1226 (busy timeout and BEGIN IMMEDIATE) before any --concurrency above 1, or ship PR A with the default pinned to 1 and raise it when Concurrent squirrel audit processes fail with 'SQLite database is busy (locked)' #1226 lands. Recommendation: wait, since concurrency is the point of the feature.
    2. Default concurrency: min(4, floor(cores / 2)), cap 16. Recommendation: keep, with the memory warning at concurrency * 600 MB.
    3. Batch default keep_audits = 1 for children unless the config sets it, versus leaving the single-site default of 3. Recommendation: 1, printed in the preamble, with --keep-data to opt out.
    4. Signed-in batches: ephemeral by default, --yes required, --max-credits cap, in PR B and refusing signed-in runs in PR A. Recommendation: as written.
    5. Private hosts rejected unless --allow-private-hosts, even though a single squirrel audit allows localhost. Recommendation: reject by default for a list input.
    6. Whether --isolated-home and --status (PR C) are wanted at all, or dropped from the first release.

    nik

  5. 45 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    clienhancementsize: L

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions