Plan: cross-process chaos observability harness — phase 1 (#480, epic &50)
- Context — the larger picture
- Strategy decision (ADR-020)
- Plan-file location
- Status — phase 1: the harness (#480, shipped)
- Harness API surface
- Critical files
- CHANGELOG entry template
- Verification
- Project-specific gotchas
- Documentation updates
- Out of scope (separate issues / future MRs — all since shipped)
- Reuses existing patterns
Status: Done (2026-05-19) — !333
Successor: Phase 2 — contested-environment parity (epic &80)
Split out of docs/modules/ROOT/pages/plans/cross-process-chaos-observability-harness.adoc on 2026-09-16 so the live plan carries phase 2 alone. The sections below are the phase-1 text as written (its Status table was back-filled on 2026-08-25), with three mechanical changes: workstation-absolute paths made repo-relative, agent-memory notes removed, and two crate paths repointed to their crates/ homes.
Context — the larger picture
Phase-1-era diagnosis (2026-05). Line anchors in the phase-1 sections below are as of 54b0fbd1 (2026-05-19) — grep by name against today’s tree.
Three of the four chaos tests then in flight (jwks_rotation and
outbox_catches_up in crates/canopy-test-lib/tests/evil_proxy_test.rs,
plus the multi_replica_test.rs suite) named invariants the SpanCapture
primitive could not observe. SpanCapture::install_scoped at crates/canopy-test-lib/src/observability.rs:120-130 uses tracing::subscriber::set_default, which is thread-local in the test process. Production code emitting events inside devstack containers (canopy-auth’s JwksProvider refresh task, canopy-mq’s OutboxDrainer running inside each service) is invisible to the test process’s subscriber — the chaos tests today are "fixture landed" rather than "invariant proven" (the diagnosis that drove #469 + #470, both now closed as duplicates under epic &50).
#462 (retry middleware, merged via MR !332) closed the in-process retry contract. The remaining three contracts (#481 JWKS, #482 outbox, multi-replica work) needed a harness primitive that lets them run production components in the test process so SpanCapture can see their events — all three have since shipped (see "Out of scope" below).
Strategy decision (ADR-020)
Three candidates evaluated:
-
In-process production fixtures — instantiate
JwksProviderandOutboxDrainerdirectly in the test process pointed atEvilLayer-wrapped endpoints.SpanCaptureobserves spans because they fire on the samecurrent_threadruntime as the test. -
OTEL export — devstack has no trace receiver today (
canopy-common/src/telemetry.rs:42documents this); container-to-test routing complexity; heavy dep tree (opentelemetry-proto). Rejected. -
Log scraping via Docker API — brittle (log-shape coupling), eventually-consistent polling, container-name coupling, new
bollarddep. Rejected.
Decision: in-process production fixtures. Zero new infrastructure, zero new container plumbing, zero production-code changes. Production constructors are already test-friendly. ADR-020 documents the decision + the thread-local-subscriber constraint.
Plan-file location
This canonical plan at docs/modules/ROOT/pages/plans/cross-process-chaos-observability-harness.adoc is the durable artifact per ADR-013. Linked from docs/modules/ROOT/nav.adoc under ** Infrastructure. Implementation begins only after this commit + ADR-020 + nav entries land on the feature branch (Step 1).
Status — phase 1: the harness (#480, shipped)
| Step | Description | Status |
|---|---|---|
1 |
Land canonical plan + ADR-020 + nav entry. This commit. REWRITE this canonical .adoc to match the reviewed design (replaces an earlier stale draft on the feature branch). Write |
Done (2026-05-18) — e99b1b2f |
2 |
|
Done (2026-05-19) — 54b0fbd1 |
3 |
|
Done (2026-05-19) — 54b0fbd1 |
4 |
|
Done (2026-05-19) — 54b0fbd1 |
5 |
|
Done (2026-05-19) — 54b0fbd1 |
6 |
|
Done (2026-05-19) — 54b0fbd1 |
7 |
|
Done (2026-05-19) — 54b0fbd1 |
8 |
4 unit tests across
|
Done (2026-05-19) — 54b0fbd1 |
9 |
|
Done (2026-05-19) — 54b0fbd1 |
10 |
Docs: (a) Shared Crates — new "canopy-test-lib chaos helpers" subsection under canopy-test-lib. (b) Testing — paragraph near the existing SpanCapture-thread-local note. |
Done (2026-05-19) — 54b0fbd1 (landed in the then-canonical .claude/docs directory; content migrated to the Antora pages cited here) |
11 |
Precommit Q1-Q8 + validate + push + MR. |
Done (2026-05-19) — 54b0fbd1 merged; #480 closed; epic &50 closed via #483 (runbook, 1a41ab99) |
Issue: https://gitlab.com/gadhs/application/eligibility/canopy/-/issues/480
Epic: &50 — Chaos observability contracts
Branch: feature/cross-process-chaos-harness
Labels: priority::medium, service::shared-crates, program::infrastructure, type::feature, workflow::done
Harness API surface
crates/canopy-test-lib/src/chaos/jwks.rs
pub struct ChaosJwksHandle {
pub provider: canopy_auth::JwksProvider,
pub mock_url: String,
_mock_handle: crate::mock::MockHandle, // Drop aborts axum
_evil_handle: crate::evil::EvilProxyHandle, // Drop aborts proxy
}
pub async fn spawn_jwks_provider_for_chaos(
evil_layer: crate::evil::EvilLayer,
) -> ChaosJwksHandle {
let mock = crate::mock::spawn_mock_jwks().await;
let upstream_url = format!("http://{}", mock.addr);
let evil = crate::evil::evil_proxy(&upstream_url, evil_layer);
let discovery = canopy_auth::OidcDiscovery {
issuer: "https://chaos-harness.test/realms/canopy".to_string(),
jwks_uri: format!("{}/protocol/openid-connect/certs", evil.url),
..Default::default()
};
let provider = canopy_auth::JwksProvider::from_discovery(&discovery)
.expect("from_discovery infallible for caller-built URL");
ChaosJwksHandle {
provider,
mock_url: evil.url.clone(),
_mock_handle: mock,
_evil_handle: evil,
}
}
The issuer is set to a stable mock value (https://chaos-harness.test/realms/canopy). Returning a provider with issuer: "" would be a footgun — JwksProvider::validate_token checks the JWT’s iss claim against this value. Tests that only exercise refresh() won’t notice, but a hypothetical consumer using validate_token would get confusing failures.
crates/canopy-test-lib/src/chaos/outbox.rs
pub struct ChaosOutboxHandle {
_drainer: canopy_mq::OutboxDrainer,
}
pub async fn spawn_outbox_drainer_for_chaos(
pool: sqlx::PgPool,
broker_url: &str,
) -> Result<ChaosOutboxHandle, anyhow::Error> {
let manager = canopy_mq::ConnectionManager::new(broker_url)
.await
.map_err(anyhow::Error::from)?;
let drainer = canopy_mq::OutboxDrainer::spawn(pool, manager);
Ok(ChaosOutboxHandle { _drainer: drainer })
}
Critical files
-
docs/modules/ROOT/pages/plans/cross-process-chaos-observability-harness.adoc(the plan file at the time; REWRITE in Step 1) -
docs/modules/ROOT/pages/adrs/adr-020-cross-process-chaos-observability.adoc(NEW, Step 1) -
docs/modules/ROOT/nav.adoc(+ 2 entries, Step 1) -
crates/canopy-test-lib/Cargo.toml(+canopy-auth,canopy-mqnormal-deps) -
crates/canopy-test-lib/src/chaos/mod.rs(NEW) -
crates/canopy-test-lib/src/chaos/jwks.rs(NEW) -
crates/canopy-test-lib/src/chaos/outbox.rs(NEW) -
crates/canopy-test-lib/src/mock.rs(+spawn_mock_jwks) -
crates/canopy-test-lib/src/lib.rs(+pub mod chaos;) -
CHANGELOG.adoc -
Shared Crates (
docs/modules/ROOT/pages/shared-crates.adoc) -
Testing (
docs/modules/ROOT/pages/testing.adoc)
CHANGELOG entry template
* *Cross-process chaos observability harness — `canopy_test_lib::chaos`
module (\#480 + ADR-020).* NEW module + 2 helper functions that spawn
production `JwksProvider` and `OutboxDrainer` in the test process
pointed at `EvilLayer`-wrapped endpoints. Unblocks the three chaos
contracts (\#481 JWKS, \#482 outbox, multi-replica work) that were
previously architecturally blind: `SpanCapture::install_scoped` uses
`tracing::subscriber::set_default` which is thread-local in the test
process and could not observe events fired inside devstack containers.
In-process fixtures sidestep the cross-process problem entirely while
exercising the same production constructors.
`spawn_jwks_provider_for_chaos(EvilLayer) -> ChaosJwksHandle` spawns
a canonical-shape JWKS mock under the supplied `EvilLayer`, constructs
`JwksProvider::from_discovery` with a stable mock issuer.
`spawn_outbox_drainer_for_chaos(pool, broker_url) -> Result<ChaosOutboxHandle, anyhow::Error>`
spawns `OutboxDrainer` against the supplied broker URL — chaos tests
point at a real broker (devstack) and observe the `info!("outbox drainer started")`
emit at `outbox_drainer.rs:213` immediately on spawn. Transient-failure
injection requires AMQP-transparent EvilLayer (tracked in \#482).
4 unit tests: 3 in-process JWKS tests + 1 devstack-gated outbox test
marked `+\#[ignore]+` per existing chaos pattern. ADR-020 documents
the strategy decision + the thread-local-subscriber constraint. Zero
production-code changes. `shared-crates.adoc` +
`testing.adoc` updated. Closes \#480.
Verification
-
cargo nextest run -p canopy-test-lib chaos::jwks— 3 JWKS unit tests pass (in-process only). -
cargo nextest run -p canopy-test-lib --run-ignored only chaos::outbox— outbox test passes when devstack up; skips cleanly when down. -
cargo nextest run -p canopy-test-lib— full crate green. -
cargo build -p canopy-test-lib— no cycle. -
cargo fmt --all — --check+cargo clippy --all-targets --workspace --locked — -D warningsclean (zero#[allow]). -
cargo xtask validateclean.
Project-specific gotchas
-
SPDX header on every new
.rsfile line 1. -
#![warn(missing_docs)]on canopy-test-lib (lib.rs:3) — everypubsymbol inchaos::needs///. -
Clippy
-D warnings— zero#[allow(clippy::*)]carve-outs. -
nextest only: never
cargo test. -
No Q1-Q8 in commit messages.
-
Commit title ≤72 chars, prefix
^(feat|fix|chore|refactor|docs|test|ci):. -
Thread-local subscriber constraint — chaos tests using the harness MUST use
#[tokio::test(flavor = "current_thread")]. Documented in module rustdoc + ADR-020 + Testing.
Documentation updates
-
CHANGELOG.adoc— entry under=== Added. -
Shared Crates — new
canopy-test-lib chaos helperssubsection. -
Testing — chaos-helpers paragraph + thread-local-subscriber callout.
Out of scope (separate issues / future MRs — all since shipped)
-
JWKS chaos contract rewrite — #481, closed (
target: "jwks"emit sites landed incrates/canopy-auth/src/jwks.rs). -
Outbox chaos contract rewrite — #482, closed (
target: "outbox"emit sites landed incrates/canopy-mq/src/outbox_drainer.rs). Its AMQP-transparent fault-injection residue is now phase 2’s U3/U4. -
Durable docs + runbook — #483, closed (1a41ab99; the chaos runbook).
-
Multi-replica chaos rewrite — superseded: owned by phase 2 (U14, epic &80) in the phase-2 plan.
Reuses existing patterns
-
canopy_test_lib::mock::spawn_router(mock.rs:51) +spawn_mock_persons(mock.rs:165-209) — axum mock shape,MockHandleabort-on-Drop. -
canopy_test_lib::evil::{EvilLayer, evil_proxy, EvilProxyHandle}(evil.rs) — fault-injection layer + handle that aborts on Drop. -
canopy_test_lib::observability::SpanCapture::install_scoped(observability.rs:120). -
canopy_test_lib::infrastructure_available(infrastructure.rs:14) — devstack-presence gate. -
canopy_auth::JwksProvider::from_discovery(jwks.rs:50) +OidcDiscovery(discovery.rs:70,derive(Default)). -
canopy_mq::ConnectionManager::new(connection.rs:49, async, returnsResult<_, lapin::Error>). -
canopy_mq::OutboxDrainer::spawn(PgPool, ConnectionManager)(outbox_drainer.rs:183). -
CANOPY_TEST__RABBITMQ_URL+ privatefn amqp_url()pattern (crates/canopy-mq/tests/outbox_drainer_test.rs:22-30). -
CANOPY_PORT_POSTGRES_5432+ privatefn pg_url()pattern (outbox_drainer_test.rs:35,52).