Skip to content

fix(airc-cli): Windows pipe-name uniqueness — UUIDv5 over full path - #685

Merged
joelteply merged 10 commits into
rust-rewritefrom
feat/windows-ipc-uniqueness
May 19, 2026
Merged

joelteply merged 10 commits into
rust-rewritefrom
feat/windows-ipc-uniqueness

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Work intake (per operating control board)

  • Grievance: §4 — Windows Was Treated As Install-Only, Not Runtime-Proven
  • Gap: Windows Gaps — "Pipe names derived from full scoped path or explicit stable ID, not parent basename" + "Runtime named-pipe IPC test on Windows"
  • Acceptance gate: Gate 1 (Rust Hot Path) — cross-platform daemon must be defensible
  • Python/shell impact: untouched
  • Branch: feat/windows-ipc-uniqueness off rust-rewrite, short-lived
  • Proof: 4 unit tests (runnable on any host) + 1 Windows-only integration test

What changed

crates/airc-cli/src/ipc/transport.rs — replace the parent-basename + file-basename pipe-name derivation with UUIDv5(namespace, full_path_string). UUIDv5 is SHA-1 based and stable across rustc versions, so the daemon and client compute the same pipe name independently from the same socket path.

The bug Codex flagged: two users with <home>/.airc-rs/daemon.sock both produced airc-rs-airc-rs-daemon-sock and collided. Now they get distinct 32-hex digests.

The resolver function moved from #[cfg(windows)] to #[cfg(any(windows, test))] so unit tests can exercise the logic on the dev host. Production call sites remain #[cfg(windows)]-gated as before.

Test plan

  • cargo fmt --all --check clean
  • cargo clippy --workspace --all-targets --all-features -- -D warnings clean
  • cargo test --workspace --all-features — all 7 test binaries green; airc-cli at 43 (was 39, +4 new pipe-name tests)
  • Windows runner exercises windows_two_homes_bind_concurrent_listeners in CI

🤖 Generated with Claude Code

joelteply and others added 10 commits May 18, 2026 22:53
…not parent basename

Closes grievance §4 (Windows Was Treated As Install-Only) /
Windows Gaps: "Pipe names derived from full scoped path or
explicit stable ID, not parent basename" + "Runtime named-pipe
IPC test on Windows".

Advances Gate 1 (Rust Hot Path): the cross-platform daemon claim
in #683 was not defensible because two users both running
`<home>/.airc-rs/daemon.sock` produced the same pipe name
`airc-rs-airc-rs-daemon-sock`. Identified by Codex audit
2026-05-19.

Fix: replace `parent_basename + file_basename` derivation with
`UUIDv5(namespace, full_path_string)`. UUIDv5 is SHA-1 based and
stable across rustc versions, so the daemon and client compute
the same pipe name independently from the same socket path.

Tests added (unit, runnable on macOS via `#[cfg(any(windows,
test))]` gate on the resolver):
- `pipe_names_differ_across_homes` — alice/bob with same
  `.airc-rs/daemon.sock` produce distinct pipe names
- `pipe_name_is_stable_across_calls` — same path → same pipe
- `pipe_name_passes_through_explicit_pipe_path` — `\\.\pipe\foo`
  unchanged
- `pipe_names_handle_paths_sharing_dir_basename` — explicit
  regression test for the original collision case

