Skip to content

feat(agent): add post-load semantic validation for contracts/constants.json#227

Merged
krokoko merged 1 commit into
mainfrom
feat/219-constants-semantic-validation
Jun 1, 2026
Merged

feat(agent): add post-load semantic validation for contracts/constants.json#227
krokoko merged 1 commit into
mainfrom
feat/219-constants-semantic-validation

Conversation

@nizar-lahlali
Copy link
Copy Markdown
Contributor

Enforce relational invariants (min > 0, default >= min, max >= default) on approval_timeout_s and approval_gate_cap at 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, constructs
  • agent — Python runtime / Docker image
  • clibgagent client
  • docs — guides or design sources (docs/guides/, docs/design/)
  • tooling — root mise.toml, scripts, CI workflows

Related

Changes

  1. agent/src/policy.py — new _validate_constants() function invoked at module import time. Checks all six relational invariants on the two constant groups loaded from contracts/constants.json. Raises ValueError with a descriptive message on violation, crashing the agent container at startup rather than running with broken safety bounds (e.g. a zero-valued approval_timeout_s.min would make the floor clamp ineffective).

  2. agent/tests/test_policy.py — new TestConstantsSemanticValidation class (8 tests) covering each invalid scenario via unittest.mock.patch on module-level constants, plus a sanity test confirming the real constants pass.

  3. 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 constants
  • Temporarily corrupted constants verified to raise ValueError at import and exit 1 in the sync script

@nizar-lahlali nizar-lahlali requested a review from a team as a code owner June 1, 2026 15:41
@nizar-lahlali nizar-lahlali force-pushed the feat/219-constants-semantic-validation branch from a36e15f to 5a5f1f9 Compare June 1, 2026 15:48
Copy link
Copy Markdown
Contributor

@scottschreckengaust scottschreckengaust left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

…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.
@krokoko krokoko added this pull request to the merge queue Jun 1, 2026
Merged via the queue into main with commit d164e36 Jun 1, 2026
6 checks passed
@krokoko krokoko deleted the feat/219-constants-semantic-validation branch June 1, 2026 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(agent): add post-load semantic validation for contracts/constants.json values

3 participants