Skip to content

Widen the origin-retention walk to every visited commit, not just the tip - #999

Merged
brettheap merged 3 commits into
mainfrom
fix/849-refuse-guard-range
Sep 12, 2026
Merged

brettheap merged 3 commits into
mainfrom
fix/849-refuse-guard-range

Conversation

@brettheap

@brettheap brettheap commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Lane: openxfactory-2 (openXfactory-2)

What. The origin-retention walk (ratifying_commit / ratified_under_a_former_path in scripts/proposal-support.py) now asks its "was this a move from an already-ratified path" question of EVERY commit it visits while resolving a change's ratifying commit, not only the commit whose own blob happens to declare Status: ratified. Where that commit's own blob IS ratified, the check still runs with kinds="RC" exactly as before (a move or copy landing already-ratified still refuses). Where it is NOT ratified, the check now also runs, restricted to kinds="R" (true renames only, never copies).

Why. PR #846 addressed #833 (a ratified packet renamed afterwards) but left one shape open, filed as #849: a commit that renames an already-ratified packet AND un-ratifies the destination in the same commit is never a "candidate" (its own blob isn't ratified), so it was skipped, and a later, pairing-free re-ratification commit was accepted as the baseline instead — later than the real ratification, waving through any origin mutation made in between. #846 pinned this as a stated gap via test_an_unratifying_rename_escapes_the_guard_a_stated_gap, asserting NO refusal. Copies are deliberately excluded from the broadened check: a copy that lands short of ratified and is ratified later is indistinguishable, by history alone, from a packet honestly authored as a new draft copied from a ratified one (the former path survives either way) — only a true rename (the former path gone) can safely be told apart from ordinary authoring, so only renames are widened here. This keeps the fork-by-copy case archivable, exactly as the pre-existing docstring reasoning required.

How verified.

Follow-up. A multi-hop rename-chain gap raised in Copilot's review (a rename+un-ratify hop followed by a separate later rename, then ratification) is out of this PR's scope and is tracked as #1003.

refs #849, #833, #846

🤖 Generated with Claude Code

Summary by Sourcery

Broaden origin-retention checks across every visited commit while limiting the new history validation to true renames.

Bug Fixes:

  • Extend origin-retention validation to detect ratified packets that are renamed and un-ratified before being re-ratified, preventing a later re-ratification from being incorrectly used as the baseline.

Enhancements:

  • Support restricting rename detection to true renames while preserving existing move-or-copy checks for ratified destinations.
  • Keep draft fork-by-copy workflows archivable by excluding copies from the broadened non-ratified history walk.

Tests:

  • Add coverage for the previously missed un-ratifying rename scenario and verify the refusal identifies the rename commit.
  • Add regression coverage ensuring a draft copied from a ratified packet remains archivable.
  • Consolidate shared origin-retention refusal assertions across related tests.

… tip

The #833 refuse guard (ratifying_commit / ratified_under_a_former_path)
only asked ratified_under_a_former_path about the commit whose OWN blob
declares Status: ratified. A commit that renames an already-ratified
packet AND un-ratifies the destination in the same commit is never such
a candidate, so it was skipped, and a later, pairing-free re-ratification
commit was accepted as the baseline instead -- later than the real
ratification, waving through any origin mutation in between. That is
#833's failure reached by a longer route, and PR #846 left it as a
stated gap pinned by test_an_unratifying_rename_escapes_the_guard_a_stated_gap.

ratifying_commit now calls ratified_under_a_former_path for every commit
its walk visits, not only the one that declares ratified: kinds="RC"
(unchanged) where the commit's own blob is ratified, kinds="R" (new,
renames only) where it is not. Restricting the broadened case to true
renames -- never copies -- keeps a packet honestly authored as a draft
copy of an already-ratified one archivable: only a rename destroys the
former path outright, so only a rename can be told apart from ordinary
authoring by history alone. The refusal message is reworded to stay
truthful whether or not the flagged commit itself declares ratified,
while keeping every substring the existing #833 tests assert on.

test_an_unratifying_rename_escapes_the_guard_a_stated_gap is repurposed
into test_an_unratifying_rename_now_refuses_the_walk, asserting the walk
now raises OriginRetentionError naming the rename commit rather than the
re-ratification. All other origin-retention fixtures (happy path,
draft rename then ratify, squash rename+ratify, copy into an
already-ratified destination, hostile git config) are unchanged.

