Skip to content

Fix archive-gate to resolve the ratified proposal by change id - #638

Merged
brettheap merged 3 commits into
mainfrom
fix/archive-gate-across-rename
Sep 4, 2026
Merged

brettheap merged 3 commits into
mainfrom
fix/archive-gate-across-rename

Conversation

@brettheap

Copy link
Copy Markdown
Contributor

Lane: openxfactory-max001

Fixes the --archive-gate crash filed in #633: it derived the ratified-side proposal path from CHANGE_DIR's CURRENT path, so once a change moved to openspec/changes/archive/<date>-<id>/ the gate asked git for that archived path at --ratified-ref (a commit before the rename) — which never existed there — and died with an unhandled CalledProcessError traceback instead of a finding.

Fix

  • change_id_of_dir derives the change id from CHANGE_DIR's name, reusing the existing ARCHIVE_DIR naming convention (active dir → id as-is; archived dir → strip the YYYY-MM-DD- prefix) rather than inventing a second convention.
  • proposal_path_at_ref locates the ratified-side proposal.md BY CHANGE ID against --ratified-ref's own tree — active path first, then any openspec/changes/archive/<date>-<id>/ — using git cat-file -e / git ls-tree only, no checkout.
  • When neither exists at the ref, it raises sequenced_after.SequencedAfterError naming the id, the ref and both paths tried; the CLI (_archive_gate) now catches that and prints a named finding with exit code 2, matching how --seed-ledger already handles this error class — never a traceback.
  • Pre-rename and absolute/relative CHANGE_DIR behaviour is unchanged (existing tests still green).
  • Docstrings/usage text updated to say the ratified-side proposal is located by change id at the ref.

New fixtures (tests/sequenced_after/test_integrity.py):

  • test_the_archive_gate_PASSES_across_the_archive_rename
  • test_the_archive_gate_FAILS_across_the_archive_rename_on_a_real_mutation
  • test_the_archive_gate_CLI_reports_a_ref_with_NO_PROPOSAL_as_a_finding_not_a_traceback

Verification

  • pytest tests/sequenced_after tests/scope_globs -q → 234 passed (231 pre-existing + 3 new)
  • python3 scripts/validate-sequenced-after.py . → passes
  • python3 scripts/validate-sequenced-after.py . --ledger-diff → consistent
  • python3 scripts/doc-health.py --single-repo . → unchanged (no docs touched)
  • Reproduction from the issue, before: traceback. After:
    $ python3 scripts/validate-sequenced-after.py . --archive-gate openspec/changes/archive/2026-09-04-add-per-change-sweep-ledger --ratified-ref 68f73e1d
    sequenced_after retention gate passed (declaration unchanged since ratification).
    

No OpenSpec change — this is a plain fix PR for a pre-existing implementation defect (not #623's or #632's), as scoped in #633.

Closes #633

🤖 Generated with Claude Code

https://claude.ai/code/session_01H9aKd8YF3ktcLmVJJxQYKv

`validate-sequenced-after.py --archive-gate` derived the ratified-side
proposal path from CHANGE_DIR's CURRENT path, so once a change moved to
openspec/changes/archive/<date>-<id>/ the gate asked git for that archived
path at --ratified-ref (a commit before the rename), which never existed
there, and died with an unhandled CalledProcessError traceback instead of
a finding.

Fix: derive the change id from CHANGE_DIR's name (change_id_of_dir, reusing
the existing ARCHIVE_DIR naming convention), then locate the ratified-side
proposal.md BY CHANGE ID against --ratified-ref's own tree
(proposal_path_at_ref: active path first, then any archived <date>-<id>
directory, via git ls-tree/cat-file -e — no checkout). When neither exists
at the ref, raise SequencedAfterError naming the id, the ref and both paths
tried; the CLI now catches that and prints a finding with exit code 2,
never a traceback.

Fixtures added to tests/sequenced_after/test_integrity.py:
- test_the_archive_gate_PASSES_across_the_archive_rename
- test_the_archive_gate_FAILS_across_the_archive_rename_on_a_real_mutation
- test_the_archive_gate_CLI_reports_a_ref_with_NO_PROPOSAL_as_a_finding_not_a_traceback

Fixes #633

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01H9aKd8YF3ktcLmVJJxQYKv
Lane: openxfactory-max001
Copilot AI lite review requested due to automatic review settings September 4, 2026 02:34

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

