Implementation plan / Session plan / Handover RC-1-S28-F6
Handover RC-1-S28-F6 Fix: the policy engine is warm before the first decision¶
Card: RC-1-S28-F6. Issue: cema-care/his#212. Branch: session/RC-1-S28-F6. Slice: RC-1. This is a round 1 fix of the gate session RC-1-S28, for the gate line "Criterion 3: the 49 test scenarios pass (TEST-ESS-005)". The work belongs to RC-1-S17 (MOD-ESS-002 in services/ess-runtime-decision). It comes after RC-1-S28-F4. No decision record: the fix stays inside the engine adapter of ADR-HIS-065 and changes no contract, no setting and no later session's work.
The failure¶
In the gate's build, PolicyTestPackTest TP-01 got 503 unavailable where 200 was expected. RC-1-S26 saw the same on TP-08, and RC-1-S28-F4 saw 13 of mod-ess-002's tests fail this way when every module of the unit ran at once.
The cause is in PolicyEngine. It loads the evaluator and a policy version into OPA on first use, then sends the real decision at once, held to the 200 ms decision budget (his.authz.opa-timeout). OPA plans the query data.his.authz.decision, and reads the version's content into its own form, on the first evaluation after a load. That evaluation is the slow one. On a busy host it took longer than 200 ms, and the decision that paid for it was refused as an outage. It happens after every load: the first decision of a test class (each class installs its policy again), the first decision after a new version is approved, and the first after OPA restarts empty. With the fix in place, the log shows the same thing on a quiet host: on several loads OPA needed two warm-up evaluations before one answered within 200 ms (see Checks).
What was changed and where¶
All in services/ess-runtime-decision/mod-ess-002:
engine/PolicyEngine.java. Every load is followed by a warm-up. It runs after the evaluator and a version are put into OPA: on first use, atload(approval), and on the reload after an OPA restart.- The warm-up evaluates a synthetic request against the same version: the first action of its first registered resource type, by an active human subject with no role. That runs the registry, every rule's conditions and the default Deny.
- It stops at the first evaluation that answers within the decision budget. It is bounded: at most 10 evaluations, and 25 times the budget (5 s) for all of them together.
- It decides nothing, stores nothing and audits nothing; its answer is not used. An outage during the warm-up only ends it, and the real decision then meets the outage itself, as before (503).
- New
prepare(version, contents): loads and warms a version ahead of any decision, logging an outage instead of failing. engine/OpaClient.java:decidewith a time limit of its own, used only by the warm-up.timeout()andloadTimeout()(25 times the budget, which the loads already used).policy/PolicyVersions.java:prepareInForce()prepares the version in force now.DecisionJobs.java: atApplicationReadyEvent, after the starter content, the unit runsprepareInForce(). Spring Boot turns the readiness probe to accepting traffic only after the listeners of that event return, so the engine is warm before the first caller is let in. That covers a restart of the unit as well as a first start.- New test
src/test/java/care/cema/his/ess/mod002/engine/PolicyEngineWarmUpTest.java(below). services/ess-runtime-decision/README.md: theenginerow andopa-timeoutsay what the warm-up does.
The decision budget is unchanged at 200 ms. The policy test pack does not wait or retry: a decision that the engine does not answer in time is still an outage (FR-ESS-AUZ-001 part 10), and DecisionOutageTest still holds that. No dependency was added, and no lockfile changed. No contract changed.
The test that fails before and passes after¶
PolicyEngineWarmUpTest runs PolicyEngine against a stand-in for OPA, an in-process HTTP server. It is cold the way a real OPA is on a busy host, but every time: the first evaluation after any load takes three times the decision budget (600 ms), the ones after it answer at once, and after a "restart" it holds nothing and answers no result. A real OPA's first evaluation is only sometimes that slow, which is why TP-01 failed only now and again.
| Case | Before the fix | After |
|---|---|---|
| The first decision on a cold engine is answered, not refused as an outage | failed: OpaUnavailable … request timed out |
passes |
| After OPA restarts empty, the decision that reloads it is answered too | failed, the same | passes |
A version approved ahead of use (load) is warm when it is loaded |
failed, the same | passes |
| The unit prepares the version in force before its first decision, with a synthetic request of that version | (uses prepare, new) |
passes |
| An engine that stays slow is still an outage: the warm-up is bounded and decides nothing (TEST-ESS-041) | (new) | passes |
| An unreachable engine fails the preparation without stopping the start (TEST-ESS-041) | (new) | passes |
"Before" ran the first three cases on the committed code of main (./gradlew :mod-ess-002:test --tests '*PolicyEngineWarmUpTest'): 3 tests, 3 failed.
Checks and their results¶
On the light profile (HIS_SESSION=RC-1-S28-F6), in services/ess-runtime-decision:
| Check | Result |
|---|---|
./gradlew :mod-ess-002:test --rerun-tasks |
100 tests, all passed (94 before, and the 6 new) |
./gradlew cleanTest build --continue --no-build-cache, the gate's command |
Passed. service-kit 31 (1 skipped), mod-ess-001 89 (3 skipped), mod-ess-002 100, mod-ess-003 39, app 7 |
./gradlew build --rerun-tasks, all modules at once, twice, at load averages 5 and 8 |
Passed both times, 0 failures. RC-1-S28-F4 had 13 mod-ess-002 failures in this setting |
./gradlew cleanTest build --continue --no-build-cache again, on the final commit (which bounds the whole warm-up by the load limit) |
Passed, with the same counts. The slow-engine case ends its warm-up in 5.4 s |
| The warm-up in those runs | Against the real OPA, the logs show "OPA is warm for policy version … after 2 evaluation(s)" on several loads: the first evaluation had taken more than 200 ms. Outside the stand-in and DecisionOutageTest, no test logged a warm-up that did not finish or a decision refused as unavailable |
Slice scenario. HIS_SESSION=RC-1-S28-F6 e2e/harness/scenario run e2e/scenarios/RC-1, full profile, from his-env reset. Before it, CI=true pnpm install --frozen-lockfile ran in contracts/common, ess, adm and ise (the defect of RC-1-S28-F10); no file changed. Other sessions ran on the same host, with a load average of 8 to 15.
- Run 1 (
20261129T093721Z-0ff1): 10 of 12 passed. RC-1-E2E-002, which failed at the gate, passed. - RC-1-E2E-003 failed with a 503 from registration. Its callers (adm-identity, ess-reference) ran out of their own decision budget of about 256 ms waiting for
ess-runtime-decision, right after RC-1-E2E-013 had restarted adm-patient-administration, at a load average of 13. - RC-1-E2E-006 failed 10 s after RC-1-E2E-004 had restarted
ess-runtime-decision: callers' decisions took 266 to 536 ms. The restarted unit had warmed its engine before it reported ready ("OPA is warm … after 1 evaluation(s) (8 ms)"), and its engine did not time out during either case. The slow part was the newly started process answering over HTTP, not OPA. - Every "policy engine unavailable" of the run is in RC-1-E2E-010, the load test at twice the peak, whose refusals under load RC-1-S26 records as shortfalls by design.
- Run 2 (
20261129T095242Z-8031), fromhis-env reset: 11 of 12 passed, RC-1-E2E-003 and 006 included. RC-1-E2E-010 passed its measurements but failed its last step, "the stack is ready again":registerAndOpeninrc-1-nfr.scenario.tsreadpromptsof a duplicate check that had answered an error (TypeError: Cannot read properties of undefined (reading 'map')). That is the scenario's own check of the answer, outside this card (follow-up).
The records stay in the run folders, which git ignores.
Requirements and test scenarios of the card¶
| Requirement, scenario | Test |
|---|---|
| FR-ESS-AUZ-001 AC-03, TEST-ESS-005: the policy test pack against the active version | PolicyTestPackTest (TP-01 to TP-35, unchanged), now on an engine warmed after its load; PolicyEngineWarmUpTest, the first four cases (tags FR-ESS-AUZ-001, TEST-ESS-005) |
| FR-ESS-AUZ-001 part 10, TEST-ESS-041: an engine that does not answer in time is an outage, never a decision | DecisionOutageTest (unchanged); PolicyEngineWarmUpTest, the last two cases (tag TEST-ESS-041) |
What the gate line now shows. The line is "Criterion 3: the 49 test scenarios pass", for TEST-ESS-005. Its check, the gate's build of services/ess-runtime-decision, passes. TEST-ESS-005 no longer depends on the engine being warm. The line's other failure, TEST-ISE-029, is fix RC-1-S28-F8 (#214), and TEST-ISE-001 is decision D1 of the gate. So the line stays open until those are settled, and the next gate session, RC-1-S28-G2, records it again.
Done differently from the specification or contract¶
Nothing.
Questions and follow-ups¶
- No question for a person.
- The warm-up covers the decision service's own engine. A caller's first decision through its kit can still run into its own timeout while the caller is cold (RC-1-S26 found the calling units' cold decision clients; RC-1-S28-F4 saw adm-patient-administration's 680 ms budget run out after
ess-runtime-decisionrestarted). This fix shortens that, since the restarted unit reports ready only with a warm engine, but the callers' side is outside this card. In run 1, RC-1-E2E-006 failed 10 s after the unit restarted, with a warm engine. Warming the decision path of the process as a whole, without storing or auditing a decision, would need a dry-run path throughDecisionService. That is a design change beyond this card, for the owner of the unit or of the kit's decision client. - For the RC-1 scenario (its integrate session):
registerAndOpenine2e/scenarios/RC-1/rc-1-nfr.scenario.tsshould check the status of the duplicate check before it readsprompts, so that a refusal right after the load test is reported as a refusal and asked again, as the other steps do.