refs #849, #833, #846

Lane: openxfactory-2
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Copilot AI lite review requested due to automatic review settings September 12, 2026 02:23
@sourcery-ai

sourcery-ai Bot commented Sep 12, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR closes the #849 origin-retention gap by checking every visited commit, using rename-only detection for non-ratified hops so un-ratifying renames cannot hide behind later re-ratification while legitimate copy-based forks remain archivable; tests update the former gap fixture to verify the refusal and propagation behavior.

Sequence diagram for widened origin-retention commit walk

sequenceDiagram
    participant Walk as ratifying_commit
    participant Guard as ratified_under_a_former_path
    participant Git as renamed_from

    loop Every visited commit
        Walk->>Walk: declares_ratified(blob)
        alt commit declares ratified
            Walk->>Guard: ratified_under_a_former_path(revision, rel, kinds=RC)
        else commit is not ratified
            Walk->>Guard: ratified_under_a_former_path(revision, rel, kinds=R)
        end
        Guard->>Git: renamed_from(revision, rel, kinds)
        Git-->>Guard: former path or None
        Guard-->>Walk: former path or None
        alt former path found
            Walk-->>Walk: raise OriginRetentionError
        else ratified commit with no former path
            Walk-->>Walk: return revision
        end
    end
Loading

Flow diagram for rename-only protection of un-ratifying commits

flowchart TD
    A[Walk a commit in the packet history] --> B{Commit blob declares ratified?}
    B -->|Yes| C[Check ratified_under_a_former_path with kinds=RC]
    B -->|No| D[Check ratified_under_a_former_path with kinds=R]
    C --> E{Former path found?}
    D --> E
    E -->|Yes| F[Raise OriginRetentionError]
    E -->|No| G{Commit is ratified?}
    G -->|Yes| H[Accept commit as ratification baseline]
    G -->|No| I[Continue to the next visited commit]
    D -.-> J[Copies excluded for non-ratified hops]
Loading

File-Level Changes

Change Details Files
Broaden origin-retention validation to inspect every commit in the walked history while preserving separate rename and copy handling.
  • Add optional kinds filters to rename detection helpers, retaining RC as the default.
  • Run RC checks for commits whose blob is ratified and R-only checks for non-ratified commits.
  • Raise origin-retention errors at an un-ratifying rename before a later pairing-free re-ratification can become the baseline.
  • Keep draft-copy fork scenarios exempt from the broadened check.
scripts/proposal-support.py
Replace the issue #849 gap fixture with regression coverage for the newly refused history shape.
  • Construct a ratify, mutate, rename-and-un-ratify, then re-ratify sequence.
  • Assert the rename commit—not the later re-ratification—is reported and that CLI/archive paths propagate the error.
  • Retain assertions for the relevant origin-retention, baseline, former-ID, and issue references.
tests/proposal-support/test_proposal_support.py

Assessment against linked issues

Issue Objective Addressed Explanation
#833 Prevent the origin-retention walk from silently selecting a later commit as the ratification baseline when a ratified change is renamed, including renames that also un-ratify the destination. ✅
#833 Refuse origin-retention validation with a named error instead of allowing post-ratification mutations to pass when the ratified packet moved to a different path. ✅

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

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.

🟡 Changes recommended

Outstanding history-chain, copy-path coverage, messaging, and helper API findings remain.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

This PR broadens origin-retention validation to reject already-ratified packets renamed and un-ratified before later re-ratification.

Changes:

  • Checks non-ratified commits for true renames.
  • Preserves draft fork-by-copy behavior.
  • Adds regression coverage for issue #849.
File summaries
File Findings
scripts/proposal-support.py Moderate (2 votes): Add end-to-end coverage for copied-as-draft packets later ratified.
Moderate (1 vote): Follow the complete rename chain and add multi-hop coverage.
Nit (1 vote): Make refusal messaging distinguish renames from copies.
Nit (1 vote): Make kinds keyword-only in renamed_from.
Nit (1 vote): Apply the same keyword-only contract to the second helper.
tests/proposal-support/test_proposal_support.py Moderate (1 vote): Add coverage confirming copied-as-draft packets can later be ratified and archived successfully.
Review details

