Skip to content

fix(daemon): deterministic flush primitive for event log (#146) - #162

Merged
zackees merged 2 commits into
mainfrom
fix/event-log-deterministic-flush
May 11, 2026
Merged

zackees merged 2 commits into
mainfrom
fix/event-log-deterministic-flush

Conversation

@zackees

@zackees zackees commented May 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

Replaces the 200 ms blind thread::sleep in flush_logger with a real cross-thread sync primitive on EventLogger. Fixes the slow-CI race in event_log::tests::test_rotation_triggers_at_threshold where the background writer was still mid-rotation when the sleep elapsed, leaving daemon.log renamed but not yet recreated.

  • Adds EventLogger::flush() (public).
  • Adds LogMessage::Flush(std::sync::mpsc::SyncSender<()>) sentinel. The worker drains it after all earlier Write messages (channels are FIFO) and signals back; the caller blocks on the ack. On-disk state — including rotation triggered by queued writes — is fully committed by the time flush() returns.
  • New regression test test_flush_is_deterministic_no_sleep_required asserts the file is on disk immediately after flush() returns (no polling, no tolerance).
  • The pre-existing flush_logger test helper now delegates to EventLogger::flush() — no other call sites need to change.

TDD log

  • RED (1d45b1c): rewires flush_logger to call EventLogger::flush(), which does not exist yet → compile error.
  • GREEN (7696fde): implements the sync primitive; all 11 event_log tests + all 148 daemon lib tests pass.

Test plan

  • soldr cargo test -p zccache-daemon event_log
  • soldr cargo test -p zccache-daemon --lib (148 passed)
  • soldr cargo check --workspace --all-targets
  • soldr cargo clippy --workspace --all-targets -- -D warnings
  • soldr cargo fmt --all -- --check

Closes #146.

🤖 Generated with Claude Code

zackees and others added 2 commits May 10, 2026 21:19
Tighten the event_log test harness to expose the race in flush_logger().
Adds test_flush_is_deterministic_no_sleep_required and rewires the shared
flush_logger helper to delegate to EventLogger::flush() — which does not
exist yet. This produces a compile error until the GREEN commit lands the
deterministic sync primitive.

Refs #146.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Add `EventLogger::flush()` and replace the test-only 200ms sleep with a
real cross-thread sync primitive. A new `LogMessage::Flush` sentinel
carries a `std::sync::mpsc::SyncSender<()>`; the worker drains it after
all earlier `Write` messages (channels are FIFO) and signals back. The
caller blocks on the ack, so by the time `flush()` returns the on-disk
state — including any rotation triggered by the queued writes — is fully
committed.

This eliminates the slow-CI race where the worker was still mid-rotation
when the blind 200ms sleep elapsed and `daemon.log` had been renamed but
not yet recreated, causing `test_rotation_triggers_at_threshold` to flake
on Linux runners.

The shared `flush_logger` test helper now delegates to `EventLogger::
flush()`. No public API beyond the new method; noop loggers short-circuit
without blocking.

Closes #146.

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 94.44444% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/zccache-daemon/src/event_log.rs 94.44% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@zackees
zackees merged commit 5f26bc1 into main May 11, 2026
8 of 9 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
zackees deleted the fix/event-log-deterministic-flush 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.

daemon: event_log::test_rotation_triggers_at_threshold flakes on slow CI runners

1 participant