fix(resource-contract-telemetry): remediate #26 review — real observe-mode bug + validator teeth - #35
Merged
Conversation
…-mode bug + validator teeth Addresses all four Copilot findings on #26. The second is a genuine correctness bug in the verdict algebra that reached main; the doc had been reconciled to JUSTIFY the bug rather than fix it. 1. REAL BUG — observe-mode exceedance was VIOLATION. expected_verdict returned VIOLATION for enforcement=="observe" whenever peak>limit and fired_count==0. But VIOLATION is a BROKEN ENFORCEMENT PROMISE, and observe mode makes no promise — it is the honest, declared "gauge, not gate" (ResourceContract requires an observeOnlyReason for it). Flagging its exceedance VIOLATION accuses a gauge of failing to be a gate, punishes honest declaration, and trains the learning loop to demand fixes for things explicitly declared not-controls. Fixed: the VIOLATION branch now guards on enforcement != "observe"; an observe-mode exceedance is INCONCLUSIVE. The exceedance is NOT hidden — it still flows as a resource-saturation TelemetrySignal regardless of verdict. Mapping gains the explicit rule observe_mode_exceedance_is_inconclusive_not_violation; the never-fired rule and the doc verdict table gain the guard. 2. Validator matched tokens anywhere in the YAML, including comments — a required object/rule/topic could be deleted from structure but still named in prose and pass. Replaced bare substring checks with ANCHORED regex over COMMENT-STRIPPED lines. Proven by negative control: a topic moved into a comment now fails (rc=1) where the old substring check passed. 3. Docstring claimed the mapping was token-checked with `re` while importing neither re nor using it. Now it genuinely uses re, and the docstring matches. 4. The verdict algebra was only exercised by the validator script's own example. Added tools/tests/test_resource_contract_verdict.py (10 cases) pinning every precedence branch in `make test` — gate-ineligible, proved, canonical violation, within-limit, and the observe-mode carve-out that was the bug — so a regression is caught even if the example file changes. Verified: validator 27 checks; new pytest 10/10; make validate OK; negative controls (comment-only topic -> rc=1, mislabeled verdict -> rc=1, restored -> rc=0). The only make-test failure is the pre-existing test_serve port-race flake (a different serve test fails each run, passes in isolation and on origin/main), flagged separately.
CI's manifest-validate (first target in make validate) tracks every file; the new pytest module was committed but not registered. Local make validate passed only because it ran before git add, so the file was untracked and the manifest check didn't see it — CI runs post-commit. Regenerated via make manifest-write (110 tracked files); make validate now green with the file tracked.
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.
Remediates all four Copilot findings on #26. One of them is a genuine correctness bug in the verdict algebra that reached
main— and the docstring had been reconciled to justify the bug rather than fix it.1. Real bug — observe-mode exceedance was VIOLATION
expected_verdictreturned VIOLATION forenforcement == "observe"wheneverpeak > limitandfired_count == 0. But VIOLATION is a broken enforcement promise, andobservemode makes no promise — it is the honest, declared "gauge, not gate" (ResourceContractrequires anobserveOnlyReasonfor it). Flagging its exceedance VIOLATION:observeto dodge the false VIOLATION),Fixed: the VIOLATION branch now guards on
enforcement != "observe"; an observe-mode exceedance is INCONCLUSIVE. The exceedance is not hidden — it still flows as aresource-saturationTelemetrySignal regardless of verdict, so an operator can still promote the gauge to an enforcing limit. The mapping gains an explicit ruleobserve_mode_exceedance_is_inconclusive_not_violation; the never-fired rule and the doc verdict table gain the guard.2. Validator was satisfiable by its own comments
Token checks were bare substring (
tok in text) — a required object/rule/topic could be deleted from structure but still named in a comment and pass. That is the paper-control shape this file exists to reject. Replaced with anchored regex over comment-stripped lines.3. Docstring claimed
re, used neitherDeclared-vs-actual mismatch, in the file whose job is catching those. Now it genuinely uses
re, and the docstring matches.4. Algebra only tested via the script's own example
Added
tools/tests/test_resource_contract_verdict.py(10 cases) pinning every precedence branch inmake test— gate-ineligible, proved, canonical violation, within-limit, all three enforcing modes, and the observe-mode carve-out that was the bug — so a regression is caught even if the example file changes.Verification
make validateOKrc=1, mislabeled verdict →rc=1, restored →rc=0make testfailure is a pre-existingtest_serveport-race flake — a different serve test fails each run (rejects_oversized_body, thenis_disabled_by_default), it passes in isolation and onorigin/main, and nothing in this PR touches HTTP ingest. Flagged separately, not fixed here.