Suppressed comments (5)

scripts/proposal-support.py:853

  • When ratified_here is false this call uses kinds="R", so former can only come from a true rename. The shared message still calls the commit a MOVE OR COPY and infers a copy from a surviving former path; a later commit can recreate that old path, so this diagnosis is false for the new #849 case and obscures the deliberate copy-vs-rename distinction. Make the refusal text conditional on the detected kind and omit the copy deduction for rename-only refusals.
                f"(`{rel}`), and {short} is a MOVE OR COPY of that ratified "
                f"packet rather than its ratification, whatever `{rel}` "
                f"itself declares as of {short} — and if `{former}` still "
                f"stands in the tree then the packet was COPIED to this id "
                f"rather than moved to it, which git pairs the same way and "

scripts/proposal-support.py:840

  • This calls the guard for every revision in listed, but listed is still produced by git log ... -- <rel> without --follow, so the revision set stops at the first rename. A ratified packet moved A→B while being un-ratified, then moved B→C while still draft and finally ratified at C will visit only the B→C hop; its source is draft, so this returns no former path and the later C ratification remains the baseline. Enumerate the full rename chain (or otherwise retain predecessor paths) and add a multi-hop fixture so an earlier ratified rename cannot bypass the guard.
        former = ratified_under_a_former_path(
            root, revision, rel, kinds="RC" if ratified_here else "R")

scripts/proposal-support.py:574

  • The PR contract describes kinds as keyword-only, but this signature still accepts positional calls such as renamed_from(root, revision, rel, "R"). Add the keyword-only separator so the new optional filter cannot become an accidental positional API and the helper matches the stated compatibility contract.
def renamed_from(root: Path, revision: str, rel: str,
                 kinds: str = "RC") -> str | None:

scripts/proposal-support.py:672

  • This second helper has the same mismatch with the stated keyword-only contract: kinds is currently positional-or-keyword. Keep the new filter explicitly keyword-only here as well, consistently with the caller and the other helper.
def ratified_under_a_former_path(root: Path, revision: str, rel: str,
                                 kinds: str = "RC") -> str | None:

tests/proposal-support/test_proposal_support.py:1682

  • The new rename-only branch is justified by preserving lawful fork-by-copy authoring, but this replacement test covers only rename-plus-unratify. The existing copy test keeps the destination ratified and therefore exercises the unchanged RC path. Add a fixture that copies a ratified packet into a new id as draft and ratifies it later, asserting the walk/archive succeeds; otherwise regressing this branch to RC would make that promised case unarchivable without a failing test.
        `ratifying_commit` now asks EVERY commit it visits, not only the one
        whose own blob declares `ratified`, so the rename-and-un-ratify
        commit answers the question before the re-ratification is ever
        reached, and refuses there instead — naming the RENAME commit, not
        the pairing-free re-ratification a caller might otherwise suspect.
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

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

Comment thread scripts/proposal-support.py Resolved
…ity case

Two fix-round items, both confined to the guard's tests.

SonarCloud flagged 9.3% duplication on new code (gate: <=3%). The
un-ratifying-rename regression test (test_an_unratifying_rename_now_
refuses_the_walk) asserted the same "walk refuses, names the right
commit, origin_retention_errors and archive_change both stop" shape as
the pre-existing test_a_ratified_change_renamed_afterwards_refuses_the_
walk, nearly line for line -- the two differ only in which commit the
message must name and one #849-only substring. Both now call a new
shared helper, assert_walk_refuses, that asserts the common shape once;
each caller passes only what is actually different.

Copilot's outstanding review thread on the kinds="R" branch (added to
close #849): the sibling copy test, test_a_ratified_packet_copied_to_a_
new_id_refuses_too, copies a destination that is ALREADY ratified at
the copy commit, so it exercises the kinds="RC" arm and would still
pass even if the kinds="R" arm were accidentally widened back to
"RC" -- which would make a lawful fork-by-copy (a new packet authored
as a draft copy of a ratified one, ratified later) unarchivable, the
exact failure ratified_under_a_former_path's own docstring says that
arm exists to avoid. Added
test_a_ratified_packet_copied_as_a_draft_and_ratified_later_is_not_
refused: copies a ratified packet, flips the copy back to draft in the
same commit, ratifies it later, and asserts the walk does not refuse.
Verified against a local mutation (kinds="RC" unconditionally): the new
fixture fails on it while the existing copy test still passes, then both
pass again once the mutation is reverted.

