Skip to content

perf(audit-engine): stop sending dead-links chunks once one comes back unanswered #753 - #755

Merged
nc9 merged 2 commits into
mainfrom
fix/dead-links-stop-on-unanswered-753
Oct 14, 2026
Merged

nc9 merged 2 commits into
mainfrom
fix/dead-links-stop-on-unanswered-753

Conversation

@nc9

@nc9 nc9 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Closes #753.

What changed

A signed-in squirrel audit sends its external links to the cloud dead-links service 200 at a time, and checks locally any link the service leaves out of a reply. Since squirrelscan/repo#2799 the service waits up to a minute for links it has not seen and gives up after 20 seconds without a new answer, so a busy service could answer every batch with nothing, one wait per batch, before the local checks started.

runBulkChecker (packages/audit-engine/src/external-checker.ts) now ends the bulk pass when a chunk comes back answering none of the urls it asked about, the same way it already did on a throw. The remaining urls go to the local per-link checker straight away. A chunk that answers at least one of its urls keeps the pass going, so partial answers behave as before.

  • Where the loop lives: the issue names runBulkChecker in apps/cli/src/audit/adapter.ts, but that copy, and the checkExternalLinksOnStorage around it, has been unreferenced since the CLI moved its post-crawl phases onto the engine's streaming pipeline (perf(cli): run the audit's post-crawl phases on the streaming pipeline #252). The live loop is the engine's. This PR fixes the engine's and deletes the adapter's unreferenced copy (and the imports only it used), keeping the ExternalBulkChecker type that cloud.ts imports. The CLI's other fork, apps/cli/src/crawler/external-checker.ts, is also unreferenced in src (only its ExternalCheckResult type is used) but two tests still exercise it; that is CLI: delete the unreferenced external link checker and sitemap parser copies, and point their tests at the shared packages #756.
  • What counts as an answer: only results keyed by a url the chunk requested. A map holding only other keys is no answer.
  • Cloud runs: the engine loop is shared, so the hosted runtime gets the same rule. A cloud run's dead-links call carries a run id, and the API fills every url Perch leaves unanswered from its own checker, so a cloud chunk comes back empty only when the service really failed; the rule changes nothing there. The hosted runtime's link-check-service checker (behind SQUIRREL_LINK_CHECK_SERVICE_URL, unset in production) can answer a chunk with nothing when its shared deadline is spent, when the service returns no ticket, or when the first poll fails before any verdict arrived. With this PR each of those now sends the remaining chunks to the local checker too, where before only a throw did. Its comments that say only a throw ends the pass need a follow-up in the private repo: squirrelscan/repo#2820.
  • Never throws: the chunk is read inside the try, so a checker that resolves to something other than a map still ends the pass instead of failing the phase.

