Skip to content

Hidden bazel lockfile caching - #11

Closed
Silic0nS0ldier wants to merge 55 commits into
cre4ture:mainfrom
Silic0nS0ldier:hidden-bazel-lockfile-caching
Closed

Silic0nS0ldier wants to merge 55 commits into
cre4ture:mainfrom
Silic0nS0ldier:hidden-bazel-lockfile-caching

Conversation

@Silic0nS0ldier

@Silic0nS0ldier Silic0nS0ldier commented Dec 3, 2026 •

Copy link
Copy Markdown

- Available packs are discovered up-front to cull existance checks of evicted packs
- Manifest lookup ordered by creation date so new entries are included when over max manifests limit.
- Truncation of discovered manifests is now reported in metrics (boolean).
- If cache entries are skipped due to prefix mismatch (indicating GH API acting out of spec), it is logged. Previously silently ignored.
- Pagination traversal now uses `Link` header for continuation.
- Manifests skipped due to limit are now precisely reported.
- Manifests now include the hash of the pack they are for, so reads can be skipped if the associated pack is missing. This allows manifests to expire.
- Ophaned manifests are reported in stats.
* Presence checks do not trigger pack downloads
- Presence checks for blobs no longer trigger an eager download of packs.
- To ensure packs containing blobs prescence checks included are not discarded, renewal is scheduled (skipped if downloaded before a timeout). Configurable with `--pack-renew-interval`.
- Pack renewals are reported in stats.

* Expose pack renewal duration in action interface
- Blobs in packs can now be zstd compressed.
- Compression is configurable (off/on, level).
- New stats for compressed blocks and saved bytes.
- gRPC can now be used in conjunction with HTTP
- New stat `operations` tracks operations triggered by HTTP and gRPC calls. For identical builds using different transports, these should be able the same.
- New stat `backend_requests` to measure traffic hitting GH (which has a quota that a high request volume can exhaust).
* Source server binaries from releases rather than version control

