Skip to content

feat(#339): add GRACE semantic code-contract anchor eval (slice 1)#375

Merged
azalio merged 1 commit into
mainfrom
claude/compassionate-cerf-eynfn6
Jul 18, 2026
Merged

feat(#339): add GRACE semantic code-contract anchor eval (slice 1)#375
azalio merged 1 commit into
mainfrom
claude/compassionate-cerf-eynfn6

Conversation

@azalio

@azalio azalio commented Jul 18, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds src/mapify_cli/grace_eval/ package implementing the data contracts and deterministic sweep logic for the GRACE semantic code-contract anchor evaluation (issue [GRACE] Add semantic code-contract anchor eval for bug-fix workflows #339, slice 1).
  • No external model calls in this slice — purely data layer + heuristic sweep.
  • 97 tests covering schema round-trips, validation, aggregation, and sweep detection.

Changes

src/mapify_cli/grace_eval/schema.py

Data contracts (contract-first pattern, all consumers import from here):

  • GraceFixture — fixture.json schema (fixture_id, title, description, bug_summary, expected_changed_files, tags)
  • VariantRunRecord — per-run JSONL row (success, retry_count, total_tokens, output_tokens, repeated_reads, stale_detection, error)
  • VariantAggregate — rolled-up stats per variant with vs-baseline delta fields and trajectory_delta_note (improvement/regression/tie/no_baseline)
  • SweepFinding — frozen dataclass for one stale/contradictory contract detection (severity, location, detail, variant)
  • GraceReport — root report object (aggregates list, sweep_findings, schema_version, generated_at)
  • Six canonical variants: baseline, inline, lex, min, inj, lie; classified into CODE_LOCAL_VARIANTS, PROMPT_INJECTED_VARIANTS, NO_ANCHOR_VARIANTS
  • aggregate_runs() — computes success_rate, mean_retries, mean_total_tokens, stale_detections, and trajectory delta vs baseline
  • make_run_id() — deterministic run identifier

src/mapify_cli/grace_eval/sweep.py

Heuristic stale-anchor detection (pure, no I/O, no subprocess):

  • Recognises # CONTRACT: <claim> and # ANCHOR: <claim> comment patterns (case-insensitive)
  • 7 contradiction signal pairs (e.g. "never returns none" + return None, "idempotent" + .append()
  • 8-line lookahead window to limit false-positive blast radius
  • sweep_source() — sweeps a single source string, returns SweepFinding list
  • sweep_variant_sources() — aggregates across a {location: source} dict

src/mapify_cli/grace_eval/__init__.py

Re-exports all public symbols.

tests/test_grace_eval_schema.py + tests/test_grace_eval_sweep.py

97 tests across 16 test classes (GE1–GE9, GS1–GS7). Cover variant enumeration, all to_dict/from_dict round-trips, JSON serialisability, validation errors, aggregate_runs stats, baseline delta computation, anchor extraction, contradiction detection, false-positive guard, multi-file sweep aggregation, and invalid-variant rejection.

docs/ARCHITECTURE.md

Marks #339 closed (slice 1) with PR reference.

Closes

Resolves #339 (slice 1). Future slices: CLI entry point (mapify grace-eval run/report), token-log replay, model-call dispatcher, HTML report viewer.


Generated by Claude Code

Pure data + deterministic-logic layer for the GRACE eval harness.
No external model calls in this slice.

- grace_eval/schema.py: GraceFixture, VariantRunRecord, VariantAggregate,
  SweepFinding, GraceReport, aggregate_runs(), make_run_id() — six variants
  (baseline, inline, lex, min, inj, lie) with variant-set classification,
  per-run JSONL row schema, rolled-up stats, and vs-baseline delta notes
  (improvement/regression/tie/no_baseline).
- grace_eval/sweep.py: sweep_source() / sweep_variant_sources() —
  heuristic stale-anchor detection via CONTRACT/ANCHOR comment patterns
  with 7 contradiction signal pairs and an 8-line lookahead window.
- 97 tests across test_grace_eval_schema.py + test_grace_eval_sweep.py.
- docs/ARCHITECTURE.md: mark #339 closed (slice 1).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011jmbBkJwJByEJGXFAihgh8
@azalio
azalio merged commit a560a06 into main Jul 18, 2026
1 check passed
@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@azalio, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 52 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 35a56050-4d88-4a1f-b8c2-31240bb6a3b2

📥 Commits

Reviewing files that changed from the base of the PR and between 7e80fd8 and acbbe5d.

📒 Files selected for processing (6)
  • docs/ARCHITECTURE.md
  • src/mapify_cli/grace_eval/__init__.py
  • src/mapify_cli/grace_eval/schema.py
  • src/mapify_cli/grace_eval/sweep.py
  • tests/test_grace_eval_schema.py
  • tests/test_grace_eval_sweep.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/compassionate-cerf-eynfn6

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

[GRACE] Add semantic code-contract anchor eval for bug-fix workflows

2 participants