Identity plane split, plan I3e3: canopy-web’s sender (epic &133)

Status: Done (2026-10-10) — !1589
Epic: &133 (stage I3 of &130)
Issues: #2824 (U1, w2); #2825 (U2, w3); #2826 (U3, w5); #2827 (U4, w3); #2828 (U5, w2).
MR: feat/identity-web-sender, "canopy-web’s sender (#2824 … #2828)".

One MR, one commit per issue, under the maintainer’s one-MR-per-related-group ruling. It merges once the pre-push battery passes. This is a Design + Scope plan: GitLab owns tracking, and the plan freezes when U1 starts. X1–X8 are this plan’s decisions (ADR-049 Amendment 19); R5–R8 are the maintainer’s rulings.

Context

Amendment 18 V1 named I3e3, canopy-web’s sender; plan I3e2’s ruling R3 gave its scope: delegation for each backend call, the session_stale renew-and-retry, and system purposes. Plan I3e2 built the session engine this sender stands on.

The maintainer’s rulings (2026-10-10):

  • R5. A request’s concurrent calls share one per-request cache, with single-flight per target, and receive owned bearers.

  • R6. canopy-web’s sender is its own type, WebSender. IdentitySender stays the service-only sender E4 describes.

  • R7. The sender renews a session_stale session itself, once per request.

  • R8. On narrowing, the maintainer asked for the architecturally correct answer. That is X3: no narrowing.

What exists:

  • canopy-auth’s sender pieces:

    • DelegationTokenSource::from_session(&mut DelegationCache, &SessionCredential, target, &Narrowing) (identity_client/delegation.rs);

    • SystemTokenSource, process-wide with single-flight slots (identity_client.rs), a precedent for per-key interior mutability;

    • OwnedBearer and client_key_secret (identity_sender.rs);

    • SENDER_BUDGET (6.5 s).

  • The call graph (identity_policy/call_graph.rs): canopy-web has 14 Delegation edges and one Both edge, to canopy-security. Its one system purpose is canopy-web/canopy-security (identity_policy.rs).

  • The engine: WebSessionEngine::current(key, budget) → LiveSession (identity_web_session/engine.rs). It has no way to force maintenance.

canopy-web today (replaced at the switch):

  • Reads carry canopy-web’s own service token, and fail open without a page deadline (services/canopy-web/src/clients.rs, with_service_identity).

  • Writes use an RFC 8693 exchange.

  • The dashboard fans out up to 8 calls at once (bounded_join, UPSTREAM_FANOUT_LIMIT).

  • A backend 401 is treated as just another 4xx.