Neither change touches scripts/proposal-support.py (unmodified from
99adaa9) or what the guard refuses; the CLI contract is unchanged.
Confirmed test_an_unratifying_rename_now_refuses_the_walk still fails
against origin/main's pre-#849-fix guard ("OriginRetentionError not
raised") and passes against this branch's guard.

refs #849, #833, #846

Lane: openxfactory-2
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Copilot AI review requested due to automatic review settings September 12, 2026 03:11

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.

🟡 Changes recommended

The retention walk misses earlier renames in a rename chain, and API and diagnostic issues remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Review details

Suppressed comments (2)

scripts/proposal-support.py:672

  • This companion signature has the same mismatch: kinds is described as keyword-only, but callers can pass it positionally. Add * before kinds so both helper APIs enforce the documented calling convention.
def ratified_under_a_former_path(root: Path, revision: str, rel: str,
                                 kinds: str = "RC") -> str | None:

scripts/proposal-support.py:846

  • The new refusal diagnostic says carries ... in from ..., which is malformed and makes the source/destination relationship harder to parse for operators. Remove in so the message reads as carrying the current path from the former path.
                f"origin-retention walk CANNOT RUN. Commit {short} carries "
                f"`{rel}` in from `{former}`, which already declared "
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Lite

Comment thread scripts/proposal-support.py Resolved
Comment thread scripts/proposal-support.py Resolved
Copilot review on PR #999: the PR description states kinds is
keyword-only, but both signatures still accepted it positionally as a
fourth argument -- inconsistent with origin_errors(..., *, strict) in
this same module, which does enforce its own keyword-only boundary.
Every existing call site already passes kinds=... by keyword or omits
it (grepped scripts/ and tests/), so adding the `*` separator to both
renamed_from and ratified_under_a_former_path is a pure API-boundary
tightening with no behavioural change: full module test run is
unaffected (85 passed, 67 subtests passed).

refs #849

Lane: openxfactory-2
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Copilot AI review requested due to automatic review settings September 12, 2026 03:22

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.

🔵 Needs a closer look

The moderate contract issue remains unresolved.

Review details

Suppressed comments (2)

scripts/proposal-support.py:840

  • This broadened call changes the no-ratification contract: a history like ratified change-r → true rename to change-s + draft, with no later re-ratification, now raises OriginRetentionError at the rename. That contradicts ratifying_commit's documented ... or None when no commit ... result and makes origin_retention_errors use the moved-path refusal instead of its not ratified arm. Either defer the broadened refusal until a later ratification is found, or update the function/caller contract and add a regression test documenting this intentional behavior.
        former = ratified_under_a_former_path(
            root, revision, rel, kinds="RC" if ratified_here else "R")

scripts/proposal-support.py:731

  • This new exception for a copy that enters as draft and is ratified later contradicts the public archive contract in docs/document-lifecycle.md:453-456, which currently says that copying a ratified packet to a second id refuses identically without qualification. Please update that documentation to distinguish a copy that lands ratified (still refused) from a fork-by-copy that lands draft (now allowed), so operators are not given contradictory guidance.
    default `kinds="RC"` — and a copy that enters as a draft and is ratified
    later remains the fork-by-copy this gate must not trap, exactly as
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@sonarqubecloud

Copy link
Copy Markdown

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

Sorry @brettheap, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 2 days and 2 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@brettheap
brettheap merged commit 2dd54b8 into main Sep 12, 2026
14 checks passed
@brettheap

Copy link
Copy Markdown
Contributor Author

Lane: openxfactory-2 (openXfactory-2)
LANDED — lane openxfactory-2 (openXfactory-2), 2026-09-12T14:59:17Z, PR #999 → 2dd54b8 (no Rule 6 window)
Brett Heap ${WORD_WHEN:-2026-09-11, in session, multi-choice SELECTION}, verbatim: "Land all when green and thread-free, in order". --squash --admin at head adb82cc (code-owner review cannot clear on a self-authored PR; admin merge on his word, B2 pattern).

brettheap added a commit that referenced this pull request Sep 12, 2026
origin/main moved five commits ahead of this branch's fork point,
three of which touch files this PR also declares edits on:

