Skip to content

test(review): record code-enforced gates as not proven - #562

Closed
sumithr wants to merge 24 commits into
mainfrom
perf/issue-557-code-enforced-review-gates
Closed

sumithr wants to merge 24 commits into
mainfrom
perf/issue-557-code-enforced-review-gates

Conversation

@sumithr

@sumithr sumithr commented Jul 20, 2026 •

Copy link
Copy Markdown
Owner

Summary

Records issue #557 as NOT PROVEN after an exhaustive no-cache comparison and a quality-constrained reduction sweep. No production skill or MCP behavior changes.

Exhaustive compact result

  • Coverage: all 19 non-control reviewing-before-merge configs, 46 scenarios.
  • Quality: full skill 40/46; compact candidate 31/46 (graded figure; two of the 46 scenarios were repaired, so the one-prompt pass count is at most 31).
  • Per-scenario regressions: 12 under the grade-only rule in force when the run was made; 12 to 14 under the current comparator rule, which also counts each repaired scenario.
  • Model input: 865,740 to 126,342 tokens, 85.41% lower.
  • Total candidate generation: 1,079,443 to 291,169 tokens, 73.03% lower.
  • Deterministic validation: 46/46 candidate outputs valid; all comparator integrity checks passed.

The nine .ab.yaml files are historical controls that embed alternate skill bodies and are intentionally excluded. Every current-skill behavior config was run.

Quality-constrained frontier

Candidate Input effect Quality result Decision
Full skill plus deterministic response gate 4.25% higher 39/46 vs 40/46 Reject
Compact prompt 85.41% lower 31/46; 12 regressions Reject
Root minus optional ledger/scorecard appendices, with explicit full-skill routes 6.69% lower Corrected AC screen 1/3 vs 2/3 Reject

The conservative routed candidate retained the original red flags, examples, process flow, and all non-appendix instructions. It still regressed on the AC-UNMET case by marking changelog evidence UNVERIFIED where the unchanged rubric required MET.

The 6.69% token result is valid provider-reported generation usage across all 46 scenarios: 908,313 full-skill input tokens versus 847,554 routed input tokens. Quality results from the first fallback sweep are invalid and excluded because structured anti-pattern lists were serialized as strings. The serializer and regression tests now preserve native rubric lists and stringify only structured cold prompt context.

A corrected exhaustive rerun is externally blocked: OpenAI returns 429 insufficient_quota, and the Gemini fallback stopped returning judge results. The fail-closed conclusion is that no non-zero reduction is proven quality-neutral.

Changes

  • Generalize the POC into reproducible full, gated, conservative, and compact profiles.
  • Add direct Promptfoo comparison with exact prompt/config/rubric/usage validation.
  • Add corrected echo-provider regrading for captured outputs.
  • Guard structured rubric serialization and exact skill-body substitution.
  • Record the quality/token frontier and invalidated evidence.

Review-driven fixes (per-file merge review, two codex review threads, sixteen codex rounds, four per-file backstop rounds)