Decisions (ADR-049 Amendment 19, X1–X8; land with U1)

  • X1. Staging (R5–R8). I3e3 is canopy-auth library code, unwired until the switch, which moves canopy-web’s roster, its exchange wrappers and its panel-cache key (#2647) (W1).

  • X2. WebSender (R6) is a new module, canopy_auth::identity_web_sender. It is a cheap Clone handle over an Arc, holding a WebSessionEngine<S>, a DelegationTokenSource and a SystemTokenSource, both minting with canopy-web’s key.

    • WebSender::over_http(engine, &IdentitySettings, Arc<dyn KeySigner>, IdentityHttpClient).

    • from_secrets(engine, &IdentitySettings, &dyn SecretProvider, IdentityHttpClient) → Result<_, SenderError> reads the key under client_key_secret(ConfidentialClient::Web) (CANOPY_WEB__IDENTITY_CLIENT_PRIVATE_KEY, D10), with no file fallback (SenderError::Key).

  • X3. Routing; no narrowing. This amends B3’s "a mint narrows per request" to "a mint may narrow". canopy-web’s never does.

    • Inside a request (WebOutbound), a Delegation or Both edge mints from the session (G1’s session form, act [canopy-web]). A System edge takes a system token. No edge is NoEdge, and nothing is sent.

    • System calls: system_bearer(target), on the outbound for M4’s in-request system call (the worker-name refill) and on the sender for detached tasks. It works on System and Both edges only; a Delegation edge is NoSystemEdge (E5).

    • Mints never narrow: every mint takes G4’s base, the session’s current roles and programs.

    • Why not narrow: by G4, canopy-web’s narrowing becomes the ceiling for every onward hop. Narrowing at the edge would make canopy-web encode the transitive role needs of each downstream chain (eligibility → SOLQ, for example), and that would fail closed whenever a downstream policy changed. D4 keeps policy compiled and judged at every receiver against the session’s current roles. Least privilege comes from structure instead: one audience per token, at most 300 s, reuse within one request only, the act chain, and freshness. A narrowing parameter can be added later, without breaking callers, for a locally known case.

  • X4. The session form’s sender-side check (D3, G9). DelegationTokenSource::from_session takes the &FederatedSession, not only its credential. A minted token must name the session’s sub and sid, and its exp must be no later than session_ends_at, else AnswerDefect::Subject or OutlivesSubject. All are issuer-clock times. This mirrors the onward form’s check. Its callers update in the same diff:

    • the token broker, which holds a FederatedSession;

    • web_session_engine_test.rs, which passes &record.session;

    • identity_client/delegation/tests.rs's 11 call sites;

    • canopy-security’s identity_delegation/end_to_end.rs and identity_admin/end_to_end.rs. These read only part of F2’s answer today. Their answer structs gain F2’s remaining fields (auth_time, session_ends_at, fresh_until, roles, programs, username), from which they build the FederatedSession, whose fields are public.

  • X5. The per-request outbound (R5).

    • Construction: WebSender::calls(key, LiveSession, deadline: tokio::time::Instant) → WebOutbound<S> owns everything it needs, so it is 'static, Send and Sync, and canopy-web can share it through an Arc extension at the switch. Compile-time probes hold this, along with bearer()'s future being Send.

    • The cache: a parking_lot::Mutex<HashMap<CanopyService, Arc<TargetSlot>>>, plus an outbound-wide renewal epoch. A target’s slot is created once and never removed. It holds a tokio::sync::Mutex over the target’s DelegationCache and the epochs it was filled under, and a parking_lot-guarded state: the slot’s own epoch, an attempt counter, a last-failed flag, and a stale flag tagged with the renewal epoch it was refused under. The parking_lot guards cover only reads and writes of that state, never an await.

    • Invalidation by generation. rejected(target) bumps the slot’s epoch, and a successful renewal (X6) bumps the outbound’s. Nothing is removed, so every caller, queued or new, meets the same slot.

      • Holding the slot’s lock, a caller first clears a cache filled under an older pair of epochs, so a rejected or pre-renewal token is never served.

      • A token minted while either epoch moved is returned to its own caller, being a new token, but is not cached.

      • A caller whose epochs moved while it waited re-reads the current pair before serving.

      • Renewal happens at most once per request, and rejected only on the caller’s own 401, so this converges within the call’s bound.

    • Failure sharing, as SystemTokenSource shares it: callers queued during a failed attempt answer SharedFailure instead of minting again.

      • The attempt runs under a guard that publishes a failure (attempts + 1, last failed) on drop unless it completed, so an attempt cancelled by its bound still publishes its outcome to the callers queued behind it.

      • A session_stale refusal is not a shared failure. It sets the slot’s stale flag at the current renewal epoch, and every caller that sees the flag goes straight to the shared renewal (X6) without minting, then retries under the new epoch.

    • Bearers: bearer(&self, target) → Result<OwnedBearer, WebSendError> copies the token out under the slot’s lock into a zeroizing OwnedBearer, through a new pub(crate) constructor (E7). A fan-out holds no borrow.

    • Bounds. This amends E6’s per-acquisition bound for canopy-web, which computes every stage from one request deadline.

      • Each mint attempt, its wait for the slot included, is bounded by the lesser of SENDER_BUDGET and what remains to deadline.

      • The renewal (X6) is bounded by what remains less MINT_RESERVE.

      • The whole bearer() is bounded by deadline.

      • Past a bound, the answer is Timeout, or RenewalPending for the renewal.

    • The ADR exception: this is interior mutability, which the coding conventions allow only with an ADR, and this decision is that ADR. It follows SystemTokenSource's pattern, scoped to one request.

  • X6. session_stale (R7, G2).

    • One renewal per request. A mint refused session_stale renews the session once per request, through a tokio::sync::OnceCell<Result<NumericDate, Renewal>> that concurrent calls share.

      • Renewal is Copy: Ended, Pending, NotAdvanced or Store(StoreFault).

      • The renewal is engine.maintain_now(key, served_version, remaining − MINT_RESERVE).

      • MINT_RESERVE (1 s) guarantees the retried mint at least that long; the retry gets the lesser of SENDER_BUDGET and what remains. A slow issuer’s retry may therefore time out, a deliberate trade so that the renewal fits the request.

      • With no more than the reserve remaining, the answer is RenewalPending without renewing.

      • Not advanced: a renewal that answers a session whose fresh_until did not pass the served one is NotAdvanced, and the request answers RenewalPending with no retry. canopy-identity refused or failed it without ending the session, and the leader committed a retry.

    • After a successful renewal:

      • the outbound bumps its renewal epoch once (F5 re-projected roles and programs), so no pre-renewal token is served again (X5);

      • each stale call retries its mint once, with the same credential (F2 echoes it);

      • the retry is classified as the first attempt was, and only a second session_stale is WebSendError::Delegation.

    • Refusals:

      • session_ended and subject_suspended call engine.end_refused(key, refusal, remaining) and answer SessionEnded;

      • any other refusal, a 429 (G10’s limit), a 503 or a transport failure answers its typed error, with no retry and no fallback (E6: never fail open).

    • Renewal outcomes: Unserved::NoSession or Ended is SessionEnded; Pending is RenewalPending; Store is Store.

  • X7. The engine’s two new entries.

    • maintain_now(key, seen: RecordVersion, budget) → Result<LiveSession, Unserved> runs V4’s loop under one deadline, with decide_forced, in this precedence:

      1. no row → NoSession;

      2. unbound → end UpstreamChanged;

      3. lapsed claim → end RefreshLost;

      4. version past seen → V4’s ordinary decide, since another leader maintained it;

      5. at seen, not maintainable → end Expired;

      6. at seen, inside V3’s retry spacing (maintain_at > now and maintain_at > fresh_until − FRESHNESS_LEAD, which no scheduled time exceeds) → Pending. This holds a failed renewal’s 30 s spacing while the local freshness is within FRESHNESS_LEAD plus MAINTENANCE_RETRY of fresh_until. Beyond that skew, each new version may be forced once per request, single-flight (see Risks);

      7. deadline passed → Pending;

      8. a live claim → wait;

      9. free → lead.

        Otherwise it ignores the local freshness and maintain_at, because canopy-identity’s freshness has spoken. The claim at the version keeps it single-flight.

    • end_refused(key, refusal: CanopyRefusal, budget) → Result<(), Unserved> ends the record IdentityRefused:

      • under SessionEnded, with no identity revocation;

      • under SubjectSuspended, revoking canopy-identity’s session within 2 s, since F8 revokes a suspended subject’s session only at a renewal.

        revoke_identity's skip rule (no revocation for IdentityRefused) moves into its callers. A spawn_revocation(inner, credential) revokes, and each end path decides whether to call it.

  • X8. A receiver’s 401 (E6).

    • WebOutbound::rejected(target), which is sync, bumps the target slot’s epoch (X5), so the request’s delegation tokens for it are never served again, even to callers already queued, and it invalidates the process’s system token for it.

    • The caller retries once. The sender never retries a 401 on its own.

Rate

Reuse is per request, so canopy-web’s mints are roughly page loads × distinct targets per page: about 3 on P1’s assumption. That is within P4’s ≥ 60 000 a minute at two replicas. A 429 is a typed error, never retried by the sender.

Units

Every commit goes through the J1–J8 review. Each subject is at most 72 characters with its ` (#N)`.

Erratum (2026-10-10): each piece landed with its first use, so nothing sat unused between units. The engine_world re-export landed in U3, not U2. calls took the record’s key in U4, with the renewal. The delegation mock’s one-shot answer arrived in U4. X4’s callers also included the capacity harness (xtask/src/cmd/perf/identity/senders.rs). The admin end-to-end test’s SignedIn keeps the session in place of the bare credential. The renewal cell holds Result<(), Renewal>, since nothing read the new freshness. U4’s "minted across the renewal" test became the deterministic "no token minted before the renewal is served after it", the property the epoch pair guarantees.

  1. U1 (#2824, w2) docs(adr): record canopy-web’s sender.

    • ADR-049 Amendment 19 (R5–R8, X1–X8), plus the Status line.

    • This page (In progress), with the ** Identity Plane Split (epic &130) nav group above the archive line.

  2. U2 (#2825, w3) feat(auth): force a web session’s maintenance (X7).

    • Files:

      • identity_web_session/decide.rs: decide_forced(facts, seen, now, deadline_passed);

      • engine.rs: maintain_now and end_refused. current and maintain_now share a private loop taking a mode, Serve or Force(seen), split into helpers to stay within 40 lines. A second impl block holds the methods past the 16-method cap.

    • Test access:

      • engine.rs's [cfg(test)] mod tests becomes pub(crate) mod tests, and identity_web_session.rs re-exports it under [cfg(test)] as pub(crate) use self::engine::tests as engine_world, for U3 and U4.

      • One pair of test ids, TEST_SID and TEST_SUB (pub(crate) in identity_client/delegation/tests.rs), is shared by the delegation endpoint’s minted claims, the engine world’s f2 answers and World::record, so X4’s check passes.

    • Tests:

      • a locally fresh session at seen is led, and one refresh and one renewal are posted;

      • a version past seen is served as decide would;

      • a row inside its retry spacing is Pending, and nothing is posted;

      • 16 concurrent maintain_now calls at one version post one refresh;

      • a live claim is waited on;

      • unbound, lapsed and tokenless sessions end as V4 does;

      • the deadline gives Pending;

      • end_refused(SessionEnded) ends IdentityRefused and posts no revocation, while end_refused(SubjectSuspended) posts one;

      • a proptest: at seen, decide_forced never leads past the deadline, inside the spacing or over a claim; past seen, it equals decide.

    • Docs: shared-crates.adoc.

  3. U3 (#2826, w5) feat(auth): add canopy-web’s sender (X2–X5, X8).

    • Files:

      • crates/canopy-auth/src/identity_web_sender.rs (+ tests.rs), with re-exports in lib.rs: WebSender, WebOutbound (with a hand-written Debug naming only the key’s presence and the served version), and WebSendError (NoEdge, NoSystemEdge, Timeout, SharedFailure, System(SystemTokenError), Delegation(DelegationError), SessionEnded, RenewalPending, Store(StoreFault)), no variant carrying a token or credential;

      • identity_sender.rs: OwnedBearer::from_call(&str), a pub(crate) constructor;

      • identity_client/delegation.rs: X4’s from_session(&FederatedSession, …) and its check;

      • the callers X4 names.

    • Test helpers: the delegation tests' Script (its fields), script() and endpoint become pub(crate). The endpoint gains a delay (a stall gate) and a one-shot raw answer.

    • Tests:

      • a Delegation edge sends the session form: requested_token_type the access-token type, subject_token_type web-session, the target’s resource, and neither requested_roles nor requested_programs;

      • the Both edge (canopy-security) delegates in a request;

      • system_bearer(Security) takes a system token, and system_bearer(Persons) is NoSystemEdge;

      • a target with no edge is NoEdge, and nothing is sent;

      • concurrency:

        • 8 concurrent bearers to 3 targets post 3 mints, and calls to one target get one token;

        • 8 concurrent bearers to one target against a 503 post one mint, the rest answering SharedFailure;

        • staggered waiters: one caller’s attempt against a stalled endpoint is cancelled by its bound, and a caller queued behind it answers SharedFailure with no second mint;

        • rejected while callers are queued on the target and a mint is in flight: no queued caller receives the rejected token, the in-flight token is returned but not cached, and every later caller is served one new token from the same slot;

      • two outbounds mint separately (request scope);

      • rejected re-mints, and invalidates the system token;

      • a stalled endpoint gives Timeout by the lesser of the budget and the deadline;

      • X4’s check: a token naming another sid, or outliving session_ends_at, is refused;

      • probes:

        • WebOutbound is Send + Sync + 'static, and bearer()'s future is Send;

        • WebOutbound has no Clone (it owns the session’s credential);

        • OwnedBearer has no Debug.

    • Docs: shared-crates.adoc.

  4. U4 (#2827, w3) feat(auth): renew a stale session once per request (X6).

    • Tests (engine_world plus the delegation endpoint):

      • session_stale then success: one renewal posted, the renewal epoch bumped, the mint retried once, a bearer;

      • 8 concurrent calls refused session_stale share one renewal;

      • several callers to one target, the first refused session_stale: the others join the renewal without minting, all receive bearers, and the target sees exactly two mints (the refused one and one retry, its token served to every caller);

      • a renewal completing while mints to other targets are in flight: their tokens are returned but not cached, and later calls are served post-renewal tokens;

      • session_stale on the retry gives Delegation, with no second renewal;

      • session_ended on the retry gives SessionEnded;

      • a renewal that does not advance fresh_until (canopy-identity 503) gives RenewalPending with no retry;

      • too little time left gives RenewalPending without renewing;

      • session_ended gives SessionEnded, the record ended IdentityRefused with no revocation;

      • subject_suspended does the same and revokes;

      • a 429 or another refusal leaves the record untouched.

    • Docs: shared-crates.adoc.

  5. U5 (#2828, w2) test(auth): prove canopy-web’s sender on the devstack.

    • The test file: crates/canopy-test-lib/tests/web_sender_test.rs.

      • It duplicates web_session_engine_test.rs's plane construction, since each test file builds alone: a cast worker per test signs in through the engine.

      • Probes sit behind IdentityReceiver::over_http for canopy-persons and canopy-security, as identity_sender_test.rs's serve_probe does.

    • The tests:

      • a bearer for Persons admits the worker’s user principal, act [canopy-web];

      • 8 concurrent bearers across Persons and Security get one token per target;

      • in a request, Security takes a delegation, and system_bearer(Security) admits canopy-web’s system principal;

      • rejected mints a new token;

      • after sign_out, a bearer from a fresh outbound (an empty cache, so the mint reaches the issuer) is SessionEnded.

    • A real session_stale needs 900 s, so U4’s scripted tests prove it, and this unit does not.

    • Close:

      • CHANGELOG.adoc Added (and Changed for X4’s signature);

      • Amendment 19’s as-built record;

      • the plan Done and archived;

      • plan-lint --done with --allow-open for U1–U5, #2344, #2345, #2521 and #2647;

      • after merge, update the epic.

Scope

In: WebSender and WebOutbound; X4’s session-form check; the engine’s maintain_now and end_refused; the devstack proof.

Out:

  • The switch: canopy-web’s roster, exchange wrappers, handlers, the panel-cache key (#2647), and removing its fail-open read path.

  • The device-approval and security-admin clients, and the edge forwarder: later I3e plans.

  • A narrowing parameter: added only when a route needs one.

Risks

  • The per-request cache is interior mutability. X5 records it as an ADR exception, scoped to one request, as SystemTokenSource does.

  • A renewal adds latency to the first call that finds the session stale. It runs once per request, within the request’s deadline less MINT_RESERVE, and answers RenewalPending rather than overrunning.

  • Clock skew beyond V3’s 15 s margin makes stale answers routine: each costs one forced maintenance per version. While the local freshness is near its end, a failed renewal’s 30 s spacing holds (X7 step 6). Beyond that skew, a session whose renewals keep failing is forced once per request at each new version: single-flight, bounded by its request rate.

  • A forced maintenance within one second of the last refresh is refused at canopy-identity as not newer (F5). The request answers RenewalPending, and the next request recovers.

Verification

  • Per unit: fmt; clippy with and without test-helpers; quality-budgets, plan-lint, check-docs and private rustdoc.

  • nextest:

    • canopy-auth (U2–U4);

    • cargo xtask test --integration --host -p canopy-test-lib --no-refresh --skip-static (U5).

  • Per MR: the pre-push battery.

Review log

Round Vendor Resolved model Verdict

1

Anthropic

Claude Opus 5.5 (fresh subagent)

no-ship. Two blockers, fixed in-plan:

  • X4’s canopy-security callers hold no FederatedSession (now built from F2’s full answer), and the caller list missed the delegation tests' 11 sites;

  • X5’s per-call bound contradicted X6’s renewal budget (now three bounds stated).

  • Notes folded in: the shared test session ids; the retry spacing’s real bound; end_refused's own revocation path; the Context attribution; U5’s duplicated plane; the 40-line split and the method cap.

2

not stated (the maintainer’s other vendor)

not stated

1 finding (P2) and 4 clarifications, fixed in-plan:

  • invalidation by generation (slot and renewal epochs; slots never removed), with tests for queued callers and in-flight mints;

  • a session_stale keeps queued callers attached to the shared renewal;

  • a cancelled attempt publishes its failure through a drop guard, with a staggered-waiter test;

  • the post-sign-out proof uses a fresh outbound;

  • the form asserts no requested_roles or requested_programs.

The maintainer shipped after round 2 (2026-10-10).

Edit this page · default