Repository navigation
Harden merge-master scripts against undocumented OS-level failures - #911
Conversation
scope_globs.py's scope_retention_at_archive() and sequenced_after.py's retention_at_archive() both document that they raise a named error class "never a traceback" -- but Path(change_dir).resolve() (ValueError, e.g. an embedded NUL, or OSError, e.g. a broken/looping symlink) is the first thing each does, uncaught. Both modules' _git_toplevel() helper has the same gap one call further in: subprocess.run(["git", ...]) can itself raise OSError (FileNotFoundError when git is not on PATH) before ever producing a CompletedProcess, escaping the returncode check entirely. validate-scope-globs.py's CLI archive-gate wrapper caught only (ScopeGlobsError, subprocess.CalledProcessError), so either escape still crashed the CLI instead of reporting "CANNOT RUN" (exit 2). Each call site is now wrapped in a narrow try/except that re-raises the module's own documented error class (ScopeGlobsResolutionError / SequencedAfterError) with a message naming the path or command that could not be resolved/run; the CLI's except tuple gains OSError and ValueError as a second backstop, consistent with its own module docstring's promise that every failure to run is a named finding, never a traceback. No change to any success path. One focused monkeypatch-driven test is added per call site in the existing tests/scope_globs/test_integrity.py and tests/sequenced_after/test_integrity.py style. These three files are vendored byte-for-byte into codexFactory's merge gate under scripts/merge_master/ (tests/merge-master/test_vendored_*.py pin them, per scripts/merge_master/vendored/vendored-scope-globs.pin.yaml's lockstep); codexFactory picks this fix up at its next declared-pin advance. No codexFactory edit is made here. Findings: Copilot review on codeXfactory/codeXfactory#333 -- discussion_r3979986464, r3979987510, r3980489825, r3980489901, r3980489953 (r3979988037, codexFactory's own vendored-test line-index assertion, is out of this repo's scope and is left untouched). Lane: openxfactory-2 Co-Authored-By: Claude Sonnet 5 <[email protected]>
Reviewer's GuideHardens both merge-master archive gates and the scope-globs CLI so filesystem resolution and Git launch failures are consistently converted into documented cannot-run findings, with targeted regression tests and no success-path changes. Sequence diagram for archive-gate OS failure handlingsequenceDiagram
participant CLI as validate-scope-globs.py
participant Gate as scope_retention_at_archive()
participant FS as Path.resolve()
participant Git as _git_toplevel()
participant OS as Operating system
CLI->>Gate: scope_retention_at_archive(change_dir, ratified_ref)
Gate->>FS: resolve()
alt OSError or ValueError
FS-->>Gate: raise OS-level exception
Gate-->>CLI: ScopeGlobsResolutionError
else path resolved
Gate->>Git: _git_toplevel(change_path)
Git->>OS: subprocess.run(git rev-parse)
alt OSError or SubprocessError
OS-->>Git: raise launch exception
Git-->>Gate: ScopeGlobsResolutionError
else git completes
Git-->>Gate: repository root or documented error
end
end
CLI-->>CLI: print CANNOT RUN and return exit 2
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
🟢 Approval recommended
The changes are narrowly scoped to exception translation paths, preserve success-path behavior, and add targeted tests covering each new failure-handling arm.
Pull request overview
This PR hardens the merge-master archive validation flow so unexpected OS-level failures (e.g., Path.resolve() failures and inability to launch git) are consistently surfaced as the documented “cannot run” error classes, preventing raw tracebacks from escaping the gates/CLI.
Changes:
- Wrap
Path(change_dir).resolve()in both archive-gate entrypoints to convert(OSError, ValueError)into the module’s documented “cannot run” exception. - Wrap
_git_toplevel()’ssubprocess.run(...)in both modules to convert(OSError, subprocess.SubprocessError)into the documented “cannot run” exception. - Add a CLI-level backstop in
validate-scope-globs.pyto map raw(OSError, ValueError)to theCANNOT RUN(exit 2) reporting path, plus targeted tests for all new failure modes.
File summaries
| File | Description |
|---|---|
| scripts/scope_globs.py | Converts OS-level Path.resolve() and subprocess.run() launch failures into ScopeGlobsResolutionError to uphold “never a traceback” contract. |
| scripts/sequenced_after.py | Mirrors the same hardening in SequencedAfterError for parity with scope_globs and consistent archive-gate behavior. |
| scripts/validate-scope-globs.py | Widens the archive-gate exception backstop so unexpected OS-level exceptions still report CANNOT RUN (exit 2) instead of crashing. |
| tests/scope_globs/test_integrity.py | Adds regression tests for Path.resolve() failure, git launch failure, and the CLI backstop behavior. |
| tests/sequenced_after/test_integrity.py | Adds regression tests for Path.resolve() failure and git launch failure in the sequenced-after archive gate. |
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
There was a problem hiding this comment.
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 6 hours and 17 minutes by commenting @sourcery-ai review. Upgrade to get a review now.
|
Lane: openxfactory-2 (openXfactory-2) |
…g before the ratification encode THE SECOND MERGE BEFORE THE ENCODE, FOR THE SAME REASON AS THE FIRST: every ratification figure is taken on a tree that already carries current `main`. The branch was frozen at `5dd724f5` when `origin/main` was `e0638f11` — the tree the pull request body and `tasks.md` § 2 and § 5 were measured on. `480fb996` merged `main` at `bd1c54c6`; `origin/main` has since advanced by one further commit, `ea34f22a` (three merge-master scripts hardened against undocumented OS-level failures, PR #911), so that commit is merged HERE and the ratification commit lands on top of it. The single gate capture `review/verification-2026-09-10.md` is therefore written on a tree carrying `main` @ `ea34f22a` and no re-measure is owed at landing. NOTHING CONFLICTED AND NOTHING OF THIS PACKET'S IS TOUCHED. `ea34f22a` moves `scripts/scope_globs.py`, `scripts/sequenced_after.py`, `scripts/validate-scope-globs.py`, `tests/scope_globs/test_integrity.py` and `tests/sequenced_after/test_integrity.py` — no `README.md`, nothing under `openspec/`, nothing under `scripts/doc_health/` and nothing under `tests/doc-health/`. So the README `## OpenSpec Records` block had no conflict to resolve, this packet's delta and its realization are byte-unmoved, and the `doc-health` corpus it measures is unchanged by the merge. Two of the gates the capture runs — `validate-sequenced-after.py` and `validate-scope-globs.py` — are the hardened ones, so the capture exercises them at their current main implementation rather than at the pre-#911 one. Refs #856, refs #860 Lane: openxfactory-1 Co-Authored-By: Claude Fable 5.1 <[email protected]>
RATIFIED 2026-09-10 by Brett Heap (openxFactory operator authority), lane openxfactory-1, verbatim: "ratify as encoded" — given in session and recorded on openxFactory PR #908 at 2026-09-10T18:06:52Z (comment 5623230781). THE WORD IS A MULTIPLE-CHOICE RULING AND IT REACHES BOTH OF THE PACKET'S DECLARED VETO POINTS, design.md D1 (#860) and D2 (#856), each put with the recommendation first and the alternative's cost written out beside it. BOTH ARE RESOLVED AS OPTION A: a `Removed from canon` marker whose tail carries no code span stays a MARKER and is REPORTED as marker-defect ground FIVE at `info` rather than being un-formed by a document-lifecycle grammar rule; and a name matching no unit of the requirement's basis and matching a unit THE BLOCK ITSELF ADDS is REPORTED as ground FOUR at `info` rather than the silence being ruled correct in canon. The earlier word of 2026-09-10, verbatim "do the 860 856 batch, land each when green", stays recorded as the ORIGIN of the AUTHORING and is not read as an approval. THE RULING IS APPLIED BY LEAVING THE TEXT ALONE, AND THAT IS VERIFIED BY DIFF RATHER THAN ASSERTED. Because A is the option the packet already encoded in each case, the withdrawals D1 and D2 costed were NOT performed: git diff 5dd724f -- openspec/changes/amend-marker-declaring-nothing/specs/ is EMPTY and so is git diff 5dd724f -- scripts/doc_health/ tests/doc-health/, so both grounds, both added scenarios, both new test groups and the ONE flipped assertion are ratified exactly as the bench reviewed them. D0's measurement stands with them — both new grounds have a population of ZERO on main @ e0638f1 — and D3 through D9 were carried beside them, none vetoed, which the recording says in as many words. THE WORD AND ITS RECORDING FALL IN THE SAME MINUTE, and both facts are stated rather than collapsed: the word was given in session at approximately 18:06Z and recorded on the pull request at 18:06:52Z. Both instants fall inside one UTC day, so the decision date, approved_on and both record file names are all 2026-09-10. WHAT MOVES. proposal.md, design.md and tasks.md carry Status: ratified with EXACTLY ONE citation line each (Ratified: in proposal.md, Ratified by: in the other two), which is what ratified-provenance counts. .openspec.yaml gains approved_by + approved_on BESIDE the drafting provenance it was authored with -- kind, id, reason, proposed_by and proposed_on byte-unmoved, git diff --numstat reading 46 0 -- the addition-not-rewrite shape add-drafted-proposal-origin (issue #318) defined and the shape the archive gate's origin-retention arm reads, which is why the status flip and the approval pair move in ONE commit. tasks.md section 1 is ticked and names the word that ticked it, a new 5.10 names this tree's gate re-run and 4.7 records the README fix. The README OpenSpec Records row flips to the ratified standing. Two records are captured beside the packet: review/ratification-2026-09-10.md, which carries Status: ratified per document-lifecycle's *A review record records a ratification* and satisfies the SUBJECT arm 804a917 (#878) added, and review/verification-2026-09-10.md, which keeps Status: record because its subject is the GATE RUN. TWO MERGES FROM MAIN WERE OWED AND BOTH WERE TAKEN FIRST, EACH AS ITS OWN COMMIT. origin/main advanced from e0638f1 -- the tree the pull request body and tasks.md sections 2 and 5 were measured on -- by three commits while the branch sat frozen at 5dd724f: 40d2f82 and bd1c54c, merged as 480fb99, then ea34f22 (PR #911), merged as 6aebb29. Neither merge touches README.md, openspec/, scripts/doc_health/ or tests/doc-health/ (git diff --stat 5dd724f 6aebb29 over those paths is EMPTY), so the delta is byte-unmoved and the corpus this packet measures is unchanged; every figure below is a post-merge figure and no re-measure is owed at landing. THE BENCH: SIX COPILOT ROUNDS, ONE CODEX REQUEST, THREE INLINE THREADS AND ALL THREE TAKEN. T1 the suppression() docstring's colliding ordinals (Copilot 17:47:19Z, taken in f59a462 by order plus a mapping, no code moved); T2 the corpus ceiling test's ground-four predicate, which shared ground one's precondition and would have misattributed a failure (Copilot 17:58:38Z, taken in 5dd724f by resolving each block to its promoted basis and asserting on suppression's own output); T3 the README row's defect sentence, which read as a live defect of a branch that realizes both grounds (Copilot 18:29:30Z, on the merge head and AFTER the word, TAKEN HERE: the paragraph is past tense and named to main @ e0638f1, the promoted-canon sentence says STILL and names the archive, and "canon now states FIVE grounds" becomes "the block states FIVE grounds"). COPILOT'S VERDICT ON THE FROZEN HEAD 5dd724f IS "Needs a closer look" WITH ZERO NEW COMMENTS, on the ground that the change "combines normative spec amendment text with behavioral changes to a core doc-health checker path, which warrants final human review" -- which is the standing of a packet awaiting a ratification word, and what this word supplies. CODEX NEVER REVIEWED THIS PULL REQUEST: one request at 17:45:40Z drew a usage-limit notice at 17:45:50Z, recorded as an ABSENCE rather than as approval. Sourcery's "directly resolves #856/#860" reading is REFUSED -- there is no closing keyword and closingIssuesReferences is []. SonarCloud's gate PASSED with eight python:S9073 composite-assertion issues refused on a measurement: the file carries 33 composite assertions and 24 of them are on origin/main. VERIFIED ON THE RATIFIED TREE, every number re-derived after both merges and after the encode, with both records inside the lifecycle scan set: openspec validate amend-marker-declaring-nothing --strict valid (exit 0); --all --strict exit 1 with Totals: 97 passed, 4 failed (101 items) and the failure SET IDENTICAL to origin/main ea34f22's same four (change/disposition-codexfactory-declared- renames, change/disposition-codexfactory-floor-relocation-retitle, spec/neutral-product-pin -- the requirements.16 defect openxFactory #882 names -- and spec/repo-boundary-governance), this change the one extra item and it PASSES; the pinned CLI 1.12.0 exit 0 both --change and --all --no-cache with 0 undispositioned failures and the same two pre-existing accepted exceptions; proposal-support verify ok; validate-sequenced-after passed (39 active, 9 declaring) with the sweep ledger consistent at 195 rows and ZERO rows moved; --ledger-diff clean, this change one of the corpus's four explicit [] root claims; validate-scope-globs passed; doc-health --single-repo exit 0 at 32 critical / 5 error / 47 warning / 16 info, 0 new regressions, NO finding naming this change, and the 350-line report BYTE-IDENTICAL to both controls -- the pre-ratification tree 6aebb29 and origin/main ea34f22 share its md5 exactly -- so this ratification adds no doc-health finding and removes none; the modified-block-currency family reporting marker defects: 0 over the whole corpus while this block's own standing flips draft -> ratified; ratified-provenance 28 critical, none of them this change; record-immutability 4 critical, none of them this packet's; proposal-origin no findings; and pytest tests/doc-health 1689 passed plus the four-directory selection 2178 passed, 66 subtests passed (2173 + the five tests ea34f22 added), test_modified_block_currency.py 144 passed. WHAT DOES NOT MOVE. No promoted canon is touched (git diff 5dd724f -- openspec/specs/ is EMPTY), so canon still states THREE grounds until the archive writes the block over it. No script, no test, no contract, no schema and no workflow moves; no ledger row moves; no archived change and no other active change's files are touched; no committed record is edited. tasks.md section 6 (archive) and section 7 (residue) stay ENTIRELY OPEN -- the archive is a separate act on merged-plus-green realization evidence and a separate word, so openxFactory #856 and #860 close AT THE ARCHIVE and not at this landing, which is why this pull request carries no closing keyword. The section 7 successors named on the recording at 18:15:34Z (7.1 -> #914, 7.3 -> #915, 7.4 already #893) tick at that archive act and not here. THIS LANE ENCODES AND FREEZES; IT DOES NOT MERGE. The Rule 6 LANDING/LANDED post belongs to the landing lane on the already-recorded word "land each when green". Refs #856, refs #860 Lane: openxfactory-1 Co-Authored-By: Claude Fable 5.1 <[email protected]> Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>



Lane: openxfactory-2 (openXfactory-2)
Refs #745
Refs codeXfactory/codexFactory#333
Summary
Hardens three merge-master scripts so undocumented OS-level failures are
re-raised as their documented "cannot run" error class instead of escaping
as raw tracebacks. Both archive-gate functions (
scope_retention_at_archivein
scope_globs.py,retention_at_archiveinsequenced_after.py)document "never a traceback", but
Path(change_dir).resolve()— the firstthing each does — and the
subprocess.run(["git", ...])call inside eachmodule's
_git_toplevel()helper were both uncaught. The CLI(
validate-scope-globs.py's_archive_gate) only caught(ScopeGlobsError, subprocess.CalledProcessError), so either escape stillcrashed the CLI instead of reporting
CANNOT RUN(exit 2).Authority: Brett Heap 2026-09-10 ~17:2xZ, verbatim "do 1 and 2, sign, file
it, do 744" (item 2, "Vendored merge-master OSError hardening"), recorded on
openxFactory #745:
#745 (comment)
Findings: Copilot review on codeXfactory/codexFactory#333, where these three
files are vendored byte-for-byte from this repo
(
scripts/merge_master/vendored/vendored-scope-globs.pin.yaml's lockstep).codexFactory picks this fix up at its next declared-pin advance — no
codexFactory edit is made here.
Per-finding table
scope_globs.py::scope_retention_at_archive()L563 —Path(change_dir).resolve()try/except (OSError, ValueError), re-raisesScopeGlobsResolutionErrornamingchange_dirand the underlying errortest_a_PATH_RESOLVE_FAILURE_is_a_finding_not_a_traceback(tests/scope_globs/test_integrity.py)sequenced_after.py::retention_at_archive()L889 —Path(change_dir).resolve()SequencedAfterErrortest_a_PATH_RESOLVE_FAILURE_is_a_finding_not_a_traceback(tests/sequenced_after/test_integrity.py)scope_globs.py::_git_toplevel()L491 —subprocess.run([...])try/except (OSError, subprocess.SubprocessError), re-raisesScopeGlobsResolutionErrornaming the directorytest_a_GIT_TOPLEVEL_LAUNCH_FAILURE_is_a_finding_not_a_traceback(tests/scope_globs/test_integrity.py)sequenced_after.py::_git_toplevel()L736 —subprocess.run([...])SequencedAfterErrortest_a_GIT_TOPLEVEL_LAUNCH_FAILURE_is_a_finding_not_a_traceback(tests/sequenced_after/test_integrity.py)validate-scope-globs.py::_archive_gate()L99 —exceptclauseOSError, ValueErroras a second, CLI-level backstop (defense in depth alongside the library-level hardening above)test_the_CLI_BACKSTOP_reports_a_raw_OSError_as_CANNOT_RUN(tests/scope_globs/test_integrity.py)Excluded per the claim: r3979988037 (
tests/merge-master/test_vendored_sequenced_after.pyhard-coding.splitlines()[74]) is codexFactory's own test file, not vendored from this repo — left untouched.What did NOT change
try/exceptwraps only thecall, and the existing return/raise logic below it is untouched.
except Exceptionbroadening anywhere; every new clause namesOSError,ValueError, and/orsubprocess.SubprocessErrorexplicitly.openspec/,contracts/, workflows, or any file outside thethree named scripts and their two existing test modules.
validate-sequenced-after.py(the CLI forsequenced_after.py) isuntouched — no finding named it, and the claim's scope is exactly the five
threads above.
Testing
python3 -m pytest tests/scope_globs tests/sequenced_after -q— 361passed (includes the 5 new tests, one per call site above, plus every
pre-existing test in both modules — no regression).
python3 scripts/validate-scope-globs.py .—scope_globs validation passed (all active changes conform)., exit 0 (corpus success pathunaffected).
python3 -m pytest -q(full suite, 11286 tests collected) — started inbackground; see the PR thread / final report for the outcome, since a full
collection alone took ~45s in this environment and the run did not finish
inside the ~20-minute budget. The scoped runs above are the evidence for
the modules this change actually touches.
OPENSPEC_TELEMETRY=0 openspec validate --all --strict— not run: this isa code-only change (no
openspec/changes/content touched), per thebrief's own guidance.
Lane: openxfactory-2
Co-Authored-By: Claude Sonnet 5 [email protected]
🤖 Generated with Claude Code
Summary by Sourcery
Harden merge-master archive validation against undocumented OS-level failures so they are reported as cannot-run findings rather than raw tracebacks.
Bug Fixes:
Enhancements:
Tests: