Skip to content

fix(cli): name the local store an audit cannot write, before it starts (#403) - #429

Merged
nc9 merged 1 commit into
mainfrom
fix/cli-local-store-errors
Oct 1, 2026
Merged

nc9 merged 1 commit into
mainfrom
fix/cli-local-store-errors

Conversation

@nc9

@nc9 nc9 commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Closes #403.

Two field failures had one root: the CLI never checked that it could write its local stores, and the crawler treated a store failure as one failed page.

  • Audit failed: Storage error during write: SQLiteError: attempt to write a readonly database (CLI v0.0.98, macOS). SQLite opens a file it cannot write read-only without saying so. Reproduced three ways: project.db owned by another user or chmod 444, and a macOS sandbox that denies writes to ~/.squirrel, which is what coding agents run commands in. The audit got through reachability and run registration, then died at its first write.
  • No pages were crawled on a site that serves 200s. Reproduced with a read-only content-store.db and with SQUIRREL_CONTENT_STORE_PATH pointing at a directory (audit reports success with 0 pages when the content store cannot be opened #403): every page is fetched, upsertPage throws inside the content store, the crawler logs it at debug and marks the page failed, and the audit ends with no pages and no reason. A signed-in run had already registered, so it was charged.

What changed

  • apps/cli/src/crawler/storage/store-check.ts (new): probes each store with a write inside a transaction that is rolled back (BEGIN IMMEDIATE, CREATE TABLE, ROLLBACK; BEGIN IMMEDIATE alone succeeds on a file SQLite opened read-only). A failure becomes one line with the file, the cause and the fix:
    • owned by another user: sudo chown -R "$(id -un)" ~/.squirrel
    • read-only: chmod -R u+w ~/.squirrel
    • EPERM from access(2) or mkdir: blocked by a sandbox or security policy, allow writes to ~/.squirrel or run outside the sandbox
    • a directory (blamed on SQUIRREL_CONTENT_STORE_PATH when it came from there), not a database, disk full
    • a busy store (another squirrel writing) is not a failure; the probe waits 250 ms at most
    • recursive fixes only ever cover ~/.squirrel; outside it the fix names the file alone
  • squirrel audit runs the check before the run is registered (the audit base is debited at register) and before any request goes out. runAudit and runCrawl run it before creating storage, for the MCP and squirrel crawl paths. The link cache is checked only when external links will be checked.
  • packages/crawler: a StorageError no retry fixes (read-only, cannot open, not a database, malformed, disk full, I/O error; isPermanentStorageError in core-contracts) now ends the crawl instead of being swallowed per page, so a store that breaks mid-crawl fails the audit rather than producing a smaller one. A transient one (locked) still drops the page, and a crawl that stored nothing records the first such failure as its root failure (unknown): No pages were crawled from example.com: a page could not be saved to the local store (it was locked by another squirrel process).
  • Paths stay local: the detailed message prints on the terminal; the run's error sent to the API gets a path-free class.
  • Docs: a "When the CLI cannot write its local store" section in guides/failed-audits.mdx.

Behaviour change for other packages/crawler consumers: a permanent storage error from processUrl now fails start() instead of marking the page failed. Transient errors are unchanged apart from the recorded root failure.

Before and after (from source, local fixture site)

Store state Before After
project.db chmod 444 Audit failed: Storage error during write: ... readonly database after register ✗ Cannot write to ~/.squirrel/projects/<site>/project.db: it is read-only. Fix: chmod -R u+w ~/.squirrel, nothing registered
content-store.db chmod 444 No pages were crawled ✗ Cannot write to ~/.squirrel/content-store.db: it is read-only. ...
sandbox denies writes to ~/.squirrel readonly database error ... it is blocked by a sandbox or security policy ... Fix: allow writes to ~/.squirrel in the sandbox settings, or run the audit outside the sandbox
SQUIRREL_CONTENT_STORE_PATH is a directory No pages were crawled ... it is a directory, not a database file. Fix: set SQUIRREL_CONTENT_STORE_PATH to a file path, such as .../content-store.db
writable audit runs audit runs

Tests

  • apps/cli/tests/crawler/store-check.test.ts (new, 11): writable, new path, directory, not a database, read-only file, read-only directory, uncreatable directory outside ~/.squirrel, recursive fix only inside it, busy store left intact, a real macOS sandbox-exec run (darwin only), message dedupe.
  • apps/cli/tests/commands/audit-local-store-wiring.test.ts (new, 3): through citty, signed in: a directory store and a read-only store exit 1 with no POST /v1/agent-runs and no request to the site; a writable store (control) registers and crawls.
  • packages/crawler/tests/local-store-failure.test.ts (new, 4): permanent failure ends the crawl at the first refused pages, a store that turns read-only after 3 pages fails the crawl, a locked store records the root failure and reason text, isPermanentStorageError through a FiberFailure.
  • Re-run: audit-no-publish-wiring, audit-discovery-probes-wiring, audit-non-public-host-wiring, storage-error, content-store, db-lock-warning, storage-project-path, zero-success-breaker, root-failure-classification, entry-fetch-timeout, crawler-stop-hard-cap: all pass.
  • tsgo --noEmit clean in apps/cli, packages/crawler, packages/core-contracts. bun run lint and bun run format:check clean in apps/cli. tangly check --strict in docs/: all checks passed. detect-secrets-hook on the changed files: clean.

@nc9
nc9 marked this pull request as ready for review October 1, 2026 19:02
…#403

SQLite opens a file it cannot write read-only without saying so, so a store owned by root after a sudo run, or blocked by a coding agent's sandbox, failed at the first page with 'attempt to write a readonly database', and a content store that failed dropped every page and ended 'No pages were crawled'.

- squirrel audit and squirrel crawl probe the project database, content store and link cache with a rolled-back write before the run is registered or any request is sent, and stop with the file, the cause (owner, read-only, sandbox, directory, damaged) and the fix.
- The crawler ends the crawl on a storage error no retry fixes (read-only, cannot open, not a database, disk full) instead of counting each page as failed.
- A crawl that stored nothing because pages failed locally records that as its root failure, so the reason says why instead of only 'No pages were crawled'.

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the fix/cli-local-store-errors branch from c703a0e to 4f4435f Compare October 1, 2026 19:02
@nc9
nc9 merged commit 3cd3505 into main Oct 1, 2026
14 checks passed
@nc9
nc9 deleted the fix/cli-local-store-errors branch October 1, 2026 19:11
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.

audit reports success with 0 pages when the content store cannot be opened

1 participant