Repository navigation
Description
Summary
When -max-queries or -max-duration stops admitting candidates, stopAdmitting splits the untested candidates into excluded and skipped. Both of its counting paths get multi-label wordlist entries wrong: the no-visited-set shortcut counts names that -exclude would have removed as skipped, and the visited-set branch can count one untested name twice. The skipped count and the verdict (complete vs degraded) are then wrong; the first case brings back the problem #238 fixed.
Where
internal/scan/dispatcher.go:221-226internal/scan/dispatcher.go:254-292internal/scan/dispatcher.go:43-56internal/scan/dispatcher.go:350-356internal/scan/dispatcher.go:221-252internal/scan/dispatcher.go:337-349internal/scan/dispatcher_test.go:128-166
Details
A budget stop counts excluded multi-label candidates as skipped. stopAdmitting takes the countUnbuilt shortcut whenever d.visited == nil and there are exclusions. visitedSet returns nil for every non-recursive scan, including one whose entries hold several labels (wordlist lines like dev.api, CT/Wayback names merged by passive.Merge, permutations; wordlist.Normalize keeps multi-label entries, reader.go:50). countUnbuilt assumes "every entry is a single label": it only checks subtreeExcluded(e.parent) and exact patterns split as <first label>.<parent> against the frontier parent. For entry a.dev under root example.com with -exclude '*.dev.example.com', next() (line 350) would call scope.excluded("a.dev.example.com") -> true, but countUnbuilt checks subtreeExcluded("example.com") -> false and finds no exact label, so the candidate is added to skipped. Same for an exact pattern a.dev.example.com (split to label a, parent dev.example.com, never a frontier parent in a non-recursive scan). The comment at 254-256 states the precondition the caller does not guarantee. Related: expand (367-381) counts all children of a parent found after the cap as skipped, though exact patterns among them would be counted excluded by countUnbuilt.
Untested cap branch of stopAdmitting counts a duplicate candidate twice. stopAdmitting's default branch (a recursive scan whose wordlist has a multi-label entry, so a visited set exists, #248/#301) is never executed by any test: a cross-package run (go test -coverpkg=./internal/scan ./internal/cli ./pkg/subenum ./internal/tui ./internal/scan) gives stopAdmitting 31.6%, all of it the first two cases. The branch checks each remaining candidate against d.visited but never adds it, while admission (next, 344-348) inserts every key it generates. So when the not-yet-generated remainder holds the same name twice (entry "a.b" under the root and entry "a" under a found b.example.com), the uncapped run tests it once and the capped run counts it as skipped twice.
default:
for _, e := range d.frontier[d.head:] {
for i := e.next; i < d.n; i++ {
...
if _, dup := d.visited[key]; dup {
continue
}
// key never added to d.visited here
if d.cfg.scope.excluded(name) { d.excluded++ } else { d.skipped++ }A scratch test in a copy of the tree (entries b, x, a.b, a; Recursive; MaxQueries 2; b.example.com expanded) printed: "uncapped distinct candidates 7; capped admitted 2 ... skipped 6" -> admitted+skipped = 8, one more than the candidates that exist. TestCapCountsRecursiveRemainderWithoutBuildingIt (#301) covers only single-label entries, so it takes the countUnbuilt path.
Impact
Under -max-queries or -max-duration with -exclude, out-of-scope names that would have been excluded are reported as skipped. The skipped count and the "skipped N additional jobs" notice are inflated and, when every untested candidate was out of scope, the verdict drops from complete to degraded ("{max_queries} reached; N candidates not tested", verdict.go:44-47) -- the case #238 fixed, reintroduced for multi-label entries by the #301 shortcut.
With -max-queries or -max-duration on a recursive scan whose wordlist contains dotted entries (common: "dev.api", "mail.internal"), skipped_by_cap in -stats, the run-quality report and the MCP report is overstated by the number of duplicate names left, and tested+skipped exceeds the true candidate count. Small numbers, but it is the counter the #238/#301 work set out to make exact, and nothing guards it.
Steps to reproduce
Non-recursive scan, -simulate, wordlist www then a.dev, b.dev; -exclude '*.dev.<domain>' -max-queries 1. www is tested; the two *.dev entries are counted skipped (2) and excluded 0, so the verdict is degraded. Without the cap they would be excluded 2.
In internal/scan: d := testDispatcher(Config{Entries: []string{"b","x","a.b","a"}, Recursive: true, MaxQueries: 2}, 2); b, _ := d.next(); d.expand(job{domain: b.domain, depth: 1}); drain(d) -> d.skipped == 6; the same scan with MaxQueries 0 generates 7 candidates in all (2 admitted + 5 left).
Suggested fix
Use countUnbuilt only when every entry is a single label (compute that once in newDispatcher, as visitedSet already scans for a .), else fall back to the per-candidate walk; or make countUnbuilt split each exact/suffix pattern against <entry>.<parent> with multi-label entries in mind. Add a test with a multi-label entry, an exclusion and a cap.
In the default branch keep a local set (or insert into d.visited, which is discarded after the cap anyway) so each remaining name is counted once. Add a dispatcher test with multi-label entries and a cap that asserts admitted+skipped+excluded equals the uncapped run's candidate count, with and without an -exclude pattern hitting the duplicate name, and one where the duplicate is excluded under one parent spelling.
Acceptance criteria
- Non-recursive scan with multi-label entries,
-excludeand a cap counts the out-of-scope entries as excluded, not skipped, and keeps a complete verdict when nothing in scope was left - Recursive scan with dotted entries stopped by a cap reports tested + skipped + excluded equal to the candidate total
- Tests for both branches of
stopAdmitting
Related: #238 (closed as completed; the multi-label case of the same problem is back through the #301 shortcut), #301
Getting started
- Relevant files:
internal/scan/dispatcher.go,internal/scan/dispatcher_test.go - How to run tests:
go test ./...(tests must stay hermetic: use-simulate, a lab zone orinternal/dnstest, never a live domain) - Related docs:
docs/DEVELOPER_GUIDE.md,docs/ARCHITECTURE.md
Filed by repo-audit/full-audit at 0f3b0b6. Severity: medium. Effort: S. audit-key: bug|internal/scan/dispatcher.go|stopAdmitting
Activity
TMHSDigital commentedon Nov 16, 2026
Fixed in 87db011.
stopAdmittingnow uses thecountUnbuiltshortcut only when every entry is a single label (computed once innewDispatcher); multi-label entries take the per-candidate walk, which now also adds each name to the visited set so a name the remainder would reach through two parents is counted once.Verified with two new dispatcher tests, both failing before the change and passing after:
TestCapCountsExcludedMultiLabelEntries(flat scan,a.dev/b.devwith*.dev.example.comor an exact pattern,MaxQueries 1: counts match the uncapped run) andTestCapCountsRecursiveMultiLabelRemainderOnce(entriesb, x, a.b, a, recursive,MaxQueries 2, with no exclusion, an exact one on the duplicate name, and a subtree one: admitted + skipped + excluded equals the uncapped candidate total). gofmt, go vet, golangci-lint v2.15.0 andgo test ./...pass.Not changed: the related note that
expandcounts every child of a parent found after the cap as skipped (exact patterns among them, or duplicates in a multi-label recursive scan, are not split out). That path was outside this issue's acceptance criteria.Count a capped expand's children as stopAdmitting counts its remainder (