Appearance
Clock Migration Backlog (K-TIME-3, #4784)
| Status | No wall-clock reads remain in apps/ or packages/. Every app and every package that had one opts into the ban; core-models, telemetry, ddf, templating, storage, sentinels and contracts have none and are not opted in yet |
| Date | 2026-09-29 |
| Spec | docs/kernel/CLINICAL_KERNEL_SPECIFICATION.md §4.1 K-TIME-3, §10 |
| Issue | #4784 |
What is done
Cadence.Kernel.Time.IClock(DateTimeOffset UtcNow) andSystemClocklive inpackages/kernel/src/Cadence.Kernel.Abstractions/Time/.Cadence.Testing.Time.FakeClock(settable, advanceable, frozen by default) lives inpackages/testing/src/Time/.apps/executionuses the kernel clock. Its ownApplication/Abstractions/IClock.csandInfrastructure/SystemClock.csare deleted. The semantics are the same: both returnDateTimeOffsetin UTC.Microsoft.CodeAnalysis.BannedApiAnalyzersis pinned inDirectory.Packages.props. The repo-rootBannedSymbols.txtbansDateTime.Now,DateTime.UtcNow,DateTimeOffset.Now,DateTimeOffset.UtcNow,TimeProvider.SystemandTimeProvider.GetUtcNow.Microsoft.CodeAnalysis.BannedApiAnalyzersandBannedSymbols.txtare included unconditionally in rootDirectory.Build.props, enforcing K-TIME-3 globally across all C# projects in the repository. BecauseTreatWarningsAsErrorsis on, a violation fails the build with RS0030. Tests useFakeClock, orSystemClock.Instancewhere the code under test checks the real clock (TESTING.md, Time in tests).- In the app entities every timestamp is a
DateTimeOffset(execution'sObservationDateaside, see below). The ones a writer must supply (CreatedAt,UpdatedAt,Timestamp,ReceivedAt, interop'sDeviceTimestampandServerTimestamp, eConsent'sSignedAtandWithdrawalDate) arerequiredwith no default, so code that creates a row must pass a time it took fromIClock(or, forDeviceTimestamp, the device's own time). The columns were alreadytimestamp with time zone, so the change needs no migration (dotnet ef migrations has-pending-model-changesreports none). packages/database'sGxPAuditInterceptortakes a requiredIClockand no longer falls back to the wall clock, so every audit field and audit entry timestamp comes from the injected clock (#4784). Execution passes its registeredIClock. The value is still normalized to UTCDateTimebefore hashing, so the Merkle block hash format is unchanged and no migration is needed.
Last packages (done)
The last three packages with wall-clock reads were the audit, signing and replay-protection packages the security thread owns (#4784):
packages/database:GxPAuditInterceptortakes a requiredIClock.packages/compliance:GxPSigner.SignGxpMarkdown,Pkcs7Signer.GenerateSigningCredentialsandRtmGeneratorService.GenerateRtmtake an optionalIClock(defaultSystemClock.Instance).ComplianceAuditLogRecord.Timestampno longer defaults to the current time: a record without one stays without one.packages/security:ReplayCacheandAuditDigestEnginetake an optionalIClock(defaultSystemClock.Instance;AddCadenceSecuritypasses the registered clock when there is one).AuditLogRecord.Timestampisrequired.
Shared packages (done)
These projects opt into the ban. They needed no migration.
| Project | Change |
|---|---|
packages/deid | DicomDeidentifier.Deidentify takes deidentifiedAt and RedactionManifestBuilder.BuildRedactionManifest takes recordedAt. The certificate and manifest Timestamp default to empty, so the builder is the only place that sets them. |
packages/hexagonal | DomainEvent.OccurredAt is required. BaseEntity/AggregateRoot take createdAt as a required constructor argument. |
packages/tooling_core (all three projects) | CreateAdrService.CreateAdr takes the date |
packages/cli | scaffold adr dates the file from SystemClock.Instance, its composition root |
packages/testing | TestSecurityContext signs headers and step-up tokens at SystemClock.Instance.UtcNow unless a time is given, because the gateway checks the real clock |
The counts below are from main at the base of this change and exclude EF Migrations/.
packages/engine_core (done)
The project opts into the ban. None of these changes needed a migration or changes the audit hash format.
| File | Violations | Change |
|---|---|---|
AggregateRootBase.cs | CreatedAt has no default. Every save path already stamps it from its clock: the kernel command transaction, and GxPAuditInterceptor for execution. It stays DateTime, so IGxPAuditable and the columns do not change. No code in quality, ctms, etmf or fileshare writes their aggregates yet. The first writer there needs a save path that stamps CreatedAt, such as GxPAuditInterceptor. | |
Audit/AuditLogEntry.cs | Timestamp is required and stays DateTime, so the hashed {timestamp:O} text does not change. The only writer, GxPAuditInterceptor, already set it. | |
Rules/RuleAst.cs | RuleDefinition.CreatedAt is a required DateTimeOffset | |
Rules/RuleEvaluator.cs | asOf is a required constructor argument | |
Toxicity/LabToxicityGradingEngine.cs | EvaluateObservation and EvaluateHysLaw take evaluatedAt | |
Supply/DTPLogisticsEngine.cs | EvaluateDtpDispatch takes authorizedAt |
How to count again
bash
grep -rEn '(DateTime(Offset)?\.(Utc)?Now|TimeProvider\.System|\.GetUtcNow)\b' --include=*.cs --exclude-dir=Migrations apps packages