@brettheap

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

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 ref-side archived directory enumeration uses git ls-tree in a way that may not list child directories, which can break resolution when the proposal exists only under an archived path at --ratified-ref.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR fixes validate-sequenced-after.py --archive-gate so it can locate the ratified-side proposal.md by change id at --ratified-ref, even when the current CHANGE_DIR points to an archived location, and so “missing at ref” is reported as a named finding (exit code 2) rather than a traceback.

Changes:

  • Add change-id–based ratified proposal resolution (change_id_of_dir, proposal_path_at_ref) to keep the archive gate working across the archive rename.
  • Catch SequencedAfterError in the CLI archive-gate path and report an explicit “CANNOT RUN” finding (exit 2).
  • Add regression tests covering pass/fail across the archive rename and the “no proposal at ref” refusal behavior.
File summaries
File Description
tests/sequenced_after/test_integrity.py Adds regression tests for archive-gate behavior across the archive rename and missing-proposal-at-ref handling.
scripts/validate-sequenced-after.py Updates CLI usage text and catches SequencedAfterError in --archive-gate to emit a named finding (exit 2).
scripts/sequenced_after.py Adds change-id extraction and ratified-side proposal path resolution by id at a ref, then uses it in retention_at_archive.
Review details
  • Files reviewed: 3/3 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 on lines +660 to +668
def _archive_dir_names_at_ref(repo_root: Path, ref: str) -> list[str]:
"""Directory names directly under `openspec/changes/archive/` in `ref`'s
tree — empty when that path did not exist there yet. Read with `ls-tree`,
never a checkout."""
out = subprocess.run(
["git", "-C", str(repo_root), "ls-tree", "--name-only", ref,
"openspec/changes/archive/"],
capture_output=True, text=True,
)
Copilot review flagged (correctly worth confirming) that
_archive_dir_names_at_ref's enumeration of archived directories at a ref
was not directly exercised by the three required fixtures: all three have
--ratified-ref predate the archive rename, so proposal_path_at_ref always
resolved via the ACTIVE-path shortcut and never needed the archived-
directory enumeration branch.

Verified empirically first (git ls-tree <ref> <path>/ with a trailing
slash does enumerate the tree's children — 128 archived dirs resolved
against the real corpus at ref 68f73e1), then added a fixture where
--ratified-ref IS the archival commit itself, so the active path
genuinely does not exist there and only the archived-directory
enumeration branch can produce a pass.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01H9aKd8YF3ktcLmVJJxQYKv
Lane: openxfactory-max001
Copilot AI review requested due to automatic review settings September 4, 2026 02:45
@brettheap

Copy link
Copy Markdown
Contributor Author

Re Copilot's inline finding on _archive_dir_names_at_ref (git ls-tree not listing children): verified empirically — git ls-tree --name-only <ref> openspec/changes/archive/ with the trailing slash DOES enumerate the tree's children (non-recursive listing), not just the single archive entry. Confirmed directly against this repo's real history: it returns all 128 archived directory names at ref 68f73e1. The trailing slash is what makes ls-tree list contents rather than show the tree entry itself.

That said, none of the three required fixtures actually exercised that enumeration branch (all three have --ratified-ref predate the rename, so proposal_path_at_ref always resolved via the active-path shortcut). Added a fourth fixture, test_the_archive_gate_resolves_a_ratified_ref_that_is_ITSELF_ALREADY_ARCHIVED, where --ratified-ref is the archival commit itself so a pass can only come from the enumeration branch. Pushed in 87371ce.

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

proposal_path_at_ref can silently choose among multiple archived directories for the same change id at a ref, conflicting with the codebase’s established “ambiguity must be refused” behavior.

Review details

Suppressed comments (2)

Previously missed (2) — in code that hasn't changed since the last review.

scripts/sequenced_after.py:703

  • proposal_path_at_ref can silently pick one archived proposal when multiple openspec/changes/archive/<date>-<id>/ directories exist at the same ref. Elsewhere (archived_change_dirs/resolve) this situation is treated as AMBIGUOUS and refused, so this should raise SequencedAfterError when more than one archived proposal blob matches, rather than returning an arbitrary one.
    scripts/sequenced_after.py:641
  • The change_id_of_dir docstring currently states that an archived directory always yields <id> with the date prefix stripped, but the implementation falls back to returning path.name when the directory name does not match ARCHIVE_DIR. Clarify the docstring so behavior for non-conforming archived directory names is accurate.
  • Files reviewed: 3/3 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@brettheap