* Validate tag inputs
- Add reap function to delete unmanifested packs that are unreachable.
- Introduce EntryLister interface for listing cache entries with creation times.
- Enhance RunOptions struct to include options for reaping packs.
- Modify Run function to incorporate reaping logic and log reaped packs.
- Create a new remover type to handle the deletion of packs and their manifests.
- Update Layout struct to track unmanifested packs.
- Implement tests for reaping functionality, ensuring correct behavior for old, recent, and unknown packs.
- Update action.yml and main.js to support new inputs for reaping configuration.
- Ensure that the publish budget and upload rate are correctly passed to the binary.
…t miss (#28)

Bazel stamps execution timestamps into every ActionResult, so any action
uploaded twice (e.g. by overlapping CI runs) stored differing results under
one key. The packed store then refused that key forever, silently, and every
re-execution uploaded yet another result so it could never heal.

Resolve such keys deterministically (lowest pack ID, then CID) in both the
cache server and the optimiser layout, log a warning with the count at
discovery, and let the optimiser reclaim the losing copies.
Flushing held packStore.mu across the pack and manifest uploads, so every
read and presence check waited for each upload to finish. A pack download
also takes p.mu while holding a backend slot, so a flush waiting for a slot
deadlocked with finishing downloads until the backend timeout, and could
re-enter the same deadlock immediately after.

Flushes are now serialised by a dedicated mutex and only take p.mu for
bookkeeping between backend calls.
Silic0nS0ldier and others added 25 commits October 30, 2026 16:05
…ping

The optimiser rebuilt the same packs on every pass: it chose packs by waste
alone, even when no grouping could improve them, so a pass re-uploaded
gigabytes to reclaim megabytes. Unused entries could also sit in packs
indefinitely when they were too small a share to trigger a rebuild.

Eviction: entries no job has downloaded or presence-checked for
evict-after-hours (default 168, matching GitHub's expiry of unused caches)
are dropped from packs at least that old. Each affected pack is rewritten
on its own, and keeps its age via a new optional `since` field on manifest
pack descriptors, which older readers ignore. Packs with no used entries are
left for GitHub to expire. Nothing is evicted unless the usage records
provably cover the whole window. Records are now kept per job rather than one
per run, so entries used by any job in a run are never mistaken for unused.

Reshaping: only packs at least twice the eviction threshold old are
regrouped, and only when at least two qualify. A pack is rebuilt only if the
regrouping cuts its restore cost by min-improvement, measured on held-out
runs so it does not chase noise in the window. Grouping uses a per-download
overhead (download-overhead-mb) so small packs restored by the same jobs
merge, and caps entries per pack below the manifest entry limit.

Also: rebuilds publish concurrently with a concurrency-safe repacker that
shares source pack downloads, manifests whose pack is gone are reaped under
reap-unmanifested-packs, and the job summary reports eviction, overfetch and
downloads per job.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Bazel fans uploads out to roughly 10k concurrent ByteStream writes (100
connections x 100 streams). Each upload spooled to disk with unbounded
os.CreateTemp, write, and fsync calls, and every blocking file syscall pins
an OS thread. A large burst, such as uploading the llvm-project repo
contents, exceeded the Go runtime's 10k-thread limit and aborted the server
with "fatal error: thread exhaustion", failing the build with UNAVAILABLE
and then connection refused.

Gate each blocking spool filesystem call through a 64-slot ioGate. Slots are
held only for the duration of a syscall, never across network reads, so a
slow client cannot starve other uploads, and goroutines queued on the gate
hold no thread. Queued calls honour request cancellation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Fixes a panic on two-block frames reachable through the zstd block codec, flagged by govulncheck.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ole (#32)

The post step printed only the last 16 KB of the server log. When the
server crashed, the runtime's goroutine dump filled that window and pushed
the fatal error, and everything before it, out of view.

- Print an excerpt with the log's first lines, the start of any Go runtime
  crash (panic:, fatal error:, runtime:), and its last lines, cut on line
  boundaries with the omitted size marked. The main step's startup-failure
  message uses the same excerpt.
- Publish the whole log as a job artifact, named by the new log-artifact
  input (default bazel-cache-server-log; empty disables). The post step runs
  the server binary's new upload-artifact subcommand, reusing the existing
  artifact uploader, since a crashed server cannot publish its own log.
  Logs over 256 MiB keep their first and last 128 MiB.
- Save the log state before startup so a server that never became ready
  still has its log published. A failed upload warns and never fails the job.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Compute heads from all loaded manifests instead of relying on CID sort order. This prevents a child visited before its parent from leaving that parent marked as a head, bloating the parents list of later manifests.

Example: the child sorts before the parent, but the child is still the only head.

```mermaid
graph LR
  C[Child sorts first] -->|parent| P[Parent sorts later]
  C:::head
  classDef head fill:#dff0d8,stroke:#3c763d
```

The regression test covers layout heads, server discovery, and the parents written by a later flush.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Stop retaining action closure-pack lists that runtime validation does not use, omit raw block metadata that readers can reconstruct, and compact the long-lived CAS index by deriving content CIDs and reusing pack IDs.

Example: many CAS entries reference the same pack and each raw block is determined by its digest.

```mermaid
graph LR
  P[One pack ID] --> C1[CAS digest 1]
  P --> C2[CAS digest 2]
  C1 -. derives raw CID and block .-> H1[Digest 1]
  C2 -. derives raw CID and block .-> H2[Digest 2]
```

Keep the format-2 closure field empty for older readers, and keep compressed block metadata explicit. Add wire-shape and compact-index regression tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Reuse the verified asset download spool in the existing cache publication path. This avoids copying, hashing, and syncing the same bytes a second time while preserving packed staging and local object retention.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Order rebuild groups by their share of source-pack size so completing groups can retire source packs sooner during partial optimization passes. Group contents and packing decisions are unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Wait for an upload-rate reservation before acquiring a backend transfer slot. Recheck start spacing after acquiring a slot, releasing it while waiting when necessary, so delayed acquisitions do not bunch uploads into bursts.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace future timestamp reservations with retry-based start spacing, so canceled waits do not leave unused gaps. Keep backend slots free while the server waits, and open repacker files before rate limiting.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Avoid forcing ephemeral cache-directory spools to disk before they are uploaded or consumed. os.CreateTemp already creates private mode-0600 files, so the extra chmod is unnecessary.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Build, attest, and publish the Darwin ARM64 server in releases and pre-releases. Add platform-aware binary resolution and native macOS CI and smoke coverage while keeping the optimiser Linux-only.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Add Windows x64 and ARM64 cache server support

Publish Windows server executables with checksums and provenance. Handle native architecture selection, process cleanup, and Windows spool file lifetimes; add lifecycle tests and native Windows CI and smoke coverage. Keep the optimiser Linux-only.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Fix Windows asset and pack cleanup in CI

Close asset spool handles before deletion and close restored pack readers in tests. Quote Windows workflow arguments and use an array for optional race flags to satisfy ShellCheck.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Silic0nS0ldier

Copy link
Copy Markdown
Author

Whoops! Forgot to change the target.

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