Skip to content

Address each catalog run by its content, so one run id can never name two snapshots (for opensoft/xFactory#519) - #1175

Merged
brettheap merged 12 commits into
mainfrom
fix/519-content-addressed-catalog-run-id
Sep 27, 2026
Merged

brettheap merged 12 commits into
mainfrom
fix/519-content-addressed-catalog-run-id

Conversation

@brettheap

@brettheap brettheap commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Lane: openxfactory-1

For opensoft/xFactory#519 (run-id determinism), which proceeds under Brett Heap's ruling on opensoft/xFactory#480 (comment 5850005209, item 4). DRAFT: this lands only on Brett Heap's word.

The defect (main 79a720a2)

  • scripts/doc_health/catalog.py:373-395: run_id(inv, taxonomy) = sha256(inventory snapshot id, taxonomy digest).
  • scripts/doc_health/catalog_dispatch.py:280: _recompute mints that id before anything is merged, and :816-829 records merge_recommendations(...) under it. That content also depends on three things the id never saw: the classification carried forward from the writing tree's latest run (:269-274), the validated recommendations a cataloger child did or did not return (:803-805), and the state_since date stamped on every new pending marker (:816-817).
  • catalog.py:657-661 and :677-681: the immutability guard compares bytes only on the writing tree. It cannot see a run recorded on another branch or under another date.

The recorded history shows it twice:

run id where what differs
87544bd5… (2026-09-24) the nightly 28f8d918 (CATJOB-3598b7b01caa merged) vs the manual run of opensoft/xFactory#513 on main 4f3fd69c (no worker) AdxFactory / HealthLinc / LedgerxFactory snapshots: 70 vs 23 suggested facets. This is the collision that left #396 CONFLICTING.
5ac351da… main: runs/2026-08-16/ vs runs/2026-08-17/ and runs/2026-08-18/ openxFactory.yaml f10dbd4d… vs 574e0ebc… (560 diff lines: pending markers stamped 2026-08-17)

The same scenario run against main's code and against this branch (two independent trees, same inventory, taxonomy and day; one merges a fake-worker recommendation, one has no worker):

main    nightly run id b01b131a3f13  manual run id b01b131a3f13  same id: True   same content: False
branch  nightly run id 6b6864be76e7  manual run id 9b623e1d4aee  same id: False  same content: False

What is deterministic now

  • catalog.run_id(entries_by_repo, taxonomy) is the content address of exactly the per-repository snapshot documents the run records. It is sha256 over the domain separator xfactory-document-catalog-run/content-v1, then a framed [repo, byte length] header per repository and the document's byte-stable rendering with its own run.run_id blanked.
  • catalog.write_run mints that id and writes every repository under it. merge_catalog_findings records only through it.
  • Identical content from independent trees gets the same id and byte-identical files, so two such producers merge cleanly. Different content always gets a different id. The same content on a later date keeps its id, so "latest date when the same content recurred" is now literally true.
  • The old key survives as legacy_run_id, used only to recognize runs recorded under it. catalog.run_id_scheme classifies a recorded run as content-addressed, legacy-input-key, or neither.
  • The prepare phase no longer reports a run_id, because the id exists only after the merge. _recompute no longer returns rid.

What refuses

  • write_snapshot still refuses a differing write under an existing id. Nothing the writer mints can reach that refusal now; only a hand-edited directory, a mixed directory, or a foreign id can. Both existing-file checks now compare raw bytes, so a CRLF edit is refused rather than taken as a completed no-op. The writer persists exactly render()'s bytes (newline="\n", research D3) on every platform (review round 3).
  • run_id and write_run raise before anything lands for an empty run, an incomplete taxonomy, or anything write_snapshot would refuse for any repository of the run. That covers a repository id that is not a safe path segment, preflighted since review round 1, and an ambiguous or duplicate locator, a foreign entry, or mixed revisions. write_run also checks every existing target of the run, and every node it would create, before its first write. So a directory holding a conflicting file for a later repository is refused before anything is written or a sequence is claimed, and so is a directory where a snapshot or run.yaml goes, or a file where a run, date, repository, claims or catalog directory goes (review rounds 3-5). An existing run directory holding a symlink, or a snapshot of a repository the run does not record, is refused too (review round 6), so a stranger's file is never left inside a closed run. A run is never left partial.
  • The writer never follows a symlink (review rounds 5-6). Every directory it writes through, from the root itself down, and every file it writes or accepts must be a real directory or regular file. The runner resolves every root it hands over, so a symlinked root can only come from a caller that did not resolve it. So a symlinked catalog, runs, claims, date, run or repository directory cannot carry a run's writes or claims outside the tree. A snapshot or run.yaml linked to an outside file holding the recorded bytes is refused, not taken as a completed no-op.
  • An existing run.yaml must be exactly the record this run writes, byte for byte: its id, its date, and a positive integer sequence whose .sequence/ claim is this run's own (review round 5). A regular but edited run.yaml used to pass as a completed run, and load_snapshot then ordered the run by whatever sequence it stated. It is now refused before anything is claimed or written. A claim-named node under .sequence/ that is not a regular file is refused before any claim too (review round 7). A directory or a dangling link there used to loop the claim step forever.
  • A complete content-addressed run is closed to additions (review round 8). If a recorded run's snapshots already make up exactly the content its id addresses, write_snapshot refuses to add another repository's snapshot under that id. A partial run, one that crashed between its first snapshot and its last, still heals on retry, unless it holds a link anywhere inside it (review round 9). All 31 recorded runs on the aggregation's real tree pass every round-5 and round-6 check.
  • The document-catalog family gains [run-identity] (ERROR, auto-fixable). It flags a recorded run whose 64-hex name is neither the content address of its snapshots nor the legacy key those snapshots derive: the run was edited after recording, lost a repository snapshot, or mixes files from two runs. The content address is verified against the raw persisted bytes: only the canonical run_id pair is blanked, and nothing is decoded or re-rendered. So a serialization-only or line-ending (CRLF) edit breaks a run's identity too (review rounds 1-2). Legacy runs pass on the derivation alone, because their content was never covered and so cannot be verified. Hand-named runs (fixtures, foreign records) are outside the check. A torn historical run is reported as that run's own catalog-integrity finding and does not abort the family. So is a run that is not the plain tree the writer makes: a symlink from the catalog root down to the run, at the claims directory (review round 10), or anywhere inside it. It is refused before anything behind the link is read, so outside bytes can never verify a run clean (review round 6). So is a run whose run.yaml is not exactly the record the writer writes for its directory, or whose sequence another run claimed (review round 7).
  • On the aggregation's real tree (xFactory main 102c9742), all 31 recorded runs classify legacy-input-key, so the check reports nothing there today (0.56 s). The two 87544bd5 contents would have received eb48079c… and 754aa828…. The 5ac351da contents give 3624ef2e… (08-16) and d6a1cdb3… (08-17 and 08-18, which are identical).

Shape: a tooling fix, no promised behaviour changes

  • The promoted document-cataloging spec names runs/YYYY-MM-DD/<run-id>/ and never says how the id is derived.
  • contracts/schemas/xfactory-document-catalog-snapshot.schema.yaml requires run.run_id to be a non-empty string. Ids are still 64 hex, and no fields are added.
  • The change brings the code closer to that spec's "Historical record is closed" scenario: a later run that changes classification MUST create new snapshots. The old code instead either reused the id under a new date (5ac351da) or raised CatalogError on the same tree.
  • The Speckit realization spec (codexFactory specs/001-document-catalog-nightly) still holds. US2 acceptance 3 and FR-008 require that a differing write under one id is refused. A same-day differing run now "lands to a non-colliding path", which that spec's own independent test allows.
  • No openspec/ path is touched. The derivation lived only in code docstrings (research D4), and those are updated.

Tests and validators

  • New tests:
    • test_catalog.py: content address, write_run, the two-tree convergence, and run_id_scheme over content, legacy, edited, lost and mixed runs.
    • test_catalog_dispatch.py: the doc-health: stop uncited-resolution findings from echoing themselves #519 two-producer reproduction, and the 5ac351da shape (different selection, one inventory, different id).
    • test_document_catalog.py: [run-identity] for edited and mixed runs, the legacy-key boundary, the hand-named carve-out, a torn historical run, and the 24th pinned action string.
  • Updated tests: the old same-identity refusal test becomes "same-day replay is a no-op, a new classification is a new run". Call sites of the old run_id(inv, …) are updated.
  • Targeted catalog tests (test_catalog, test_catalog_dispatch, test_document_catalog, test_catalog_baseline, test_cataloger, tests/document_catalog): 269 passed at head 12ca85ca (main: 242). With test_families, test_suite and test_lifecycle_scan_set added, 390 passed.
  • Full suite, run the way pytest-suite.yml runs it (submodules initialized, pinned OpenSpec CLI, hash-locked deps), on head 018b00e2: 8480 passed, 8 skipped, 338 deselected, 392 subtests passed, 1 failed. The failure is the load-sensitive 30 s subprocess budget in tests/hermes_runtime_contracts/test_validator_cli.py::test_release_mode_field_is_preserved_on_the_real_repository (TimeoutExpired). Run alone it passes (2 passed in 54.8 s), and it has nothing to do with doc_health. An earlier full run of the same diff had that test green. Review rounds 1-10 (657af746, f2219e4e, f2cae5f9, ddea4519, 5fdbc7b4, a050b05e, a3ebe078, 8bf78876, e5a09b69, 12ca85ca) change only catalog.py, document_catalog.py and their tests, and the pytest-suite check runs the whole suite at the head.
  • scripts/validate-document-catalog.py: rc 0, 0 error(s), 0 warning(s), on this tree and on the aggregation tree.
  • scripts/validate-openspec-cli-pin.py --all: rc 0. There is one ACCEPTED exception, the pre-existing add-chain-attestation one.

How the aggregation consumes this

The nightly runs scripts/doc_health/ from the aggregation's openxFactory gitlink, so this change takes effect only after a separate, later pin-sync. Under the two-file rule, that pin-sync moves the gitlink and .github/clearing/openxfactory/PIN.yaml in one commit. It is not part of this PR.

Observed, not fixed here (needs a ruling)

  • The Amendment 2: openXwallet takes the openX<type> form #396 landing did not carry the nightly's content. The rolling-PR delivery in .github/workflows/doc-health-reusable.yml ("Commit report", :3414-3421) builds each night's tree as main plus that night's health/. So the 2026-09-25 nightly (0c9b97bb) replaced the 2026-09-24 nightly's classified 87544bd5 files with Tranche three builds to a ruled configuration, and the receipt comes first #513's bytes, with no conflict and no finding. It also dropped recommendations/2026-09-24/CATJOB-3598b7b01caa.yaml. Amendment 2: openXwallet takes the openX<type> form #396 then landed (2ba08b67) holding Tranche three builds to a ruled configuration, and the receipt comes first #513's bytes. That is not the "nightly wins" content the The council's wallet declares its four seat keys; pin + gitlink to wallet-v1.3 #480 ruling named. The 47 suggested facets on 14 documents that were dropped survive only in history at 28f8d918.
  • Two producers can still claim the same sequence number. With content-addressed ids, two producers of different content on different branches still both claim the next runs/.sequence/NNNNNN.yaml. That is an honest conflict over which run is latest, and this PR does not prevent it. It now becomes visible, though. The .sequence/ claim file conflicts when the branches merge, and after the merge is resolved the run whose claim lost gets a catalog-integrity finding (review round 7). Before, the two runs silently tied on (as_of, sequence), and "latest" was decided by run-directory name.
  • Run discovery still follows links (declined in review round 8, a follow-up). catalog._iter_runs is the shared scan behind load_snapshot, the claim step and all thirteen checks, and this PR does not change it. It reads each run's run.yaml sequence through a symlink. A linked run is never accepted. If its run.yaml parses, run-identity reports it as catalog-integrity for that run. If it is malformed, the family returns its whole-family finding, as it does for any unreadable run.yaml. Making the scan link-safe means deciding whether a linked run is invisible to load_snapshot or visible and reported, which is a reader-semantics change of its own.
  • Symlinked ancestors above the root are out of scope (declined in review round 9). The no-follow guarantee covers the tree from the root down, because that is where git can carry a link. The runner resolves every root it hands over.

🤖 Generated with Claude Code

… two snapshots (for opensoft/xFactory#519)

The document-catalog run id was sha256(inventory snapshot id, taxonomy
digest), but the snapshot recorded under it is also shaped by the
classification carried forward from the writing tree's latest run, by the
validated recommendations a cataloger child did or did not return, and by
the state_since date stamped on every new pending marker. Two producers of
one corpus state therefore recorded different snapshots under one id:
87544bd5 on 2026-09-24 (the nightly with CATJOB-3598b7b01caa merged, and
the manual run of opensoft/xFactory#513 with no worker), and 5ac351da on
2026-08-16 and again, with pending markers added, on 2026-08-17. The
write-side immutability guard only sees its own tree, so the collision
surfaced as a merge conflict on the rolling nightly PR.

catalog.run_id is now the content address of exactly the per-repository
snapshot documents the run records (domain-separated, framed, run_id
blanked); catalog.write_run mints it and writes every repository under
it, and merge_catalog_findings records through write_run. Identical
content converges on one id and byte-identical files from independent
trees; different content is always a different run, never a conflicting
rewrite. The old key survives as legacy_run_id, used only to recognize the
runs recorded under it. The prepare phase no longer reports a run id: the
id exists only after the merge.

The document-catalog family gains a run-identity class: a recorded run
whose 64-hex name is neither the content address of its snapshots nor the
legacy key they derive is reported (edited after recording, lost a
repository snapshot, or mixed files from two runs). All 31 runs on the
aggregation's main are legacy-named, so it reports nothing there today.

Lane: openxfactory-1
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI lite review requested due to automatic review settings September 27, 2026 02:11
@brettheap

Copy link
Copy Markdown
Contributor Author

@codex review

@sourcery-ai

sourcery-ai Bot commented Sep 27, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR fixes run-ID collisions by making new catalog run IDs content addresses of the complete merged snapshot set, minting them only during merge, while preserving and classifying legacy runs and adding validation for tampered or mixed recorded content.

Sequence diagram for content-addressed catalog run recording

sequenceDiagram
    participant Dispatch as merge_catalog_findings
    participant Merge as merge_recommendations
    participant Catalog as write_run
    participant Identity as run_id
    participant Storage as Catalog storage

    Dispatch->>Merge: merge_recommendations(base_entries, records)
    Merge-->>Dispatch: merged entries by repository
    Dispatch->>Catalog: write_run(merged_by_repo, taxonomy)
    Catalog->>Identity: run_id(entries_by_repo, taxonomy)
    Identity-->>Catalog: content-addressed run id
    Catalog->>Storage: write_snapshot(run_id, repository, entries, taxonomy)
    Storage-->>Catalog: snapshot paths
    Catalog-->>Dispatch: run id and paths
Loading

Flow diagram for catalog run identity verification

flowchart TD
    A[Recorded run] --> B{64-hex directory name?}
    B -- No --> C[Skip run-identity check]
    B -- Yes --> D[Load snapshot documents]
    D --> E{run_id_scheme}
    E -- content-addressed --> F[Pass: id matches snapshot content]
    E -- legacy-input-key --> G[Pass: legacy id derives from inventory and taxonomy]
    E -- neither --> H[ERROR: run-identity finding]
    D --> I[Unreadable or torn record]
    I --> J[ERROR: catalog-integrity finding]
Loading

File-Level Changes

Change Details Files
Replace inventory/taxonomy-derived run IDs with content-addressed IDs for the exact snapshots being recorded.
  • Hash rendered per-repository snapshot documents with a domain separator, deterministic repository framing, and the run ID field blanked.
  • Add write_run as the single API that mints an ID and writes all repository snapshots.
  • Retain legacy_run_id and add scheme detection for content-addressed and pre-doc-health: stop uncited-resolution findings from echoing themselves #519 runs.
  • Validate inputs before writing, including empty runs, incomplete taxonomy, invalid entries, and mixed revisions.
scripts/doc_health/catalog.py
tests/doc-health/test_catalog.py
tests/doc-health/test_cataloger.py
Move run identity creation to the merge phase so recommendations, carried-forward classifications, and pending-marker dates are included in the address.
  • Remove run IDs from recomputation and prepare metadata.
  • Aggregate all merged repository entries before calling catalog.write_run.
  • Ensure identical producers converge to byte-identical runs while different merged content receives a new ID and sequence.
scripts/doc_health/catalog_dispatch.py
tests/doc-health/test_catalog_dispatch.py
Add document-catalog validation for recorded runs whose directory names do not address their contents.
  • Introduce the auto-fixable ERROR run-identity finding for edited, incomplete, or mixed writer-named runs.
  • Recognize valid legacy-key runs without attempting to verify content their historical key did not cover.
  • Report torn historical runs as per-run catalog-integrity findings and exempt hand-named records.
  • Pin the new finding action and update finding-class documentation.
scripts/doc_health/document_catalog.py
scripts/doc_health/families.py
tests/doc-health/test_document_catalog.py

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.

Copilot review overview

🟡 Changes recommended

Two moderate findings remain unresolved: repository validation can permit partial writes, and malformed historical metadata can suppress later checks.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

This PR makes document-catalog run IDs content-addressed and adds historical run-identity validation.

Changes:

  • Adds content-addressed IDs with legacy-ID recognition.
  • Defers run creation until merge time.
  • Adds identity, corruption, and producer-convergence tests.
File Summary
tests/​doc-health/​test_document_catalog.py Tests run-identity findings and corruption cases.
tests/​doc-health/​test_cataloger.py Updates cataloger run-ID callers.
tests/​doc-health/​test_catalog.py Tests content addressing, legacy handling, and run writing.
tests/​doc-health/​test_catalog_dispatch.py Tests merge behavior and producer convergence.
scripts/​doc_health/​families.py Updates catalog finding documentation.
scripts/​doc_health/​document_catalog.py Adds historical run-identity checks; malformed runs need isolated handling.
scripts/​doc_health/​catalog.py Implements content-addressed IDs and run writing; repository paths need preflight validation.
scripts/​doc_health/​catalog_dispatch.py Mints IDs after merged catalog content is finalized.

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

Comment thread scripts/doc_health/catalog.py Resolved

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 018b00e29b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/doc_health/catalog.py Resolved
…id before any write (review round 1, for opensoft/xFactory#519)

Codex: parsing a re-serialized snapshot and rendering it again reproduces
the original bytes, so run_id_scheme over parsed documents called a file
whose serialization had been edited intact. run_id_scheme now takes the
persisted texts and recomputes the content address byte for byte, blanking
only the one "run_id" pair the canonical rendering carries. For the
writer's own files the address is unchanged, and any byte edit breaks it.
The family reads each writer-named run's texts (catalog._load_run_texts)
and passes them in.

Copilot: run_id validated entries and the taxonomy but not the repository
path segments write_snapshot refuses, so write_run could record a valid
repository's snapshot and run.yaml and then fail on a later, invalid id,
leaving a partial run. run_id now preflights every repository id, so
nothing lands.

The family docstring also now says precisely which torn records it
isolates: an unreadable snapshot file is reported for that run alone. An
unreadable run.yaml aborts the shared run scan, which load_snapshot walks
too, and is still reported once as the family-wide finding, as before.

Lane: openxfactory-1
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI review requested due to automatic review settings September 27, 2026 02:19

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.

Copilot review overview

🟡 Changes recommended

Fix raw-byte snapshot verification and add CRLF regression coverage.

Review effort: Lite
Findings: 1 High severity

Open (1)
Resolved since last review (1)

Comment thread scripts/doc_health/catalog.py Resolved
…ntity too (review round 2, for opensoft/xFactory#519)

Copilot: Path.read_text() translates universal newlines, so a hand edit
that turned a persisted snapshot from LF to CRLF was normalized back to LF
before _persisted_digest hashed it, and the run-identity check accepted a
byte-level edit it promises to catch. The verifier now reads raw bytes
(catalog._load_run_bytes, replacing _load_run_texts) and blanks the single
canonical "run_id" pair in bytes. Nothing is decoded before hashing, and
the writer's own LF files still address to their run id.

A CRLF regression case now sits beside the re-serialization cases, both at
run_id_scheme and through the document-catalog family.

Lane: openxfactory-1
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI review requested due to automatic review settings September 27, 2026 02:26

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.

Copilot review overview

🟡 Changes recommended

Unresolved byte-exact persistence and partial-write risks remain in catalog.py.

Review effort: Lite
Findings: 1 High severity · 1 Medium severity

Open (2)
Resolved since last review (1)

Comment thread scripts/doc_health/catalog.py Resolved
Comment thread scripts/doc_health/catalog.py Resolved
…ots as raw bytes (review round 3, for opensoft/xFactory#519)

Copilot, partial runs: write_run wrote repositories one by one, so in a
directory already holding a conflicting file for a later repository
(edited by hand, or mixed from another run) the earlier repository was
written and the sequence claimed before the conflict raised, leaving a
partial recorded run. write_run now checks every existing target of the
run, as raw bytes, before its first write.

Copilot, CRLF no-op: write_snapshot's two existing-file checks read text,
and universal-newline translation turned a CRLF-edited snapshot back into
the writer's LF bytes, so a retry returned it as a completed no-op. Both
checks now go through _holds_exactly, which compares raw bytes.

For those byte comparisons to hold on every platform, _write_rendered and
the sequence claim now write with newline="\n", so the persisted bytes are
exactly render()'s, as research D3 always specified (LF line endings). A
default text-mode write would use the platform line separator. On POSIX,
where every producer runs today, the bytes are unchanged.

Lane: openxfactory-1
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI review requested due to automatic review settings September 27, 2026 02:33

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.

Copilot review overview

🟡 Changes recommended

Catalog preflight must reject non-file targets and validate existing run metadata before writing.

Review effort: Lite
Findings: 1 High severity

Open (1)
Resolved since last review (2)

Comment thread scripts/doc_health/catalog.py Resolved
opensoft/xFactory#519)

Copilot: _holds_exactly treated an existing directory at a snapshot path as
absent, so write_run passed preflight, claimed a sequence, and then failed
with IsADirectoryError mid-run, leaving an orphaned claim or a partial run
instead of a controlled refusal. The review summary also names the rest of
that category: existing run metadata.

Any node at a snapshot path that is not a regular file now raises
CatalogError. write_run's preflight also refuses, before the first write,
a non-directory where the date directory, the run directory, or a
slash-separated repository's subdirectory goes, and a non-file at
run.yaml. Every refusal write_run can make is now reached before anything
is written or claimed.

Lane: openxfactory-1
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI review requested due to automatic review settings September 27, 2026 02:39

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.

Copilot review overview

🟡 Changes recommended

Run-writing preflight still has unresolved symlink, ancestor-occupancy, and metadata-validation gaps.

Review effort: Lite
Findings: 1 High severity

Open (1)
Resolved since last review (1)
Previously missed (2)

In code that hasn't changed since last review

Medium severity Reject symlinked snapshot targets during preflight

scripts/​doc_health/​catalog.py:823

target.is_file() also follows symlinks, so a snapshot path linked to an external regular file is accepted as an exact no-op when its bytes happen to match. The run then retains a non-regular, externally mutable artifact, defeating the byte-level immutability check; reject target.is_symlink() before accepting an existing snapshot.

Medium severity Validate existing run metadata before accepting completed run

scripts/​doc_health/​catalog.py:848

A regular but edited or malformed run.yaml passes this check. When every snapshot matches, write_snapshot() then treats any regular metadata file as a completed run and write_run() returns without validating it, so a retry can silently accept metadata with a wrong run_id/date or invalid sequence (and later load_snapshot() may misorder or fail on the run). Validate the existing metadata bytes/fields, or refuse the run before claiming or writing.

Comment thread scripts/doc_health/catalog.py Resolved
…run (review round 5, for opensoft/xFactory#519)

Copilot's round-5 review of ddea451 found that is_dir() and is_file()
follow symlinks. A symlinked run, date or repository directory passed the
preflight, and the run's writes could escape health/document-catalog/runs.
Its overview listed three related gaps. A snapshot linked to an outside
file holding the recorded bytes was accepted as a completed no-op. A
regular but edited run.yaml was accepted as a completed run. And the
catalog directories above the date directory were never checked.

- _refuse_unsafe_run_paths replaces _refuse_occupied_run_paths. It walks
  every directory the run writes through, from health/ down: the claims
  directory, the date and run directories, and repository subdirectories.
  It also checks run.yaml and every snapshot file. It refuses any symlink,
  even a dangling one or one pointing inside the tree, and any node of the
  wrong type. write_run runs it in its preflight, and write_snapshot runs
  it first, so both refuse before anything is claimed or written.
- _holds_exactly reads through _read_record, which refuses a symlink.
- _recorded holds an existing run.yaml to the record this run writes. That
  is _run_meta_document(rid, day, sequence), byte for byte, with a positive
  integer sequence whose claim is this run's own _claim_document.
  write_run checks it in its preflight, and write_snapshot checks it at
  each of its run.yaml decisions. The claim and run.yaml records are now
  built by one helper each, shared by the writer and this check.

Tests: the occupied-path test gains four cases for the claims, runs,
catalog and health directories. Two new tests cover symlinks at every
depth, and thirteen run.yaml and claim edits, each run once over a
complete run and once over a run missing a snapshot. Every case was
accepted on ddea451, and the symlinked directories had files written
outside the tree. Every case is refused now. All 31 recorded runs on the
aggregation's real tree pass both new checks.

Lane: openxfactory-1
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI review requested due to automatic review settings September 27, 2026 03:20

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.

Copilot review overview

🟡 Changes recommended

Unresolved path-safety, extra-snapshot preflight, and symlink-handling issues remain.

Review effort: Lite
Findings: 3 High severity

Open (3)
Resolved since last review (1)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Reject untracked snapshot files in existing run directories

scripts/​doc_health/​catalog.py:1058

The preflight only compares the repositories supplied to this call. If a previously recorded run directory contains an extra *.yaml snapshot from another run/repository, _recorded() is true and all expected targets can match, so this loop returns successfully while leaving the extra file in the closed run. _snapshot_files() later includes that file, making the same run fail run_id_scheme as mixed content. Reject any existing snapshot path not represented in entries_by_repo before entering the write loop.

Comment thread scripts/doc_health/catalog.py Resolved
Comment thread scripts/doc_health/catalog.py Resolved
Comment thread scripts/doc_health/document_catalog.py Resolved
…; verify only the tree the writer makes (review round 6, for opensoft/xFactory#519)

Copilot's round-6 review of 5fdbc7b found four gaps.

- The writer never checked the root itself. A symlinked root carried
  the claims and snapshots behind the link. _catalog_chain now starts at
  the root, so _refuse_unsafe_run_paths refuses it like any other
  catalog directory. The runner already resolves every root it hands
  over, so only a caller that skipped resolving its root is affected.
- The verifier followed symlinks. _load_run and _load_run_bytes read a
  linked snapshot, run.yaml or run directory through the link, so a run
  verified clean against bytes that live outside the catalog. Path.rglob
  also skipped a linked directory inside a run without a word.
  _refuse_foreign_run_tree now refuses a symlink or a wrong-type node from
  the root down to the run, and _refuse_links_inside refuses a symlink
  anywhere inside it. _run_identity_findings calls it before anything is
  read and reports such a run as catalog-integrity for that run alone.
  _load_run_bytes also reads each file through _read_record.
- A run directory holding a stranger's snapshot passed. The preflight
  compared only the repositories this call records. A snapshot for
  another repository, or one mixed in from another run, was accepted as a
  completed no-op. Crashed before its run.yaml, the run was completed
  around the stranger. write_run's preflight now refuses an existing run
  directory holding a symlink or a snapshot it does not record, before
  anything is claimed or written.

Tests: the symlink test gains a symlinked root and a linked directory
inside a recorded run. A new writer test covers top-level, nested and
crashed-run strangers. A new family test covers a linked snapshot,
run.yaml, run directory, and directory inside the run. Every case was
accepted or verified clean on 5fdbc7b, and the symlinked root had 4
files written behind the link. Every case is refused or reported now. All
31 recorded runs on the aggregation's real tree pass every writer and
verifier check, and run-identity still reports nothing there.

Lane: openxfactory-1
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI review requested due to automatic review settings September 27, 2026 04:25
….yaml on the read path (review round 7, for opensoft/xFactory#519)

Copilot's round-7 review of a050b05 raised two threads and one
previously-missed item.

- Foreign claim nodes (thread). _read_claims skipped a claim-named node
  that was not a regular file. A directory or a dangling symlink at
  .sequence/000001.yaml therefore looped _claim_sequence forever: its
  O_EXCL open kept colliding with a number the scan never counted. A
  symlinked claim was also followed, importing an outside sequence and
  date. _read_claims now refuses any claim-named node that is not a
  regular file (_refuse_foreign_node), before anything is claimed or
  written. That covers write_snapshot and write_run alike.
- run.yaml on the read path (previously missed). _run_identity_findings
  verified only the snapshots, so a run.yaml edited to another id, date
  or sequence passed unseen, and so did one left without its claim. It
  now calls catalog._recorded before reading the run. That requires the
  record the writer writes for this directory, byte for byte, with a
  sequence claimed by this run. Anything else is catalog-integrity for
  that run. A sequence claimed by another run is caught too, since it
  would break the total order that "latest" relies on.
- Overlapping identical writers (thread). No code change. _recorded
  holds an existing run.yaml to its own sequence and that sequence's
  claim, both of which name this run, and never to the caller's
  sequence. So the writer that reaches its run.yaml step second
  completes as a no-op, and its claim stays orphaned, as a crashed run's
  does. test_overlapping_identical_runs_both_complete replays exactly
  that interleaving, and it passes on a050b05 as well.

Tests: test_a_foreign_sequence_claim_node_is_refused_before_claiming
covers a directory, a dangling symlink and a symlinked claim. It runs
under a thread join, because on a050b05 the directory case never ends.
test_edited_run_metadata_is_reported_as_catalog_integrity covers an
edited id, date and borrowed sequence, and a missing claim; it fails on
a050b05. All 31 recorded runs and 31 claims on the aggregation's real
tree pass, and run-identity still reports nothing there.

Lane: openxfactory-1
Co-Authored-By: Claude Opus 5.5 <[email protected]>

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.

Copilot review overview

🟡 Changes recommended

Unresolved critical and moderate findings affect run immutability and corruption detection.

Review effort: Lite
Findings: 2 High severity

Open (2)
Resolved since last review (2)

Comment thread scripts/doc_health/catalog.py Resolved
Comment thread scripts/doc_health/document_catalog.py Resolved
…nd 8, for opensoft/xFactory#519)

Copilot's round-8 review of a3ebe07 raised two threads.

- Additions to a closed run (fixed). Once run.yaml existed,
  write_snapshot wrote any missing target. A caller could record a
  content-addressed id for one repository and then append another under
  the same id, mixing a closed run. A recorded run whose snapshots already
  make up exactly the content its id addresses (_addresses_itself, over
  the raw bytes) is complete, and write_snapshot now refuses an addition
  to it before writing. The exception is a concurrent identical writer
  that has just landed the same target, which is the completed no-op. A
  partial run that crashed between its first snapshot and its last still
  heals on retry, and write_run already refuses strangers in the run it
  records.
- Link-safe run discovery (declined here, documented). _iter_runs, the
  shared scan behind load_snapshot, the claim step and every family
  check, follows links when it reads run.yaml's sequence. This PR does not
  change it, and the family's earlier checks walk it before run-identity
  runs, so a fix confined to the run-identity loop could not isolate a
  bad linked run anyway. A linked run is never accepted: it is reported
  per run when its run.yaml parses, and it takes the whole-family finding
  when it does not, like any unreadable run.yaml. The run-identity
  docstring now states that boundary. Making the shared scan link-safe
  changes every reader and is left for a follow-up.

Tests: test_write_snapshot_never_adds_to_a_complete_run covers the
refusal, and a crashed partial run's heal. It fails on a3ebe07. The
targeted catalog tests pass (268). All 31 recorded runs on the
aggregation's real tree pass, and run-identity reports nothing there.

Lane: openxfactory-1
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI review requested due to automatic review settings September 27, 2026 05:01

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.

Copilot review overview

🟡 Changes recommended

Two critical catalog persistence issues involving ancestor symlinks and partial-run healing remain unresolved.

Review effort: Lite
Findings: 2 High severity

Open (2)
Resolved since last review (2)

Comment thread scripts/doc_health/catalog.py Resolved
Comment thread scripts/doc_health/catalog.py Resolved
… to the tree below the root (review round 9, for opensoft/xFactory#519)

Copilot's round-9 review of 8bf7887 raised two threads.

- Healing a partial run that holds a link (fixed). write_snapshot checked
  only its own target's path. A partial run holding an unrelated symlink
  was still completed and closed: the missing snapshot was written, and an
  unrecorded run was also claimed and given its run.yaml. That left a
  closed run holding a link, and a linked directory can hide files from
  _snapshot_files. write_snapshot now runs _refuse_links_inside on an
  existing run directory before anything else, as write_run does.
- Symlinked ancestors above the root (declined, documented). The
  no-follow guarantee covers the tree from the root down, because that is
  where a symlink can arrive as content: committed, merged, or copied in
  with a run. The directories above the root belong to the host holding
  the checkout, and git never carries a link there. The runner resolves
  every root it hands over. Refusing unresolved ancestors would break
  checkouts reached through a linked home or workspace directory and
  protect no catalog content. _catalog_chain's docstring now states that
  boundary.

Tests: test_write_snapshot_never_heals_a_partial_run_around_a_link
covers an unrecorded and a recorded partial run, each holding a linked
directory. It fails on 8bf7887. The targeted catalog tests pass (269).

Lane: openxfactory-1
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI review requested due to automatic review settings September 27, 2026 05:09

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.

Copilot review overview

🟡 Changes recommended

Catalog tree safety, legacy-ID validation, and foreign-node handling remain unresolved.

Review effort: Lite
Findings: 1 High severity

Open (1)
Resolved since last review (2)

Comment thread scripts/doc_health/catalog.py Resolved
Copilot AI review requested due to automatic review settings September 27, 2026 05:19
…view round 10, for opensoft/xFactory#519)

Copilot's round-10 review of e5a09b6 found that _refuse_foreign_run_tree
did not check runs/.sequence. Since round 7 the run-identity check reads
the claim that vouches for a run's run.yaml sequence (_recorded).
_read_record refused a linked claim file but followed a linked claims
directory, so an outside copy of the claims could vouch for a run.

- _refuse_foreign_run_tree now includes the sequence-claim directory in
  its tree check, so such a run is reported as catalog-integrity.
- _recorded refuses a foreign claims directory before reading a claim,
  so no caller can trust an outside claim. The writer's preflight
  already checked that directory.

Tests: test_symlinked_run_is_reported_as_catalog_integrity gains a
linked claims directory. That case fails on e5a09b6. The targeted
catalog tests pass (269), and the aggregation's 31 recorded runs pass
with run-identity reporting nothing.

Lane: openxfactory-1
Co-Authored-By: Claude Opus 5.5 <[email protected]>

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.

Copilot review overview

🔵 Needs a closer look

Unresolved moderate integrity findings remain in broad filesystem and run-validation changes.

Review effort: Lite
Findings: None

Resolved since last review (1)

Copilot AI review requested due to automatic review settings September 27, 2026 15:39
@sonarqubecloud

Copy link
Copy Markdown

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.

Copilot review overview

🟡 Changes recommended

Unresolved moderate findings remain in legacy run-key validation and unexpected-file handling.

Review effort: Lite
Findings: 1 Medium severity

Open (1)

Comment thread scripts/doc_health/catalog.py Resolved
@brettheap
brettheap marked this pull request as ready for review September 27, 2026 16:06

@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 4 days and 22 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@brettheap
brettheap merged commit c5e2614 into main Sep 27, 2026
16 checks passed
brettheap added a commit that referenced this pull request Sep 27, 2026
Brings in #1175 and #1184 (a9e7db7). #1184 repairs the three dangling
cl-plane-1 cluster refs (#1159), so the real seal of this branch runs
over the corpus the nightly will seal next. Neither touches a file of
this change.

Lane: openxfactory-5 (openXfactory-5)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
brettheap added a commit that referenced this pull request Sep 27, 2026
#1189)

* Preflight every run-directory descendant against the exact allowed set

write_run's stranger preflight only ever saw paths _snapshot_files
yields, which filters to *.yaml -- so a non-YAML file (notes.txt), a
*.yaml.bak-style file, or a stranger subdirectory (empty, or holding
only non-YAML content) inside an existing run directory was never
checked against the run's recorded content, and the run-identity hash
never saw it.

_refuse_foreign_descendants walks every descendant of the run
directory -- file or subdirectory, at any depth -- and refuses
anything outside the exact allowed set (run.yaml plus the
repository-snapshot paths the run records) before the first write or
claim, reported the same way (CatalogError, "does not record") as the
existing stranger-snapshot refusal. write_run's preflight now calls it
in place of the *.yaml-filtered strangers check; _snapshot_files
itself is unchanged, and still serves its other callers (_load_run,
_load_run_bytes) exactly as before.

Five new tests: a non-YAML stranger (top-level and nested), a
*.yaml.bak-suffixed stranger, an empty stranger subdirectory, a
stranger subdirectory holding a non-YAML file, a symlinked stranger
(already refused pre-existing by _refuse_links_inside -- kept as an
interaction guard, not new coverage), and a clean run (fresh, and a
repeat over an already-recorded nested-repository run) that still
passes. Verified against the aggregation's real recorded runs (31
directories, 237 real document-cataloging artifacts): every one still
passes the new preflight and scripts/validate-document-catalog.py.

For #1186, a follow-up to #1175 (squash
c5e2614), raised by Copilot's review thread on catalog.py:1161 and
declined there as out of scope for that landing.

Lane: openxfactory-1
Co-Authored-By: Claude Sonnet 5 <[email protected]>

* Fail closed on enumeration errors; tolerate writer-owned temps

Two findings from review on PR #1189 (for #1186):

Copilot: os.walk silently swallows a directory it cannot enumerate
when onerror is omitted, so a foreign descendant hidden inside an
unreadable subdirectory of an otherwise legitimate, allowed ancestor
would never be seen at all -- the preflight would complete over a
subtree it never actually verified. _refuse_foreign_descendants now
passes an onerror callback that raises CatalogError, failing closed
instead.

Codex (P1): _write_rendered's tempfile.mkstemp deliberately creates
"<final-name>.<random>.tmp" inside the run directory. An identical
writer racing this one -- caught between its own mkstemp and
os.replace when this preflight runs, the overlap
test_overlapping_identical_runs_both_complete already relies on -- or
a hard crash that orphaned one before write_rendered's own cleanup
could run, was mistaken for a foreign descendant, turning a normally
harmless race or a normally healable crash into a permanent refusal on
every retry. _is_writer_temp now excludes exactly that shape (a
same-directory sibling of an allowed file, named "<that file's
name>.<anything>.tmp") from the refusal; neither the run-identity hash
nor _snapshot_files ever reads a .tmp file, so this does not weaken
what the run records.

Four new tests, each proven to fail against the prior commit and pass
on this one: a concurrent writer's in-flight temp and a crash-orphaned
one (both tolerated), and an unreadable allowed-ancestor subdirectory
(now refused, "could not be fully enumerated", instead of silently
passing).

Lane: openxfactory-1
Co-Authored-By: Claude Sonnet 5 <[email protected]>

* Require a random component and a regular file for a writer temp

Review round 2 continued (Copilot, PR #1189 for #1186, after the
first onerror/temp-tolerance round): _is_writer_temp's first cut
accepted "<final-name>.tmp" with no random component at all, and any
non-symlink special node (a FIFO, for instance) sharing a temp-shaped
name. mkstemp never omits its random component and never creates
anything but a plain file, so both shapes can only be a stranger
deliberately or accidentally named to resemble a temp -- outside the
exact allowed set, and still refused now: the random component between
the prefix and ".tmp" must be non-empty, and the node must satisfy
is_file() (safe once _refuse_links_inside has already refused every
symlink in the tree).

One new test, two cases, each proven to fail against the prior commit
and pass on this one: a same-directory "alpha.yaml.tmp" with no random
part, and a FIFO named "alpha.yaml.z9k2p7.tmp".

Lane: openxfactory-1
Co-Authored-By: Claude Sonnet 5 <[email protected]>

---------

Co-authored-by: Claude Sonnet 5 <[email protected]>
brettheap added a commit that referenced this pull request Sep 27, 2026
… (#1190)

* Make the shared catalog run scan link-safe for every caller (for #1187)

_iter_runs, the scan behind load_snapshot, the writer's sequence claim and
the run-identity check, followed symlinks: is_dir(), is_file() and the
run.yaml read all do. A symlinked day directory, run directory or run.yaml
was enumerated, and its run.yaml read, as though it were a recorded run,
and a malformed linked run.yaml aborted the scan for every caller. #1175
(c5e2614) made the writer refuse links but left this reader unchanged
(Copilot round-8 thread on #1175, registered as this follow-up).

The scan now checks each node for a link before it lists, stats or reads
it, and never reads through one:

- a link where the writer makes a day directory, run directory or run.yaml
  (dangling, pointing inside the tree, or escaping the catalog root), and a
  recorded run holding a link anywhere inside it, is yielded as a refused
  entry for that entry alone, with no sequence read;
- a link at the catalog root or a catalog directory above the day
  directories puts every run behind it, so the scan raises CatalogError;
- a missing or non-directory catalog node still means no runs, and a
  regular run.yaml that cannot be parsed still raises, both unchanged.

Per caller:

- load_snapshot never selects a refused entry, as latest, by date or by
  id; it returns the latest matching run readable without a link, or None;
- _claim_sequence claims nothing beside a refused entry: its sequence and
  date were never read, so a claim could reuse the number it records or
  land a run dated before it. The writer records nothing until the entry
  is repaired or removed, as it already does beside a foreign claim node;
- the run-identity check reports each refused entry as the existing
  catalog-integrity finding for that entry alone, whatever its name (a
  symlinked day directory is reported as the day itself).

On a tree without links every caller sees exactly the runs the scan saw
before: the clean-tree test compares against a copy of the old scan, and
over the aggregation's 31 real recorded runs every scan row, lookup, next
sequence and document-catalog finding is byte-identical to main.

Lane: openxfactory-1
Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Refuse a claim before creating or reading anything through a link (for #1187)

Review on #1190 (Copilot and Codex, one finding): _claim_sequence created
runs/.sequence before the run scan could refuse. A write_run refused beside
a linked entry, or as stale, still left the claims directory behind, and a
direct claim through a linked root or runs directory created it inside the
link's target before the scan raised. A linked claims directory was read,
and claimed into, through the link.

The claim loop now runs the run scan first, which refuses a link on the
catalog chain before anything follows it. It then refuses a claims
directory that is a link or not a directory (_refuse_foreign_node), reads
the claims, applies the stale refusal, and creates the claims directory
only when a number is about to be claimed. The new
test_a_refused_claim_creates_nothing covers all five refusals; each case
fails on main and on b6a7064.

Lane: openxfactory-1
Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Fail closed on a directory the run scan cannot list (for #1187)

Review round 2 on #1190 (Copilot): the walk inside a recorded run reused
_refuse_links_inside, whose os.walk passes no onerror. A directory it could
not list was skipped in silence, so the run was yielded as link-free over a
subtree nobody saw, and a link below it would evade the refusal. An entry
it could list but not lstat escaped the scan as a raw PermissionError,
which no caller catches.

The run scan now has its own walk, _link_inside. Its onerror raises, and an
entry it cannot lstat is caught, so either refuses that run alone, as the
existing catalog-integrity finding, exactly like a link inside it.
load_snapshot never selects that run and no sequence is claimed beside it.
_refuse_links_inside, which write_run's preflight also calls, is left as it
is, so the writer's behaviour does not change here.

New tests: test_run_scan_fails_closed_on_a_directory_it_cannot_list
(unlistable and unsearchable) and
test_a_run_holding_a_directory_the_scan_cannot_list_is_reported_alone.
Both fail on main and on 3f80fe1.

Lane: openxfactory-1
Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Check every node the run scan meets with an explicit lstat, failing closed (for #1187)

Review round 3 on #1190 (Copilot): from Python 3.13 Path.is_symlink is
os.path.islink, which reports a node whose lstat is denied as no link. So
a scan built on it would pass a child of a listable but unsearchable
directory, a link included, as link-free. Python 3.12 raises instead, but
out of the scan, as a raw PermissionError that no caller catches. The
same held at the positions: a day or run directory the scan could not
list or search escaped as a raw PermissionError on 3.12 (on main too),
and would be passed over on 3.13.

Every link check in the scan now goes through _link_refusal, an explicit
os.lstat that refuses a symlink or a node whose lstat fails for any reason
but its absence. Every listing goes through _listing, which refuses a
directory it cannot list. Whatever the scan cannot check or list refuses
that entry alone (a day directory it cannot list is refused as the day),
and a node on the catalog chain it cannot check or list refuses the whole
scan, as a chain link does. Behaviour on a readable tree is unchanged.

test_run_scan_never_takes_an_unchecked_node_for_link_free pins
Path.is_symlink to its 3.13 behaviour and covers the exact case plus an
unsearchable run directory, an unsearchable and an unlistable day
directory, and an unlistable runs directory. Each case fails on main and
on 47132d0.

Lane: openxfactory-1
Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Walk a recorded run by each node's own lstat, never stat-ing a link's target (for #1187)

Review round 4 (Copilot, #1190): the scan's walk inside a recorded run
was os.walk, which sorts every entry it lists into directories and files
with DirEntry.is_dir(). That follows a link to stat its target before the
scan's own lstat check sees the link, so a link inside a run had its
target stat-ed although nothing behind it was read.

_link_inside now walks by each node's own lstat (_own_mode, which
_link_refusal now wraps): it lists names only, identifies a link before
anything else touches it, and descends only into a real directory, in
the same depth-first name order, failing closed as before. The writer's
own walk (_refuse_links_inside) is unchanged.

test_run_scan_never_stats_a_link_target records every call that stats a
link's target (os.stat following links, and a listed entry classified
following links) while the scan, load_snapshot and the claim run. A
control proves the recorder sees both ways os.walk does it. Every
link-inside position fails on 9635c64, where the recorder names the
link, and every position fails on main.

Lane: openxfactory-1
Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Classify each node the run scan meets by its own lstat, never a second stat (for #1187)

Review round 5 (Copilot, #1190): its review at 7bd2330 posted no
finding, but its overview counted two moderate fail-closed issues, and
its job log shows the two candidate comments it stored and never posted,
at the catalog chain's is_dir() and at run.yaml's is_file(). After its
lstat check the scan still asked is_dir() and is_file() what a node was.
Each stats the node a second time, following links, and from Python 3.13
swallows every OSError. So a catalog, day or run directory, or a
run.yaml, whose second stat failed read as absent: the scan reported no
catalog, or passed over a day or a recorded run, instead of failing
closed.

_iter_runs now classifies every node by the mode its own lstat returned
(_own_mode), at all four sites, so it makes no following stat at all.
_link_refusal, left unused, is removed. For a node that is not a link,
lstat and stat report the same mode, so on a tree nothing races every
caller sees the same runs as before.

test_run_scan_classifies_every_node_by_its_own_lstat records every
following stat while the scan runs (there are none now). Then it pins
is_dir() and is_file() to their 3.13 behaviour and denies the following
stat of a catalog directory, a day directory, a run directory, a
run.yaml, or every node; the scan yields every run each time. Each phase
and case fails on 7bd2330 and on main, where the scan silently yields
nothing.

Lane: openxfactory-1
Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.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