Skip to content

Make content sniffing trim-safe - #1398

Merged
quinnj merged 1 commit into
masterfrom
fix/trim-safe-sniff
Oct 14, 2026
Merged

quinnj merged 1 commit into
masterfrom
fix/trim-safe-sniff

Conversation

@quinnj

@quinnj quinnj commented Oct 9, 2026

Copy link
Copy Markdown
Member

HTTP.sniff, and servecontent without a content_type (or a name with a known extension), failed juliac --trim=safe on Julia 1.13.1 with three verifier errors:

  • HTTP._sniff_match(::Any, data, ::Int64)
  • HTTP._sniff_content_type(::Any)
  • convert(String, ::Any)

Root cause: _SNIFF_SIGNATURES was an Any[...] vector, so each call in the sniff loop dispatched at runtime. The table holds six signature types, more than inference will union-split (four), so giving it a concrete element type alone isn't enough.

Fix: the table is now Union{_SniffHTMLSig,_SniffMasked,_SniffExact}[...]. The three data-free signatures that always ran last (MP4, JSON, text) move to a tuple that sniff checks after the table. Both loops have three types, so dispatch is static. Signature order and results are unchanged.

Coverage: test/http_trim_open_fileserver.jl now calls servecontent with bytes and no content type, plus HTTP.sniff on a string, and checks the results. That workload runs the built executable, so the content types are also checked at runtime.

Found while reviewing #1397, whose router workload passes content_type explicitly to avoid this gap.

Verification (Julia 1.13.1, macOS arm64)

  • Trim workload with the fix: verifier clean, executable exits 0 (6/6).
  • Same workload with only the src change reverted: 12 verifier errors, all the three sniff calls above (once each for the Vector and SubArray inputs, via both callers).
  • Old vs new sniff on 25,371 inputs (every signature with whitespace, case, and suffix variants, plus random bytes up to 600 long), as both Vector and view: 0 mismatches, 27 distinct content types.
  • http_forms_tests.jl, http_multipart_tests.jl, http_server_http1_tests.jl, public_api_tests.jl: 909/909 pass.

Not in this PR

servecontent(request, io) with an IO source and no size still fails trim: _source_size formats a caught error with sprint(showerror, err), which adds about 18 verifier errors. That's a separate change.

🤖 Generated with Claude Code

`_SNIFF_SIGNATURES` was an `Any[...]` vector, so every `_sniff_match` and
`_sniff_content_type` call in the `sniff` loop dispatched at runtime, which
`juliac --trim=safe` rejects. Type the table as a three-member union and
check the three trailing data-free signatures (MP4, JSON, text) from a
tuple afterwards. Both loops stay within inference's union-splitting
limit, so dispatch is static. Signature order is unchanged.

The open-fileserver trim workload now calls `servecontent` without a
content type and `HTTP.sniff` directly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.79%. Comparing base (52ba567) to head (d2d982d).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1398      +/-   ##
==========================================
- Coverage   90.80%   90.79%   -0.02%     
==========================================
  Files          31       31              
  Lines       12835    12838       +3     
==========================================
+ Hits        11655    11656       +1     
- Misses       1180     1182       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@quinnj
quinnj merged commit f9eaa66 into master Oct 14, 2026
9 of 10 checks passed
@quinnj
quinnj deleted the fix/trim-safe-sniff branch October 14, 2026 00:23
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.

1 participant