Appearance
ADR-2818: Clinical and Gateway Endpoints Take Time From IClock and Ban TimeProvider
- Status: Accepted
- Date: 2026-11-20
- Authors: @fderuiter
- Deciders: @fderuiter
- Requirements: PRD-SYS-001 (audit entries carry a trustworthy timestamp), kernel spec K-TIME-3
1. Context & Problem Statement
Kernel rule K-TIME-3 and ADR-2512 require clinical, security, and compliance code to read timestamps from Cadence.Kernel.Time.IClock rather than directly from the wall clock. However, BannedSymbols.txt only banned System.DateTime.Now/UtcNow and System.DateTimeOffset.Now/UtcNow, leaving System.TimeProvider.System and System.TimeProvider.GetUtcNow unguarded by Roslyn analyzer rule RS0030.
As a result, clinical and gateway code paths read wall-clock timestamps via TimeProvider while audit and replay components in the same request pipeline read IClock:
apps/econsent(EconsentEndpoints),apps/knowledge(TrainingEndpoints),apps/intelligence(BiometricEndpoints), andapps/gateway(SignatureTokenEndpointsandGatewayIdentityForwarding) tookTimeProviderinstead ofIClock.apps/knowledge/src/Program.csandapps/gateway/src/Program.csregisteredTimeProvider.System, whileapps/econsent/src/Program.csrelied on implicitIClockregistration.BiometricLivenessTokenServicedefaulted optionalDateTimeOffset? nowparameters toTimeProvider.System.GetUtcNow().- Unit tests (
TrainingEndpointsTests,EconsentEndpointsTests,BiometricLivenessTests) maintained ad-hocTestTimeProvidersubclasses or passedTimeProvider.SystemalongsideCadence.Testing.Time.FakeClock.
2. Decision Drivers & Constraints
- Single Clock Source (PRD-SYS-001, K-TIME-3): Endpoint handlers, identity-forwarding transforms, token helpers, and audit interceptors must derive timestamps from the same
IClock. - Compile-Time Enforcement:
BannedSymbols.txtmust banP:System.TimeProvider.SystemandM:System.TimeProvider.GetUtcNowsoRS0030(TreatWarningsAsErrors=true) catches regressions across all projects. - Framework Interop Boundaries: ASP.NET Core
AuthenticationHandler<TOptions>.TimeProvider(GatewayAuthenticationHandler.IsFresh) and theSystemClockimplementation itself require narrow, justified#pragma warning disable RS0030pragmas.
3. Options Considered
Option 1: Migrate Endpoints and Token Fallbacks to IClock and Ban TimeProvider Reads (Selected)
- Overview: Inject
IClockinEconsentEndpoints,TrainingEndpoints,BiometricEndpoints,SignatureTokenEndpoints, andGatewayIdentityForwarding; registerSystemClock.InstanceasIClockineconsent,knowledge, andgatewayProgram.cs; defaultBiometricLivenessTokenServicetoSystemClock.Instance.UtcNow; banP:System.TimeProvider.SystemandM:System.TimeProvider.GetUtcNowinBannedSymbols.txtwith narrowRS0030suppressions atSystemClock,GatewayAuthenticationHandler.IsFresh, andClockTests.SystemClockReturnsCurrentUtcInstant; and migrate unit tests toFakeClock. - Pros:
- ✅ Satisfies PRD-SYS-001 and K-TIME-3 with one clock abstraction across clinical endpoints, gateway signing, security tokens, and audit records.
- ✅ Closes the
TimeProviderloophole inBannedSymbols.txtand enforcesBannedClockSymbolsviaClockTests. - ✅ Eliminates bespoke
TestTimeProvidertest doubles in favor ofFakeClock.
- Cons:
- ❌ Requires explicit justified
RS0030pragmas at the three framework/adapter boundary sites that legitimately touchTimeProvider.
- ❌ Requires explicit justified
Option 2: Standardize on System.TimeProvider Instead of IClock
- Overview: Replace
IClockacross the kernel, security, compliance, and audit packages with BCLTimeProvider. - Pros:
- ✅ Aligns directly with ASP.NET Core authentication handler primitives.
- Cons:
- ❌ Reverses K-TIME-3 and ADR-2512 across the kernel, audit interceptor, replay cache, and GxP signing packages without adding domain capability.
4. Decision Outcome
- Chosen Option: Option 1
- Justification: Completing the migration onto
Cadence.Kernel.Time.IClockand banningTimeProvider.SystemandTimeProvider.GetUtcNowenforces K-TIME-3 and PRD-SYS-001 uniformly at compile time with minimal surface change.
5. Consequences & Trade-offs
- Positive Impact: All eConsent, Knowledge, Intelligence, and Gateway timestamps are deterministic under
FakeClock, andRS0030fails the build on any unguardedDateTime,DateTimeOffset, orTimeProviderwall-clock read. - Negative Impact / Technical Debt: Three boundary sites (
SystemClock,GatewayAuthenticationHandler, andClockTests) carry#pragma warning disable RS0030suppressions. - Mitigation Strategy:
WarningSuppressionPolicyTestsrequires every#pragma warning disableline to state an inline justification, andClockTests.BannedSymbolsBanWallClockAndKernelIsWiredverifiesBannedSymbols.txtentries against reflection metadata.
6. Implementation & Verification
- Affected Repositories / Services:
apps/econsent,apps/knowledge,apps/intelligence,apps/gateway,packages/kernel,packages/security,BannedSymbols.txt,docs/kernel/CLOCK_MIGRATION_BACKLOG.md,tests/Cadence.UnitTests. - Verification Plan: Verified via
dotnet build Cadence.sln(RS0030clean across all projects),ClockTests,EconsentEndpointsTests,TrainingEndpointsTests,BiometricLivenessTests,WarningSuppressionPolicyTests, andcadence check.