Copy link
Copy Markdown
Contributor Author

Freezing here — no further commits.

Local gates all green on head 87371ce:

  • pytest tests/sequenced_after tests/scope_globs -q → 235 passed
  • python3 scripts/validate-sequenced-after.py . → passes
  • python3 scripts/validate-sequenced-after.py . --ledger-diff → consistent
  • python3 scripts/doc-health.py --single-repo . → unchanged (no docs touched by this PR)

CI: pytest-suite is showing fail, but it is failing on main right now too, with the identical unrelated failure — tests/doc-health/test_release_tag_publication.py::test_this_repository_reads_zero_and_the_probe_can_fire, because contract-v3.3 has no published annotated tag yet (an ops/publication action, unrelated to sequenced_after/archive-gate). Confirmed against main's latest push run (33830081521, 2026-09-04T02:35Z): same single FAILED line. Not a regression from this PR — every sequenced_after/scope_globs test in the suite passed in that same CI run.

All other required checks pass on this head. Codex (@codex review) returned only a usage-limit refusal, no substantive review. Copilot's one inline finding (ls-tree not enumerating archived directories at a ref) was checked empirically and found incorrect for this code as written (trailing slash makes it enumerate contents — verified against the real corpus at ref 68f73e1, 128 dirs); a fourth fixture (test_the_archive_gate_resolves_a_ratified_ref_that_is_ITSELF_ALREADY_ARCHIVED) was added anyway to exercise that exact branch directly, since none of the original three fixtures did.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits. You can see your limits in the Codex usage dashboard.

Main is green at 92e662c; merging to pick up the fix before CI reruns.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01H9aKd8YF3ktcLmVJJxQYKv
Lane: openxfactory-max001
Copilot AI review requested due to automatic review settings September 4, 2026 04:28

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 new ref-based proposal resolver currently prefers one candidate on ambiguity (and change_id_of_dir() silently accepts malformed archived dir names), which can produce incorrect or misleading results instead of refusing ambiguous/invalid inputs.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (1)

scripts/sequenced_after.py:693

  • proposal_path_at_ref() currently prefers the first matching archived directory (and also prefers the active path) when multiple candidates exist at the same ref. Elsewhere the resolver explicitly refuses ambiguous ids (“MUST NOT prefer either”); this should likewise raise SequencedAfterError when both active+archived exist at the ref or when multiple archived <date>-<id> dirs exist, instead of picking one silently.
    active_rel = f"openspec/changes/{change_id}/proposal.md"
    if _blob_exists_at_ref(repo_root, ref, active_rel):
        return active_rel
    for name in sorted(_archive_dir_names_at_ref(repo_root, ref)):
        match = ARCHIVE_DIR.match(name)
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment on lines +643 to +647
if path.parent.name == "archive":
match = ARCHIVE_DIR.match(path.name)
if match is not None:
return match.group("id")
return path.name
@brettheap

Copy link
Copy Markdown
Contributor Author

Lane: openxfactory-max001 (session 5e783e4d)

Provenance for the admin merge of #638 (plain fix PR for #633; no OpenSpec change — realized code, no contract/boundary/policy delta).

  • Word: Brett Heap, in session, 2026-09-04 — "fix 633 and 626", then "hold until main is green" (main was red on the untagged contract-v3.3 from 0d5e1ba to 92e662c), then "land both when green".
  • Head merged: 8976c59c on base main, brought up to date with main at or after 92e662c; all required checks SUCCESS.
  • Why admin: self-authored PR; code-owner review structurally unclearable (standing pattern B2).
  • Codex: absent (usage-limit refusals) — absence, not clearance. Copilot findings dispositioned on the PR.
  • What it fixes: validate-sequenced-after --archive-gate now locates the ratified-side proposal BY CHANGE ID at the ratified ref (active path first, then any archived - dir) instead of deriving it from the current path, so the retention check runs across the archive rename; a missing proposal at the ref is a named finding with exit 2, never a traceback. Four fixtures in tests/sequenced_after/test_integrity.py.

🤖 Generated with Claude Code

https://claude.ai/code/session_01H9aKd8YF3ktcLmVJJxQYKv

@brettheap
brettheap merged commit 963c5b7 into main Sep 4, 2026
8 checks passed
This was referenced Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants