Skip to content

fix(daemon): auto-classify warm + warn on bad persisted depgraph (#320) - #337

Merged
zackees merged 1 commit into
mainfrom
issue/320-warm-classifier
May 21, 2026
Merged

zackees merged 1 commit into
mainfrom
issue/320-warm-classifier

Conversation

@zackees

@zackees zackees commented May 21, 2026

Copy link
Copy Markdown
Collaborator

Closes #320.

Summary

zccache v1.8.1 emitted verdict=Cold reason=cold_skip for every lookup on
warm rebuilds even when the persisted depgraph.bin from a prior session was
present. The daemon was already loading the depgraph at startup, but a load
failure (version mismatch / corruption) only logged via tracing::warn!,
which gets swallowed by the daemon's detach_stdio() — so the cold fallback
was invisible in both stderr and last-session.log.

This PR ships Option 2 from the issue: classify the session by what is on
disk, not by session lineage. No new flag, no protocol version bump.

Changes

Non-changes

  • PROTOCOL_VERSION unchanged — no wire format change.
  • --no-depgraph-cache path is preserved verbatim.
  • Existing depgraph_persistence_test integration tests still pass.

Test plan

  • soldr cargo fmt --all
  • soldr cargo clippy --workspace --all-targets -- -D warnings
  • soldr cargo test --workspace --lib — 1370+ unit tests pass, including
    five new classify_load_* tests in snapshot.rs.
  • soldr cargo test -p zccache-daemon --test depgraph_warm_classify_test -- --ignored — all 5 new integration tests pass.
  • soldr cargo test -p zccache-daemon --test depgraph_persistence_test -- --ignored — existing 3 persistence tests still pass.

🤖 Generated with Claude Code

Issue #320 reported that a fresh zccache daemon emitted
`verdict=Cold reason=cold_skip` on every lookup of warm rebuilds even when
the on-disk `depgraph.bin` from a prior session was present and valid. The
daemon was already loading the depgraph at startup, but a load failure
(version mismatch / corruption) only logged via `tracing::warn!` — which
gets swallowed by the daemon's `detach_stdio()` and so was invisible in
both stderr and the per-session `last-session.log`.

Option 2 from the issue: classify the session by what is on disk, not by
session lineage. No new flag, no protocol bump.

Changes:
- `zccache-depgraph`: add `classify_load(path) -> DepGraphLoadOutcome`
  with structured `Loaded` / `Missing` / `VersionMismatch` / `Corrupt` /
  `IoError` variants. Each non-`Loaded` variant carries a human-readable
  warning via `DepGraphLoadOutcome::warning(path)`. Unit-tested in
  `snapshot.rs`.
- `zccache-daemon` main: replace ad-hoc load+log with `classify_load`.
  Print warnings to stderr at startup AND forward them to
  `DaemonServer::set_depgraph_load_warning` so the daemon can mirror
  them into every session log at `SessionStart`. This makes the cold
  fallback visible in `last-session.log`.
- `zccache-daemon` server: new `Mutex<Option<String>>` field on
  `SharedState` plus `handle_session_start` mirrors the warning into
  the session log on the first write.
- Integration tests covering: valid file → warm, missing → no warning,
  corrupt → warning, version-mismatch → warning, loaded-but-artifact-
  missing → still classified warm (artifact existence is a downstream
  miss, not a classifier responsibility).

No `PROTOCOL_VERSION` bump (no wire change). `--no-depgraph-cache`
behavior is preserved.

Closes #320

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees merged commit 35f7713 into main May 21, 2026
13 of 14 checks passed
zackees added a commit that referenced this pull request May 22, 2026
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 added a commit that referenced this pull request May 22, 2026
* feat(cli): zccache defender-exclusions helper for Windows cache root

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

* fix(test): set profile: false in depgraph warm classify test

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]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees deleted the issue/320-warm-classifier 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.

bug(daemon): fresh session emits cold_skip for every lookup even when persisted depgraph + artifacts are present on disk

1 participant