Skip to content

feat(tgb): add AllTargetsFileHashes column 22 support - #285

Merged
yushan8 merged 6 commits into
yushan/all-targets-config-basefrom
yushan/all-targets-config-v2
Aug 20, 2026
Merged

feat(tgb): add AllTargetsFileHashes column 22 support#285
yushan8 merged 6 commits into
yushan/all-targets-config-basefrom
yushan/all-targets-config-v2

Conversation

@yushan8

@yushan8 yushan8 commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds TGB (Target Graph Binary) format support for AllTargetsFileHashes, stacked on #286.

  • New column 22 (ALL_TARGETS_FILE_HASHES) — length-prefixed key-value string pairs, zstd compressed
  • Forward/backward compatible: old readers skip unknown column IDs, new readers on old blobs get nil (no version bump needed)
  • Reader.AllTargetsFileHashes() lazy accessor decodes only column 22 (cheap, no full graph decode)
  • Controller TGB comparison path checks AllTargetsFileHashes before dispatching to normal TGB diff
  • MergeChunks propagates AllTargetsFileHashes from metadata chunks before TGB encoding

Files changed

  • internal/tgb/format.go — column ID 22
  • internal/tgb/encode.goencodeStringMap + column emission
  • internal/tgb/reader.godecodeStringMap + AllTargetsFileHashes() accessor + DecodeGraph integration
  • internal/tgbdiff/adapt.goMergeChunks propagation fix
  • controller/getchangedtargets.goallTargetsChangedFromTGB(), TGB path wiring
  • controller/getchangedtargets_tgb_test.go — trigger/no-trigger tests
  • internal/tgb/tgb_test.go — round-trip tests

Test plan

  • TGB round-trip tests — AllTargetsFileHashes survives encode/decode (present/absent/empty)
  • TGB Reader.AllTargetsFileHashes() accessor test — lazy single-column decode
  • TGB controller test — trigger fires → all targets changed, skips normal TGB diff
  • TGB controller test — matching hashes → normal TGB diff proceeds
  • All existing TGB tests pass

Stack: depends on #286

@yushan8
yushan8 force-pushed the yushan/all-targets-config-v2 branch from dc9447b to 45cd0c3 Compare August 19, 2026 16:49
@yushan8 yushan8 changed the title feat(config): add AllTargetsFiles to invalidate all targets on trigger file change feat(tgb): add AllTargetsFileHashes column 22 support Aug 19, 2026
@yushan8
yushan8 changed the base branch from main to yushan/all-targets-config-base August 19, 2026 17:28
@yushan8
yushan8 marked this pull request as ready for review August 19, 2026 21:55
@yushan8
yushan8 requested review from a team as code owners August 19, 2026 21:55
yushan8 and others added 6 commits August 19, 2026 20:56
Add TGB support for the AllTargetsFileHashes sidecar so the
AllTargetsFiles feature works regardless of graph_format. Column 22
stores a length-prefixed sequence of (key, value) string pairs,
zstd-compressed. Old readers skip unknown column IDs; new readers on
old blobs get nil — no format version bump needed.

The TGB comparison path in the controller now checks
AllTargetsFileHashes via a cheap single-column decode before the full
columnar diff, matching the gob path's behavior.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Verify that AllTargetsFileHashes survives TGB encode/decode via both
full Decode and the lazy Reader.AllTargetsFileHashes() accessor. Covers
present, absent, and empty-map cases. Also fixes canonicalise() to
preserve AllTargetsFileHashes so existing round-trip tests remain
correct when graphs carry the sidecar.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
MergeChunks was not merging AllTargetsFileHashes from metadata chunks,
so the field was silently dropped before TGB encoding. This caused the
AllTargetsFiles trigger to never fire on the TGB comparison path.

Also adds controller-level TGB tests for both trigger and no-trigger
cases, verifying end-to-end that AllTargetsFileHashes survives the full
write → read → compare pipeline.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Map iteration order is random in Go, so the same logical
AllTargetsFileHashes could produce different byte sequences across
runs, violating the deterministic computation property and causing
spurious cache misses.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
- gofmt alignment in colNames map and a test's Params struct literal
- DecodeGraph now reuses Reader.AllTargetsFileHashes() instead of
  duplicating the column-decode logic inline
Makes it clearer that all targets in the graph are reported as changed
when the trigger fires, not just the ones that happen to have different
hashes.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@yushan8
yushan8 force-pushed the yushan/all-targets-config-v2 branch from 681fe6f to c51d4b7 Compare August 20, 2026 03:57
@yushan8
yushan8 merged commit e29dbca into main Aug 20, 2026
10 checks passed
yushan8 added a commit that referenced this pull request Aug 20, 2026
…r file change (#286)

## Summary

- Adds `RepositoryConfig.AllTargetsFiles`: a list of repo-relative file
paths that, when their content hash differs between two revisions, cause
`GetChangedTargets` to report every target in the second revision as
changed (distance 0)
- File hashes are computed from `git ls-tree` during graph computation
in `targethasher.FromProto`, stored as sidecar data in
`Metadata.AllTargetsFileHashes`, and compared at diff time in the
controller
- Intended for files that affect the build globally but are invisible to
the target graph (toolchain definitions, CI config, Bazel wrapper
scripts)
- Gob-format graphs carry this field automatically via gob serialization

### Data flow

```
git ls-tree → HashConfig.KnownSourceHashes
  → targethasher.FromProto filters by AllTargetsFiles
  → Result.AllTargetsFileHashes
  → mapper → entity.Metadata.AllTargetsFileHashes
  → stored in graph blob (gob auto-serialization)
  → read back at comparison time in controller
  → if any hash differs → all targets reported as changed
```

### Example config

```yaml
repository:
  - remote: "git@github.com:org/repo.git"
    all_targets_files:
      - .bazelrc
      - .bazelversion
      - tools/bazel
      - rules/go/sdk.bzl
```

## Test plan

- [x] `allTargetsFileChanged` unit tests — nil/empty/matching/differing
hash scenarios (table-driven)
- [x] `compareTargetGraphs` gob-path test — trigger fires → all targets
changed
- [x] `compareTargetGraphs` gob-path test — matching hashes → normal
diff
- [x] Mapper propagation tests — Result → Metadata, including via
ResultToGraphChunks
- [x] All existing tests pass

**Stack:** TGB format support in PR #285

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
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.

2 participants