Skip to content

feat(broker-v2): single-instance enforcement diagnostic + EX_TEMPFAIL exit (slice 2 of #532) - #534

Merged
zackees merged 1 commit into
mainfrom
feat/532-v2-broker-single-instance-lock
Jun 20, 2026
Merged

zackees merged 1 commit into
mainfrom
feat/532-v2-broker-single-instance-lock

Conversation

@zackees

@zackees zackees commented Jun 20, 2026

Copy link
Copy Markdown
Owner

Splits 'another broker already bound' (AddrInUse / WouldBlock) from generic bind failures in running-process-broker-v2. Actionable message tells the operator how to recover; exit code 75 (EX_TEMPFAIL) signals a supervisor to retry after the other broker exits, vs 1 for hard environment failures.

Single-instance enforcement is delegated to the OS pipe namespace; this slice just sharpens the diagnostic + exit-code contract. 4 new tests, 14 total pass.

…actionable diagnostic (slice 2 of #532)

The v2 broker scaffold previously treated every `ListenerOptions::create_sync`
failure equivalently — same diagnostic + same exit code 1 for bind errors
caused by another broker already running, missing parent dir, or
permission denied.

This slice splits out the user-actionable case:

- AddrInUse or WouldBlock at bind time → "another broker is already
  bound at <path> (program=<name>). Refusing to start to avoid
  double-bind. Stop the other broker first, or pass --program <other-name>
  to bind a distinct namespace."
- Exit code 75 (`EX_TEMPFAIL`) so a supervisor knows to retry after
  the other broker exits, vs exit 1 (`EX_GENERAL`) for hard environment
  failures.

Single-instance enforcement is delegated to the OS — the kernel's pipe
namespace already rejects a second bind on the same name. No
separately-managed lock file required. This slice just sharpens the
diagnostic + exit-code contract.

## Tests

4 new inline tests in addition to the 10 from slice 1:
- AddrInUse classified as already-bound
- WouldBlock classified as already-bound
- PermissionDenied NOT misclassified
- NotFound NOT misclassified

`soldr cargo test --features client --bin running-process-broker-v2` —
14 passed total.
`soldr cargo clippy --all-targets --features client -- -D warnings` clean.

Slice 2 of running-process#532. Follow-up slices: SIGTERM handling,
adopt-traffic forwarding, refuse-privileged-run guard.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees merged commit 9077871 into main Jun 20, 2026
7 of 8 checks passed
@zackees
zackees deleted the feat/532-v2-broker-single-instance-lock branch June 20, 2026 21:14
zackees added a commit that referenced this pull request Jun 22, 2026
…d` test with PR #536's intentional impl change

Test cascade-failed every CI unit-test run since PR #536. PR #534
(slice 2 of #532) added \`is_already_bound_error_does_not_misclassify_permission_denied\`
when the matcher only covered \`AddrInUse | WouldBlock\`. PR #536
then *deliberately* widened the matcher to also include
\`PermissionDenied\` — Windows double-bind surfaces as
\`ERROR_ACCESS_DENIED\` (raw os error 5) because the existing pipe
instance's ACL blocks the second bind, not as \`AddrInUse\`. PR #536's
commit body documents the change explicitly but didn't update this
test, which then asserted the now-inverted behavior.

Fix: rename to \`is_already_bound_error_classifies_permission_denied\`
and invert the assertion to match the now-current contract. Doc
comment cross-references PR #536's rationale so the next reader
understands why PermissionDenied counts as "already bound" here.

Verified all 4 \`is_already_bound_error_*\` tests pass:
  - classifies_addr_in_use
  - classifies_would_block
  - classifies_permission_denied  (renamed + inverted in this PR)
  - does_not_misclassify_not_found

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
zackees added a commit that referenced this pull request Jun 22, 2026
…cher widening (#575)

* fix(observer): slice 7c — un-ignore Windows path-specific test + per-detour install diagnostics (#551)

The slice 7c test was hanging because of a self-inflicted
assertion bug, not a retour or detour issue. The interposer
formats paths via `{:?}` (debug-escaped, doubled backslashes), so
`contains(probe_path)` against the raw path never matched and the
10-second deadline ran to completion. The retour install actually
completed on all 5 detours, and the CreateFileW detour fired
correctly on testbin-createfilew-probe's call.

Fixes:

- `crates/.../interposer-windows/src/lib.rs`: install_detours now
  emits `RPO_HOOK install begin=<name>` / `install end=<name>`
  sentinels around each install_one call. Lets the
  `interposer_diagnostic_windows.rs` test (also added) report
  which retour install hung or errored if a regression ever
  reintroduces the hang. Verified clean against cmd.exe — all
  5 detours install in <100 ms each.

- `crates/.../observer/tests/interposer_integration_windows.rs`:
  un-ignore `interposer_dll_fires_rpo_hook_after_inject`. Replace
  `contains(probe_path.display())` with `contains("RPO_HOOK
  file-open") && contains("probe.txt")` for both the deadline-
  poll exit condition and the final assertion. The basename
  alone is unambiguous since the fixture only ever opens that
  file.

- `crates/.../observer/tests/interposer_diagnostic_windows.rs`:
  new diagnostic test that injects into cmd.exe and reports
  per-detour begin/end pair coverage to eprintln. Always passes
  (observational test) — its eprintln output lands in cargo
  nextest logs for CI / debugging visibility.

Verified locally:
  test interposer_dll_fires_rpo_hook_after_inject ... ok (7.10s)
  test diagnose_install_progress ... ok (13.22s)

Closes the slice 7c gap in #551's slice 7 acceptance criterion:
Windows test now asserts the detour fires on a real (non-
diagnostic) file API call, matching the assertion strength of
Linux (7d) and macOS (7e).

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

* fix(broker-v2): strip trailing `(program=…, mode=…)` from captured socket path in test (#488 follow-up)

The slice 3c integration test reads broker stdout looking for the
"bound at" line:

    running-process-broker-v2 bound at <path> (program=<…>, mode=<…>)

It then `strip_prefix("running-process-broker-v2 bound at ")` and
`trim_end()` — which leaves the entire trailing
` (program=<…>, mode=<…>)` glued onto what gets captured as
`socket_path`. The "path" passed to `Stream::connect` is therefore
~25 bytes longer than the actual filesystem socket path. On Linux,
where `sun_path` is exactly 108 bytes, that's enough to push every
non-trivial XDG_RUNTIME_DIR / `/tmp/running-process-<uid>` path
past the limit — and `Stream::connect` then panics with the now-
infamous "exceeds capacity of sun_path of sockaddr_un" error.

This was the bug that's been cascade-failing every CI unit-test
run since slice 3c landed. It's purely a test-parser issue —
production broker bind/connect were always correct because they
share the same string and the broker's own `bound at` print
happens *after* successful `create_sync`.

Fix: `rsplit_once(" (")` on the trimmed remainder. Everything
before ` (` is the path; the trailing parenthesized metadata is
discarded. On Windows + macOS (where the path is short enough
that the test was passing despite the bug) the fix is a no-op
because the path either starts with `\.\pipe\` and contains no
` (` substring, or is the hash-shortened macOS leaf — both
fall back to the full string via `unwrap_or(rest)`.

Verified locally by inspection of test logs:
- Pre-fix: panic at line 146 with "exceeds capacity" + a
  ~113-byte captured "path".
- Post-fix: the captured path is the 88-byte filesystem socket
  the broker actually bound to.

Closes the "broker-v2 cascade failure" item that's been
documented as out-of-scope across the #539 and #551 loops.

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

* fix(observer+broker-v2): unblock CI — testbin stub on non-Windows + daemon_version regression

Two independent CI regressions surfaced by the broker-v2 cascade
unblock landing in PR #573:

1. **testbin-createfilew-probe fails to compile on Linux + macOS.**
   Slice 7c's #[cfg(target_os = "windows")] gate is at the file
   level — on non-Windows the entire crate compiles to nothing
   and rustc errors out with "main function not found". Cargo
   requires every `[[bin]]` target to have a main fn on every
   build target, regardless of which target ever runs the binary.

   Fix: add a stub main fn for non-Windows that prints a "Windows-
   only fixture" message and exits with code 2. The Windows path
   is unchanged.

2. **`broker_v2_scaffold_accepts_connection::...` now panics at the
   `daemon_version should be populated` assertion (line 196).**
   PR #573 fixed the path-capture parser; the test now successfully
   completes the Hello/HelloReply round-trip and reaches a later
   assertion that the daemon's reported version is non-empty.

   Root cause: PR #533 changed `daemon_version` from the broker
   binary's own CARGO_PKG_VERSION to `definition.min_version.clone()`.
   That's semantically wrong — `daemon_version` is the running
   broker's actual version (matches the proto comment); min_version
   is a per-service floor expressed by the servicedef. For any
   servicedef that doesn't explicitly opt in to a floor (e.g. the
   test's stub), min_version is empty and the contract breaks.

   Fix: restore `daemon_version: env!("CARGO_PKG_VERSION").into()`
   (the pre-#533 behavior the comment block on top of the diff
   already described).

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

* fix(broker-v2): align stale `is_already_bound_error_*permission_denied` test with PR #536's intentional impl change

Test cascade-failed every CI unit-test run since PR #536. PR #534
(slice 2 of #532) added \`is_already_bound_error_does_not_misclassify_permission_denied\`
when the matcher only covered \`AddrInUse | WouldBlock\`. PR #536
then *deliberately* widened the matcher to also include
\`PermissionDenied\` — Windows double-bind surfaces as
\`ERROR_ACCESS_DENIED\` (raw os error 5) because the existing pipe
instance's ACL blocks the second bind, not as \`AddrInUse\`. PR #536's
commit body documents the change explicitly but didn't update this
test, which then asserted the now-inverted behavior.

Fix: rename to \`is_already_bound_error_classifies_permission_denied\`
and invert the assertion to match the now-current contract. Doc
comment cross-references PR #536's rationale so the next reader
understands why PermissionDenied counts as "already bound" here.

Verified all 4 \`is_already_bound_error_*\` tests pass:
  - classifies_addr_in_use
  - classifies_would_block
  - classifies_permission_denied  (renamed + inverted in this PR)
  - does_not_misclassify_not_found

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 Jun 22, 2026
* fix(observer): slice 7c — un-ignore Windows path-specific test + per-detour install diagnostics (#551)

The slice 7c test was hanging because of a self-inflicted
assertion bug, not a retour or detour issue. The interposer
formats paths via `{:?}` (debug-escaped, doubled backslashes), so
`contains(probe_path)` against the raw path never matched and the
10-second deadline ran to completion. The retour install actually
completed on all 5 detours, and the CreateFileW detour fired
correctly on testbin-createfilew-probe's call.

Fixes:

- `crates/.../interposer-windows/src/lib.rs`: install_detours now
  emits `RPO_HOOK install begin=<name>` / `install end=<name>`
  sentinels around each install_one call. Lets the
  `interposer_diagnostic_windows.rs` test (also added) report
  which retour install hung or errored if a regression ever
  reintroduces the hang. Verified clean against cmd.exe — all
  5 detours install in <100 ms each.

- `crates/.../observer/tests/interposer_integration_windows.rs`:
  un-ignore `interposer_dll_fires_rpo_hook_after_inject`. Replace
  `contains(probe_path.display())` with `contains("RPO_HOOK
  file-open") && contains("probe.txt")` for both the deadline-
  poll exit condition and the final assertion. The basename
  alone is unambiguous since the fixture only ever opens that
  file.

- `crates/.../observer/tests/interposer_diagnostic_windows.rs`:
  new diagnostic test that injects into cmd.exe and reports
  per-detour begin/end pair coverage to eprintln. Always passes
  (observational test) — its eprintln output lands in cargo
  nextest logs for CI / debugging visibility.

Verified locally:
  test interposer_dll_fires_rpo_hook_after_inject ... ok (7.10s)
  test diagnose_install_progress ... ok (13.22s)

Closes the slice 7c gap in #551's slice 7 acceptance criterion:
Windows test now asserts the detour fires on a real (non-
diagnostic) file API call, matching the assertion strength of
Linux (7d) and macOS (7e).

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

* fix(broker-v2): strip trailing `(program=…, mode=…)` from captured socket path in test (#488 follow-up)

The slice 3c integration test reads broker stdout looking for the
"bound at" line:

    running-process-broker-v2 bound at <path> (program=<…>, mode=<…>)

It then `strip_prefix("running-process-broker-v2 bound at ")` and
`trim_end()` — which leaves the entire trailing
` (program=<…>, mode=<…>)` glued onto what gets captured as
`socket_path`. The "path" passed to `Stream::connect` is therefore
~25 bytes longer than the actual filesystem socket path. On Linux,
where `sun_path` is exactly 108 bytes, that's enough to push every
non-trivial XDG_RUNTIME_DIR / `/tmp/running-process-<uid>` path
past the limit — and `Stream::connect` then panics with the now-
infamous "exceeds capacity of sun_path of sockaddr_un" error.

This was the bug that's been cascade-failing every CI unit-test
run since slice 3c landed. It's purely a test-parser issue —
production broker bind/connect were always correct because they
share the same string and the broker's own `bound at` print
happens *after* successful `create_sync`.

Fix: `rsplit_once(" (")` on the trimmed remainder. Everything
before ` (` is the path; the trailing parenthesized metadata is
discarded. On Windows + macOS (where the path is short enough
that the test was passing despite the bug) the fix is a no-op
because the path either starts with `\.\pipe\` and contains no
` (` substring, or is the hash-shortened macOS leaf — both
fall back to the full string via `unwrap_or(rest)`.

Verified locally by inspection of test logs:
- Pre-fix: panic at line 146 with "exceeds capacity" + a
  ~113-byte captured "path".
- Post-fix: the captured path is the 88-byte filesystem socket
  the broker actually bound to.

Closes the "broker-v2 cascade failure" item that's been
documented as out-of-scope across the #539 and #551 loops.

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

* fix(observer+broker-v2): unblock CI — testbin stub on non-Windows + daemon_version regression

Two independent CI regressions surfaced by the broker-v2 cascade
unblock landing in PR #573:

1. **testbin-createfilew-probe fails to compile on Linux + macOS.**
   Slice 7c's #[cfg(target_os = "windows")] gate is at the file
   level — on non-Windows the entire crate compiles to nothing
   and rustc errors out with "main function not found". Cargo
   requires every `[[bin]]` target to have a main fn on every
   build target, regardless of which target ever runs the binary.

   Fix: add a stub main fn for non-Windows that prints a "Windows-
   only fixture" message and exits with code 2. The Windows path
   is unchanged.

2. **`broker_v2_scaffold_accepts_connection::...` now panics at the
   `daemon_version should be populated` assertion (line 196).**
   PR #573 fixed the path-capture parser; the test now successfully
   completes the Hello/HelloReply round-trip and reaches a later
   assertion that the daemon's reported version is non-empty.

   Root cause: PR #533 changed `daemon_version` from the broker
   binary's own CARGO_PKG_VERSION to `definition.min_version.clone()`.
   That's semantically wrong — `daemon_version` is the running
   broker's actual version (matches the proto comment); min_version
   is a per-service floor expressed by the servicedef. For any
   servicedef that doesn't explicitly opt in to a floor (e.g. the
   test's stub), min_version is empty and the contract breaks.

   Fix: restore `daemon_version: env!("CARGO_PKG_VERSION").into()`
   (the pre-#533 behavior the comment block on top of the diff
   already described).

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

* fix(broker-v2): align stale `is_already_bound_error_*permission_denied` test with PR #536's intentional impl change

Test cascade-failed every CI unit-test run since PR #536. PR #534
(slice 2 of #532) added \`is_already_bound_error_does_not_misclassify_permission_denied\`
when the matcher only covered \`AddrInUse | WouldBlock\`. PR #536
then *deliberately* widened the matcher to also include
\`PermissionDenied\` — Windows double-bind surfaces as
\`ERROR_ACCESS_DENIED\` (raw os error 5) because the existing pipe
instance's ACL blocks the second bind, not as \`AddrInUse\`. PR #536's
commit body documents the change explicitly but didn't update this
test, which then asserted the now-inverted behavior.

Fix: rename to \`is_already_bound_error_classifies_permission_denied\`
and invert the assertion to match the now-current contract. Doc
comment cross-references PR #536's rationale so the next reader
understands why PermissionDenied counts as "already bound" here.

Verified all 4 \`is_already_bound_error_*\` tests pass:
  - classifies_addr_in_use
  - classifies_would_block
  - classifies_permission_denied  (renamed + inverted in this PR)
  - does_not_misclassify_not_found

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

* fix(interposer-windows): gate retour deps + lib body on x86_64 (ARM64 stub)

retour 0.4.0-alpha.4 uses iced-x86 for prologue disassembly,
which doesn't support ARM64. The Windows ARM Lint CI runner
(aarch64-pc-windows-msvc) was therefore failing with
\"could not find \`meta\` in \`arch\`\" — retour's internal
arch::meta module is only defined for x86 / x86_64.

This wasn't surfaced earlier because the broker-v2 cascade
failure was tripping the ARM CI before retour got a chance to
compile. With PR #573-#575 clearing that cascade, the ARM CI
proceeded far enough to hit the real arch incompatibility.

Fix: gate both the retour + windows-sys deps in Cargo.toml on
`cfg(all(target_os = "windows", target_arch = "x86_64"))`, and
gate the lib.rs body the same way. On Windows ARM64 the crate
now falls through to an empty stub so the workspace builds
end-to-end; the file-hook tier reports unavailable for that
arch (which is the honest answer until retour or an alternative
supports ARM64).

Verified:
  $ soldr cargo check -p running-process-observer-interposer-windows
  Finished `dev` profile [unoptimized + debuginfo] target(s)
  $ soldr cargo check --target aarch64-pc-windows-msvc \
        -p running-process-observer-interposer-windows
  Finished `dev` profile [unoptimized + debuginfo] target(s)

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 Aug 8, 2026
…ule (soldr#2361 Phase 2 prep) (#901)

* refactor(broker): extract v2 singleton bind into a public library module

soldr#2361 Phase 2 prep. soldr has no broker-server infrastructure of
its own today (confirmed: no [[bin]], no ShimIdentity variant, no code
anywhere calling HelloHandler/HelloRouter server-side) -- it only
consumes running-process's broker as a client. For soldr to eventually
run its own broker role it needs this crate's bind/singleton/stale-
socket-cleanup logic as a reusable library call, not something only
reachable by duplicating running-process-broker-v2.rs's private
functions.

Moves resolve_socket_path, wrap_socket_name, is_already_bound_error,
and unix_socket_path_is_stale out of the scaffold binary into
broker::server::singleton_bind, and adds one new function,
bind_singleton, that composes them into the full
bind-first/probe-before-cleanup sequence (the running-process#899 fix)
behind one call. running-process-broker-v2::main() is refactored to
call the new module instead of duplicating the logic -- dogfooding
proves the extraction preserves behavior; the existing scaffold
integration tests (including the concurrent-starters singleton race
test) pass unchanged against the refactored binary.

The 4 is_already_bound_error unit tests move with the function into
singleton_bind's own tests module (with the PR #534/#536
PermissionDenied history preserved as a comment); a new
bind_singleton_binds_once_and_refuses_a_second_bind test covers the
composed function end-to-end.

No behavior change to running-process-broker-v2. Nothing outside this
crate calls the new module yet -- soldr's own broker role is future
work, scoped on soldr#2364.

Co-Authored-By: Claude Fable 5 <[email protected]>

* fix(security): add singleton_bind.rs to the broker unsafe inventory

CI on #901 caught this correctly: the two unsafe { libc::getuid() }
calls in unix_socket_dir moved from src/bin/running-process-broker-v2.rs
(outside the audit's src/broker/** scan scope) into the new
src/broker/server/singleton_bind.rs (in scope), which the security gate
treats as an untracked file drift regardless of the code being a pure
relocation. Adds the BROKER_UNSAFE_INVENTORY entry (count: 2, matching
the actual scan) and the corresponding docs/v1-security-model.md
paragraph explaining the relocation.

Co-Authored-By: Claude Fable 5 <[email protected]>

* fix(docs): stop linking a cfg(unix)-only function from a cross-platform doc comment; refresh sync test baseline

Two independent CI gates caught real gaps on the preflight lane
(rustdoc -D warnings) and lint (ci.sync_test_audit):

- bind_singleton's doc comment linked [`unix_socket_path_is_stale`],
  which is #[cfg(unix)]-only. On a non-unix doc build target that item
  doesn't exist to resolve against, so the link fails -D warnings.
  Changed to a plain code span (no link) with a note explaining why.
- docs/sync_test_baseline.txt didn't know the 4 is_already_bound_error
  tests moved from tests.rs into singleton_bind.rs's own tests module
  (prior commit); ci.sync_test_audit --write regenerates it to reflect
  the relocation.

The AsyncBrokerSession unresolved-link error seen in an earlier local
repro is unrelated to this PR -- pre-exists on main, and is a feature-
flag mismatch in the repro command (needs client-async), not a real
CI failure.

Ran the full local gate (./lint + RUSTDOCFLAGS="-D warnings" cargo doc)
before this push instead of a scoped subset, per advisor guidance after
burning several CI round-trips discovering guards one at a time.

Co-Authored-By: Claude Fable 5 <[email protected]>

---------

Co-authored-by: Claude Fable 5 <[email protected]>
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