- #995 (9e43f3d, ASK-7 window): four declared lines on the cli.py and
  serve.py rows of docs/opendox-carve-manifest.yaml, plus the four
  scripts/tests files that quote the running "862" declared-line total
  (carve_lines.py, validate-carve-manifest.py, verify-carve-arrival.py,
  tests/carve_manifest/test_carve_manifest.py).
- #984 (a1ef886): carve tooling/admissions hardening unrelated to the
  five rows this PR touches.
- #997, #996, #999: no overlap with this PR's files.

Conflict resolution, keeping both sides:

- docs/opendox-carve-manifest.yaml: the header comment block now
  carries the ASK-7 window's paragraph (landed first, 2026-09-11) ahead
  of the § 3.4 SLICE-S3 paragraph (2026-09-12), in landing order. The
  S3 paragraph's own arithmetic is untouched (it was already stated as
  a DELTA — "+40 over two rows" — precisely so a later-landing sibling
  act would not need to rewrite it); only its framing of the ASK-7
  window changed from "is in flight" to "already moved the running
  total to 866", since this merge is the event that makes ASK-7's
  landing a fact rather than a future one. The four ASK-7 row edits
  (cli.py:834, serve.py:155/725/1338) and the two S3 row edits
  (app.js's 37 lines, test_bullseye_widget.py's 3 lines) are all kept.
- scripts/carve_lines.py, scripts/validate-carve-manifest.py,
  scripts/verify-carve-arrival.py: each had a single docstring line
  citing the running declared-line total — "866" from main (ASK-7),
  "902" from this branch (which assumed the pre-ASK-7 base of 862).
  Corrected to 906 in all three: 866 (post-ASK-7) + 40 (this act's
  own delta) = 906, matching the pinned test assertion.
- tests/carve_manifest/test_carve_manifest.py: merged both narrative
  additions to test_the_real_manifest_carries_the_ruled_q_l7_amendment
  in landing order (ASK-7 then S3), corrected the final aggregate
  assertion from this branch's stale (902, 151) to (906, 151), kept
  main's per-row pinned ASK-7 checks (cli_row/serve_row) verbatim, and
  fixed their comment's citation of the aggregate from (866, 150) to
  (906, 151) to match the corrected assert two lines above. Also fixed
  a second, non-conflicting docstring in
  test_the_line_count_is_exactly_the_expression_the_validator_carried
  that still read "902".

A pre-existing defect, unrelated to the conflict, found while
resolving: the test_bullseye_widget.py row's two edits (already on
this branch's HEAD before any merge, commit 6843a25) had a blank line
splicing them apart, which left the `adapter calls` edit's `note:` key
duplicated with the `path constants` edit's original note — YAML
silently keeps the last of a duplicate key, so the S3 note was
silently discarded and the wrong note landed on the wrong edit.
Confirmed with a duplicate-key-aware loader before and after. Fixed by
restoring each edit's own note; a full-document duplicate-key scan
afterward finds none remaining anywhere in the manifest.

Verified after resolution:
- python3 scripts/validate-carve-manifest.py: OK, 456 rows, 168
  moved_verbatim / 150 moved_with_declared_edit / 138 not_moved.
- python3 scripts/verify-carve-arrival.py --destination opendox_code
  --phase B against openDox-code PR #14's head (09b42f5b): DECLARED
  src/opendox/web/app.js, DECLARED tests/test_bullseye_widget.py, 0
  refusals (three newly-created files admitted ad hoc for this local
  check only: src/opendox/view_extension.py,
  src/opendox/web/views/view_extension.js, tests/test_view_registry.py
  — the governed admissions-file entries for those belong to the
  pin-bump PR that follows #14's own landing, not this row-annotation
  PR). The one "unapplied" declared-edit row the summary counts is
  scripts/ideation_dashboard/doxbench_scope_types.py, an unrelated
  pre-existing row (successor #838, open at the carve) — not S3.
- pytest tests/carve_arrival tests/carve_manifest tests/carve_conformance -q:
  269 passed (121 + 110 + 38).

Lane: openxfactory-4-opendox-extraction
Refs #656

Co-Authored-By: Claude Sonnet 5 <[email protected]>
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.

2 participants