Identity plane split, plan I3b: issuer readiness (epic &133)

Status: Done (2026-10-08) — !1580
Epic: &133 (stage I3 of &130)
Issues: #2777 (w2), #2778 (w3), #2779 (w3), #2780 (w2), #2781 (w5), #2782 (w3), #2783 (w3); the gates' #2759 and #2760 close per Outcomes
MR: fix/issuer-readiness: U1–U7 in order, titled "canopy-identity issuer readiness (#2759, #2760 and the unit issues)".

The seven issues ship as one MR under the maintainer’s one-MR-per-related-group ruling, one commit per issue: each measurement builds on the one before it (baseline, attribution, the sweeps, final), so no unit stands alone. The sole developer merges it once the pre-push battery passes, the maintainer’s standing rule while CI is broken upstream. U1’s commit adds this page and its nav entry; U7’s closes it.

This is a Design + Scope plan. GitLab owns tracking. The plan freezes when U1 starts. S1–S9 are this plan’s decisions (ADR-049 Amendment 12); "G1"–"G7" are Amendment 10’s gates unless "Amendment 7’s G1" says otherwise.

Context

Plan I2g’s recorded capacity run failed two gates the switch (Amendment 11 K1) waits on:

  • #2759 (G1): delegation p99 was 55.1 ms (session) and 55.3 ms (onward) at the design load, 603 requests a second on two replicas, against 50 ms.

  • #2760 (G6): at the peak, 1206 a second, the issuer pool (22) sat at its ceiling in a median 65 summed one-second samples. The one-replica saturation cell held 600 a second and collapsed at 750: 1764 tokens were refused 503 "could not be audited" (the issue’s "four" is wrong).

In the tree and the recorded run’s own logs:

  • Delegation is sequential: the jti INSERT (client_auth.rs:256-261), the session read (sessions.rs:950-958), in-process signing, then the wait for the issuance-log row (token_endpoint.rs:1307-1315, issuance_log.rs:760-776). p50 41.3 ms; client credentials, with no session read, 34.2.

  • The audit wait dominates. One writer runs one batch at a time (issuance_log.rs:847-870), gathers for 10 ms after a batch’s first row, timed from the previous batch’s answer (:877-880), and acquires from the shared issuer pool, in the requests' FIFO, for BEGIN, INSERT and COMMIT (:907-911, :1012-1019).

  • The 750/s collapse was the writer starved in that queue: every refusal in replica-0.log is caller_deadline; no batch failed.

  • The harness relay inflates its stated 1 ms about threefold: DelayRelay waits each half with tokio’s 1 ms-tick timer and sets no TCP_NODELAY (delay_relay.rs:39-44, 93); the 7.1 ms delegation-to-client-credentials gap is two round trips. A model fitted to the record (55.0 ms predicted, 55.1 measured) puts HEAD near 32 ms behind an honest relay.

I3b makes the harness honest and records a baseline, lands writer changes that remove the collapse and pass G1 even at a 3 ms round trip, sets the defaults by stated rules, and records the run.

Scope

