feat(decision): add read-only replay diffing a candidate against recorded decisions - #184
Merged
Merged
Conversation
…rded decisions Replay evaluates a candidate ruleset against caller-supplied historical inputs and diffs each outcome against the decision that was actually recorded, so an author can see which past decisions a rule change would flip before publishing it. For each input it finds the most recent recorded decision by the canonical input hash, evaluates the candidate, and reports unchanged, changed, or no-baseline plus aggregate counts. The endpoint is strictly read-only: it never writes a decision log, never stores the candidate, and runs in a read-only transaction. The candidate is validated fail-closed and size-capped, then evaluated under the same bounded-time guard as evaluation, so a catastrophic candidate pattern fails the replay with a typed error instead of hanging. The input-mapping caps are now shared with the evaluate path through one mapper. Authorization is scope based. Closes #173
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Closes #173. Replay (champion/challenger): evaluate a candidate ruleset against caller-supplied historical inputs and diff each outcome against the decision that was actually recorded, so a rule author can see the blast radius of a change before publishing. Read-only and deterministic.
Endpoint
POST /v1/decision/replay(decision:write):For each input it computes the canonical input hash, finds the most recent recorded
decision_logsrow for that hash, evaluates the candidate, and diffs. Response:statusisUNCHANGED(recorded equals candidate),CHANGED, orNO_BASELINE(no recorded decision for that input).Guarantees
decision_logsrow is written, the candidate is never stored,@Transactional(readOnly = true), no log-writer dependency. The IT asserts the audit row count is unchanged after a replay.BoundedEvaluatorguard as evaluation; a catastrophic candidate pattern fails the whole replay with a typed 503 rather than hanging.@JsonSetter(... = FAIL)), not 500.Refactor
Extracted a shared
InputMapper(the input-JSON-to-typed-attributes mapping + caps) used by both evaluate (#172b) and replay, so the caps live in one place. The merged evaluate tests were updated to the new constructor and the mapping/cap tests migrated intoInputMapperTest.Tests
InputMapperTest,ReplayServiceImplTest(changed/unchanged/no-baseline incl. both-not-matched, aggregate sums, never-writes, invalid/too-large/cap),ReplayControllerTest(@WebMvcTest: scopes, 422, null-body -> 400), andDecisionReplayApiIT(@SpringBootTest: a CHANGED diff with the audit count unchanged, no-baseline, a ReDoS candidate -> 503, scope authz).Note
A pre-existing observation (carried to the #176 perf gate, not changed here):
EvaluationServiceImplholds its JDBC connection during the bounded evaluation inside@Transactional; it is timeout-bounded and the read-only replay path is unaffected.Closes #173