Skip to content

feat(guardian): give the finder diff-check's dependants as leads (flagged) - #736

Merged
zaebee merged 5 commits into
mainfrom
feat/733-guardian-diff-check-context
Oct 22, 2026
Merged

zaebee merged 5 commits into
mainfrom
feat/733-guardian-diff-check-context

Conversation

@zaebee

@zaebee zaebee commented Oct 22, 2026

Copy link
Copy Markdown
Owner

Implements the change in #733. The flag stays off: the pre-registered evaluation in #733 decides whether production turns it on. This PR does not close #733.

Change

  • Flag: GUARDIAN_FEATURES=diff_check.
  • Collector: GraphContextCollector.collect_dependants runs check_database from the PR's merge base (SourceCollector.merge_base) to HEAD.
    • Results are capped at 15 in diff-check's own ranking: score first, then the fixed kind order.
    • The section is added only when there are items.
    • Any failure (no graph, no merge base, a range git cannot read) logs a warning and drops the section. The review still runs.
  • Prompt, section 8: "code outside this diff that depends on it". It tells the finder these are leads, not findings: raise one only with a nameable breakage, anchored on a line of the diff.
    • Without the key the prompt is byte-identical.
  • Workflow: ingests with --data-keys exactly when diff_check is in vars.GUARDIAN_FEATURES. A test runs the step's real shell with a stand-in uv for 5 values, and it fails with the case removed.
  • Boundaries: guardian adds no storage import (the surface-storage gate caught the first draft).

Deviation from the issue text

#733 said callers before key sites. I kept diff-check's existing ranking instead (score, then the fixed kind order). That ranking is the one measured in the data-key lab note, and re-ranking it here would change two things at once.

Not covered yet

  • Chunked mode (collect_for_chunk) does not carry the section.
  • guardian_martian still ingests without data keys. The Martian regression guard will rebuild those graphs with --data-keys as part of the experiment.

Checks

  • tests/unit/test_guardian_dependants.py: 7 tests. The caller of a changed function is listed, and the flag-off, no-graph and bad-range cases add nothing.
  • Workflow tests, all guardian and review-fingerprint unit tests, and tests/self_parsing: 1151 passed.
  • mypy clean.

🤖 Generated with Claude Code

…gged)

A new GUARDIAN_FEATURES value, `diff_check` (#733), off by default. The
collector runs diff-check from the PR's merge base to HEAD on the review's
graph and adds a prompt section, "code outside this diff that depends on
it": callers, subclasses and other readers or writers of changed data keys,
capped at 15 in diff-check's own ranking. The finder is told these are leads,
to be raised only with a nameable breakage anchored on a diff line.

- Any failure (no graph, no merge base, a range git cannot read) costs the
  section, never the review. Without the flag the prompt is unchanged.
- It goes through check_database, so guardian gains no storage edge.
- guardian.yml ingests with --data-keys exactly when the feature is set;
  a test runs the step's own shell with a stand-in `uv` for five values.

The pre-registered evaluation in #733 decides whether it is switched on.
Chunked mode does not carry the section yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new 'diff_check' feature to the guardian service, which identifies and reports code outside the current diff that depends on the modified data keys. The changes include updates to the collector and prompt builder to support this feature, as well as comprehensive unit tests. My review highlights two areas for improvement: ensuring robustness against missing system dependencies by catching OSError in subprocess calls, and improving environment variable handling in tests to avoid potential failures on different platforms.

Comment thread src/cgis/guardian/collector.py
Comment thread tests/unit/test_guardian_workflow.py Outdated
zaebee and others added 2 commits October 22, 2026 10:37
Sonar's new-code coverage was 77.4% (gate 80): DiffError, an unexpected
error and an empty report each now have a test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ator hints

Review of #736:
- The section is rendered here, not by diff-check's terminal text: paths are
  repo paths as in the diff (`src/report.py`, not `report.py`), and the MCP
  and re-ingest hints, which the finder cannot act on, are gone. It is bound
  to 6,000 characters.
- diff-check gets the ingest prefix explicitly (the graph collector's
  source_root) instead of inferring it from a recorded ingest root.
- A CI-shaped test: `pr/` cloned from an origin whose main moves on, sources
  under src/, no base_ref. It fails with the range taken from the base tip
  instead of the merge base.
- The workflow reads GUARDIAN_FEATURES as parse_features does, ignoring any
  whitespace, so a tab cannot switch the feature on without --data-keys.
- Chunked mode not carrying the section is now said in the docstring.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From Gemini's review of #736: merge_base also catches OSError, with a test;
the workflow shell test extends os.environ instead of replacing it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@zaebee

zaebee commented Oct 22, 2026

Copy link
Copy Markdown
Owner Author

/guardian review

@codegraph-brain codegraph-brain Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Summary: Checked the workflow shell feature-flag parsing against the tr/case logic and its parametrized test, the render_dependants truncation bound, the merge-base range choice (base sha to HEAD, avoiding moved-base symbols), and the best-effort exception handling; these are correct as written. The concerns raised are a test that does not reach the path it names and a silent degradation when merge-base fails.


🤖 claude-haiku-5-5 · 17,499 prompt + 3,520 completion = 21,019 tokens · graph 2/5 files (40%)

Comment thread tests/unit/test_guardian_dependants.py Outdated
Comment thread src/cgis/guardian/collector.py
Comment thread src/cgis/guardian/prompts.py
github-actions Bot added a commit that referenced this pull request Oct 22, 2026
From guardian's own review of #736 (posted as codegraph-brain[bot]):
- the dependants block sits in a text fence introduced as data extracted
  from the code under review, never instructions;
- a failed merge-base logs a warning, so an inert feature shows in CI;
- the test that covered the missing-merge-base path no longer claims to
  cover DiffError (which has its own test).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@zaebee
zaebee merged commit f7546cc into main Oct 22, 2026
4 checks passed
@zaebee
zaebee deleted the feat/733-guardian-diff-check-context branch October 22, 2026 11:08
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.

feat(guardian): give the finder diff-check's dependants as context (flagged, pre-registered)

1 participant