Plan: Close the ambient-clock class — widen check 6 and inject the decision clock in six services (#2634)
- Context
- Scope
- Design
- Units (weights by complexity) — U1 → U2 → (U3 ‖ U4 ‖ U5 ‖ U6 ‖ U7) → U8
- U1 (w3) — canopy-wic reads its one injected clock
- U2 (w3) — check 6 sees every spelling
- U3 (w3) — canopy-renewals threads the handle it already has
- U4 (w5) — canopy-appeals
- U5 (w3) — canopy-persons
- U6 (w5) — canopy-eligibility
- U7 (w5) — canopy-applications: the request path
- U8 (w5) — canopy-applications: workers and sagas, then the gate
- Verification
- Documentation Updates
- Review log
Status: Done (2026-10-25) — !1785
Epic: &138
Issues: #2634 (parent) · #2999 U1 (w3) · #3000 U2 (w3) · #3001 U3 (w3) · #3002 U4 (w5) · #3003 U5 (w3) · #3004 U6 (w5) · #3005 U7 (w5) · #3006 U8 (w5)
Branches: fix/wic-decision-clock, fix/ambient-clock-lint-forms, fix/renewals-decision-clock, fix/appeals-decision-clock, fix/persons-decision-clock, fix/eligibility-decision-clock, fix/applications-decision-clock-handlers, fix/applications-decision-clock-workers
Erratum (2026-10-25): U3 adds scheduler::DailyCheckDeps (db, publisher, clock) and api::deps::PolicyClock (params, clock), because renewals' daily-pass chain and four of its handlers were at clippy’s seven-argument limit; and run_daily_pass takes the legal day its caller read, so the fenced probe keys its window and runs its pass on one read (D3).
Erratum (2026-10-25): U4 adds canopy-appeals' api::deps::PolicyClock (params, clock), because record_final_appeal_decision and finalize_withdrawal were at clippy’s seven-argument limit.
Erratum (2026-10-25): U5 adds canopy-persons' api::deps::TzClock (tz, clock), because create_person, update_person, create_household and get_household_full were at clippy’s seven-argument limit.
Erratum (2026-10-25): U6 bundles the bulk arm’s per-case arguments into bulk::arm::CaseCtx (bulk, run, case, request, the dispatch’s instant), because handle_signed_response and classify_error_response were at clippy’s seven-argument limit; BulkConsumerDeps and BulkWorkerDeps carry no clock, since neither stamps a decision instant (the worker’s deadline and backoff gates are allowlisted); and create_combined_result and the determination-of-record insert now bind assembled_at/created_at and received_at/created_at, which had fallen to their column defaults.
Erratum (2026-10-25): U7 adds canopy-applications' api::deps::TzClock (tz, clock) and the ExpeditedScreen input struct, because create_rep, update_rep and run_expedited_screening would exceed clippy’s seven-argument limit; applications.submitted_at stays a column default, tracked with administrative_denials.denied_at in #3007.
Erratum (2026-10-25): U8 adds clock to canopy-applications' ReopenDeps, because the reopen route read no clock and head_of_household now takes its caller’s legal day; and it allowlists a reopen episode’s reopened_at instead of binding it, because the void step compares that horizon with program rows' database-clock created_at (#2703).
This is a Design + Scope plan: GitLab owns tracking, the child issues carry the implementer brief, and the plan freezes when U1 starts.
Context
ADR-033 §5 (amendment #1684) gives a service ONE canopy_common::clock::DecisionClock, constructed at boot with DecisionClock::shared() and threaded, as a router extension or a deps field, to every writer. A request or pass reads it once (clock.now()), and every guard, legal day (clock.legal_today(tz) or clock::date_in(instant, tz)) and stamp comes from that instant. A steered test clock then moves them together, and a unit test pins them with DecisionClock::fixed. canopy-snap is the reference: services/canopy-snap/src/main.rs:267 constructs the handle, main.rs:347 layers it, determine.rs:698 carries it in SnapDetermineDeps, determine.rs:783 reads it once, and the store functions take the instant as a parameter (store/mod.rs:27, store/verification.rs:492).
Check 6 of cargo xtask test-lanes-lint (xtask/src/cmd/test_lanes_lint/ambient_clock.rs, #2588) refuses, in the production code of five program services, canopy-overpayments and canopy-db’s redaction store, the path Utc::now, DecisionClock::fixed outside tests, and a SQL clock inside a string literal. Operational instants are entries in compliance/prod-ambient-clock-allowlist.toml (file, context, reason, count). The B8 budget (run_b8 in xtask/src/cmd/quality_budgets.rs; xtask/quality-budgets.lock) counts clock::now( and clock::today( CALL sites — the trailing paren excludes the unwrap_or_else(clock::now) function-pointer form — plus DecisionClock::shared( constructions, workspace-wide, outside test scope.
Two gaps keep the class open. First, match_clock passes Local::now, SystemTime::now and the module-level accessors canopy_common::clock::{now,today,legal_today}; its own test (injected_reads_bound_instants_and_comments_are_not_findings) pins canopy_common::clock::now() as not a finding. B8 never counted legal_today( or the function-pointer form at all. Second, six services read the clock ambiently through exactly those forms, mostly behind a local funnel: canopy-wic’s Tick::read (src/tick.rs, 12 callers), canopy-applications' decision_now() (src/api/interviews.rs, 21 callers), its create_reopen_attestation (services/canopy-applications/src/api/reopen.rs), head_of_household and its scheduler legs and sagas; canopy-appeals' crate::clock::legal_today (services/canopy-appeals/src/clock.rs, 14 callers) and three Utc::now() IPV stamps; canopy-renewals' periodic_reports::legal_today (18 callers) and refresh_rollup_now, beside a handle it already wires at boot but does not thread to its workers; canopy-persons' resolve_as_of (services/canopy-persons/src/api/mod.rs, 30 callers) and two CompensationTime::at(Utc::now(), tz) sites; and canopy-eligibility’s determine_inner (two reads), update_request_status, quarantine::record_row and rewrite_combined_result (SQL assembled_at = now()). Only wic is in the lint’s scope today, and its one read is the accessor form the lint does not see.
Scope
In scope:
-
Check 6 refuses
Local::now,SystemTime::nowandclock::{now,today,legal_today}(call or function pointer), and its scanned-service list grows by each service as that service is fixed. -
Each of the six services wires or threads one
DecisionClockand reads it once per request, delivery or pass; every decision-bearing stamp binds that instant, including the SQL stampsinterim_contact_completed_at,terminated_at,expedited_screened_at,assembled_at. -
Operational instants in the six services become allowlist entries with reasons.
-
The lint’s limits, the allowlist header and
coding-conventions.adoc§ Decision clocks say what the check now sees and still cannot.
Out of scope:
-
Column defaults (
DEFAULT now()): #2589. Snap’s double read: #2591. -
Aliased imports (
use chrono::Utc as U), bare-importednow/legal_today, wrapper functions in other crates and SQL assembled at run time: the token scan has no import resolution. They are documented as unseen, not matched heuristically. -
A second
DecisionClock::shared()outside a service’s boot (canopy-medicaid/src/scheduler.rs:812,canopy-renewals/src/subscriber.rs:869): a one-construction rule is a separate lint decision, filed as an issue if U3 confirms the renewals one is production code. -
New
as_ofwire parameters on casework endpoints: #1098 forbids backdating from the wire; the clock is the tier-3 read these endpoints are entitled to.
Design
D1 — module-level accessors are findings in a scanned service. This closes the question the issue leaves open. Inside a scanned service the injected handle is the only sanctioned read; every residue site in this plan reached the clock through clock::now, clock::legal_today or a funnel over one of them. B8 keeps counting the accessors workspace-wide as a ratchet; check 6 refuses them, with the allowlist, in the services it scans. match_clock gains one arm per form, all ClockKind::Wall except the accessors, which get a new ClockKind::Accessor so the report names the fix ("read the injected handle"):
match (ident(0)?, path_sep(1), ident(3)) {
("Utc" | "Local" | "SystemTime", true, Some("now")) => Some(Hit::at_head(ClockKind::Wall, 4)),
("clock", true, Some("now" | "today" | "legal_today")) => Some(Hit::at_head(ClockKind::Accessor, 4)),
("DecisionClock", true, Some("fixed")) => Some(Hit::at_head(ClockKind::Pinned, 4)),
_ => None,
}
The path form matches a call and a function pointer alike (unwrap_or_else(canopy_common::clock::now)), as Utc::now does today. clock.now() on a handle is Ident . Ident, never ::, so it is not matched; clock::date_in and clock::DecisionClock are not matched.
D2 — PROGRAM_SERVICES becomes SCANNED_SERVICES. Five of the six are not program services. The constant, the module doc, the allowlist header and coding-conventions.adoc:179 say "scanned services" and list them. A service joins the list in the unit that fixes it, never before.
D3 — one read per request, delivery or pass. A handler or worker reads let now = clock.now(); once and derives its legal day with canopy_common::clock::date_in(now, tz) (or clock.legal_today(tz) where it needs only the day). Two reads in one request (canopy-applications' finalize_via_saga reads Utc::now() at finalize_saga.rs:1058 and legal_today at :1061) collapse to one.
D4 — funnels take the handle or go. A local function that hides an ambient read is the bypass pattern. decision_now(), appeals' clock::legal_today(tz) and renewals' periodic_reports::legal_today(tz) are deleted; their callers read the handle they now receive. wic’s Tick stays, because it is already the one-read struct, and its constructors take the handle: Tick::read(clock: DecisionClock, as_of: Option<DateTime<Utc>>, tz) → Self and Tick::now(clock: DecisionClock, tz) → Self. persons' resolve_as_of(as_of: Option<&str>, tz: LegalTimezone) becomes resolve_as_of(as_of, tz, clock: DecisionClock).
D5 — how the handle reaches a writer. Mirror snap. Boot: let clock = DecisionClock::shared(); once in main.rs, .layer(axum::Extension(clock)), and clock as a field of every background-deps struct built there. Handlers: Extension(clock): Extension<DecisionClock>, or a clock: DecisionClock field on the service’s existing FromRequestParts bundle (WicDetermineDeps, AppealWriteDeps, applications' services/canopy-applications/src/api/deps.rs bundles, eligibility’s DetermineDeps → DetermineConfig), filled with required_extension(parts, "DecisionClock extension") as canopy-snap/src/api/determine_handler/deps.rs:56 does. Store functions take the instant as a DateTime<Utc> (or NaiveDate) parameter and bind it; they never take the handle.
D6 — decision-bearing against operational. The allowlist header’s rule stands: an instant is operational when no decision reads it (a lease, retry gate, heartbeat, metric window, updated_at, a hash chain’s order key, the real time FTI was read). Three calls this plan makes explicit, each reviewable in its unit’s MR:
-
canopy-persons'
recorded_aton every*_versionsrow andincome_proposalsis transaction time: the readers (list_by_persons_as_of,list_by_household_as_of, …) filter on valid time only and readrecorded_atfor DTO metadata and a sort tie-break. Operational, allowlisted with that reason. If the maintainer rules it decision-bearing, U5 binds it from the request’s instant instead; the unit’s size does not change. -
ADR-038 lease machinery (
canopy-applications/src/store/finalize_ops.rsclock_timestamp(), canopy-eligibility’sstore/operations.rs,orders/store.rs,bulk/store.rs, appeals'assessments.rsqueue) is operational by design. -
canopy-eligibility’s
bulk/arm.rsassembled_aton a synthesized response (lines 1067, 1103, 1143) is a stamp a consumer stores: bound from the arm’s clock, not allowlisted.
D7 — the B8 lock moves by the measured count, with the note. B8 counts clock::now(/clock::today( calls and DecisionClock::shared( constructions, outside test scope; it does not count legal_today( or a function pointer. So a service that gains its one DecisionClock::shared() and retires no counted call raises B8 by one: a ruler correction, noted as # B8: n → n+1 (#NNNN). A RULER correction, not new debt: … after the #1684/#2581 precedent. Measured on main today, the production call sites are renewals' refresh_rollup_now and applications' decision_now(); every other residue read is legal_today or a function pointer. Expected per unit: U1 +1, U3 −1, U4 +1, U5 +1, U6 +1, U7 0 (+1 for the handle, −1 for decision_now), U8 0; net +4 across the plan. --write-lock, never by hand.
D8 — tests. Each service unit ships the #1684 property at least once: an infra test pins Extension(DecisionClock::fixed(t)) (or a deps struct with the fixed handle) and asserts that the guard and the stamp both follow t, mirroring canopy-snap/src/api/decision_clock_infra_tests.rs:88. Each store function that gains an instant parameter asserts the bound value to the microsecond. U2’s fixture tests cover every new form, and the flipped expectation on canopy_common::clock::now().
Units (weights by complexity) — U1 → U2 → (U3 ‖ U4 ‖ U5 ‖ U6 ‖ U7) → U8
Weights: 1 trivial · 2 small · 3 medium · 5 large · 8 very large. One unit = one independently shippable MR = one child issue. U2 follows U1 because wic’s tick.rs:35 is the only accessor read in the trees the lint already scans; once U1 removes it, U2 widens the forms with no new allowlist entry. U3–U7 each touch SCANNED_SERVICES and the allowlist; the conflicts are one-line.
U1 (w3) — canopy-wic reads its one injected clock
Files: services/canopy-wic/src/{main.rs,tick.rs,lifecycle_sweep.rs}, src/api/{handlers.rs,terminations.rs,appointment_handlers.rs}.
-
main.rs: constructclock, layer it, put it inLifecycleSweepDeps(new fieldpub clock: DecisionClock) and capture it in thenotice.dispatchedsubscriber closure (main.rs:85). -
Tick::readandTick::nowtake the handle (D4);run_lifecycle_sweepreadsTick::read(deps.clock, deps.as_of, deps.legal_tz). -
WicDetermineDepsgainsclock; the eight direct handlers (post_redact_determination,create_assessment,schedule_terminations,cancel_termination,schedule_appointment,list_upcoming_appointments, and the two inhandlers.rsthat callTick::now) takeExtension(clock). -
Tests:
post_determinewith a fixed clock stamps the determination’sas_ofandcreated_aton the pinned instant’s legal day;schedule_terminationswith a fixed clock judges the advance-notice window on it. -
B8 +1 (ruler correction: wic’s read was a function pointer B8 never saw); CHANGELOG under
=== Fixed.
U2 (w3) — check 6 sees every spelling
Files: xtask/src/cmd/test_lanes_lint/ambient_clock.rs, compliance/prod-ambient-clock-allowlist.toml (header), docs/modules/ROOT/pages/coding-conventions.adoc (§ Decision clocks), xtask/src/cmd/test_lanes_lint.rs (module doc).
-
D1 and D2. The
Unseenparagraph of the module doc lists: aliased imports, bare-importednow/today/legal_today, wrapper functions outside the scanned trees,std::time::Instant(monotonic, not a clock), runtime-built SQL, column defaults (#2589). -
Tests: one fixture per new form (
Local::now(),std::time::SystemTime::now(),canopy_common::clock::now(),clock::today(),clock::legal_today(tz), andunwrap_or_else(canopy_common::clock::now)), each at its line;clock.now(),clock::date_in(..)andDecisionClock::shared()stay non-findings. The existing "not a finding" test loses itsclock::now()line. -
Run the lint on the tree: zero new findings after U1, or the unit stops and reports them.
U3 (w3) — canopy-renewals threads the handle it already has
Files: services/canopy-renewals/src/{main.rs,scheduler.rs,periodic_reports.rs,determination_subscriber.rs,store.rs,pr_pipeline.rs}, services/canopy-renewals/src/continuation/mod.rs, services/canopy-renewals/src/api/mod.rs, allowlist, ambient_clock.rs (list).
-
spawn_scheduler_taskandspawn_caseload_rollup_tasktakeclock;refresh_rollup_now(db, clock, tz)readsclock.now().DeterminationArmDepsandContinuationDepsgainclock.periodic_reports::legal_todayis deleted (D4); its 18 callers readclock.legal_today(tz); the handlers that still lack it takeExtension(clock)aslist_certifications(api/mod.rs:965) does. -
record_interim_contactandupdate_certification_statustake the instant and bind it instead of SQLnow(). -
Allowlist:
updated_at = now()(one entry per file withcount),action_at,converted_at, the snapshot purge cutoff. -
Tests:
run_daily_checkwith a fixed handle stages the NOE on the pinned legal day;record_interim_contactbinds the given instant. -
B8 −1.
U4 (w5) — canopy-appeals
Files: services/canopy-appeals/src/{main.rs,clock.rs,assessment_worker.rs,store.rs,assessments.rs}, services/canopy-appeals/src/api/mod.rs, src/ipv/{api.rs,store.rs}, allowlist, ambient_clock.rs.
-
Boot wiring;
AppealWriteDepsandWorkerDepsgainclock;run_daily_check(db, publisher, params, clock, as_of).clock::legal_todayis deleted (D4); the 14 callers readclock.legal_today(params.timezone). Thefunnel_testsmodule goes with the funnel; the tz-composition it pinned moves to a test on one handler with a fixed evening instant. -
IPV:
create_referral,send_adh_notice,record_adh_decisionreadclock.now()once each and pass it to the store;send_adh_noticederives its advance-noticetodayfrom the same instant (D3). -
Allowlist:
updated_at = now()instore.rsandipv/store.rs,cb_stay_receipt_at,voided_at, the queue lease columns inassessments.rs,backoff_due_at, the ack-sweep and parked-election cutoffs. -
Tests:
confirm_withdrawalthenreinstate_appealunder fixed clocks eleven days apart is refused;send_adh_noticeunder a fixed clock stampsadh_notice_sent_atto the instant and judges the 30-day window on its legal day. -
B8 +1 (ruler correction).
U5 (w3) — canopy-persons
Files: services/canopy-persons/src/main.rs, src/api/{mod.rs,export.rs}, src/discrepancy_resolution_subscriber.rs, allowlist, ambient_clock.rs.
-
Boot wiring;
resolve_as_oftakes the handle (D4) and its 30 callers passExtension(clock)or the clock the subscriber’s deps carry (discrepancy_resolution_subscriber.rs:200).cancel_operationandsweep_abandoned_orphansbuildCompensationTime::at(clock.now(), tz). -
Allowlist per D6:
recorded_at(one entry per*_versions.rsandincome_proposals.rs),created_at/updated_atinstore/persons.rsandstore/households.rs,soft_delete, the two DEK-shredredacted_at(crypto-shredding time, ADR-014 class),superseded_at, the export window default. -
Tests: a valid-time read without
as_ofunder a fixed 23:30 Eastern instant answers for that legal day, not the UTC day;cancel_operationunder a fixed clock compensates on that legal day. -
B8 +1 (ruler correction).
U6 (w5) — canopy-eligibility
Files: services/canopy-eligibility/src/{main.rs,orchestrator.rs,quarantine.rs}, services/canopy-eligibility/src/api/handlers.rs, src/store/{mod.rs,quarantine.rs}, src/bulk/{arm.rs,consumer.rs,worker.rs}, allowlist, ambient_clock.rs.
-
Boot wiring;
DetermineConfiggainspub clock: DecisionClock, filled fromDetermineDeps.determine_innerreads once:let now = cfg.clock.now(); let as_of = clock::date_in(now, cfg.legal_timezone);and stampsassembled_at/created_atfromnow(D3).update_request_status(executor, id, status, at),record_row(routing, received, benefit_effective_date, received_at)andrewrite_combined_result(conn, result, assembled_at)take the instant.BulkConsumerDepsandBulkWorkerDepscarryclock; the arm’s threeassembled_atbind it (D6). -
Allowlist:
STALE_REQUEST_TTLcutoffs,requested_at, the claim, lease, settle and breaker columns instore/operations.rs,orders/store.rsandbulk/store.rs(one entry per distinct context withcount), the worker deadlines and backoff gates. -
Tests:
determineunder a fixed evening instant evaluates members' ages on that legal day and stampsassembled_atto the instant;rewrite_combined_resultbinds the given instant. -
B8 +1 (ruler correction).
U7 (w5) — canopy-applications: the request path
Files: services/canopy-applications/src/{app.rs,main.rs,finalize_saga.rs,postponement_saga.rs}, src/api/{deps.rs,interviews.rs,mod.rs,reopen.rs,authorized_reps.rs,rep_disqualifications.rs,postponement*.rs,administrative_denials.rs}, services/canopy-applications/src/store/mod.rs.
-
AppDepsgainsclockandbuild_routerlayers it.decision_now()is deleted (D4); each bundle inservices/canopy-applications/src/api/deps.rs(ReopenDeps,PostponementDeps,DenialDeps,RepDisqualificationDeps,InterviewDeps,FilingDeps) andVerificationEvidenceDepsgainsclock; the 21 callers read it.create_reopen_attestation(services/canopy-applications/src/api/reopen.rs), which takes bare extensions rather thanReopenDeps, addsExtension(clock)and judgesattested_cured_onagainstclock.legal_today(tz.0).postponement_conversion::legal_todaytakes the instant. -
The postponement saga calls both funnels, so it moves with them:
PostponementSagaDepsgainsclock(built inmain.rs);compensateandstep_dispatch_conversionread it, and the purerecord_back(result, determination_id, at)takes the instant from its caller. -
FinalizeDepsgainsclock;finalize_via_sagareads once forreceived_at,submitted_at, the legal filing basis andconsent_given_at(D3).update_expedited_resulttakes and bindsscreened_at. -
Tests:
schedule_intake_interviewunder a fixed clock refuses a past slot judged against the pinned instant;finalizeunder a fixed 23:30 Eastern instant files on that legal day and stampssubmitted_atto the instant. -
B8 net 0. The lint list is not widened here; U8 does it when the service is clean.
U8 (w5) — canopy-applications: workers and sagas, then the gate
Files: services/canopy-applications/src/{scheduler.rs,reopen_saga.rs,household_head.rs,main.rs}, allowlist, ambient_clock.rs.
-
NomiLegDepsandDay30LegDepsgainclock, and their two production legs (plan_interview_nomi,Tick::start) readas_of.unwrap_or_else(|| deps.clock.now());RepDisqLegDepsandReopenSagaDepsgainclock;run_rep_disq_effect,run_rep_disq_expiryandstep_void_later_episodesread the handle;process_rep_effect_rowstampssuspended_atfrom the leg’s one read;head_of_household(persons, household_id, today: NaiveDate)takes the day its caller already has. Test modules inscheduler.rsandhousehold_head.rsthat read the accessors are test scope, outside both the lint and B8, and are left alone. -
Allowlist:
finalize_ops.rsclock_timestamp()leases (ADR-038),drafts.rsexpiry,recovery.rsreveal and lifecycle stamps,determination_received_at, the caseload-trenddate_truncwindows,updated_at/settled_atbookkeeping, the keyset cursor fallback. -
SCANNED_SERVICESgainscanopy-applications; the lint runs clean. -
Tests: the day-30 leg under a fixed clock auto-dispositions an application whose deadline is the pinned day and not one a day later;
run_rep_disq_effectunder a fixed clock enacts on the pinned legal day. -
B8 0 (the legs were function pointers B8 never counted).
Verification
-
cargo xtask test— the unit and integration lanes pass (see Testing); the D8 tests are in them. -
cargo xtask test-lanes-lint --staticis clean after each unit, with the service added to the scan in the same MR; in U2, a fixture per new form fails before the matcher arm and passes after. -
cargo xtask quality-budgetsshows B8 at the value D7 predicts, and the lock note explains each raise. -
cargo xtask dev reload, thencargo xtask e2e— no schema changes, so no restart; the test-clock journeys still steer the new reads becauseDecisionClock::shared().now()isclock::now(). -
cargo xtask validate— the pre-push battery is green. -
Close: each unit’s merge posts its merge SHA on its child issue; U8’s MR sets this plan’s Status to
Done (YYYY-MM-DD) — !N, moves it underplans/archive/, and passescargo xtask plan-lint --done;Closes #2634rides on U8.
Documentation Updates
-
coding-conventions.adoc§ Decision clocks — the forms and the scanned-service list (U2, then each service unit adds its name); the allowlist header and the lint module doc say the same -
CHANGELOG.adoc— one=== Fixedentry per unit under== Unreleased; U2’s names the new forms and what stays unseen -
No
api/canopy-.adocordata-models/canopy-.adocchange: no endpoint, event or column changes; stamps already existed and are now bound
Review log
| round | vendor | resolved model | verdict |
|---|---|---|---|
1 |
Anthropic |
Claude Fable 5.1, gadhs/pi’s plan review at exit_plan_mode |
FLAGS (2026-10-25), fixed: the header named no epic or child issues and no close step (both added); D7’s B8 arithmetic assumed B8 counts the |
2 |
Gemini 4 Argon, pi’s integrated second-vendor review |
FLAGS (2026-10-25), fixed: the same B8 arithmetic; |