In: the issuer’s writer, its gather window, the pool’s default, the capacity harness. Out: every I3c–I3g concern; retention (#1303, the open I2g call); test_before_acquire for requests (except F2); synchronous_commit; a second writer (except F1); reordering the delegation path.

Design

Decisions (recorded in ADR-049 Amendment 12, which lands with U1)

  • S1. The writer has a pool of its own. WriterPool: one connection under the issuer login, built lazily through canopy_db::pool_options() from the issuer’s connect options, application_name canopy-identity-writer. The writer holds it across batches, so requests never queue behind a batch and batches never behind requests. The per-replica budget gains it; the issuer pool’s background holders drop from six to five. No PoolName: a held one-connection pool reads size = max permanently and would trip the guide’s pool alert.

  • S2. A batch is one autocommitted statement, INSERT … SELECT FROM UNNEST, atomic as one implicit transaction. A6 and D13 are unchanged: a caller is answered only after its row commits; every failure fails closed.

  • S3. The writer never returns its connection to the pool. An idle-for-1 s connection is pinged within the batch’s deadline before use, and replaced if the ping fails. After any failure (deadline, broken connection, database refusal) it is disposed of: detached, freeing the slot at once, then closed within 1 s or dropped. Neither the #2538 release check nor sqlx’s release ping, both unbounded network calls, ever runs on it. test_before_acquire stays on.

  • S4. The gather window runs from the batch’s oldest row, so a row that already waited it goes in the next batch at once, and becomes the setting identity_issuance_gather_ms, 0–20 ms, default by S8.

  • S5. The writer reports its queue wait: canopy_identity_issuance_queue_wait_seconds, each attempted row’s time from submission to its batch’s start (the moment gather returns the batch); canopy_identity_issuance_commit_seconds runs from that start to the statement’s end. Boundaries in U4.

  • S6. The harness relay delivers the round trip it states. TCP_NODELAY; chunks released from a timer thread. A chunk’s hold is its read returning to its write starting. Over a window (snapshot deltas), each direction’s holds need a median ≥ --db-rtt-ms ÷ 2 and a p95 ≤ --db-rtt-ms ÷ 2 + 0.25 ms (bucket bounds): a tail limit per direction catches a relay that delays a large minority of exchanges, which a sum of medians does not. A cell is judged on its worst replica’s relay; a repetition or saturation step failing either bound is invalid (G7); under 100 chunks (the idle probe) is exempt. The record reports p50 and p95 round trips (sums of the directions'). --db-rtt-ms is 0–10 ms; hold buckets are 25 µs to 7 ms plus overflow. The as-built reports U2’s reconstruction of the old relay’s round trip (a fresh run on the same host), and attribution to the relay carries that limit.

  • S7. The record keeps what sizing needs: the effective settings (F1, F2 active or not) and the relay’s round trip; each window’s pool in-use maximum, mean and at-ceiling count from 1 s and 10 ms samplers, replacing the lifetime maximum; the writer’s commit, batch-size and queue-wait buckets; issuance failures by cause. The saturation cell runs the peak (design × --peak) as its own step, and "carries the peak" is read there.

  • S8. Defaults come from stated rules: the window from Rule G, the pool from Rule P. The pool’s bounds stay 12–64.

  • S9. Scope under K1: additive-only binds the cut-over’s receivers and senders; I3b changes only the issuer canopy-security already serves, which no caller uses until the switch. Unchanged: test_before_acquire (except F2), the release check on every connection but the writer’s, synchronous_commit=on, and jti before session (Amendment 7’s G1, G10).

Measurement

Every run: a release build, a reloaded devstack, nothing else on the host; the default load model with --replicas 2 --replica-threads 2 --db-rtt-ms 1 --reps 3; seed 541770337227324816 (I2g’s, S below). An INVALID cell is re-run up to twice; still INVALID, an issue "the capacity run is INVALID on this host" is filed under &133, Status becomes Blocked (#N), and work stops.

  • Baseline (after U4) and attribution (after U5): cargo run --release -p xtask — perf identity --cells idle-probe,design,peak,saturation --seed S.

  • Rule G (pool 22): for W in [0, 2, 5, 10], --cells idle-probe,design --issuance-gather-ms W. W qualifies when every G1 row, G2, G4 and both cells' G7 pass; p(W) is the larger delegation p99 median; best the smallest qualifying p(W). The default is the largest qualifying W with p(W) ≤ min(best + 5 ms, 40 ms); if no qualifying W is ≤ 40 ms, the W with p(W) = best, ties to the larger. No W qualifying: F2, then Rule G again; still none, Rule G selects nothing: an issue under &133, the default stays 10, Status Blocked (#N), work stops before Rule P.

  • Rule P (W from Rule G): for v in [22, 28, 36, 48, 64] ascending, --cells peak,saturation --db-max-connections v. v passes when the peak cell’s G3, G5, G6 and G7 pass and carries_peak is true; the default is the first passing v, never below 22. None passing: F2, then Rule G and Rule P again. Still none, but some v passes the peak cell’s own G3, G5, G6 and G7 (two replicas carrying the peak, the R − 1 case at three): the smallest such v, the guide’s minimum three replicas, and the as-built stating each v’s failed criterion from the record. No v even then: an issue, the default stays 22, Status Blocked (#N), work stops.

  • Final: cargo run --release -p xtask — perf identity --seed S (all cells, new defaults, no overrides), then an informational --cells design --db-rtt-ms 3. A gate that passed in the sweeps but fails here is re-run once.

About 5½ hours of an idle host in all.

Conventions every unit follows

Each unit ships a CHANGELOG.adoc bullet; the commit histogram’s semantics and buckets and IssuanceLogWriter::spawn's signature go under Changed. DB-backed tests follow testing.adoc's CANOPY_TEST_INFRA pattern, as identity_registry_test.rs does. Each subject is at most 64 characters before its ` (#N)`.

Units

  1. U1 (w2) docs(adr): record issuer readiness in ADR-049 (#2777). Amendment 12 (S1–S9) under [#amendment-12] before == References, and the Status line naming it; this page and its nav entry.

  2. U2 (w3) chore(xtask): hold the harness relay to its stated round trip (#2778). S6.

    • delay_relay.rs, in order: (1) holds first, each direction’s task owning its buckets and publishing them through a tokio::sync::watch (send_modify), so the relay has no shared mutable state of its own, read by holds(); (2) one --cells design --reps 1 run on the old relay records its true round trip for the as-built; (3) set_nodelay(true) on both sockets and a private ReleaseTimer (one std::thread, a BinaryHeap of due times, recv_timeout) that write_chunks awaits, order holding because a direction’s due times never decrease.

    • xtask: fleet.rs keeps the relay (relay_holds()); measure.rs' RelayMeasure (stated, each direction’s p50/p95, the p50/p95 round trips, chunks); gates.rs' validity applies S6 per direction and to saturation steps; mod.rs refuses --db-rtt-ms outside 0–10.

    • Tests: the_relay_never_releases_a_chunk_before_its_due_time (200 echoes at 1 ms, each ≥ 1 ms); the_relay_counts_each_chunk_it_held; the_timer_fires_each_due_time_in_order; a_relay_off_its_stated_round_trip_invalidates_the_cell (at 1 ms: 0.5 ms both ways valid; a direction’s p95 0.8 or median 0.45 invalid; 40 % of exchanges holding 1.5 ms one way invalid; under 100 chunks exempt); the_round_trip_flag_is_held_to_its_range (0, 10 accepted; 11 refused). Precision is proven by step (2)'s comparison and G7 on every run, not in the parallel unit lane, where a timing bound would be flaky. Docs: tooling/xtask-catalog.adoc.

  3. U3 (w3) chore(xtask): record what the issuer’s sizing needs (#2779). S7.

    • replica.rs' PoolSampler keeps cumulative per-value in-use counts at 1 s and adds a 10 ms sampler; report.rs/tap.rs export counter points beside histograms. measure.rs: pool_max_in_use (today lifetime, measure.rs:418 from replica.rs:362) becomes the window’s maximum from count deltas, plus the mean and at-ceiling count at both samplers; WriterMeasure (commit, batch rows, queue wait: the window’s bucket counts and p50/p99 bounds); issuance_failures by cause.

    • saturation.rs: step_rates(peak) inserts the peak among 300 + 150i (an equal step marked; not counted toward MAX_STEPS); Step.peak; carries_peak read at that step (valid, held, no 429); bottleneck checks the queue wait (p99 above 50 ms) before the pool and the commit. cells.rs iterates step_rates. record.rs adds RunSettings (replicas, threads, db_rtt_ms, db_max_connections, token_rate_limit_rpm, writers 1 or 2, acquire_test always or stale_only), read from the replica’s effective settings. --db-max-connections defaults to IssuerPoolSize::DEFAULT.get().

    • Tests: the_peak_runs_as_a_step_of_its_own; carrying_the_peak_is_read_at_the_peak_step (held, a 429, invalid, absent); the_window_pool_figures_count_only_the_windows_samples; the_writer_buckets_are_kept_per_window; a_flush_reports_every_counter_cumulatively; the_harness_defaults_follow_the_product_defaults; the report proptest extended. Docs: tooling/xtask-catalog.adoc.

  4. U4 (w2) feat(security): measure the issuance writer’s queue wait (#2780). S5.

    • Pending.queued_at, stamped in enqueue_and_wait; run records each live row’s wait once when gather returns. Boundaries: queue wait [0.0005, 0.001, 0.002, 0.003, 0.005, 0.0075, 0.01, 0.0125, 0.015, 0.02, 0.025, 0.027, 0.03, 0.035, 0.05, 0.1, 0.5, 2.0] (W + 25 ms an edge for every Rule G W); commit [0.0005, 0.001, 0.0015, 0.002, 0.003, 0.004, 0.005, 0.0075, 0.01, 0.025, 0.05, 0.1, 0.5, 2.0]; batch rows [1, 2, 4, 8, 16, 24, 31, 32].

    • Test each_attempted_row_records_its_queue_wait_once (tests/identity_registry_test.rs, the in-memory exporter as latency_tests.rs:36-50 installs it): park_writer_on holding the pool’s only connection, 64 rows queued, 100 ms, release; 65 observations, at least 64 above 0.05 s, batches [1, 32, 32]. Docs: security-operations.adoc, deployment-guide.adoc metrics. Then the baseline run.

  5. U5 (w5) feat(security): give the issuance-log writer its own connection (#2781). S1–S3.

    • registry.rs: WriterPool(PgPool), constructed by WriterPool::lazy(PgConnectOptions) (pool_options().max_connections(1).acquire_timeout(5 s).connect_lazy_with(options.application_name("canopy-identity-writer")), the archive pool’s idiom, main.rs:269-271); writer_pool(&IssuerPool) passes the issuer’s options, fixtures their pool’s (pool.connect_options().as_ref().clone()), database-free tests their idle pool’s; as_pool() lends it to park the writer. The IssuerPoolSize doc says five holders, the floor leaving seven for requests.

    • issuance_log.rs: spawn(WriterPool, …); Writer holds conn: Option<PoolConnection> and used_at (IDLE_CHECK_AFTER 1 s); write splits into connection(deadline) (reuse; ping if idle ≥ 1 s; dispose and reacquire on failure), insert (no transaction) and settle (keep on success; dispose on any error or past the deadline); dispose is detach() then timeout(1 s, conn.close()), else drop, and shutdown disposes the same way; insert_and_commit deleted; the first batch acquires.

    • Every spawn caller takes a WriterPool: main.rs; the harness replica.rs, closing it after writer.finished() (PgPool::close waits for checked-out connections); issuance_log/tests.rs:1033, 1047; the rigs in identity_token_test.rs, identity_federation_test.rs, identity_native_test.rs, identity_delegation_test.rs, identity_admin/end_to_end.rs; identity_registry_test.rs, parking through as_pool().

    • Adapt a_stalled_connection_trips_the_batch_deadline_and_the_next_batch_reconnects: after the writer’s first batch it captures the writer’s backend from pg_stat_activity by the fixture’s unique login and canopy-identity-writer (the name alone is shared by concurrent tests), stalls it, and checks size == 1 && num_idle == 0 in place of await_idle(&pool, 1). Unchanged and passing: concurrent_rows_commit_in_batches_of_at_most_32, a_failed_commit_fails_every_waiter (the deferred trigger fires at the implicit commit; only its comment changes), the queue tests, U4’s test, every audit-before-release test.

    • New: the_writer_keeps_one_connection_across_batches; the_writer_commits_while_every_issuer_connection_is_held; a_writer_connection_killed_while_idle_is_replaced_before_its_next_batch; a_writer_connection_killed_mid_traffic_fails_one_batch_closed_and_the_next_reconnects; a_refused_batch_frees_the_slot_even_when_closing_its_connection_stalls (a deferred-trigger refusal, the connection then stalled with a StallingRelay: the next batch commits within its deadline on a new backend, the pool reads one connection, the stalled one gone within 1 s); the_writer_pool_is_the_issuer_login_under_its_own_name; registry.rs' the_writer_pool_holds_one_tested_connection.

    • Docs: security-operations.adoc; configuration-reference.adoc:434; deployment-guide.adoc (41 a replica, 43 with the verifier; the gauge note). Then the attribution run.

  6. U6 (w3) feat(security): gather from the oldest row, by setting (#2782). S4. GatherWindow (0–20 ms; DEFAULT 10 until U7) replaces GATHER_WINDOW; spawn(pool, window); gather sleeps until batch[0].queued_at + window. config.rs: identity_issuance_gather_ms, GatherWindowError, issuance_gather_window(); main.rs passes it. The harness --issuance-gather-ms (default GatherWindow::DEFAULT.millis()), forwarded and recorded. Tests (issuance_log/tests.rs, paused clock, Writer::gather, no database): a_row_that_waited_through_the_last_batch_is_written_at_once, a_fresh_row_waits_its_window_for_company, a_zero_window_takes_only_what_is_queued; config.rs' the_gather_window_is_held_to_its_bounds. Docs: configuration-reference.adoc (new row), security-operations.adoc, xtask-catalog.adoc. Then Rule G and Rule P.

  7. U7 (w3) feat(security): set the measured writer and pool defaults (#2783). S8. GatherWindow::DEFAULT per Rule G and IssuerPoolSize::DEFAULT per Rule P, their pinning tests, the IssuerPoolSize doc’s numbers, both configuration-reference.adoc rows. The final runs. Amendment 12’s as-built (the gate table, both relays' round trips, the attribution chain: baseline, after U5, each window, final), with one dated line in Amendment 10’s pointing to it. deployment-guide.adoc: sizing table, connection budget, replicas paragraph, connection-ms a request and the round trip measured at. Closes the plan per Outcomes.

Triggered units, each with its own issue, before U7:

  • F0. a_failed_commit_fails_every_waiter failing under autocommit: U5 keeps BEGIN/INSERT/COMMIT on the held connection.

  • F1 (a second writer). Judged on every valid Rule P run, passing or not, at the saturation peak step, or the first step that gave out if saturation stopped below the peak: an issuance failure, 1 % or more of batches in the (31, 32] bucket, or a queue-wait p99 above the window + 25 ms. The writer pool goes to 2, two writer tasks sharing the queue, gathering serialized under a tokio::sync::Mutex; no third.

  • F2 (a staleness-only acquire test). Rule G with no qualifying window, or Rule P with no v up to 64. canopy-db’s DbPoolOpts gains it (the db-pools gate requires canopy-db, db_pools.rs:44-45): no ping unless idle 1 s. Only the issuer pool takes it (about −2 round trips a delegation, −25 % pool demand); admin_pool_opts() derives from the issuer’s (registry.rs:623), so it sets test_before_acquire back on, pinned by the_admin_pool_keeps_its_acquire_test.

  • Each lands at most once; when either lands, Rule G then Rule P re-run in full, since both move what Rule G compares. RunSettings records which are active.

Outcomes

  • The MR closes U1–U7 and any triggered unit’s issue.

  • Done needs the final run to pass every gate (each G1 row, G2–G7, carries_peak) after at most the one re-run: the MR closes #2759 and #2760; Status Done (YYYY-MM-DD) — !N; the page to plans/archive/, nav to Archive; cargo xtask plan-lint --done <page> with --allow-open for each cited issue still open (#1303 always, and each later-stage issue named).

  • Otherwise each gate still failing is filed under &133 (P9); for #2759 (G1, G2, G4) and #2760 (G6, carries_peak) the MR says Relates to, and the issue stays open with the record. Status Blocked (#N, …) naming every blocker; the page and its nav entry stay; plain cargo xtask plan-lint runs (Blocked is not a completion).

Risks

  • The relay fix can read as moving the goalposts. The record states the measured round trip and G7 makes it a validity condition; the baseline and U2’s old-relay run separate the relay’s share from the levers'; the 3 ms run shows the levers' own margin.

  • A held connection can go stale: S3 and the fault-injection tests; one dying mid-traffic fails one batch closed, as today.

  • A small window costs commits: W = 0 adds about 0.4 WAL-flushing commits a request; Rule G discards a window failing G4.

  • G6 is noisy near its edge: the fixed seed and Rule P’s coarse steps (about 30 %) give margin.

  • The timer thread depends on host load: S6 invalidates a cell rather than hiding a slow relay.

Maintainer calls

  1. The R − 1 reading: one replica carries the peak step (held, no 429), per #2760; zero pool-at-ceiling samples there is recorded, not gated.

  2. S9’s reading of K1: additive-only binds the cut-over’s senders and receivers, not the issuer.

  3. S6’s relay condition is new to G7.

  4. F2 drops test_before_acquire for requests, on its trigger only.

  5. The 3 ms design run is informational.

Errata

  • Erratum (2026-10-08): U2’s holds are one count per direction, shared by every relayed connection through one watch channel, not per-task buckets, which would lose a closed connection’s counts; the quantile is an integer per-mille rank; a saturation cell stops at, and reports, a step whose relay is off.

  • Erratum (2026-10-08): U2 step (2), at I3a’s code: the old relay measured a 3.05 ms p50 and 4.45 ms p95 round trip for its stated 1 ms, with delegation p99 55.1 and 55.4 ms (I2g’s own figures); the new relay 1.15 ms, with 28.4 and 28.6 ms (one repetition each).

  • Erratum (2026-10-08): U3’s acquire_test reads always or off, from sqlx’s test_before_acquire; stale_only would have come with F2, which did not land. RunSettings also records U6’s issuance_gather_ms.

  • Erratum (2026-10-08): U5’s stalled-close test is a_refused_batch_disposes_of_its_connection_and_the_next_reconnects, the pool read at size 0 once the caller is answered: StallingRelay holds only answers, so a close (a client write) cannot stall, and a reconnect during a stall stalls too. Under autocommit the stalled test’s row exists (the statement commits while only its answer is held, the documented case). Added: a stalled-idle-ping test, the two kill tests, and FINISH_WITHIN 4 s for the shutdown close.

  • Erratum (2026-10-08): U6’s window runs from the batch’s minimum queued_at, not batch[0]'s (a caller stamps its row before waiting for room), and gather's select is biased to the window; a test pins the out-of-order case.

  • Erratum (2026-10-08): U7 commits as two, the defaults and then the as-built, so the final run’s record names a commit that stays.

  • Erratum (2026-10-08): the final run failed carries_peak, so the plan closed Blocked (#2760) per its Outcomes. #2760 is closed by ADR-049 Amendment 13’s three-replica minimum, the issue’s own alternative ("or the guide’s replica count rises to one that does"; plan I3b2), so the plan is Done; one replica’s margin stays informational.

  • Erratum (2026-10-08): the host was shared with another project’s devstack and test battery. The first baseline was contaminated and re-run from a worktree at U4, whose design cell, INVALID once on its relay, was re-run; attribution ran from a worktree at U5. At Rule P’s 28 the first saturation stopped on a disk stall G7 cannot see (commit p99 100 ms against 7.5 ms) and was re-run under the maintainer’s instruction to re-run disturbed numbers, F1 not judged on it; the re-run’s INVALID peak cell was re-run. Amendment 12’s as-built lists every run.

Review log

Round Vendor Resolved model Verdict

1

Anthropic

Claude Opus 5.5 (fresh subagent)

no-ship; nine blockers, all fixed in-plan: two subjects over the hook’s 72 characters; the one-MR reason, title and merge rule; U2 split into the relay and the record; the relay’s round trip defined and judged at saturation steps; every boundary array listed, the (31, 32] batch bucket, the batch’s start; every rule’s and the final run’s outcomes; the queue-wait test’s file, park and assertion, and the window tests driving gather; the lifetime-maximum citation; the Status line, anchor, pinning tests, config rows and the flag’s default. Notes folded in: the CANOPY_TEST_INFRA pattern, Scope, maintainer calls, Changed entries, labels, a deterministic relay test, the old-relay run at full load, the bottleneck order, the peak step’s counting, a lazy WriterPool newtype, missed spawn callers, F2 through canopy-db, no shared mutable state in the relay.

2

not stated (the maintainer’s other vendor)

not stated

12 findings (3 P1, 8 P2, 1 P3), all fixed in-plan: F1 judged on every valid Rule P run; the writer never returns a connection (detach, a 1 s close) with a stalled-close fault test; Done needs every final gate; Rule G’s empty fallback blocks; the three-replica minimum needs the peak cell’s gates; per-direction median and p95 bounds; --db-rtt-ms 0–10, buckets to 7 ms; WriterPool::lazy for fixtures and the stalled test’s backend by login; F2 keeps the admin pool’s acquire test; F1/F2 rerun Rule G then Rule P; plan-lint --done with --allow-open, plain plan-lint when Blocked; the old relay’s round trip labelled a reconstruction.

Edit this page · default