Acceptance criteria

  • A bulk-checker test where the service answers some urls of a chunk: the unanswered urls get a local per-link check and appear in the external-link results with their local status. (checkExternalLinks test in the engine; through the CLI's own checker, the stored link rows carry the local 200 and 404.)
  • A test where the service answers no url of the first chunk: no further chunks are sent, and every url is checked locally. (450 urls, three chunks' worth: one call, 450 local requests, each result with its local status. Engine and CLI.)
  • A chunk that answers at least one url does not stop the bulk pass. (One answer per chunk: three calls of 200, 200 and 50.)
  • An empty answer is never read as "all links fine": a real crawl whose two external links the service leaves unanswered gives links/dead-links Checked 2 external link(s); 1 dead, and links/broken-external-links lists the 404.

Verification

  • bun test tests/bulk-checker-unanswered-753.test.ts in packages/audit-engine: 9 pass (also after the never-throws fix). Against main's runBulkChecker 4 of them fail (the stop cases), the rest pin today's fallback.
  • bun test tests/audit/dead-links-unanswered-753.test.ts tests/audit/cloud-spend.test.ts in apps/cli: 10 pass.
  • Neighbours: link-checks-not-run-e2e, external-link-cap-2729 (engine), quick-skips-cloud, undecoded-fetches (CLI): pass.
  • tsgo --noEmit in packages/audit-engine and apps/cli: clean. apps/cli format:check and lint: clean.
  • docs/: tangly check --strict passes. docs/rules/links/dead-links.mdx says squirrel stops asking after a batch with no answers.

Agent skill

No change needed: the skill does not describe how the CLI batches dead-link checks.

@claude

claude Bot commented Oct 14, 2026

Copy link
Copy Markdown

Reviewed the diff. No blocking issues.

  • (low) packages/audit-engine/src/external-checker.ts: the stop-on-empty rule also fires on a chunk whose urls the service legitimately answered under a different key (for example a normalised url). The doc says the map is keyed by the exact requested url, so this is fine today. If the service ever normalises keys, the pass would silently end after the first chunk. The new "answer for urls not asked about" test pins this, which is good.
  • (nit) A single transient empty reply now disables bulk checking for the rest of the audit, where before a later chunk could recover. That is a reasonable trade-off and matches the stated intent. The CHANGELOG/docs wording covers it.
  • Cleanup: I found no remaining references to the deleted adapter checkExternalLinksOnStorage or ExternalLinkCheckProgress in the CLI. The engine's copy is still exported and used.
  • Tests: coverage is good. It covers empty, partial, throw, unrelated-key and mixed chunks, plus engine-level and CLI-level integration, and the summary never reports all links fine after an empty reply. I did not run the suite.

nc9 added 2 commits October 14, 2026 22:05
…k unanswered #753

A chunk the bulk checker answers with none of its urls now ends the bulk
pass, like a throw: the remaining urls go to the local per-link checker
straight away instead of each later chunk costing the service's full wait.
A chunk that answers at least one url keeps the pass going.

Tests pin the local fallback for urls the service leaves out (stored with
their local status, a 404 reported as dead by links/dead-links), the stop
after an unanswered chunk, and that partial answers do not stop the pass,
through the engine and through the CLI's own dead-links checker.

Removes the CLI adapter's unreferenced fork of checkExternalLinksOnStorage
and runBulkChecker; the live path has been the engine's since #252.

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the fix/dead-links-stop-on-unanswered-753 branch from cc4689a to df8e56e Compare October 14, 2026 11:05
@claude

claude Bot commented Oct 14, 2026

Copy link
Copy Markdown

Review of #755. I read the diff and grepped for leftover references. I did not run the tests, and CI was still pending when I looked.

The change is small and does what it says. runBulkChecker now breaks when a chunk answers none of the urls it was asked about. The check sits inside the try, so a non-map return still ends the pass instead of throwing. The adapter dead code is removed, and a grep finds no remaining callers of the CLI's checkExternalLinksOnStorage (the remaining hits are the engine's own copy and comments). The tests cover the stop case, the partial-answer case and the CLI path.

  • (low) packages/audit-engine/src/external-checker.ts:99 A single empty reply now disables the cloud path for every remaining chunk, so one transient empty answer sends all remaining links to local checking. That is the intended trade-off. A short comment, or a follow-up to allow one retry, would make it explicit.
  • (nit) apps/cli/src/audit/adapter.ts:863 The doc comment now names checkExternalLinksOnStorage in backticks, but that function no longer exists in this file. Pointing at the engine's equivalent would be clearer. The comments in controllers/audit.ts and streaming-pre-rules.ts still mention it too.
  • (nit) The hosted-runtime comments that say only a throw ends the pass are tracked in squirrelscan/repo#2820. Please make sure that follow-up lands.

No correctness, security or performance problems found. Looks good to merge once CI is green.

@nc9
nc9 merged commit 7e991f5 into main Oct 14, 2026
15 checks passed
@nc9
nc9 deleted the fix/dead-links-stop-on-unanswered-753 branch October 14, 2026 11:22
nc9 added a commit that referenced this pull request Oct 15, 2026
…ers #764

A rate-limited bulk answer (rateLimited 503, 429, 430) or one the
service could not verify (wafBlocked, null status) is never written to
the local link cache, and the next run asks the service again. Fixed in
the engine by #755 and #800; this pins it through the real SQLite cache.

Signed-off-by: Nik Cubrilovic <[email protected]>
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.

CLI: stop sending dead-links chunks once one comes back unanswered, and test the local fallback for urls the service leaves out

1 participant