Skip to content

Refuse a --previous-report stamped under a foreign repo identity (#342) - #531

Merged
brettheap merged 1 commit into
mainfrom
fix/342-previous-report-identity
Aug 31, 2026
Merged

brettheap merged 1 commit into
mainfrom
fix/342-previous-report-identity

Conversation

@brettheap

Copy link
Copy Markdown
Contributor

Mechanism (verified before designing the fix)

Finding identity is (family, repo, path) (Finding.match_key), and for
--single-repo <path> the repo component is the directory basename
(runner.build_context). Nothing tied a written report to the identity its
run covered, and nothing checked one on the way back in. Point
--previous-report at a baseline built under a different basename and every
finding key misses: regressions() reads every current critical/error
finding as new, and uncited_resolutions() reads every baseline contested
finding as vanished without citation — 36 phantom regressions and 23
phantom uncited-resolution errors in the issue's own PR #333
reproduction, exit code 0 throughout.

Fix

Write side — every report is stamped with the repo(s) its run covered: a
Repo-Identity: <slug>[, <slug>...] header line beside Status:/Kind:
(sorted, comma-separated; (none) for an explicit empty set), emitted by
report.render's new repo_slugs keyword and read back by the new
report.parse_repo_identity. Neither the doc-health spec's "Health report
contract" requirement nor
specs/022-modified-block-currency-reporting/contracts/report-section.md
(the one byte-level report contract in this repo) enumerates the top header
line-for-line, so this is not a contract violation — both were read before
writing this.

Read side, the identity rule (runner.main) — every repo the current
run covers must already be a member of the baseline's stamped identity:
current_repo_slugs <= previous_repo_slugs. This generalizes the
single-repo case ("the slug must be IN the baseline's set") to an
aggregation run ("equality or subset"), reasoned from how the two
comparison rules key: a repo the current run has that the baseline never
scanned makes every one of that repo's critical/error findings miss
previous_keys by construction (regressions()) — the exact
phantom-regression mechanism the issue reports, with a foreign-basename
baseline as the disjoint-sets instance of the same rule. A violation
REFUSES: runner.main exits nonzero with REFUSE previous-report-identity-mismatch: ... naming both stamped identities and
the uncovered repo(s), styled after verify-openxwallet-pin.py's
fail-closed refusals.

The mirror direction — the baseline knows a repo the current run does
not (a proper superset, which the subset rule accepts) — is closed
separately: uncited_resolutions gained an unavailable_repos parameter so
a contested finding for a repo outside the run's scope is never read as
resolved just because this run never looked at it (fix-shape item 3 of the
issue).

Backward compatibility

A --previous-report carrying no Repo-Identity: stamp (every report in
health/reports/*.md as of 2026-08-31) is accepted exactly as today, with
one [repo-identity] WARNING line on stderr naming the gap — the nightly
does not break the night this lands, and phases in as reports become
stamped.

Tests

tests/doc-health/test_suite.py, +8 tests:

  • the stamp round-trips through render → parse (sorted, positioned before
    ## Headline)
  • the stamp is omitted (byte-identical output) when repo_slugs is not
    passed, and reads back as None — never confused with an explicitly
    empty, stamped set (frozenset() via (none))
  • a foreign-identity baseline reproduced in the issue's own shape — a repo
    built under directory basename base-wt, diffed by a run over a checkout
    named openxFactory — REFUSES, names both identities, writes no report
  • matching identity compares normally
  • an unstamped legacy baseline is accepted with a warning and reproduces the
    exact outcome of the pre-existing
    test_full_run_still_fires_uncited_resolution_when_genuinely_resolved
    (behaviour unchanged)
  • a superset baseline is accepted but does not manufacture a resolution for
    the repo outside the run's scope, while a repo inside scope still owes its
    citation

python3 -m pytest tests/doc-health -q: 1339 passed on the unmodified
worktree (baseline), 1347 passed after (1339 + 8 new, zero
regressions).

Real-corpus sanity

Ran scripts/doc-health.py --single-repo . --family location-conformance --previous-report <xFactory root's committed health/reports/2026-08-26.md, origin/main> from a detached worktree of this branch named openxFactory
(basename matters — the issue is about exactly that). That baseline
predates this change and carries no stamp, so the legacy path fires: one
[repo-identity] WARNING line on stderr, exit code 0, and the Findings By Family / Ranked Plan sections byte-identical to a parallel run of
unmodified origin/main code against the same corpus and baseline (0
critical, 12 error, 0 warning, 0 info; 12 regressions — pre-existing corpus
drift since 2026-08-26, unrelated to and unaffected by this change).

Docs / spec

  • docs/doc-health.md: added a sentence on the identity stamp and the
    refusal under "Finding Severities" (beside the existing regression rule)
    and in "Report Contract" describing report contents.
  • openspec/specs/doc-health/spec.md's "Health report contract" and
    "Finding severity and regression handling" requirements were read and do
    not enumerate the header byte-level or otherwise constrain this — no
    ratified scenario conflicts, so no OpenSpec change was needed for this
    fix.

Closes #342

🤖 Generated with Claude Code

Mechanism (verified before designing the fix): finding identity is
`(family, repo, path)` (`Finding.match_key`), and for `--single-repo <path>`
the `repo` component is the directory BASENAME (`runner.build_context`).
Nothing tied a written report to the identity its run covered, and nothing
checked one on the way back in. Point `--previous-report` at a baseline
built under a different basename and every finding key misses:
`regressions()` reads every current critical/error finding as new, and
`uncited_resolutions()` reads every baseline contested finding as vanished
without citation — 36 phantom regressions and 23 phantom
`uncited-resolution` errors in the issue's own PR #333 reproduction, exit
code 0 throughout. A benign operator path/scope slip reported in the
vocabulary of the family's most serious findings.

Fix, write side: every report is now stamped with the repo(s) its run
covered — a `Repo-Identity: <slug>[, <slug>...]` header line beside
`Status:`/`Kind:` (sorted, comma-separated; `(none)` for an explicit empty
set), emitted by `report.render`'s new `repo_slugs` keyword and read back by
the new `report.parse_repo_identity`. Neither the `doc-health` spec's
"Health report contract" requirement nor
`specs/022-modified-block-currency-reporting/contracts/report-section.md`
(the one byte-level report contract in this repo) enumerates the top header
line-for-line, so adding one line is not a contract violation; both were
read before this was written.

Fix, read side, the identity rule (`runner.main`): every repo THIS run
covers must already be a member of the baseline's stamped identity —
`current_repo_slugs <= previous_repo_slugs`. This is the single-repo case
("the slug must be IN the baseline's set") generalized to an aggregation run
("equality or subset"), reasoned from how the two comparison rules key: a
repo the current run has that the baseline never scanned makes every one of
that repo's critical/error findings miss `previous_keys` by construction
(`regressions()`), which is the exact phantom-regression mechanism the issue
reports — a foreign-basename baseline is the disjoint-sets instance of this
same rule. A violation REFUSES: `runner.main` exits nonzero with a message
naming both stamped identities and the uncovered repo(s) (`REFUSE
previous-report-identity-mismatch: ...`), styled after
`verify-openxwallet-pin.py`'s fail-closed refusals. The mirror direction —
the baseline knows a repo THIS run does not (a proper superset, which the
subset rule accepts) — is closed separately: `uncited_resolutions` gained an
`unavailable_repos` parameter so a contested finding for a repo outside this
run's scope is never read as resolved just because this run never looked at
it (fix-shape item 3 of the issue).

Backward compatibility: a `--previous-report` carrying no `Repo-Identity:`
stamp (every report in `health/reports/*.md` as of 2026-08-31, and every
report this change's own tests build without passing `repo_slugs`) is
accepted exactly as today, with one `[repo-identity] WARNING` line on
stderr naming the gap — so the nightly does not break the night this lands,
and phases in as reports become stamped.

Tests (tests/doc-health/test_suite.py, +8): stamp round-trips through
render -> parse (sorted, positioned before "## Headline"); the stamp is
omitted (byte-identical output) when `repo_slugs` is not passed, and reads
back as `None` (never confused with an empty set, which round-trips as
`frozenset()` via the explicit `(none)` spelling); a foreign-identity
baseline reproduced in the issue's own shape — a repo built under directory
basename `base-wt`, diffed by a run over a checkout named `openxFactory` —
REFUSES with both identities named and writes no report; matching identity
compares normally; an unstamped legacy baseline is accepted with a warning
and reproduces the exact outcome of the pre-existing
`test_full_run_still_fires_uncited_resolution_when_genuinely_resolved`
(behaviour unchanged); a superset baseline is accepted but does not
manufacture a resolution for the repo outside the run's scope, while a
repo inside scope still owes its citation. `python3 -m pytest tests/doc-health
-q`: 1339 passed on the unmodified worktree (baseline), 1347 passed after
(1339 + 8 new, zero regressions).

Real-corpus sanity: ran `scripts/doc-health.py --single-repo . --family
location-conformance --previous-report <xFactory root's committed
health/reports/2026-08-26.md, origin/main>` from a detached worktree of
this branch named `openxFactory` (basename matters — the issue is about
exactly that). That baseline predates this change and carries no stamp, so
the legacy path fires: one `[repo-identity] WARNING` line on stderr, exit
code and finding counts unchanged from the pre-fix behaviour.

docs/doc-health.md: added a sentence on the identity stamp and the refusal
under "Finding Severities" (beside the existing regression rule) and in the
"Report Contract" section describing report contents.

Closes #342

Co-Authored-By: Claude Fable 5 <[email protected]>
Copilot AI lite review requested due to automatic review settings August 31, 2026 10:27

@sourcery-ai sourcery-ai 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.

Hi @brettheap! 👋

Your private repo does not have access to Sourcery.

Please upgrade to continue using Sourcery ✨

Copilot AI 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.

Pull request overview

This PR hardens doc-health.py --previous-report comparisons by stamping each report with the repo identity (repo slug set) it was generated under and refusing comparisons when a stamped baseline does not cover the current run’s scope, preventing phantom regressions and uncited-resolution errors caused by identity mismatches.

Changes:

  • Add Repo-Identity: header stamping in report.render() plus parsing via report.parse_repo_identity().
  • Enforce baseline identity compatibility in runner.main (current_repo_slugs <= previous_repo_slugs), with backward-compatible warnings for unstamped legacy baselines.
  • Prevent uncited_resolutions() from manufacturing resolutions for repos outside the current run’s scope (unavailable_repos), plus add tests and docs.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
tests/doc-health/test_suite.py Adds regression tests covering repo-identity stamping, backward compatibility, refusal behavior, and unavailable-repo suppression.
scripts/doc_health/runner.py Computes current repo identity, parses baseline identity, refuses mismatches, warns on legacy baselines, and threads unavailable_repos + repo_slugs.
scripts/doc_health/report.py Introduces identity stamp constants + parsing, adds unavailable_repos exclusion to uncited_resolutions, and stamps reports during render.
docs/doc-health.md Documents the new identity stamp and refusal behavior in the doc-health report contract/behavior overview.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +343 to +345
m = REPO_IDENTITY_RE.search(text)
if not m:
return None
assert report.parse_repo_identity(text) is None


def test_render_stamps_an_explicit_empty_repo_set_as_none_not_absent():
@brettheap
brettheap merged commit 95a22a4 into main Aug 31, 2026
4 checks passed
@brettheap
brettheap deleted the fix/342-previous-report-identity branch August 31, 2026 11:47
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.

doc-health accepts a --previous-report from a different repo identity, turning a path slip into phantom regressions and uncited-resolution errors

2 participants