Windows-only integration test (runs in CI's Windows runner):
- `windows_two_homes_bind_concurrent_listeners` — two daemons at
  distinct `<home>` dirs bind named-pipe listeners simultaneously

Python/shell impact: untouched.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…ound-trip + cross-platform CI matrix

Addresses Codex review findings on PR #685:

1. Windows runtime test was not actually running in CI.
   Workflow ran fmt/clippy/test only on ubuntu-latest, so the
   #[cfg(windows)] test compiled out. Now matrix runs cargo test on
   ubuntu-latest + macos-latest + windows-latest. The Windows IPC
   test will actually execute.

2. The Windows test only proved two binds, not a full IPC round
   trip. Replaced `windows_two_homes_bind_concurrent_listeners`
   with `windows_two_homes_round_trip_concurrently`: each home runs
   a server task that read_exacts 6 bytes, writes a home-specific
   reply, shuts down — and the test asserts no cross-contamination
   (home A's server receives "PING-A", not "PING-B"). Closes the
   Windows Gaps "Runtime named-pipe IPC test on Windows" item.

3. Raw path hashing split equivalent Windows path spellings (case,
   separator, presence of `..`). Added `canonicalize_for_hash`:
   tries `fs::canonicalize` on the whole path, then on the parent
   dir, then falls back to string-level normalisation (backslash
   → forward slash, lowercase — correct on NTFS case-insensitive
   FS, and only active in this code path because the resolver is
   `#[cfg(any(windows, test))]`-gated). Two new unit tests cover
   the case and separator normalisation guarantees.

Test count: airc-cli bin tests 43 → 45.

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

Surfaced by the cross-platform CI matrix in this PR. On Windows
`File::set_modified` requires the file handle to be opened for
write; the test helper `set_mtime_seconds_ago` used `File::open`
which opens read-only and the syscall fails with ERROR_ACCESS_DENIED
(Os code 5). On Unix `utimes(2)` only requires ownership so the
bug never surfaced under ubuntu/macos runners or my macOS dev box.

Three `gc` tests were failing on windows-latest:
- gc_age_deletes_only_older_than_cutoff
- gc_capacity_deletes_oldest_first
- gc_capacity_stops_when_under_cap

Test-only change. Production GC code never touches mtime.

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

The original daemon RPC relied on TCP-style half-close shutdown:
client wrote request + \n, shutdown(write), daemon read_to_end
until EOF, processed, wrote response + \n, shutdown(write), client
read_to_end. That works on Unix sockets where shutdown half-closes.
Windows named pipes have NO half-close — shutdown is either a no-op
or fully disconnects. Under the new windows-latest CI matrix this
manifested as three daemon tests hanging indefinitely (>60s):
- client_ping_round_trips_via_real_socket
- status_returns_peer_id
- subscribe_then_send_then_inbox_round_trips

Fix: switch the protocol to newline-delimited single-line framing
on BOTH sides. Each side reads exactly one line via BufReader::
read_line, parses, drops. No half-close anywhere. Works identically
on Unix sockets and Windows named pipes.

Changes:
- daemon/server.rs handle_connection: split stream, BufReader the
  read half, read_line; write_response writes line + \n + flush
  (no shutdown).
- ipc/client.rs DaemonClient::call: same pattern — write request
  line, flush, read_line for response.
- ipc/transport.rs windows_two_homes_round_trip_concurrently:
  switched to read_exact + flush + read_exact (each side knows
  exact byte counts), removed shutdown calls that were ambiguous
  on Windows.

Closes the protocol-level dependency on half-close that grievance
§4 indirectly surfaced. The cross-platform daemon claim from
PR #683 is now defensible at the protocol layer.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
The pipe-name uniqueness + daemon protocol fixes in this PR are
defensible — `windows_two_homes_round_trip_concurrently` passes on
the Windows CI runner, and the three previously-hanging daemon
tests now complete. Of those, two still fail because they exercise
`airc-transport::LocalFsAdapter`, which hits ERROR_ACCESS_DENIED on
Windows under fs2's exclusive flock + append open. That's an
airc-transport file-locking bug, not an airc-cli IPC bug, and
belongs in remediation slice 3 (Transport send correctness).

Changes:
- `second_daemon_refuses_to_steal_live_socket`: accept BOTH the
  Unix variant (DaemonError::StaleSocket wrapping AddrInUse) and
  the Windows variant (DaemonError::Io / PermissionDenied raised
  by `first_pipe_instance(true)`). The test pins the contract
  "second daemon must refuse", not a specific error shape — the
  OS gets to pick the error kind.

- `subscribe_then_send_then_inbox_round_trips`: `#[cfg_attr(
  target_os = "windows", ignore = "...")]` with explicit pointer
  to the follow-up slice. Per the operating doc's proof standard:
  not claiming a gap is closed if the test isn't running.

- `send_dispatches_against_local_fs_transport`: same ignore +
  pointer for the same root cause.

Windows runner should now go green for the airc-cli IPC layer.
LocalFsAdapter Windows file-lock fix tracked separately.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Same root cause as the daemon `send_dispatches_against_local_fs_transport`
and `subscribe_then_send_then_inbox_round_trips` tests ignored in the
previous commit: airc-transport's LocalFsAdapter opens the wire's
frames.jsonl with append + fs2 exclusive flock, which hits
ERROR_ACCESS_DENIED on Windows. The e2e tests spawn two airc-rs
processes sharing a wire dir, so they exercise the same code path.

`#[cfg_attr(target_os = "windows", ignore = "...")]` with explicit
pointer to follow-up slice 3 (Transport send correctness). On
Unix/macOS the tests still run and pass.

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

The real root-cause behind every Windows test failure outside the
IPC layer. On Unix, `OpenOptions::new().create(true).append(true).
open(path)` opens with permissive sharing by default — concurrent
readers (subscribers tailing the file) and other writers can coexist.
Windows defaults to `FILE_SHARE_NONE` (exclusive), so the moment a
sender holds the handle for the flock + append + fsync critical
section, every subscriber's `File::open(path)` returns
ERROR_ACCESS_DENIED.

Surfaced by the cross-platform CI matrix as 16 failing tests in
airc-transport (every local-fs and signed test) plus the airc-cli
daemon and e2e tests that depend on LocalFsAdapter.

Fix: two helpers in local_fs.rs, `open_for_append_shared` (sync,
used by send) and `open_for_read_shared` (async, used by subscribe
tail). Both call `apply_windows_share_mode[_async]` which on Windows
sets `FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE` via
`OpenOptionsExt::share_mode`. On Unix the helpers are no-ops.

The truncation test in this module also updated to use the same
helper for share-mode parity.

With the underlying fix in place, the four `#[cfg_attr(target_os =
"windows", ignore = "...")]` annotations from the previous two
commits are reverted — the tests are no longer blocked.

Per the operating doc: gap closure requires the test running, not
ignored. This is the real proof.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
… import in async helper

`tokio::fs::OpenOptions::share_mode` is an inherent method on
tokio's own type (not via the std extension trait), so the `use
std::os::windows::fs::OpenOptionsExt` import was unused on Windows
and clippy under `-D warnings` rejected it.

The sync helper still needs the trait import because std's
`OpenOptions::share_mode` IS exposed via that extension trait.

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

fs2's `lock_exclusive` on Windows calls LockFileEx, which requires
the file handle to grant GENERIC_READ. The previous opener used
`OpenOptions::new().create(true).append(true)`, which produces a
handle with FILE_APPEND_DATA only and no read access — Unix flock
accepts that handle but Windows LockFileEx returns ERROR_ACCESS_DENIED.

This was the final blocker for the daemon dispatch tests on Windows
(send_dispatches_against_local_fs_transport,
subscribe_then_send_then_inbox_round_trips). The share_mode fix in
the previous commit handled concurrent-reader contention; this fix
handles the lock-handle access-rights formality.

Adding `.read(true)` gives the handle GENERIC_READ + FILE_APPEND_DATA.
Append semantics are preserved because `append(true)` controls
seek-to-end behaviour on writes — read access on the handle is a
Windows ACL gating bit, not a behavioural change.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…ory, blocks readers

After the share-mode and access-rights fixes, three local_fs tests
still failed on Windows with `ERROR_LOCK_VIOLATION` (Os code 33):
the subscriber's read on `frames.jsonl` collided with the sender's
exclusive lock.

Root cause: on Unix, fs2's `lock_exclusive` (flock) is *advisory*
— it coordinates between writers that take the lock and ignores
processes that don't. On Windows, fs2 uses `LockFileEx` which is
*mandatory* — it actually locks the byte range and any read
attempt by another process gets `ERROR_LOCK_VIOLATION` until the
lock is released.

Locking the frames file itself can't work on Windows: the whole
point of having tail-loop subscribers is to read concurrently with
sends, and that's exactly what mandatory locking blocks.

Fix: introduce a sidecar `frames.jsonl.lock` file. Senders take
the exclusive lock on the sidecar, then open and write `frames.jsonl`
without any lock. Readers touch only `frames.jsonl`, never the
sidecar — so writer serialization works on both platforms and
readers proceed unbothered on Windows the same way they do on Unix.

Reverts the `.read(true)` addition from the previous commit — the
frames-file handle no longer takes LockFileEx, so it doesn't need
GENERIC_READ on its ACL. The lock-file handle is the one with
read+write access for the lock.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@joelteply
joelteply merged commit 755e41a into rust-rewrite May 19, 2026
6 checks passed
@joelteply
joelteply deleted the feat/windows-ipc-uniqueness branch May 19, 2026 08:16
This was referenced May 28, 2026
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