Deterministic review gate (src/sumo_qa/review_gate_poc.py):

  • The verdict line is one literal, case-sensitive line with horizontal whitespace only, so a trailing qualifier (Verdict: SAFE TO MERGE only if a future test passes) or a split line no longer crosses the boundary as a favourable verdict.
  • A second verdict statement beside the well-formed line is rejected instead of ignored: a Markdown-decorated verdict: label, or any line carrying the phrase SAFE TO MERGE in either direction, whitespace-tolerant, not letter/digit-adjacent. A decorated label with no phrase (Verdict (final): alone) states no direction and is deliberately not chased.
  • Exactly one complete GATE_REPORT/REVIEW envelope pair is required, so a second pair absorbed by the lazy REVIEW group is rejected while prose may still mention a tag.
  • The unresolved-field guards (Classification/Coverage/Status values UNMET, UNVERIFIED, UNCOVERED, UNPROVEN, and Coverage: NONE) tolerate any punctuation, HTML tag or HTML entity around the label and the value (**Classification**:, Classification&#058;, **UNMET**, ~~UNMET~~, (UNMET), <UNMET/>, <strong>UNMET</strong>, &nbsp;UNMET), so none of those can coexist with a SAFE verdict, while identifiers (UNMET_BY_DESIGN, UNMET__BY_DESIGN, serialized_Classification:, serialized__Classification:) are neither values nor labels. The decoration alternatives are exclusive by position (CodeQL flagged the earlier tag/character overlap as exponential backtracking); a timing test holds the patterns linear on hostile input.

Evidence harness (experiments/issue_557):

  • Repaired candidate responses are not one-prompt evidence. The comparator records a per-scenario repaired flag, reports repaired_count and candidate_passed_first_attempt, and counts a repaired scenario as a quality regression regardless of grade. Repair attempts still count toward token usage.
  • The comparator fails closed on malformed attempts (non-list, non-object elements) instead of raising.
  • The MCP A/B runner rejects a candidate trace that loads the review skill through sumo_qa_load_skill_context (exact skill_name match), requires every review-tool result to hash to the candidate prompt, validates each frozen baseline record (scenario id, description, config hash, full-skill prompt hash, graded output with a score in 0..1), counts only a first-attempt pass as preserved quality, and pins its own file hash in the evidence metadata so evidence from an earlier harness cannot be resumed. The frozen grade is trusted as captured; regrading all 46 baseline outputs is deliberately out of scope.
  • The candidate A/B server substitutes the review skill's manifest record at the source, so the skill tool, sumo_qa_load_skill_context, the manifest index, the sumoqa:// resources, and sumo_qa_execute_external_skill (for a host-installed copy of the review skill, matched by normalised directory name, frontmatter name, or line overlap with the production body so a case-insensitive filesystem, a renamed copy with its own frontmatter name, or an edited, commented, stripped, or older copy cannot leak it) all serve the compact prompt; no MCP path returns the full skill to the candidate. The override is process-wide (the loader resolves records at request time), removable, and cleared after each in-process test. Candidate resource reads (read_mcp_resource and friends) and candidate external-skill execution of the review skill (matched on the normalised last path segment, so ../../skills/<name>/. and <name>/references/.. count, and on the served body, so a symlink alias counts too) are rejected by the trace validator; external-skill loads count toward the skill-context estimate because they are invisible to the skill-context token estimate.
  • README: regression count qualified under the current rule, the "runs once" claim corrected, trace, resource, and frozen-record checks documented.

Tests:

  • tests/test_e2e_mcp_initialize.py imports the POC package inside the one A/B test, so the production contract tests collect without experiments/.
  • Regression cases for every bypass above and for the false positives the fixes must not introduce (prose mentioning a tag, an identifier containing the phrase, an AC row naming the verdict, UNMETERED beside a MET classification); every review surface checked on both variants, including the resource over the real stdio transport.

Verification

  • Ruff check and format: passed.
  • Mypy: passed.
  • Full pytest suite: 3468 passed, 6 skipped, 1 xfailed, 100% source coverage.
  • Pre-push pytest and mutation gates: passed.
  • Behavioural check: the bypass classes reproduce on the pre-review module (90e4fda accepts each as safe_to_merge=True) and are rejected on the branch; legitimate forms still validate; the trace, first-attempt, frozen-record, and every-surface checks fire on representative inputs.
  • Production skill files changed: none. review_gate_poc is not registered as a tool and is not imported by any production module.
  • Known residual (reasoned non-fix): the envelope regexes are quadratic on adversarial inputs with many unmatched <GATE_REPORT> tags (about 2 s at 84 KB); model responses are a few KB, the pattern is not exponential, and a linear hand parser would be a rewrite of the POC boundary.

Related issue

Closes #557

Checklist

  • Tests, lint, type, mutation, and coverage gates pass
  • All current behavior configs included in the authoritative compact comparison
  • Invalid fallback evidence explicitly excluded
  • POC remains isolated from production behavior
  • Final result remains NOT PROVEN

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3cb9d7d763

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/sumo_qa/review_gate_poc.py Resolved
Comment thread experiments/issue_557/run_candidate.py Resolved
@sumithr sumithr changed the title perf(review): prove code-enforced gates test(review): record code-enforced gates as not proven Jul 21, 2026
@sumithr
sumithr force-pushed the perf/issue-557-code-enforced-review-gates branch 2 times, most recently from 88c8681 to bfb0c6d Compare August 3, 2026 15:33
sumithr added 15 commits August 6, 2026 17:10
…xt (#557)

Widen validate_review_response to accept the host-supplied ReviewContext so
completeness rules can be checked in code instead of bought as prompt prose,
and repair scorecard/ledger ordering deterministically rather than instructing
it in the contract layer.

Model-authored lines survive verbatim; only block order changes, and a review
already in contract order is returned untouched.
Move the contract layer's completeness and cross-field rules into the
deterministic boundary now that ReviewContext carries what the host supplied:
one row per acceptance criterion and none invented, one inventory-drift row
copying its pair verbatim, mutually exclusive memory branches, no external
producer declined as internal, no unresolved field under a SAFE verdict, and
NONE rejected as a coverage status.
…#557)

Build ReviewContext from each scenario's ground-truth block so the completeness
rules actually fire during the eval, and carry the required emit shape in each
rejection message so a repair can succeed in one attempt.

Only the appendix-ordering rule is removed from the contract layer. A smoke run
showed why: deleting a reject-class instruction costs a full repair round trip
(~17.5k tokens) to recover a ~38-token instruction, so reject-class rules keep
their prompt text and code enforces them on top.
…#557)

A failed response contract is a shape defect, not a judgment defect. The repair
now carries the machine-enforced contract, the validation error, and the previous
response, but not the scenario task, cutting the repair prompt ~70%.

The 46-scenario run lost 25.41 points of token reduction to repair traffic
(42.63% first-attempt vs 17.22% realised), with 17 of 19 repairs caused by one
recurring envelope defect.
…#557)

A scenario that errored in the frozen run has no baseline to reuse, which made
the whole reuse path fail closed and forced regenerating all 46. Regenerate just
the missing ones; the model/auth/skill metadata check still gates reuse.
@sumithr
sumithr force-pushed the perf/issue-557-code-enforced-review-gates branch from bfb0c6d to 90e4fda Compare August 6, 2026 15:30
…dates (#557)

Two review findings on the issue #557 proof harness:

- The verdict regex accepted trailing text after a favourable verdict, so a
  conditional approval such as 'Verdict: SAFE TO MERGE only if a future test
  passes' crossed the deterministic boundary as safe_to_merge=True. Anchor
  the line to end-of-line and add regression cases for both directions.
- Repaired candidate responses are generated after a corrective user turn the
  baseline never receives, so their rubric grade is not a one-prompt
  comparison. The comparator now records a per-scenario repaired flag, reports
  repaired_count and candidate_passed_first_attempt, and counts a repaired
  scenario as a quality regression regardless of its grade. Repair attempts
  still count toward candidate token usage. The README records the limitation
  against the recorded 31/46 result; NOT PROVEN stands under either reading.
…gaps (#557)

Findings from the per-file merge review and nine codex rounds on the proof
harness, all fixed in this PR:

Deterministic review gate (src/sumo_qa/review_gate_poc.py):
- A second GATE_REPORT/REVIEW pair absorbed by the lazy REVIEW group
  validated the first report while the second was never parsed. Exactly one
  complete envelope pair is now required; prose may still mention a tag.
- The verdict line is one literal, case-sensitive line with horizontal
  whitespace only, so it cannot be split across lines.
- A second verdict statement beside the well-formed line (a decorated
  "verdict:" label, or any line carrying the phrase SAFE TO MERGE in either
  direction, with whitespace tolerance and no letter/digit adjacency) is
  rejected instead of ignored, closing the contradictory-verdict bypass.

Evidence harness (experiments/issue_557):
- compare_results fails closed on malformed attempts instead of raising.
- The MCP A/B runner rejects a candidate trace that loads the review skill
  through sumo_qa_load_skill_context, checks every review-tool result hashes
  to the candidate prompt, validates each frozen baseline record (scenario,
  description, config hash, prompt hash, graded output with a score in
  0..1), counts only a first-attempt pass as preserved quality, and pins its
  own file hash in the evidence metadata so stale evidence cannot resume.
- README: regression count qualified under the current rule, the
  "runs once" claim corrected, trace and frozen-record checks documented.

Tests:
- tests/test_e2e_mcp_initialize.py imports the POC package inside the one
  A/B test so the production contract tests collect without experiments/.
- Regression cases for every bypass above and the false positives they
  must not introduce.
…ath (#557)

Two findings from the final per-file merge review, plus the codex follow-up:

- The unresolved-field guards in review_gate_poc required the bare value after
  Classification:/Coverage:/Status:, so a SAFE verdict with a decorated value
  (**UNMET**, ~~UNMET~~, (UNMET), "UNMET", <strong>UNMET</strong>, Coverage:
  **NONE**) was accepted. Any punctuation or HTML tag between the label and
  the value is now consumed, with letter/digit adjacency excluded; the verdict
  label pattern accepts the same decoration class.
- The candidate A/B server overrode only the review skill tool, so
  sumo_qa_load_skill_context, the manifest index, and the sumoqa:// resources
  still served the full review skill, which Codex can read through its
  built-in resource tool without the trace validator seeing it. The candidate
  now substitutes the review skill's manifest record at the source, so every
  surface serves the compact prompt; the override is process-wide (the loader
  resolves records at request time), removable, and cleared after each
  in-process test. The trace validator also rejects candidate resource reads,
  which are invisible to the skill-context token estimate.

Tests cover every decoration form (red on the previous head), every review
surface on both variants including the resource over the real stdio
transport, the resource-read trace rule, and the no-leak ordering.
…l surface (#557)

Codex follow-up on the previous commit:

- The field guards now consume HTML entities between a label and its value
  (Classification: &nbsp;UNMET), and a value followed by an underscore and a
  letter is an identifier (UNMET_BY_DESIGN) rather than the bare value, while
  Markdown emphasis (_UNMET_) still counts.
- The candidate A/B server also overrides execute_external_skill, so a
  host-installed copy of the review skill returns the compact body; the trace
  validator rejects a candidate that executes the review skill that way.
…ls (#557)

Substitute per-file review (codex quota-blocked) on the previous commit:

- The field guards accept the same decoration on the label side as on the
  value side (**Classification**:, _Coverage:_, <strong>Status</strong>:,
  Classification :, an entity colon), so a decorated label can no longer hide
  an unresolved value beside a SAFE verdict.
- The candidate external-skill override recognises the review skill by its
  normalised directory name or by the loaded body's content hash, so a
  case-insensitive filesystem resolving another spelling, or a renamed host
  copy, cannot hand the candidate the full skill.
Comment thread src/sumo_qa/review_gate_poc.py Fixed
…s, edited host copies (#557)

- CodeQL flagged the label decoration pattern for exponential backtracking:
  the HTML-tag alternative and the single-character class overlapped on '<'
  and '>'. The decoration grammar is now exclusive by position (a '<' is a
  tag start or explicitly not one; an '&' is an entity or explicitly not
  one), shared by the verdict label and both field guards, with a timing
  test on hostile input. An angle-bracketed value (<UNMET>) stays a value.
- Colon character references with leading zeros (&#58;, &#x03A;) count as
  the label's colon.
- The candidate external-skill override recognises a host copy of the review
  skill by its frontmatter name or a whitespace-normalised body, so an
  edited, BOM-prefixed, or older renamed copy cannot leak the full skill.
…ped skill names (#557)

Codex final pass on the previous commits:

- A value followed by any run of underscores and a letter is an identifier
  (UNMET__BY_DESIGN), and a label preceded by a letter and an underscore is an
  identifier (serialized_Classification:), so neither is a field guard hit;
  Markdown emphasis on either side still counts.
- The candidate external-skill override strips leading whitespace before
  reading the frontmatter name, so an edited renamed copy with leading blank
  lines and a trailing comment still serves the compact body.
- The trace rule for external-skill execution names the review skill by the
  last real path segment, so ../../skills/<name>/. and similar spellings the
  resolver accepts are rejected too.
…nderscore labels (#557)

Codex pass on the previous commit:

- The external-skill trace rule normalises the path (posixpath.normpath) before
  taking the last segment, so <name>/references/.. and similar spellings the
  resolver accepts are recognised.
- The candidate override skips whitespace, a BOM, and HTML comments before the
  copied frontmatter, so a commented renamed copy still serves the compact body.
- A label preceded by a letter and up to three underscores is an identifier;
  double-underscore emphasis (__Classification__:) still counts.
…ed-body trace rule (#557)

Final per-file backstop and codex confirmatory pass on 5b38ee7:

- An HTML-tag body may not contain a bare unresolved value anywhere, so
  <UNMET/>, <**UNMET**> and <UNMET | Anchor: none> are values, not tags, and
  the <UNMET> exclusion now has true-negative tests.
- The candidate override recognises a host copy of the review skill by line
  overlap with the production body (frontmatter removed), so a copy whose
  directory, frontmatter name and body were all changed still serves the
  compact prompt; test variants cover renamed frontmatter, stripped
  frontmatter, and an edit everywhere.
- The trace validator rejects a candidate external-skill call by the body it
  returned (full or compact review skill, raw or JSON-encoded), so a symlink
  alias the name rule cannot see is caught, and external-skill loads count
  toward the skill-context estimate.
@sumithr

sumithr commented Sep 3, 2026

Copy link
Copy Markdown
Owner Author

Closed without merging by decision of the maintainer.

The issue asked a go/no-go question and the answer is no: the compact prompt plus code-enforced gates does not preserve the full review skill's quality (31/46 vs 40/46 with 12 per-scenario regressions despite 85% fewer input tokens; the fully gated full skill costs 4% more; the conservative trim regresses the AC case). The result is recorded as NOT PROVEN on #557 together with the per-AC evidence, the token totals, and the limitations. A secondary finding from the review series: a text-level gate on model prose becomes a regex arms race, which argues against building this design for real.

Merging would add about 5,400 lines, a gate module shipping as dead code in the wheel, and roughly 500 tests of ongoing cost for a design that will not be built. The branch is kept as the evidence record (head de3144f: CI 33 of 33, Linux mutation gate green, 3468 tests at 100% coverage).

@sumithr sumithr closed this Sep 3, 2026
@sumithr
sumithr deleted the perf/issue-557-code-enforced-review-gates branch September 3, 2026 08:07
@sumithr

sumithr commented Sep 3, 2026

Copy link
Copy Markdown
Owner Author

Correction: the branch has been deleted as part of the cleanup. This PR's commits (head de3144f) remain the evidence record and are restorable from this page.

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.

[Task]: POC code-enforced review gates as an alternative to progressive loading

2 participants