Repository navigation
Fix archive-gate to resolve the ratified proposal by change id - #638
Conversation
`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
There was a problem hiding this comment.
Hi @brettheap! 👋
Your private repo does not have access to Sourcery.
Please upgrade to continue using Sourcery ✨
|
@codex review |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
🟡 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
SequencedAfterErrorin 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.
| 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
|
Re Copilot's inline finding on 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. |
There was a problem hiding this comment.
🔵 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_refcan silently pick one archived proposal when multipleopenspec/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 raiseSequencedAfterErrorwhen more than one archived proposal blob matches, rather than returning an arbitrary one.
scripts/sequenced_after.py:641- The
change_id_of_dirdocstring currently states that an archived directory always yields<id>with the date prefix stripped, but the implementation falls back to returningpath.namewhen the directory name does not matchARCHIVE_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
|
Freezing here — no further commits. Local gates all green on head 87371ce:
CI: pytest-suite is showing fail, but it is failing on All other required checks pass on this head. Codex ( |
|
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
There was a problem hiding this comment.
🟡 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 raiseSequencedAfterErrorwhen 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
| if path.parent.name == "archive": | ||
| match = ARCHIVE_DIR.match(path.name) | ||
| if match is not None: | ||
| return match.group("id") | ||
| return path.name |
|
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).
🤖 Generated with Claude Code |
Lane: openxfactory-max001
Fixes the
--archive-gatecrash filed in #633: it derived the ratified-side proposal path fromCHANGE_DIR's CURRENT path, so once a change moved toopenspec/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 unhandledCalledProcessErrortraceback instead of a finding.Fix
change_id_of_dirderives the change id fromCHANGE_DIR's name, reusing the existingARCHIVE_DIRnaming convention (active dir → id as-is; archived dir → strip theYYYY-MM-DD-prefix) rather than inventing a second convention.proposal_path_at_reflocates the ratified-sideproposal.mdBY CHANGE ID against--ratified-ref's own tree — active path first, then anyopenspec/changes/archive/<date>-<id>/— usinggit cat-file -e/git ls-treeonly, no checkout.sequenced_after.SequencedAfterErrornaming 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-ledgeralready handles this error class — never a traceback.CHANGE_DIRbehaviour is unchanged (existing tests still green).New fixtures (
tests/sequenced_after/test_integrity.py):test_the_archive_gate_PASSES_across_the_archive_renametest_the_archive_gate_FAILS_across_the_archive_rename_on_a_real_mutationtest_the_archive_gate_CLI_reports_a_ref_with_NO_PROPOSAL_as_a_finding_not_a_tracebackVerification
pytest tests/sequenced_after tests/scope_globs -q→ 234 passed (231 pre-existing + 3 new)python3 scripts/validate-sequenced-after.py .→ passespython3 scripts/validate-sequenced-after.py . --ledger-diff→ consistentpython3 scripts/doc-health.py --single-repo .→ unchanged (no docs touched)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