Skip to content

feat(cli): zccache defender-exclusions helper (closes #273) - #335

Merged
zackees merged 2 commits into
mainfrom
issue/273-defender-exclusions
May 22, 2026
Merged

zackees merged 2 commits into
mainfrom
issue/273-defender-exclusions

Conversation

@zackees

@zackees zackees commented May 21, 2026

Copy link
Copy Markdown
Collaborator

Closes #273

Summary

Cold zccache builds on Windows pay multi-minute Defender real-time-scan
penalties on every cached artifact write. zccache's own telemetry can't see
it (the daemon sees writes complete; wall clock balloons between write()
and the bytes landing on disk). One-time Defender exclusion fixes it
completely, but most users don't know to set one.

Add a zccache defender-exclusions subcommand with three modes that
collapse the fix into a single, copy-pasteable command:

  • check — print exclusion status (human-readable + --json),
    non-destructive, no elevation required.
  • add — add the cache root (and any sibling runtime/) via
    Add-MpPreference -ExclusionPath. Requires admin; exits non-zero with
    a "re-run from elevated shell" message otherwise — never attempts UAC.
  • remove — symmetric undo of add.

Non-Windows hosts print Defender exclusion is Windows-only. and exit 0,
so cross-platform scripts can call the subcommand unconditionally.

The Windows daemon emits a one-line stderr warning on startup when the
cache root isn't excluded. Suppressible via ZCCACHE_QUIET=1. Non-fatal.

Path-set computation, token-elevation detection
(GetTokenInformation/TokenElevation), the quiet-env predicate, and the
PowerShell subprocess plumbing live in zccache-core::defender so the
daemon's first-run banner and the CLI subcommands share one
implementation.

Test plan

  • soldr cargo test -p zccache-core --lib — 65 passed (incl. 8 new
    defender::* unit tests covering path-set computation, quiet-env
    predicate, Windows path matching/quoting, and the non-Windows
    unsupported path).
  • soldr cargo test -p zccache-cli --test defender_exclusions —
    integration test for non-Windows (no-op behavior, exit code, JSON
    shape) and Windows (read-only check smoke).
  • soldr cargo test -p zccache-cli --lib and --bin zccache — 31 +
    53 passed, no regressions.
  • soldr cargo test -p zccache-daemon --lib — 223 passed.
  • soldr cargo clippy -p zccache-core -p zccache-cli -p zccache-daemon --all-targets -- -D warnings — clean.
  • soldr cargo fmt --all -- --check — clean.
  • RUSTDOCFLAGS="-D warnings" soldr cargo doc --no-deps — clean.
  • Manual smoke on Windows: zccache defender-exclusions check,
    --json, and unelevated add (correctly errors with re-elevate
    message and exit 1).

Notes

  • Wire-format unchanged; no PROTOCOL_VERSION bump needed.
  • zccache-core gains Win32_Security and Win32_System_Threading
    windows-sys features for the elevation check.
  • README has a new "Windows: Defender exclusions" subsection under
    "Performance" explaining the perf cost and the fix command.

Cold zccache builds on Windows pay multi-minute Defender real-time-scan
penalties on every cached artifact write. The pathology is invisible to
zccache telemetry — the daemon sees its writes complete; the wall clock
balloons between `write()` and the bytes landing on disk.

Add a `zccache defender-exclusions` subcommand with three modes that
collapse the fix into a single, copy-pasteable command:

- `check`: prints exclusion status (human-readable + `--json`),
  non-destructive, no elevation required.
- `add`: adds the cache root (and any sibling `runtime/`) via
  `Add-MpPreference -ExclusionPath`. Requires admin; exits non-zero with
  a "re-run from elevated shell" message otherwise — never attempts UAC.
- `remove`: symmetric undo of `add`.

On non-Windows the subcommand prints `Defender exclusion is Windows-only.`
and exits 0 so cross-platform scripts can call it unconditionally.

The Windows daemon emits a one-line stderr warning on startup when the
cache root isn't excluded. Suppressible via `ZCCACHE_QUIET=1`. Non-fatal.

Path-set computation, token-elevation detection (`GetTokenInformation` /
`TokenElevation`), the quiet-env predicate, and the PowerShell
subprocess plumbing live in `zccache-core::defender` so the daemon's
first-run banner and the CLI subcommands share one implementation.

Closes #273
@zackees
zackees force-pushed the issue/273-defender-exclusions branch from 62d0a42 to 960dc56 Compare May 22, 2026 00:02
PR #336 added a `profile: bool` field to `Request::SessionStart` while PR
#337 (merged minutes earlier) added a test that constructs SessionStart
without it. Independently both compiled; together they don't. Add the
missing field so main builds.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees merged commit 039bab6 into main May 22, 2026
25 of 26 checks passed
zackees added a commit that referenced this pull request Oct 5, 2026
…#1912)

forge-ci/ci.yml#335 standardizes promotion on setup-soldr's ancestor encoding --
shortest parent-edge distance from a live git DAG walk -- rather than a
first-parent ordinal, which INVERTS on wide merges: a 50-commit branch tip
reports ordinal 53 while the merge commit containing it reports 4, so a cache
saved at the merge looks OLDER than one saved 50 commits before it. #335 keeps
the `m<n>` label for offline audit only.

This adds that opt-in to the `ci.toml` landed in be15264, which declared
`[cache.promote] mode = "off"` and no family opted in. Only the promotion
declaration changes; the measured per-shape ceilings above it are untouched.

`compile` (900MB), `deps` (810MB), `dylint-out` (850MB) and `dylint` (540MB)
are the four at or above CACHE-031's 256MB floor. `registry` (160MB), `sdk`
(100MB), `soldr-mini` (15MB) and `uv` (4MB) stay below it, where unbounded entry
count is noise rather than a budget threat.

Validated: schema CLEAN, CACHE-029 clean, CACHE-031 clean -- and it fires for
exactly those four families when the opt-in is removed. CACHE-030/032 report
`needs_review`, which is correct while setup-soldr#566 is unreleased.


Local-Gate: v1 tree=951c2bd186b4bc4dad8cb7327842d4296b28f373 secs=1187 lanes=lint:run,py-tests:run,check:run,docs:run,dylint:run,tests:run
Ci-Attestation: {"at":1791182724,"gate":"rust/all/fmt","host":"linux-x86_64","key":"6410d253b2227297d9ec675791b7f6d02634047be3076d9b4a70277470fcd7ef","lane":"lint","parents":["be15264cde5615073b8ef8e806233c32b4da2703"],"secs":84,"stamp":"16cb944d13d413e1db8eae41ecc741a1","tree":"951c2bd186b4bc4dad8cb7327842d4296b28f373","v":1,"via":"run"}
Ci-Attestation: {"at":1791182724,"gate":"python/all/static","host":"linux-x86_64","key":"6410d253b2227297d9ec675791b7f6d02634047be3076d9b4a70277470fcd7ef","lane":"lint","parents":["be15264cde5615073b8ef8e806233c32b4da2703"],"secs":84,"stamp":"0f5a084c5196103a15e68629c5a024fa","tree":"951c2bd186b4bc4dad8cb7327842d4296b28f373","v":1,"via":"run"}
Ci-Attestation: {"at":1791182724,"gate":"python/all/test","host":"linux-x86_64","key":"09d044cdfd249d644f1b6cca838156eb6d1324e30cd90ebafb51f8dde686485d","lane":"py-tests","parents":["be15264cde5615073b8ef8e806233c32b4da2703"],"secs":40,"stamp":"914e6c4944937f526693fafab4fea725","tree":"951c2bd186b4bc4dad8cb7327842d4296b28f373","v":1,"via":"run"}
Ci-Attestation: {"at":1791182724,"gate":"rust/x86_64-unknown-linux-gnu/check","host":"linux-x86_64","key":"53444381fef24041d3da0a9889572d27960ea2156fb2b87ee34c461b3095bb2c","lane":"check","parents":["be15264cde5615073b8ef8e806233c32b4da2703"],"secs":104,"stamp":"40224b980ea753b7389334638b06cca8","tree":"951c2bd186b4bc4dad8cb7327842d4296b28f373","v":1,"via":"run"}
Ci-Attestation: {"at":1791182724,"gate":"rust/x86_64-unknown-linux-gnu/doc","host":"linux-x86_64","key":"a1ddecc1ba3f70e1ecbfd4c3ee0543bbab1c04abc93378fa02fec6dc6d134a01","lane":"docs","parents":["be15264cde5615073b8ef8e806233c32b4da2703"],"secs":47,"stamp":"24a44ca8ac5d3eeb3ec7244a6b214d48","tree":"951c2bd186b4bc4dad8cb7327842d4296b28f373","v":1,"via":"run"}
Ci-Attestation: {"at":1791182724,"gate":"rust/x86_64-unknown-linux-gnu/dylint","host":"linux-x86_64","key":"6ce0a114df8d61da1345252308690a43278c751db872269ddd1029e8ee73490f","lane":"dylint","parents":["be15264cde5615073b8ef8e806233c32b4da2703"],"secs":561,"stamp":"1614593641eabc194919726d3de66822","tree":"951c2bd186b4bc4dad8cb7327842d4296b28f373","v":1,"via":"run"}
Ci-Attestation: {"at":1791182724,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"cdf8ee607199cf657806d1ea2a922a2116c78bd1570066bca1cddc00e616b1c9","lane":"tests","parents":["be15264cde5615073b8ef8e806233c32b4da2703"],"secs":352,"stamp":"066a71139e96fd5e626140155b975151","tree":"951c2bd186b4bc4dad8cb7327842d4296b28f373","v":1,"via":"run"}

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
@zackees
zackees deleted the issue/273-defender-exclusions branch November 5, 2026 05:56
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.

Windows: add Defender exclusion helper for the cache directory

1 participant