Implementation plan / Session plan / Handover RC-1-S28-F20
Handover RC-1-S28-F20 Fix: identity-source state is reconciled against the accounts, and authentication events after an outage, in ess-runtime-decision¶
Card: RC-1-S28-F20. Issue: cema-care/his#226. Branch: session/RC-1-S28-F20. Slice: RC-1. This is a round 1 fix of the gate session RC-1-S28, for the gate line "Criterion 6 (ACC-005): IF-ESS-001, IF-ESS-002 (reconciliation)". The work belongs to RC-1-S16 (MOD-ESS-001 in services/ess-runtime-decision). It comes after RC-1-S28-F16. Decision record: ADR-HIS-110. ADR-HIS-108 is taken by an open pull request (RC-3-S13), so this record is 110.
The failure¶
The gate report (interfaces) and the issue's first comment: - IF-ESS-001: "No reconciliation of identity-source state against accounts"; - IF-ESS-002: "No reconciliation of authentication events after an outage".
D10-ESS 8.6 asks for both: "authentication events reconciled" after a sign-on outage, and "after any outage, reconciliation compares … identity-source state against account state. Exceptions are queued, not silently corrected." The issue had no comment from a person besides the launcher's.
Looking at the code turned up two more defects behind the second line: - The sign-in poll lost events after an outage. It asked Keycloak for one page of 500 events, and Keycloak answers newest first. After an outage with more than 500 sign-ins, the module read the newest 500, moved its cursor past them, and never read the rest. - The provider being out stopped every later lifecycle job. A failed read of the events ended the whole run, so no block ended, no assignment expired and no request was sent until the provider answered again.
What was changed and where¶
All in services/ess-runtime-decision/mod-ess-001, following ADR-HIS-110:
feed.SourceFacts(new) is the identity source's state: the latest fact each source has stated, per workforce identity and attribute (employment status, organizational unit, account type, credential status).SourceEventsrecords the facts of every event it keeps, whatever its outcome.PractitionerChangesrecords the credential status of the credentialing record. MigrationV2__reconciliation.sqlfills the table from the events already received.reconcile.IdentitySourceReconciliation(new) compares those facts with every account. It queues each difference asaccess-after-employment-ended,not-in-source,attribute-differs(by field) orno-account, and changes no account. An exception is cleared by the first run that no longer finds it.reconcile.AuthenticationReconciliation(new) compares, for a period, the provider's sign-in events with those the module recorded. Each one missed is recovered bySignIns.recover: recorded, and audited asess.iam.sign-inat its own time withrecoveredBy. It is never counted towards a block. A recovered failure of an account is queued assign-in-failure-not-counted. A service identity's attempt is audited as misuse with its alert, and queued.reconcile.Reconciliations(new) keeps the runs (reconciliation_run: period, trigger, counts, outcome), the exceptions (reconciliation_exception) and each reconciliation's state (reconciliation_state: last run, reconciled up to, outage since). A run that opens new exceptions raises an alert (identity-reconciliation-exceptions) in the request queue. The metrics arehis.identity.reconciliation.open-exceptionsandhis.identity.reconciliation.runs.IdentityJobs:- a failed read of the provider's events records the outage and lets the other jobs run;
- when the read works again, the authentication events are reconciled from the earlier of the outage and the last reconciled time;
- the feed heartbeat records the source's outage (persisted, in place of an in-memory flag), and the identity source is reconciled when the feed delivers again;
- both reconciliations also run daily.
- The sign-in events are read whole:
ports.IdentityProvider.signInEvents(from, to)answers every event of a period, oldest first, and replacessignInEvents(since, max);KeycloakIdentityProviderpages from the newest event until a page reaches back past the period;SignIns.pollreads again from five minutes before its cursor, so an event written late is still applied once.README.mdof the unit: thefeed,reconcileandauthrows, and the migrations.
No dependency was added and no lockfile changed. No contract changed.
The tests that fail before and pass after¶
New, in mod-ess-001/src/test/java/care/cema/his/ess/mod001/:
| Test | What it shows |
|---|---|
IdentitySourceReconciliationTest.afterFeedOutage |
Three people from the feed reconcile clean. The feed goes silent for 27 hours: the outage is recorded and alerted. Meanwhile people make manual entries: a unit change, a leaver brought back, and an account the source never sent. The feed returns with a joiner it cannot apply. The after-outage run queues exactly the five differences, changes no account and alerts the identity administrator and security officer. When the source confirms the unit change, the daily run clears that one exception and keeps the other four |
AuthenticationReconciliationTest.afterProviderOutage |
A failure the provider wrote late, from before the newest event read, is never read by the poll. The provider goes down, and the outage is recorded. When it answers again, the run over the period recovers the failure and audits it at its own time with the category fields. It does not count it and queues it. The next daily run neither recovers it again nor clears its exception |
AuthenticationReconciliationTest.outageStopsNoOtherJob |
With the provider down, a block still ends at the end of its period |
ports.KeycloakSignInEventsTest (3 tests) |
Against Keycloak's API answering newest first: 1,200 events over three pages are all read, oldest first; the read stops at the page that reaches past the period; an event pushed onto the next page is kept once |
On origin/main (4af08241), in a scratch worktree, with the tests made to fit main's port (signInEvents(since, max) called with 500, as the poll calls it) and main's fixture made to refuse events while down:
- KeycloakSignInEventsTest.everyPageOfThePeriod fails: "Further request(s) expected leaving 2 unsatisfied expectation(s)". Main asks for the first page only and returns the newest 500 of 1,200.
- AuthenticationReconciliationTest.outageStopsNoOtherJob fails: IllegalStateException: identity provider unavailable. The run ends at the poll, and the block never ends.
- The two reconciliation tests cannot run on main, because nothing on main reconciles: the classes do not exist.
On this branch all six pass.
The test fixture's identity provider (IdentityTestConfiguration) now refuses to give events while it is down, as Keycloak does. It also takes the new period signature.
Checks and their results¶
Light profile as HIS_SESSION=RC-1-S28-F20 for the unit, full for the scenario.
| Check | Command | Result |
|---|---|---|
| New tests | ./gradlew :mod-ess-001:test --tests '*ReconciliationTest' --tests '*KeycloakSignInEventsTest' |
6 of 6 pass (above for main) |
| Build and every test of the unit, the gate's command | ./gradlew cleanTest build --continue --no-build-cache in services/ess-runtime-decision |
Successful in 9m 27s: service-kit 31 (1 skipped), mod-ess-001 102 (3 skipped, the Keycloak adapter tests of the full profile), mod-ess-002 101, mod-ess-003 39, app 7, with 0 failures. Contract tests are included |
| Static analysis | platform/delivery-pipeline/bin/static-analysis services/ess-runtime-decision |
No blocking finding |
| Secret scan | platform/delivery-pipeline/bin/secret-scan code origin/main HEAD, and docs |
No secret; no exception file added |
| Dependency scan | not run | No dependency or lockfile changed |
| Documentation | python3 docs/implementation_plan/tools/check_links.py; mkdocs build |
0 broken links, 0 duplicate anchors; the site builds (its warnings are in other sessions' files) |
| Decision record index | Row and count added by hand in the generator's form (109 records) | Running build_adrs.py, even on a copy, was not permitted in this session |
The slice scenario (HIS_SESSION=RC-1-S28-F20 e2e/harness/scenario run e2e/scenarios/RC-1 --fresh --keep, after CI=true pnpm install --frozen-lockfile in contracts/common, ess, adm and ise). There were three attempts on commit b1d5db74:
- 20261130T162536Z-22b8 and 20261130T172216Z-044b stopped in his-env start full: Keycloak was not healthy within its window. RC-1-S28-F18 saw the same;
- 20261130T163545Z-a2d3 ran: 2 of 15 passed. Each of the 13 failures is a 503 "Authorization service unavailable", or what follows from one: the screen never showed its result, or a response the test expected was missing. The decision service logged 1,335 warnings, 1,242 of them "policy engine unavailable", because OPA did not answer within its 200 ms budget. The host has 4 cores, and its load average was 20 to 23 during the run, shared with other sessions. RC-1-S28-F16 and F18 recorded the same pattern at that load.
- No failure involves this change. MOD-ESS-001 logged no warning or error. The migration to version 2 applied. Both reconciliations ran once at start-up, clean, in under a second (no source identities and no provider events yet), and did not run again in the run (they are daily). The sign-in poll read the provider's events throughout with no failure.
The scenario still needs a run on a quiet host to pass in full. That is the next gate session's (RC-1-S28-G2), as for F16 and F18.
What the gate line now shows¶
The line is "Criterion 6 (ACC-005): IF-ESS-001, IF-ESS-002 (reconciliation)".
- IF-ESS-001: identity-source state is reconciled against account state, after the feed returns from an outage and daily. Differences are queued, not corrected (IdentitySourceReconciliationTest). Acknowledgement, error handling, replay and monitoring were already shown at the gate.
- IF-ESS-002: authentication events are reconciled when the provider returns from an outage, and daily. Every event of the period is read, and the missed ones are recovered, audited and queued (AuthenticationReconciliationTest, KeycloakSignInEventsTest). The gate's other note on IF-ESS-002, "the shell is not wired to sign-on", is not on this card. It was not filed as a fix of this round.
- The next gate session, RC-1-S28-G2, records the line again.
Requirements and test scenarios of the card¶
| Requirement, interface, scenario | Test |
|---|---|
| IF-ESS-001 and D10-ESS 8.6, data consistency: identity-source state against account state, exceptions queued; FR-ESS-IAM-001 part 10 (manual entries reconciled when the feed returns); DQ-ESS-002; KPI-ESS-005 | IdentitySourceReconciliationTest.afterFeedOutage (tags FR-ESS-IAM-001, IF-ESS-001, TEST-ESS-001) |
| IF-ESS-002 and D10-ESS 8.6, authentication: authentication events reconciled after an outage; FR-ESS-IAM-002 part 12 (sign-ins audited) | AuthenticationReconciliationTest.afterProviderOutage, outageStopsNoOtherJob; ports.KeycloakSignInEventsTest (tags FR-ESS-IAM-002, IF-ESS-002, TEST-ESS-002) |
Done differently from the specification or contract¶
Nothing differs from the specification. It leaves these points open, and ADR-HIS-110 settles them:
- What "identity-source state" is. The contract carries events, not a snapshot of the source. So the state is the latest fact each source has stated (point 1). The weekly full file of EXT-ESS-001 reaches the unit as events and updates the same facts.
- A missed sign-in failure is not counted late. D10-ESS 8.6 says exceptions are queued, not corrected. A late count could block an account for failures long past. So the failure is audited and queued for the security officer, and the account is not changed (point 3).
- Where the exceptions are queued. identity.v1 has no operation to read a reconciliation, and this card owns no contract. The runs and exceptions are kept in the module, announced by an alert and measured. Reading and resolving them through UI-ESS-002 and UI-ESS-009 is a contract change (follow-up).
Questions and follow-ups¶
None blocks this session.
- ESS contract session (contracts/ess, identity.v1): operations to list the reconciliation runs and their exceptions, and to resolve an exception with a reason (UI-ESS-002, UI-ESS-009; REP-ESS-001 "source reconciliation exceptions"). The module's Reconciliations.runs and exceptions read what they would answer.
- Facilities without an HR feed (FR-ESS-IAM-001 part 16: the HR office enters joiners, movers and leavers on UI-ESS-002 "with the same reconciliation"). Their accounts show as not-in-source until their entries reach the unit as identity-source events. If the specification means something else for them, the owner of D10-ESS should say what they are reconciled against. The exception is only queued, so nothing is refused meanwhile.
- Deployment (Domain 2, Keycloak realm settings): keep the realm's sign-in events longer than the longest planned outage, and at least a day. An event Keycloak no longer holds cannot be recovered.
- MOD-ESS-007 delivers the alert identity-reconciliation-exceptions once the notification service is wired to this unit.
- Design system: none.