Files
2026-10-20 16:35:11 -04:00

8.2 KiB

WS-H: Phase 5 final-review fixes

Field Value
Status Merged
Owner goose
Owned files src/peers/**, src/telemetry/mod.rs, src/main.rs, tests/**, docs/consolidator.md, config.example.toml, README.md

Log

2026-10-20 Handoff

The review text (loop/final-review.md) is not present in this worktree; the six items below were taken from the task statement that quotes it. Nothing in contracts.md was touched and no contract looked wrong.

All items are done, one commit each, dev-level gate green after every commit (cargo fmt --check, cargo clippy --all-targets -- -D warnings, cargo test, cargo tree -i openssl empty). No Nix files changed, so no nix build or VM test was run.

  1. One token loader, one set of peer helpers (H: merge token loaders and peer helpers). src/peers/client.rs no longer has a loader: it calls secrets::load_token for every request. The header-validity rule (no CR, LF or NUL, and the value must be a valid Bearer header) lives in secrets.rs. secrets::under_credentials canonicalises both paths and fails closed, so the client's non-canonical starts_with is gone with load_token_in. Deny-CIDR parsing (config::deny_networks), the loopback test (config::url_is_loopback), the plain-http rule (plain_http_allowed, plain_http_off_loopback) and its warning wording (warn_plain_http) exist once in config.rs and are used by validation, the transport and registry::reload. Tests: secrets::tokens_that_cannot_be_a_header_value_are_refused, client::a_refused_token_file_sends_nothing (no request reaches the peer), config::deny_networks_rejects_a_bad_cidr_once_for_every_caller, config::loopback_detection_covers_localhost_and_both_families. Deviation: the merged mode check is the stricter union of the two old ones (0o077, message "group or world accessible" instead of the client's "readable"), so a group/world-writable token file stays refused; wording updated in secrets.rs and docs/consolidator.md. A doubled trailing newline is now invalid (it would end the header line) instead of being forwarded with one newline left.
  2. denied() canonicalises (H: canonicalise addresses in the deny check). config::denied calls IpAddr::to_canonical; config validation and the transport both use it. Tests: config::ipv4_mapped_ipv6_literals_match_the_v4_deny_list (unit) and client::an_ipv4_mapped_address_is_matched_against_the_v4_deny_list (::ffff:169.254.169.254 refused before any connect); both fail if the canonicalisation is removed.
  3. IPv6 deny defaults (H: deny IPv6 link-local and metadata addresses by default). types::DEFAULT_DENY_CIDRS adds fe80::/10, ::/128 and fd00:ec2::254/128; synced in config.example.toml, README.md, docs/consolidator.md and tests/peers_config.rs (PEERS_DEFAULT). Test: config::the_default_deny_list_covers_metadata_in_both_families_but_allows_lans.
  4. peer.request is a client span (H: mark the peer.request span as an OTel client span). otel.kind = "client" on the span, asserted in telemetry::tests::peer_request_span_names_the_peer.
  5. Gauge gating in the docs (H: correct the peer gauge gating in the docs). docs/consolidator.md now names otel.enabled with otel.export_unit_metrics (there is no otel.metrics.enabled) and states that enabled = false peers have no series; behaviour was already covered by metrics_export::tests::disabled_peer_is_not_reported.
  6. Port-stealing flakiness (H: make the SIGTERM tests immune to a stolen port). tests/tls.rs::try_start_on and tests/integration.rs::sse_stream_then_sigterm_on only accept a socket that answers as this server (a TLS handshake against the test pair; a 200 from /healthz) while the child is still running, and report "retry" otherwise; start/the test then retry on a fresh port, up to three times. The SSE exit bound is 10 s. New tests tests/tls.rs::a_probed_port_taken_by_someone_else_is_retried and tests/integration.rs::a_probed_port_taken_by_someone_else_is_retried fail if the identity check is weakened back to a bare connect().

2026-10-20 Handoff (review-1)

Every finding in loop/H/review-1.md is answered, one commit each. The full gate is green after every commit: cargo fmt --check, cargo clippy --all-targets -- -D warnings, cargo test (run twice; the SIGTERM tests pass both times), cargo tree -i openssl empty. No Nix files changed. devenv shell -- dev-test all could not be used in this worktree: devenv aborts before any command with "To use 'git-hooks', run devenv inputs add git-hooks …" (an environment problem, not a repo change), so the same cargo commands were run directly.

  1. Blocking: the SSE SIGTERM test proves identity, not liveness (H: prove the SSE test server identity). tests/integration.rs spawns the binary with stderr piped and waits for its own listening addr=127.0.0.1:<port> line (spawn_listening / logs_listening, ANSI stripped, the address parsed and compared whole so a neighbouring port cannot match). Only then is the child signalled; sigterm_and_wait now also refuses to signal a child that has already exited. A port a stranger won makes spawn_listening return None and the test retries on a fresh port; the MCP tail_journal test uses the same helper. healthz_answers is no longer an identity check. New test a_probed_port_held_by_a_lying_squatter_is_retried starts a thread that answers HTTP/1.1 200 (verified by the test itself) and asserts the helper retries; only_the_childs_own_listening_line_counts pins the parser (other port, other address, non-startup line).
  2. Blocking: mode tests for every group/world bit (H: pin the token mode check for every group/world bit). secrets::group_or_world_write_and_execute_bits_are_rejected_too covers 0620, 0602, 0610 and 0601, and tests/peers_config.rs::a_loose_token_fails_startup_and_per_request_checks_alike asserts that validate_token_readiness and peers::load_token give the same reason, "group or world accessible", for each mode. Both fail with the old 0o044 mask (checked by reverting the mask locally).
  3. The plain-HTTP warning no longer appears twice (H: warn once about plain http). The transport warning and its plain_warned set are gone: every peer set is validated before the registry uses it (startup and reload both go through Config::load), and plain_http_off_loopback_requires_the_flag_and_warns_when_set now asserts exactly one cleartext line. The remaining helper is config::warn_plain_http_peer, named after the peer it reports. Deviation: the duplicated warning survives only for a PeersConfig handed to PeerRegistry::reload directly, bypassing validation; that is test-only and validate_target still refuses a plain-http peer without the opt-in.
  4. A FIFO token file cannot block a thread (H: never open a token path that is not a regular file). load_token_at calls std::fs::metadata and refuses non-files before opening, then opens with O_NONBLOCK to close the window before the open, and reads the mode and length from the open descriptor. a_fifo_is_refused_without_waiting_for_a_writer (mkfifo, load on a thread, 5 s timeout) fails on the previous code with "must not wait on a fifo".
  5. a_refused_token_file_sends_nothing covers the whole loop (H: keep the token listener open for the whole loop). The listener is no longer consumed by a 500 ms accept inside a task: it stays open for the four cases and one bounded accept() after the loop must time out. Making a case reachable (a 0600 token) fails the test.
  6. The span kind is checked where a backend sees it (H: assert the exported peer request span kind). A capturing SpanExporter plus SimpleSpanProcessor exports the span; peer_request_span_is_exported_as_a_client_span requires SpanKind::Client, the name peer.request, and no exported otel.kind attribute. It fails if the field is changed to server.

No contract looked wrong and contracts.md was not touched.