CODEX TASK 5

You are Cedric (Codex), worker #1, pass 5: Jenny's chunked backend review (council seat, Gemini). Accepted findings below. Same rules as pass 4: surgical changes, a test that FAILS on the old code for each behavior change, commit per item with the per-command identity and the trailers. Then run the full DONE suite and append "Pass 5 (Jenny findings)" to docs/VERIFY.md with a table: finding → commit → test.

  1. Torn BP (LakehouseRunner.cs:~75-76): latest_systolic and latest_diastolic must come from the SAME most recent BP observation row (the panel with both components). Apply the same rule in the operational/Risk path if it pairs readings independently. Test: newer systolic-only plus older full panel → no torn pair.
  2. OpenTelemetry filter inverted (ServiceDefaults/Extensions.cs:19-23): the Filter must EXCLUDE /health and /alive and record everything else. Also redact patient ids from url.path (e.g. replace path segments after /patients/ with {id}) before export. Test the predicate.
  3. SyncService.cs:26-57:
  4. (a) Verify raw.ResourceType == type; quarantine mismatches without advancing that type's watermark.
  5. (b) Within a batch, a resource first inserted and then updated before SaveChanges counts as ONE insert, not insert + update.
  6. (c) Advance the watermark only after a successful map, or make the quarantine dedupe from pass 4 cover replay.
  7. Tests for each.
  8. Auth-enabled tests (ApiSecurityTests): parameterize TestHost with authEnabled. Assert 401 without a token on /api/patients, /api/sync, POST allergies and the CDS POST, and 200 with a valid test token (a test auth handler is fine).
  9. Lakehouse status/time filters:
  10. Exclude entered-in-error / cancelled / refuted statuses from silver→gold aggregations (Condition.verificationStatus, AllergyIntolerance.verificationStatus, Observation.status, Immunization.status).
  11. Bound facts to effective <= as_of.
  12. Mirror the same status rules in the operational risk path.
  13. Tests.
  14. Migration-name claim (SourceSafetyTests.cs:84): Jenny says IMigrationsIdGenerator.GetName("202611120001_InitialOperational") truncates the name, because the 12-digit prefix doesn't match EF's 14-digit timestamp format, so MigrateAsync breaks. VERIFY it:
  15. If the test currently passes because the path isn't exercised or the name resolves, write the receipt in VERIFY.md and either make the migration ids standard 14-digit or call MigrateAsync with the full id.
  16. If it's a real bug, fix it. Never rename an applied migration without a new migration.
  17. Process-wide env-var mutation in tests (SourceSafetyTests.cs:18-26): put those tests in a non-parallel xUnit collection, or inject the setting instead of mutating the env.

If pass 4 left anything NOT DONE, finish it first. Then git push origin HEAD.