Skip to content

fix(tech-detect): derive a search literal for every detector, share the extras round by round, reserve the tail #1420 - #1421

Closed
nc9 wants to merge 1 commit into
mainfrom
fix/tech-extras-budget-1420
Closed

nc9 wants to merge 1 commit into
mainfrom
fix/tech-extras-budget-1420

Conversation

@nc9

@nc9 nc9 commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1420.

Cause (confirmed in the code). Past the first 256 KB of a bundle, sampleBundleExtras fills a 24 KB budget with windows around hint literals, then the tail. 184 of the 194 script-content detectors declared no hint (Sentry.init, the React devtools hook, posthog.init, Stripe(, GA4 config, the ad pixels), so they could match only in whatever tail the windows left. #1379 let the windows take more (24 to 48 kept hits, no kept cap for pattern-tested hints, new hint literals), so the tail shrank or vanished and those detections were lost.

Fix, three parts, all in the sampler (packages/tech-detect/src/bundle-sample.ts, new hint-derive.ts).

  1. A search literal for every detector. A detector with no hint gets the literals its pattern requires, derived from the regex source (deriveHints): per top-level alternative, the longest run of plain characters every match must contain (at least 4). Conservative by construction: a group, class, ., escape class, or a character followed by ?, * or { ends a run and is never part of a hint, so a hint is never a literal a match can lack. Case-insensitive patterns get lower-cased hints and are searched in a lower-cased copy (only when its length matches the original). Of the unhinted detectors, more than 120 now have one; the rest stay tail-only.
  2. Windows are shared out, not first come first served. Each hint keeps at most 8 qualified windows (a window must match one of its detectors' patterns, as in Tech detection misses Supabase in real bundles: URL in a variable, sb_secret_ keys, matches past the bundle byte budget #1379, and identical windows count once). Then the budget is filled round by round: every hint's first window before any hint's second, skipping a window that no longer fits. A literal that repeats, or hundreds of Supabase and Firebase windows, cannot take the sample from Sentry.
  3. A tail reserve. The windows may use the extras budget minus a reserve of 6 KB (at most a quarter of it); the tail always keeps at least that, for detectors with no literal at all.

Cost. 1 MB benign: 22 ms, 5 MB: 86 ms, 16 MB: 275 ms; a body of dense hits for five detectors: 181 ms. The hostile 5 MB sampler test is unchanged.

Tests (fail on the old sampler).

  • packages/tech-detect/tests/extras-budget-1420.test.ts (13): deriveHints cases, a soundness sweep over every script-content pattern (each derived hint is a literal part of its pattern), a late Sentry.init with 400 earlier Supabase and Firebase windows (the AC test), first-window-before-second fairness across Sentry, PostHog, React and Stripe, a case-insensitive detector found, the tail reserve, and a hostile single-literal body.
  • packages/audit-engine/tests/tech-extras-budget-1420.test.ts (3): the same through the cloud payload path at the real 64 KB / 512 KB caps with buildTechInputs: Sentry, then React, PostHog and Stripe, late in a 700 KB bundle with a crowd of earlier windows.
  • Existing: bundle-content-1254 (54 with the earlier tests), the Supabase and 1254 bundle suites, pattern-bounds, fingerprints.

What I could not do here. The AC's corpus comparison against v0.0.140 needs 53's stored corpus (10,133 sites); I do not have it. The unit tests pin the mechanism and the soundness of the derived hints, not the 30 real sites. Please re-run the corpus with this branch: expect Sentry back on all 30, no losses against v0.0.140. Separately, 53's note that the uncapped build still loses Contentful (4 sites) and Clarity (4) against v0.0.140 does not come from the extras budget (an uncapped body is read whole); that is probably candidate ordering (MAX_IN_CODE_CANDIDATES, the first matches sitting in strings or comments) and is filed as #1422.

Interplay with #1413 (merging the local whole-bundle scan into the signed-in section, #1406). It touches the CLI and audit-engine technologies.ts and the docs, not the sampler, so they do not conflict in code (only CHANGELOG and technologies.mdx text). They are complementary, not one subsuming the other: #1413 gives a signed-in CLI audit the whole-bundle result, while this fixes the capped payload everything else still sends (the hosted services and cloud-audit-runtime, which keep the 64 KB / 512 KB caps and the 256 KB script limit, and the CLI payload itself).

Docs: docs/cloud/technologies.mdx (what the extras hold). CHANGELOG under Unreleased / Fixed. Skill: no change needed.

nik

…he extras across hints round by round, reserve the tail #1420

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9

nc9 commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #1433, shipped in v0.0.151.

nik

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.

Tech detection: since v0.0.146, hint windows crowd out the bundle tail, so unhinted detectors (Sentry, React, PostHog...) miss on large bundles

1 participant