serve: accept modified filepaths via POST to scope cold hashing#424
Merged
tinder-maxwellelliott merged 1 commit intoJul 11, 2026
Merged
Conversation
Threads the experimental `generate-hashes --modified-filepaths` content-
scoping optimization into the `serve` query service. A CI client already
knows the changed set cheaply (`git diff --name-only from...to`); passing
it lets the server read+hash the content of only those files at both
revisions and treat every other source file as unchanged, turning an
O(all source files) content read into O(changed files) — the expensive
part of a cold hash on a large monorepo.
Because a changed-file list is too large for a URL, it rides in a POST
body: `POST /impacted_targets` (and `/impacted_targets_with_distances`)
with `{"from","to","targetType"?,"modifiedFilepaths"?}`. GET is unchanged
and always the full-content hash; an absent/empty `modifiedFilepaths`
behaves identically to GET.
Correctness: the same set must be applied to both revisions (an unchanged,
unlisted file is content-skipped on both sides and so hashes identically),
and it must be a superset of what actually changed or impacted targets are
missed — the same caveat as the CLI flag. A scoped hash of a SHA is only
comparable to another SHA scoped with the same set, so scoped cache entries
are keyed `<sha>.<fingerprint>.<digest-of-set>`, never mixed with or served
in place of the full `<sha>.<fingerprint>` entry. The empty-set path keeps
today's key so GET/warmup keep sharing entries; existing LRU `--cacheMax*`
pruning bounds the extra entries.
Covered by unit tests (scoped cache key, both-revision threading, POST
parsing/validation) and the serve integration harness — a new `scoped`
case proves scoped-POST == full-GET parity plus a negative control where
an incomplete set correctly misses the change.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
be5093a to
a8bf2f2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds per-request modified filepaths support to the
bazel-diff servequery service — the same content-scoping optimization asgenerate-hashes --modified-filepaths, exposed over HTTP.When a request carries
modifiedFilepaths, the server reads and hashes the content of only those files at bothfromandto, treating every other source file as unchanged. On a large monorepo that turns an O(all source files) content read into O(changed files) — the expensive part of a cold hash. A CI client already has the list cheaply fromgit diff --name-only from...to.API
A changed-file list is too large for a URL, so it rides in a POST body:
POST /impacted_targetsandPOST /impacted_targets_with_distancesaccept{"from","to","targetType"?:[…],"modifiedFilepaths"?:[…]}.GETis unchanged and always the full-content hash. An absent/emptymodifiedFilepathson POST behaves identically to GET. Other verbs still405.Correctness & caching (the tricky part)
<sha>.<fingerprint>.<digest-of-set>— never mixed with, or served in place of, the full<sha>.<fingerprint>entry. The digest is order-independent (sorted) and hex, so the<key>.jsonon-disk mapping stays filename-safe.--cacheMax*pruning bounds the extra entries.No new CLI flag — this is per-request, and it is not part of the config fingerprint.
Changed
HashService— scopedcacheKey+ thread the set intohashAllBazelTargetsAndSourcefilesImpactedTargetsService— pass the same set to both revisionsBazelDiffServer— GET+POST handling, JSON body parsing/validationtools/readme_template.md+README.md(endpoint + a caching-implications note)tools/serve_harness.py— POST-body support in thehttp()helper, retargeted the oldPOST → 405assertion toPUT, and a newscopedcaseTesting
HashServiceTest,ImpactedTargetsServiceTest,BazelDiffServerTest,ServeCommandTest(+ storage/metrics) all green; ktfmt clean.tools/serve_harness.py:--only scoped→ 3/3: scoping to the changed file matched the full GET set (//:core, //:core.txt, //:mid); a negative control that omits the changed file correctly misses it, proving content-skipping takes effect.--only full/subprocess→ 28/28, including the newPUT → 405,POST body parity with GET, andmalformed POST body → 400.🤖 Generated with Claude Code