feat(agent): add post-load semantic validation for contracts/constants.json#227
Merged
Merged
Conversation
a36e15f to
5a5f1f9
Compare
…s.json (#219) Enforce relational invariants (min > 0, default >= min, max >= default) on approval_timeout_s and approval_gate_cap at agent import time and CI-time sync check, preventing corrupted constants from silently degrading the approval-gate security posture.
5a5f1f9 to
83cacbc
Compare
krokoko
approved these changes
Jun 1, 2026
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.
Enforce relational invariants (
min > 0,default >= min,max >= default) onapproval_timeout_sandapproval_gate_capat agent import time and in the CI-time sync check, preventing corrupted constants from silently degrading the approval-gate security posture.Area
cdk— infrastructure, handlers, constructsagent— Python runtime / Docker imagecli—bgagentclientdocs— guides or design sources (docs/guides/,docs/design/)tooling— rootmise.toml, scripts, CI workflowsRelated
Changes
agent/src/policy.py— new_validate_constants()function invoked at module import time. Checks all six relational invariants on the two constant groups loaded fromcontracts/constants.json. RaisesValueErrorwith a descriptive message on violation, crashing the agent container at startup rather than running with broken safety bounds (e.g. a zero-valuedapproval_timeout_s.minwould make the floor clamp ineffective).agent/tests/test_policy.py— newTestConstantsSemanticValidationclass (8 tests) covering each invalid scenario viaunittest.mock.patchon module-level constants, plus a sanity test confirming the real constants pass.scripts/check-constants-sync.ts— semantic invariant checks added after the existing shape validation. Reports all violations in a single pass before exiting 1. Belt-and-suspenders: catches corruption at PR time before it reaches the agent runtime.Test plan
python -m pytest tests/test_policy.py -v— 47/47 passing (39 existing + 8 new)node --experimental-strip-types scripts/check-constants-sync.ts— exits 0 with valid constantsValueErrorat import and exit 1 in the sync script