Skip to content

feat(cli): expose session_end_idempotent for all daemon callers (closes #159) - #163

Merged
zackees merged 2 commits into
mainfrom
feat/session-end-idempotent-lib
May 11, 2026
Merged

zackees merged 2 commits into
mainfrom
feat/session-end-idempotent-lib

Conversation

@zackees

@zackees zackees commented May 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

Promotes the session-end "daemon unreachable = success no-op" contract from a CLI-private helper to a shared library entry point so all daemon callers — CLI, soldr, future tools — agree on the same semantics.

Closes #159.

Why

#151 made zccache session-end <uuid> idempotent at the connect-failure layer. But Windows CI keeps failing at the very end of every run with:

soldr: zccache session-end ... failed: cannot connect to daemon at \.\pipe\zccache-...

That failure is not from soldr exec'ing zccache.exe session-end — it's soldr calling the same code path inside its own process via the library. cmd_session_end never runs, so the #151 idempotency fix doesn't apply.

What

  • Library: new pub fn session_end_idempotent(endpoint, session_id) -> Result<Option<SessionStats>, IpcError>. On connect-time NotFound | ConnectionRefused | BrokenPipe it returns Ok(None). On SessionEnded it returns Ok(stats). Other errors propagate.
  • Library: is_daemon_unreachable_err promoted from main.rs-private to pub in lib.rs so the same classification is shared.
  • CLI: cmd_session_end rewritten as a thin wrapper that calls the library function and preserves the existing CLI stderr output (session duration, compilation counts, hit rate, time saved).
  • Tests: classification tests (NotFound / ConnectionRefused / BrokenPipe / raw ENOENT / TimedOut / ConnectionClosed / Endpoint) moved from main.rs::tests to lib.rs::tests so they cover the public API directly. Plus new tests for session_end_idempotent against a vanished pipe (RED test of TDD).

Soldr adopting the new function is out of scope (separate repo). This PR is the library-side prerequisite.

TDD

  • RED (2270d1d): added session_end_idempotent_swallows_vanished_daemon + control tests asserting the function returns Ok(None) against a guaranteed-unbound endpoint. Confirmed failure: cannot find function session_end_idempotent in this scope.
  • GREEN (b74e658): implemented the library function and reduced cmd_session_end to a thin wrapper. All 15 lib tests pass.

Test plan

  • soldr cargo check --workspace --all-targets
  • soldr cargo clippy --workspace --all-targets -- -D warnings
  • soldr cargo fmt --all -- --check
  • soldr cargo test -p zccache-cli --lib — 15/15 passing
  • soldr cargo test --workspace --lib — 59 watcher tests + all others passing
  • CLI stderr format preserved: Session <uuid> complete (<dur>), <n> compilations: ..., Hit rate: ..., Time saved: ...
  • Integration test tests/session_end.rs::session_end_with_unreachable_daemon_is_idempotent (ignored, runs under ./test --integration) still passes — covered by the existing CLI wrapper which routes through the new library function

Out of scope (will follow up separately)

  • Soldr adoption of session_end_idempotent — that's a separate repo and requires a new zccache release first.
  • The Windows / Check CI red on main caused by soldr's bundled zccache: same reason — needs a zccache release + soldr release.

🤖 Generated with Claude Code

zackees and others added 2 commits May 10, 2026 21:20
… as ok

Issue #159: soldr's at-exit `rust-plan save` fails Windows CI because
its in-process session-end does not go through `cmd_session_end` and
so the #151 idempotency fix doesn't apply.

Add the failing test for the new shared library entry point
`session_end_idempotent`, plus control tests that protect against
widening "unreachable" to include real faults (timeouts, protocol
errors). The function does not exist yet — this commit is the RED
proof. The GREEN commit implements it.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
#159)

Adds a shared library entry point so the CLI subprocess path and any
in-process caller (e.g. soldr's at-exit rust-plan save) agree on what
"the daemon already died" means.

#151 made `zccache session-end <uuid>` idempotent at the connect-failure
layer, but the failure on Windows CI is from soldr calling the same
code path through the library — `cmd_session_end` never runs, so the
idempotency fix doesn't apply. The fix moves the unreachable-is-success
classification down to the library:

  pub fn session_end_idempotent(
      endpoint: &str,
      session_id: &str,
  ) -> Result<Option<SessionStats>, IpcError>

`Ok(None)` covers both "daemon was unreachable" and "daemon returned
no stats" — both are success no-ops from the caller's perspective.
Other errors (timeouts, protocol mismatches, daemon error responses)
propagate as `Err(IpcError)`.

`is_daemon_unreachable_err` is promoted to `pub` in the library so the
same classification is shared.

`cmd_session_end` is rewritten as a thin wrapper that calls the library
function and preserves the existing CLI stderr output (session
duration, hit rate, time saved). Test coverage for the unreachable-set
classification (NotFound / ConnectionRefused / BrokenPipe / raw ENOENT)
plus negative controls (TimedOut / ConnectionClosed / Endpoint) moves
from `main.rs::tests` to `lib.rs::tests` so it covers the library API
directly.

Soldr adopting the new function is out of scope (separate repo).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@codecov

codecov Bot commented May 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 61.22449% with 38 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/zccache-cli/src/lib.rs 74.07% 21 Missing ⚠️
crates/zccache-cli/src/main.rs 0.00% 17 Missing ⚠️

📢 Thoughts on this report? Let us know!

@zackees
zackees merged commit 4db0d89 into main May 11, 2026
18 of 21 checks passed
zackees added a commit that referenced this pull request May 11, 2026
Patch bump covering everything merged since v1.4.0:

- fix(daemon,ci): tolerate unknown sessions and stop killing soldr's
  daemon (#168, closes #166 + #167)
- feat(cli): expose session_end_idempotent for all daemon callers (#163)
- fix(daemon): deterministic flush primitive for event log (#162)
- feat(cli,daemon): relocate daemon exe to global runtime-binaries dir (#158)
- fix(depgraph): normalize workspace-path inputs out of rustc cache key (#160)
- perf(ci): trim platform Test, drop --all-targets from Check, split
  Test/Check jobs (#161, #164, #165)
- chore(ci): drop invalid target-cache-paths from build-target action (#157)

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
zackees added a commit that referenced this pull request May 11, 2026
* fix(cli): make client_session_end idempotent on vanished daemon

The Windows Test job has been failing PR teardown with

    soldr: zccache session-end <uuid> failed: cannot connect to daemon
    at \.\pipe\zccache-...: I/O error: The system cannot find the file
    specified. (os error 2)
    ##[error]Process completed with exit code 1.

even when every workspace test passed. Root cause: `client_session_end`
is the in-process entry point that soldr's `rust-plan save` and the
Python `ZccacheClient.session_end` binding call. It was the only
session-end path that did NOT yet adopt the idempotency contract from
#137 / #151 / #159 — connect-time `NotFound` on the named pipe was
returned as a hard `Err(String)` rather than `Ok(None)`. The CLI
subcommand was switched to `session_end_idempotent` in #163, but
library callers were left on the old, non-idempotent path.

Fix: collapse `client_session_end` to a thin String-error wrapper
around `session_end_idempotent`. All callers (CLI, Python, soldr,
future tools) now share one definition of "the daemon already died".

Regression test `client_session_end_swallows_vanished_daemon` mirrors
the existing `session_end_idempotent_swallows_vanished_daemon`: bind
no listener, call with a fresh UUID, assert `Ok(None)`.

Verification: `soldr cargo test -p zccache-cli --lib` — 4 / 4 relevant
tests pass; `soldr cargo clippy -p zccache-cli --all-targets -D warnings`
clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* ci(check): ignore soldr at-exit session-end teardown on vanished daemon

The Windows Test job has been failing every PR teardown with

    soldr: zccache session-end <uuid> failed: cannot connect to daemon
    at \.\pipe\zccache-...: I/O error: The system cannot find the file
    specified. (os error 2)
    ##[error]Process completed with exit code 1.

even after every workspace test passed. The bundled zccache 1.4.0
binary inside soldr 0.7.14 still uses the non-idempotent
`client_session_end` (fixed at the source level in the prior commit
on this branch). Source fix can't help in CI until soldr ships a new
release bundling zccache 1.4.1+, which is out of band.

Workflow-level workaround: after `cargo test`, if soldr exited non-zero,
check the captured output. If cargo itself reported no failed tests AND
the output contains exactly the soldr session-end teardown error, treat
the run as success and emit a GitHub workflow warning. Other non-zero
exits — real test failures, panics, build errors — still propagate
unchanged.

Targeted by:
  - "test result: FAILED" / "panicked at" must be absent (no real failure)
  - "soldr: zccache session-end .* failed: cannot connect to daemon"
    must be present (the specific teardown bug)

Once soldr's bundled zccache picks up the idempotent
`client_session_end`, this carve-out becomes dead code and can be
removed.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
zackees added a commit that referenced this pull request May 11, 2026
#171)

* fix(cli): make client_session_end idempotent on vanished daemon

The Windows Test job has been failing PR teardown with

    soldr: zccache session-end <uuid> failed: cannot connect to daemon
    at \.\pipe\zccache-...: I/O error: The system cannot find the file
    specified. (os error 2)
    ##[error]Process completed with exit code 1.

even when every workspace test passed. Root cause: `client_session_end`
is the in-process entry point that soldr's `rust-plan save` and the
Python `ZccacheClient.session_end` binding call. It was the only
session-end path that did NOT yet adopt the idempotency contract from
#137 / #151 / #159 — connect-time `NotFound` on the named pipe was
returned as a hard `Err(String)` rather than `Ok(None)`. The CLI
subcommand was switched to `session_end_idempotent` in #163, but
library callers were left on the old, non-idempotent path.

Fix: collapse `client_session_end` to a thin String-error wrapper
around `session_end_idempotent`. All callers (CLI, Python, soldr,
future tools) now share one definition of "the daemon already died".

Regression test `client_session_end_swallows_vanished_daemon` mirrors
the existing `session_end_idempotent_swallows_vanished_daemon`: bind
no listener, call with a fresh UUID, assert `Ok(None)`.

Verification: `soldr cargo test -p zccache-cli --lib` — 4 / 4 relevant
tests pass; `soldr cargo clippy -p zccache-cli --all-targets -D warnings`
clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* ci(check): ignore soldr at-exit session-end teardown on vanished daemon

The Windows Test job has been failing every PR teardown with

    soldr: zccache session-end <uuid> failed: cannot connect to daemon
    at \.\pipe\zccache-...: I/O error: The system cannot find the file
    specified. (os error 2)
    ##[error]Process completed with exit code 1.

even after every workspace test passed. The bundled zccache 1.4.0
binary inside soldr 0.7.14 still uses the non-idempotent
`client_session_end` (fixed at the source level in the prior commit
on this branch). Source fix can't help in CI until soldr ships a new
release bundling zccache 1.4.1+, which is out of band.

Workflow-level workaround: after `cargo test`, if soldr exited non-zero,
check the captured output. If cargo itself reported no failed tests AND
the output contains exactly the soldr session-end teardown error, treat
the run as success and emit a GitHub workflow warning. Other non-zero
exits — real test failures, panics, build errors — still propagate
unchanged.

Targeted by:
  - "test result: FAILED" / "panicked at" must be absent (no real failure)
  - "soldr: zccache session-end .* failed: cannot connect to daemon"
    must be present (the specific teardown bug)

Once soldr's bundled zccache picks up the idempotent
`client_session_end`, this carve-out becomes dead code and can be
removed.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* chore(release): bump workspace to 1.4.2

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
zackees added a commit that referenced this pull request May 12, 2026
…hook perf (#172)

* fix(cli): make client_session_end idempotent on vanished daemon

The Windows Test job has been failing PR teardown with

    soldr: zccache session-end <uuid> failed: cannot connect to daemon
    at \.\pipe\zccache-...: I/O error: The system cannot find the file
    specified. (os error 2)
    ##[error]Process completed with exit code 1.

even when every workspace test passed. Root cause: `client_session_end`
is the in-process entry point that soldr's `rust-plan save` and the
Python `ZccacheClient.session_end` binding call. It was the only
session-end path that did NOT yet adopt the idempotency contract from
#137 / #151 / #159 — connect-time `NotFound` on the named pipe was
returned as a hard `Err(String)` rather than `Ok(None)`. The CLI
subcommand was switched to `session_end_idempotent` in #163, but
library callers were left on the old, non-idempotent path.

Fix: collapse `client_session_end` to a thin String-error wrapper
around `session_end_idempotent`. All callers (CLI, Python, soldr,
future tools) now share one definition of "the daemon already died".

Regression test `client_session_end_swallows_vanished_daemon` mirrors
the existing `session_end_idempotent_swallows_vanished_daemon`: bind
no listener, call with a fresh UUID, assert `Ok(None)`.

Verification: `soldr cargo test -p zccache-cli --lib` — 4 / 4 relevant
tests pass; `soldr cargo clippy -p zccache-cli --all-targets -D warnings`
clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* ci(check): ignore soldr at-exit session-end teardown on vanished daemon

The Windows Test job has been failing every PR teardown with

    soldr: zccache session-end <uuid> failed: cannot connect to daemon
    at \.\pipe\zccache-...: I/O error: The system cannot find the file
    specified. (os error 2)
    ##[error]Process completed with exit code 1.

even after every workspace test passed. The bundled zccache 1.4.0
binary inside soldr 0.7.14 still uses the non-idempotent
`client_session_end` (fixed at the source level in the prior commit
on this branch). Source fix can't help in CI until soldr ships a new
release bundling zccache 1.4.1+, which is out of band.

Workflow-level workaround: after `cargo test`, if soldr exited non-zero,
check the captured output. If cargo itself reported no failed tests AND
the output contains exactly the soldr session-end teardown error, treat
the run as success and emit a GitHub workflow warning. Other non-zero
exits — real test failures, panics, build errors — still propagate
unchanged.

Targeted by:
  - "test result: FAILED" / "panicked at" must be absent (no real failure)
  - "soldr: zccache session-end .* failed: cannot connect to daemon"
    must be present (the specific teardown bug)

Once soldr's bundled zccache picks up the idempotent
`client_session_end`, this carve-out becomes dead code and can be
removed.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* chore(release): bump workspace to 1.4.2

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* ci: bump GitHub Actions to Node 24 compatible versions

GitHub deprecated Node 20 actions: they will be forced to Node 24 by
June 2, 2026 and removed by Sept 16, 2026.

- actions/checkout v4 -> v6
- actions/setup-python v5 -> v6
- actions/upload-artifact v4 -> v7
- actions/download-artifact v4 -> v8
- actions/cache v4 -> v5
- softprops/action-gh-release v2 -> v3

All targets verified to use `node24` runtime.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* ci(release): auto-trigger Auto-Release on workspace version bump

Previously the release workflow only fired on tag push or
workflow_dispatch. Merging "chore(release): bump workspace to X.Y.Z"
to main did nothing — the operator had to remember to push a matching
tag, which is how v1.4.1 shipped to main but never reached PyPI/crates.io.

Add a `push: branches: [main]` trigger gated by a new detect-bump job:

- workflow_dispatch: always proceeds (manual override)
- push to main: only proceeds when Cargo.toml workspace version differs
  from the previous commit
- tag push: proceeds unless the GitHub release already exists (avoids
  the duplicate run that publish-release creates by pushing the tag)

When detect-bump returns should_release=false, preflight (and the rest
of the chain via existing `needs` graph) skip cleanly with no failures.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* chore(deps): bump soldr from 0.7.14 to 0.7.16

soldr 0.7.16 ships fix(cli): resync zccache session on "unknown
session:" wrapper error (forge-ci/soldr#267) and bundles managed
zccache 1.4.2 (forge-ci/soldr#270), which carries the idempotent
client_session_end fix from this branch.

Updates all setup-soldr@v0 invocations across workflows and the
build-target composite action, plus the dev dependency in
pyproject.toml.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* perf(stop-hook): route every stage through soldr cargo

zccache-ci's stages were a mix of toolchains:

  Full mode:
    lint       -> uv run python -m ci.lint --fix  (uses soldr cargo)
    cross-check -> cargo check --target musl ...   (bare cargo)
    test        -> cargo test ...                  (bare cargo)
  Quick mode:
    quick-check -> uv run cargo check ...          (bare cargo via uv)

soldr passes `--target <host triple>` to cargo, so its invocations
land in `target/x86_64-pc-windows-msvc/debug/`. Bare cargo with no
`--target` lands in `target/debug/`. The two trees don't share rlib/
rmeta artifacts — only the proc-macro/build-script subtree.

Cold-cache bench in this branch showed `clippy --all-targets` populates
both dirs in a single invocation (615MB to msvc, 522MB to debug for
proc-macros). The downstream test stage then re-compiled the whole
workspace from scratch because its `target/debug/` was missing the
real rlibs. zccache showed a 0% hit rate for a normal stop-hook run.

Switching every stage to `soldr cargo` consolidates to one target dir
(`target/x86_64-pc-windows-msvc/debug/`) so clippy's artifacts are
reused by test/check. zccache's rustc-wrapper cache also starts hitting.

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 feat/session-end-idempotent-lib branch November 5, 2026 05:55
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.

ci(windows): soldr's internal session-end fails CI even after #151 — needs IPC-layer idempotency

1 participant