Orchestrata Ultimate › Plans › briefs › spec-110-s3-fix3-builder

SPEC-110 packet S3 — fix round 3 builder brief (round-3 reviewer findings F1, F2, F3)

Source: plans/briefs/spec-110-s3-fix3-builder.md at 8a2cb42ad · last changed 2026-10-07 · first committed 2026-10-07 · 917 lines.

Prose pending.

Plan text

SPEC-110 packet S3 — fix round 3 builder brief (round-3 reviewer findings F1, F2, F3)

Authority: ADR-0068 (Accepted) for REQ-110-034; contract plans/contracts/spec-110-codemod-engine.contract.json (9f7ee385d) sections classes (FR-012), check_catalogue, reuse, design_decisions D23 and D27; plan plans/spec-110-completion-plan.md §1 D5/D6/D7, §2 row S3, §3 ship-log S3 row; spec specs/110-codemod-engine/spec.md REQ-110-033/034/035, ERR-110-002. The baseline default is ADR-0073 (Proposed, Mohamed's ruling pending): do not flip it, do not add a CLI --baseline flag. Base: branch feat/spec-110-completion in /home/mohamed/workspace/orchestrata-ultimate-worktrees/wt-SPEC-110 at 325a0404b (S3 build 24b856ccd/81c5ea708/32a56e4d9; fix round 1 ace6149cb/32b00b303/13f063277; fix round 2 1e8c05eb7/325a0404b; ADR-0073 commits 2b8e510c0/ec696caf1). No rebase or amend; commits on top. Previous briefs: plans/briefs/spec-110-s3-builder.md (build). Round-3 reviewer report: summarised in §4 below with every measured number.

DESIGN_WAIVER: ADR-0068 (Accepted) for REQ-110-034; RUL-022 contract plans/contracts/spec-110-codemod-engine.contract.json (9f7ee385d, D27) for the S3 classes and the commit() wiring; plan D5/D6/D7. Scope beyond them is a STOP, not a guess.

GOAL: Close round-3 findings F1 (include-root normalisation drops every CO_LOCAL_MODULE_EXISTS finding for an absolute, . or .. include), F2 (CO_THIRD_PARTY_DECLARED reports sibling modules directly under scripts/ as undeclared third-party packages at error severity) and F3 (one docs sentence the real tree contradicts), prove each with the reviewer's probes, re-measure the whole tree once, and record the numbers in the plan S3 row.


1. Exact source under change (serialize_codebase_ast.py source, byte-exact at 325a0404b)

1a. refactor.codemod.workspace._include_root — F1 site

# src/orchestrata_ultimate/refactor/codemod/workspace.py:218-220
def _include_root(subdir: str) -> str:
    """``subdir`` as a repo-relative POSIX root without a trailing slash."""
    return os.path.normpath(subdir).replace(os.sep, "/")

Caller (CodemodWorkspace.load, workspace.py:411): include_roots=tuple(_include_root(subdir) for subdir in include). How load walks the same include (lines 40-46 of the method body):

        files: list[Path] = []
        for subdir in include:
            subdir_path = root / subdir
            if subdir_path.exists():
                files.extend(sorted(subdir_path.rglob("*.py")))

root / subdir makes an absolute subdir win over root (pathlib semantics), so the files load correctly while the stored root stays absolute and never matches a repo-relative candidate path.

1b. refactor.codemod.review_checks._outside_include_roots — F1 consumer

# src/orchestrata_ultimate/refactor/codemod/review_checks.py:153-171
def _outside_include_roots(message: str, roots: tuple[str, ...]) -> bool:
    """Whether the import a completeness finding names lies outside ``roots``. ..."""
    found = _IMPORT_IN_MESSAGE.search(message)
    if not roots or found is None:
        return False
    full = found.group(1)
    candidates = _build_module_candidates(full.split(".")[0], full)
    return not any(
        candidate.replace(os.sep, "/").startswith(root + "/")
        for candidate in candidates
        for root in roots
    )

Used once, review_checks.py:358 inside ReusedCheck.run. Candidate paths are repo-relative (src/orchestrata_ultimate/...), so a root of /abs/..., . or .. matches nothing and EVERY finding is dropped (the reviewer measured 0 findings where 1 is expected).

1c. refactor.codemod.review_engine._top_level — F2 site

# src/orchestrata_ultimate/refactor/codemod/review_engine.py:335-340
def _top_level(path: str) -> str:
    """The importable top-level name a forest path contributes."""
    parts = path.removesuffix(".py").split("/")
    if parts[0] == "src" and len(parts) > 1:
        return parts[1]
    return parts[0]

Caller: InMemoryReviewEngine._shared (review_engine.py:259-270):

        paths = set(forest) | {path for path, _ in ws.unparsable}
        return {
            "project_modules": frozenset(_top_level(path) for path in paths),
            "workspace_files": frozenset(paths),
            "declared_deps": self._declared_dependencies(ws.root),
            "banned_libraries": _banned_libraries(),
        }

_top_level("scripts/generate_rtm_evidence.py") is "scripts", so import generate_rtm_evidence from a sibling script is neither project nor declared → error. check-deps in scripts/serialize_codebase_ast.py already solves this with _local_module_names (every module and package stem under src scripts tests claude is local); mirror that rule, do not import scripts/ from src/.

2. Symbol references (refs, live AST at 325a0404b)

symbol def uses
_include_root workspace.py:218 workspace.py:411 (in load)
include_roots (property) workspace.py:422 review_checks.py:358, review_engine.py:82 (ReviewContext field), review_engine.py:292 (_context), workspace.py:252 (__init__), tests test_review_checks.py:84, test_review_engine.py:206,213,229
_outside_include_roots review_checks.py:153 review_checks.py:358
_top_level review_engine.py:335 review_engine.py:265 (_shared), test test_review_engine.py:722
_shared review_engine.py:259 review_engine.py:249
ReusedCheck review_checks.py:301 review_checks.py:989 (build_default_implementations), tests

Who imports the three modules: workspace has 36 import sites (production: __init__.py:55, _daemon_entry.py:95, review_engine.py:44, server.py:18; the rest tests); review_engine 8 (__init__.py:51, review_catalogue.py:26, review_checks.py:65, workspace.py:55, 4 tests); review_checks 3 (review_catalogue.py:405, 2 test imports). Production constructions of CodemodWorkspace all go through load(); _daemon_entry.py:102,121 and server.py:416 are full loads. Full pack: /tmp/claude-1001/-home-mohamed/42ea036c-e296-4b26-b447-2f612e9dd49a/scratchpad/s3_fix3_pack.md. Note: the Prolog code-intelligence KB (scripts/code_intel.py) predates the S3 symbols (it answers unknown_symbol for _top_level); use refs/who-imports from the live toolkit, not code_intel.

3. F1 input table — what load() stores today and what it must store

CLI passes --include through unchanged (scripts/codemod.py:228-231). root is the repo root.

--include form stored today files loaded? required stored root
src/orchestrata_ultimate/refactor/codemod/analysis same yes same
src/, ./src, src//x/ src, src, src/x yes unchanged (already right)
/home/.../wt-SPEC-110/src/orchestrata_ultimate/refactor/codemod/analysis the absolute path yes (11 files) src/orchestrata_ultimate/refactor/codemod/analysis
. . yes (whole repo) no restriction (store nothing for this entry, or the empty tuple means "no roots")
../wt-SPEC-110/src (resolves inside root) ../wt-SPEC-110/src yes src
../elsewhere (resolves outside root) stored unchanged loads foreign files raise ValueError naming the include and the root

Rule: (root / subdir).resolve().relative_to(root.resolve()), POSIX-joined; Path(".") relative → no restriction; ValueError from relative_to → raise. Keep _include_root a module function (the test at test_review_engine.py:722 style imports privates); give it the root argument.

4. F2 affected sites (reviewer's whole-tree identity review at 325a0404b)

CO_THIRD_PARTY_DECLARED errors that are sibling scripts/ modules (all exist as scripts/*.py):

file:line import
scripts/add_traces_from_evidence.py:45 generate_rtm_evidence
scripts/attribute_traces_runtime.py:86,87 add_traces_from_evidence, generate_rtm_evidence
scripts/architecture_static_check.py:38 architecture_checker
scripts/sweep_test_pollution.py:98 slot_lease
scripts/_irc_listen.py:29 _irc_conversation
scripts/_irc_send.py:20 _irc_conversation
scripts/_janus_patched/setup.py:13 _find_swipl

Fix: a file directly under a non-src root (scripts/foo.py, tests/foo.py, claude/foo.py) contributes its basename stem foo; a package directory directly under such a root contributes its directory name; src/<pkg>/... keeps contributing <pkg>. Do NOT make every nested stem local (that would silence real third-party misses); mirror exactly what _local_module_names in scripts/serialize_codebase_ast.py does — read it with source first and copy the rule, not the function.

Not F2, leave alone and do not re-classify: src/orchestrata_ultimate/gateway/config.py:59 (true positive), scripts/attribute_traces_runtime.py:82 coverage (arguable, carried), the vendored scripts/_janus_patched/** hits, scripts/check_staged_secrets.py:297, scripts/serialize_codebase_ast.py:6957.

5. F3 docs sentence

docs/codemod-review-engine.md lines 162-178, paragraph "Narrow include.". The sentence "A full load stores src, scripts and tests, so a missing module under those is reported." is false on this tree: the reused _build_module_candidates includes src/orchestrata_ultimate/__init__.py, which any wide include loads, so CO_LOCAL_MODULE_EXISTS never fires for orchestrata_ultimate.* imports on a full load, on --include src, or on --include src/orchestrata_ultimate (reviewer: core.nope_r3 and analysis.nope_r3 appended under include=("src",) → 0 findings). Replace it with the measured truth: a full load stores the three roots and drops nothing, and the check reports a missing module only when the package's __init__.py is NOT in the forest (a reused-function property, carried). Keep the closing caveat; make the two agree. Rename or re-docstring tests/refactor/codemod/test_review_checks.py::test_local_module_check_is_unrestricted_on_a_full_load so its name says what it proves (nothing is dropped), not that a missing module is reported.

6. Probes — absolute paths, commands, measured baselines, expected after

All under S=/tmp/claude-1001/-home-mohamed/42ea036c-e296-4b26-b447-2f612e9dd49a/scratchpad. Run each from the worktree with .venv/bin/python. Check scripts/observe_pytest.py list first; the whole-tree probe needs an idle box (~110 s, ~3.4 GB).

probe command baseline at 325a0404b (reviewer) expected after fix
F1 root forms .venv/bin/python $S/r3_probe.py (sections: scoping on the real tree, root normalisation, regex truth table) absolute include → 0 findings for appended ...analysis.nope_r3; relative → 1 absolute, ./, trailing-slash → 1; . → 0 with no roots stored (no restriction); ../elsewhere → ValueError
round-2 scoping .venv/bin/python $S/r2_probe.py (§5 mixed imports) exactly 1 finding, tools.nope unchanged
whole tree .venv/bin/python $S/probe_engine_fix1.py (include src,scripts,tests, identity change per file, include_phase3=False); reviewer's output $S/r3/r3_measure.log, $S/r3/r3_all.json 242 errors / 98 files; CO_THIRD_PARTY_DECLARED includes the 8 sibling-script hits of §4 the 8 §4 hits gone; config.py:59 still present; report the new totals and by-rule table
dry run tools scripts/codemod.py --repo . --include src/orchestrata_ultimate/tools --no-daemon run --pass docstring-sweep --arg old=X --arg new=Y --output $S/fix3_dry_tools.json; baseline $S/r3/dry_tools.{log,json} rc 0, 0 errors, 224 warnings unchanged
dry run gateway same with --include src/orchestrata_ultimate/gateway, output $S/fix3_dry_gateway.json; baseline $S/r3/dry_gateway.{log,json} rc 1, 1 error SF_EVAL_EXEC gateway/config.py:59 "L59: Possible hardcoded secret." unchanged
dry run scripts same with --include scripts --output $S/fix3_dry_scripts.json not measured (would abort on §4 hits) no CO_THIRD_PARTY_DECLARED error on the §4 files; report rc and the remaining error list

7. Tests to add (one function per row, real parsed modules, no doubles)

tests/refactor/codemod/test_workspace_load.py:

tests/refactor/codemod/test_review_checks.py:

tests/refactor/codemod/test_review_engine.py:

@traces on every new test: REQ-110-034 for F1/F3 (substrate/scope), REQ-110-033 for F2 (the check's behaviour); nothing else (RUL-013).

8. Gates, commands, expected results

gate command expected
ruff uv run ruff check <touched files> All checks passed!
black uv run black --check <touched files> N files would be left unchanged.
pyright uv run pyright src/orchestrata_ultimate/refactor/codemod/{workspace,review_checks,review_engine}.py 0 errors
Prolog gate uv run ast-sync && uv run python scripts/gate.py run gate: PASS, rc 0 (rc 2 = stale snapshot, run ast-sync first)
deps .venv/bin/python scripts/serialize_codebase_ast.py check-deps --include-tests rc 0
spec authority uv run python scripts/check_spec_authority.py PASS, rc 0
pytest groups OPENBLAS_NUM_THREADS=1 OMP_NUM_THREADS=1 MKL_NUM_THREADS=1 PYTHONPATH=scripts timeout 300 .venv/bin/python -m pytest <modules> -p orchestrata_pytest_observer -p orchestrata_ultimate.core.threading.pytest_live_observer -q -p no:cacheprovider -rs zero skips; baselines at 325a0404b: test_review_checks.py+test_review_engine.py 73; test_review_engine_commit_wiring.py+test_observability_wiring.py+test_workspace_load.py 58; tests/scripts/test_codemod_cli.py 53; tests/verification/review/ 161
coverage (DOD-S3-5) the build brief's command over the review test modules + test_workspace_load.py review_engine.py 100%, review_checks.py ≥ 99%, workspace.py ≥ 90% (baselines)

Run pytest in the background with a log and echo "rc=$?" >>; wait with timeout 290 bash -c 'until grep -q "^rc=" <log>; do sleep 10; done' (the wait command must not contain the tokens run_tests, passed, FAIL or a check-mark emoji). Never commit while a pytest run is in flight in this worktree (git-sentinel).


FILES: edit src/orchestrata_ultimate/refactor/codemod/workspace.py (_include_root + its call in load, nothing else), review_engine.py (_top_level), review_checks.py (only if _outside_include_roots needs the "no roots" convention adjusted; the drop rule itself is right), tests/refactor/codemod/test_workspace_load.py, test_review_checks.py, test_review_engine.py, docs/codemod-review-engine.md (§5), plans/spec-110-completion-plan.md (S3 ledger cell: "FIX ROUND 3" with the §6 numbers), reports/rtm-evidence.{md,json} (regenerate, unverified). Do not touch analysis/, review.py, verification/review/*, scripts/codemod.py, review_catalogue.py rows, the contract JSON, or core/patterns/observer.py.

CONSTRAINTS: worktree /home/mohamed/workspace/orchestrata-ultimate-worktrees/wt-SPEC-110, branch feat/spec-110-completion; never cd into the main checkout. Read Python only via .venv/bin/python scripts/serialize_codebase_ast.py source|symbols|refs|who-imports <qname> --no-daemon (qualified names omit orchestrata_ultimate.); Edit/Write tools for edits (hooks block Bash writes and cat/grep/sed on .py). No mocking/fakes/monkeypatch, no skip/xfail, no pytest-xdist, function-scope fixtures, absolute imports, os.environ.get, uv only. Commit as git -c user.name=Mohamed -c user.email=msamy@sufigeeks.org commit, no AI attribution, no "should" anywhere. Restore hook litter by name before each commit (docs/CODEBASE_MAP.md docs/CODEBASE_MAP_FULL.md plans/ast-ultimate.json plans/ast-deep-comparison.json plans/ast-tests.json reports/.ship-verified reports/run-tests-latest.json, only those present and modified). A fork the contract and D5/D6/D7 do not settle → STOP and report; do not guess.

DONE WHEN: (1) every §3 row behaves as its last column says and the §7 test_workspace_load.py tests pass; (2) the §4 files produce no CO_THIRD_PARTY_DECLARED error in the whole-tree probe and the two §7 _top_level tests pass; (3) docs/codemod-review-engine.md §5 sentence replaced and the test renamed; (4) all §6 probes give their "expected after" column, with the dry-run and whole-tree numbers written into the plan S3 ledger cell as "FIX ROUND 3"; (5) all §8 gates at their expected results, pytest groups green with zero skips at or above the baselines; (6) commits made, tree clean except hook litter; report with shas, the §6 table filled in, the pytest counts, the coverage table, and deviations with reasons.

VERIFY: the §6 table with measured values; pytest counts per group; git log --oneline 325a0404b..HEAD; git status --short.


Round 3b — the fork the round-3 builder stopped on (orchestrator's pick, 2026-10-07)

Round 3 (86859b5ce, 7b00d9d4b, a80a2c543) closed F1 and F3. F2 moved the seven sibling-script imports from CO_THIRD_PARTY_DECLARED to CO_LOCAL_MODULE_EXISTS: once generate_rtm_evidence is in project_modules, the reused check_file_completeness runs _build_module_candidates(top, full), which proposes src/<top>/... shapes and never scripts/<top>.py, so it reports "module file not found in workspace". Whole-tree errors stayed at 242.

Pick: cure (a). Drop such findings in ReusedCheck.run next to the include-root drop; do not widen the reused candidates (every other consumer of verification/review would change). The brief's F2 prose in §4 contradicted itself ("mirror _local_module_names" vs "do NOT make every nested stem local"); the round-3 builder followed the explicit prose, which is the right reading. Nested stems stay un-local; scripts/_janus_patched/setup.py:13 (_find_swipl, which lives at scripts/_janus_patched/janus/_find_swipl.py) is vendored and stays carried.

3b.1 Exact source at a80a2c543

# src/orchestrata_ultimate/refactor/codemod/review_checks.py:341-362
    def run(self, module: LosslessModule, ctx: ReviewContext) -> list[Finding]:
        ...
        findings = IssueAdapter.to_findings(
            self._fn(*self._args(module, ctx)), ctx.path, self.descriptor.severity, self.descriptor.id,
        )
        if self._arg_shape == "path_tree_files_modules":
            findings = [
                finding
                for finding in findings
                if not _outside_include_roots(finding.message, ctx.include_roots)
            ]
        if self._extension is not None:
            findings.extend(self._extension.run(module, ctx))
        return findings

_IMPORT_IN_MESSAGE = re.compile(r"Import '([^']+)'") (review_checks.py:120). ReviewContext fields available: workspace_files: frozenset[str] (forest-relative paths, parsed and unparsable), project_modules, include_roots, path. _SIBLING_ROOTS is defined in review_engine.py next to _top_level (review_engine.py:338-353); import it, do not duplicate the tuple.

3b.2 The rule

A finding of the path_tree_files_modules check is dropped when the import it names has a top-level name top such that, for some root in _SIBLING_ROOTS, f"{root}/{top}.py" or f"{root}/{top}/__init__.py" is in ctx.workspace_files. Implement as _resolves_to_sibling_module( message, workspace_files) -> bool beside _outside_include_roots, applied in the same comprehension. Nothing else: a top that is only a nested stem (scripts/_janus_patched/janus/_find_swipl.py) does not match, by design.

3b.3 Sites that must change, and the ones that must not

site before 3b after 3b
scripts/_irc_listen.py:29 _irc_conversation CO_LOCAL_MODULE_EXISTS error none
scripts/_irc_send.py:20 _irc_conversation error none
scripts/add_traces_from_evidence.py:45 generate_rtm_evidence error none
scripts/architecture_static_check.py:38 architecture_checker error none
scripts/attribute_traces_runtime.py:86,87 2 errors none
scripts/sweep_test_pollution.py:98 slot_lease error none
scripts/_janus_patched/setup.py:13 _find_swipl error unchanged (vendored, carried)
src/orchestrata_ultimate/gateway/config.py:59 SF_EVAL_EXEC error unchanged
whole tree (probe_engine_fix1.py) 242 errors / 98 files; CO_LOCAL_MODULE_EXISTS 7 235 / 92; CO_LOCAL_MODULE_EXISTS 1 (setup.py:13); report the by-rule table
dry run --include scripts, pass docstring-sweep --arg old=Args: --arg new=Arguments: rc 1, 33 errors (32 CO_THIRD_PARTY_DECLARED on orchestrata_ultimate/orchestrata_ast imports because a scripts-only forest has no src, plus SF_EVAL_EXEC) report rc and the error list; the 32 are NOT this round's (a narrow forest without src genuinely lacks those packages; record as a carried item: "narrow include without src reports the repo's own packages as third-party — scope rule for CO_THIRD_PARTY_DECLARED, design item, owner orchestrator")

Also carried, record in the plan ledger cell, do not fix here: the DocstringSweepPass SystemError the round-3 builder hit with old=X new=Y on --include scripts (a pass defect: the edit corrupts a string and the native tokenizer raises) — "docstring-sweep with a substring that lands inside a string literal raises SystemError instead of a finding or a refusal; owner: S4/S5 hygiene".

3b.4 Tests (names; real parsed modules in a temp repo loaded through CodemodWorkspace.load)

tests/refactor/codemod/test_review_checks.py:

@traces REQ-110-033 (the check's behaviour). Keep the round-3 _top_level tests as they are.

3b.5 Done when (3b)

(1) the four 3b.4 tests pass; (2) probe_engine_fix1.py gives 235 errors / 92 files with CO_LOCAL_MODULE_EXISTS = 1 (setup.py:13) and the by-rule table is written into the plan S3 ledger cell as "FIX ROUND 3b" together with the two carried items in 3b.3; (3) the §8 gates at their expected results, pytest groups at or above the round-3 counts (85 / 66 / 53 / 161), zero skips; coverage review_checks.py ≥ 99%; (4) docs/codemod-review-engine.md gains one sentence on the sibling rule in the "Narrow include" paragraph; (5) commits on top of a80a2c543 as Mohamed, tree clean except hook litter; report with shas, the 3b.3 table filled, pytest counts, deviations.


Round 4 — round-4 reviewer findings (orchestrator's picks, 2026-10-07)

Round 3b (ac003e9eb, 7eeb8bbcd, f25c0577b) closed the seven sibling-script false positives; the round-4 reviewer confirmed every number (235 errors / 93 files, five files cleared, none added) and returned NO-GO narrow on tests plus one design question. Picks:

4.1 Exact source at f25c0577b

# src/orchestrata_ultimate/refactor/codemod/review_checks.py:175-194
def _resolves_to_sibling_module(message: str, workspace_files: frozenset[str]) -> bool:
    found = _IMPORT_IN_MESSAGE.search(message)
    if found is None:
        return False
    top = found.group(1).split(".")[0]
    return any(
        f"{root}/{top}.py" in workspace_files
        or f"{root}/{top}/__init__.py" in workspace_files
        for root in _SIBLING_ROOTS
    )
# review_checks.py, inside ReusedCheck.run (the comprehension)
        if self._arg_shape == "path_tree_files_modules":
            findings = [
                finding
                for finding in findings
                if not _outside_include_roots(finding.message, ctx.include_roots)
                and not _resolves_to_sibling_module(finding.message, ctx.workspace_files)
            ]
# src/orchestrata_ultimate/refactor/codemod/review_engine.py:258-269  (_shared)
        paths = set(forest) | {path for path, _ in ws.unparsable}
        return {
            "project_modules": frozenset(_top_level(path) for path in paths),
            "workspace_files": frozenset(paths),
            "declared_deps": self._declared_dependencies(ws.root),
            "banned_libraries": _banned_libraries(),
        }
# review_engine.py:271-293  (_context) — builds ONE ReviewContext per reviewed path
        return ReviewContext(
            path=path, forest=forest, cig=ws.cig,
            project_modules=shared["project_modules"],
            workspace_files=shared["workspace_files"],
            declared_deps=shared["declared_deps"], root=ws.root,
            is_test=_is_test_path(path), is_main_file=name in _MAIN_FILES,
            banned_libraries=shared["banned_libraries"], include_roots=ws.include_roots,
        )
# src/orchestrata_ultimate/refactor/codemod/workspace.py:218-236
def _include_root(root: Path, subdir: str) -> str | None:
    rel = os.path.relpath(
        os.path.normpath(os.path.join(os.path.abspath(root), subdir)),
        os.path.abspath(root),
    ).replace(os.sep, "/")
    if rel == ".":
        return None
    if rel == ".." or rel.startswith("../"):
        raise ValueError(f"include {subdir!r} resolves outside the repo root {str(root)!r}")
    return rel

4.2 The changes

R4-2 implementation. In _shared, split the module names: "project_modules" keeps only the src/<pkg> names plus the sibling roots' own names (what _top_level returned before round 3 for src paths and for <root>/__init__.py); add "sibling_modules": frozenset of the stems and package names directly under each sibling root (what round 3 added). In _context, when path is under a sibling root (path.split("/")[0] in _SIBLING_ROOTS), pass project_modules = shared["project_modules"] | shared["sibling_modules"]; otherwise shared["project_modules"] alone. _top_level stays as it is (it is the per-path classifier); if it is cleaner, add _sibling_name(path) -> str | None beside it and keep _top_level returning the pre-round-3 answer — either way, test_top_level_of_a_script_directly_under_scripts_is_its_stem must be updated to assert the function it now tests, not a tautology. In _resolves_to_sibling_module(message, workspace_files, importer_path): return False unless importer_path.split("/")[0] in _SIBLING_ROOTS; and when the match is f"{root}/{top}.py" (a plain module) and the import has more than one component (found.group(1) contains .), return False (a submodule of a plain module cannot exist). Pass ctx.path from run.

R4-1 tests. In test_review_checks.py: _review_after_append loads include=("src", "scripts", "tests") (create empty src/ and tests/ dirs in the temp repo if needed) so the finding survives _outside_include_roots and only the sibling rule can drop it; every sibling test asserts [f for f in findings if f.rule == "CO_LOCAL_MODULE_EXISTS"] == [] (or != [] for the kept cases) explicitly. In test_review_engine.py test_sibling_script_import_is_not_an_undeclared_third_party asserts BOTH rules absent. Add:

R4-3. _include_root: compute resolved = (Path(root) / subdir).resolve() and refuse when resolved is not inside Path(root).resolve() (use relative_to in a try); keep returning the lexical rel for the accepted case so stored roots match forest paths. Test in test_workspace_load.py: a symlink ext -> <tmp outside the repo> as the include raises ValueError; a symlink alias -> src inside the repo is accepted and stores alias.

Records. Plan S3 ledger cell: "FIX ROUND 4" with the measurements below, the D27 note for R4-2, the R4-4 carried item, and the C5 wording update. docs/codemod-review-engine.md: one sentence that sibling locality applies to importers under a sibling root only.

4.3 Expected measurements after round 4

probe at f25c0577b expected after
whole tree probe_engine_fix1.py (root + include src,scripts,tests) 235 errors / 93 files; CO_THIRD_PARTY_DECLARED 6; CO_LOCAL_MODULE_EXISTS 0 unchanged totals unless a src/ module imports a scripts sibling today (report any such new error with file:line; it is a TRUE positive)
dry run tools rc 0, 0 errors, 224 warnings unchanged
dry run gateway rc 1, config.py:59 unchanged
dry run scripts (old=Args: new=Arguments:) rc 1, 33 errors unchanged
pytest groups (zero skips) 89 / 66 / 20 (test_workspace_perf.py+test_parse_cache.py) / 53 / 161 at or above; the new tests add to group 1 and 2
coverage review_checks.py 99%, review_engine.py 100%, workspace.py 94% at or above

4.4 Done when (round 4)

(1) removing and not _resolves_to_sibling_module(...) from run makes at least two tests fail (do it locally, observe, restore — do not commit the removal); (2) the three new tests and the symlink tests pass; (3) probe_engine_fix1.py numbers reported, any new src/ true positive listed; (4) §8 gates at expected results; (5) ledger, D27 note, docs sentence written; (6) commits on top of f25c0577b as Mohamed, tree clean except hook litter; report with shas, the 4.3 table filled, pytest counts, deviations.


Round 5 — execute ADR-0073 (Accepted by Mohamed 2026-10-07, repo 570160a21, wiki bc14fbe)

Authority for this round is ADR-0073 itself (docs/adr/0073-err-110-002-amended-default-review-engine-aborts-on-introduced-findings-delta-baseline.md, Accepted); the DESIGN_WAIVER is ADR-0073 plus ADR-0068 and contract D23/D27. Plan D6 is superseded. Runs AFTER round 4 lands (same files); base is round 4's HEAD.

5.1 Exact source at the sites

# src/orchestrata_ultimate/refactor/codemod/review_engine.py:167-197  (InMemoryReviewEngine.__init__)
        baseline: _Baseline = "absolute",
        ...
            baseline: ``absolute`` reports every finding of the mutated
                modules (plan D6); ``delta`` only those the pass introduced.
# src/orchestrata_ultimate/refactor/codemod/workspace.py:773-797  (_resolve_reviews)
    engine = review_engine
    if engine is None and reviews is None:
        engine = InMemoryReviewEngine()

Spec row (specs/110-codemod-engine/spec.md:957): | ERR-110-002 | REQ-110-013 | Review pass produces error-severity finding | ERROR | Abort commit, return CommitReport with findings, write nothing to disk | and the commit() docstring in the spec at line 1098: ERR-110-002: If any review produces error-severity finding.

CLI run flags (scripts/codemod.py:71-116): --pass, --arg, --apply, --dry-run, --observe, --output; _cmd_run at line 334 builds the workspace and calls commit().

5.2 The changes

  1. InMemoryReviewEngine.__init__: default baseline="delta"; docstring: delta (default, ADR-0073) reports only the findings the change introduced, matched on path, rule and line-free message; absolute reports every finding of the mutated modules (the clean-slate gate). Keep the ValueError on other values.
  2. _resolve_reviews builds InMemoryReviewEngine() → now delta by default; no code change needed there, but the docstring of commit() (workspace.py) gains: "By default an error-severity finding aborts the commit only when the change introduced it (ADR-0073); pass review_engine=InMemoryReviewEngine(baseline='absolute') for the unconditional abort."
  3. scripts/codemod.py run subcommand: --baseline {delta,absolute} (default delta), passed as review_engine=InMemoryReviewEngine(baseline=args.baseline) to commit(); help text names ADR-0073. The JSON report records baseline.
  4. Spec specs/110-codemod-engine/spec.md:957 ERR-110-002 row: append to the Recovery cell: "For the default engine an error-severity finding means one the change INTRODUCED (delta baseline, ADR-0073); baseline='absolute' restores the unconditional abort." Line 1098 docstring: append "(introduced by the change, ADR-0073; absolute baseline aborts on any)". No other spec text.
  5. Checklist specs/110-codemod-engine/checklists/requirements.md: REQ-110-033 and REQ-110-034 rows gain "(default baseline delta, ADR-0073)"; totals unchanged.
  6. Plan plans/spec-110-completion-plan.md: D6 bullet (line 67) gains a trailing sentence "Superseded by ADR-0073 (Accepted 2026-10-07): the default is 'delta'; 'absolute' is the opt-in." — do not rewrite D6's history. S3 ledger cell: "ROUND 5 — ADR-0073 executed" with the measurements in 5.4.
  7. Docs docs/codemod-review-engine.md: the baseline paragraph states the new default, the --baseline absolute escape, and the two documented delta limits (masking; measure-bearing warnings).
  8. Tests:
    • tests/refactor/codemod/test_review_engine_commit_wiring.py: test_default_commit_writes_when_the_only_error_finding_is_legacy (temp repo with a file holding API_KEY = "sk-" + 24 alphanumerics on line 1; a pass appends an unrelated line → success is True, the file is written, the legacy finding is NOT in the report because delta subtracts it) and test_absolute_engine_still_aborts_on_a_legacy_error_finding (same repo, review_engine=InMemoryReviewEngine(baseline="absolute") → success is False, files_written == ()), and test_default_commit_aborts_when_the_change_introduces_an_error (pass adds the secret → success is False). @traces REQ-110-033, REQ-110-035.
    • tests/refactor/codemod/test_review_engine.py: the existing test_absolute_is_the_default_baseline_and_delta_reports_only_new_findings is renamed and re-asserted for the new default (InMemoryReviewEngine()._baseline == "delta"; the explicit baseline="absolute" path still works).
    • tests/scripts/test_codemod_cli.py: --baseline absolute on the existing review-abort fixture → rc 1; default on a repo whose only error is legacy and whose pass is unrelated → rc 0 and the file written with --apply; the report JSON carries "baseline".

5.3 Guard against the obvious regression

The round-2 reviewer's probe_delta.py (prepend import sys above a legacy os.environ["LEGACY"]) must give delta 0 / absolute 1; run it and report. The TST-110-025 mutated-forest proof and TST-110-026 event-order test must still pass unchanged (they assert findings and order, not the baseline).

5.4 Expected measurements

probe before (round 4) expected after
dry run gateway (--include src/orchestrata_ultimate/gateway, docstring-sweep old=X new=Y) rc 1 on config.py:59 rc 0, 0 errors (the secret is legacy; the sweep did not introduce it); with --baseline absolute rc 1 as before
dry run tools rc 0 rc 0
dry run scripts (old=Args: new=Arguments:) rc 1, 33 errors report rc and errors; the 32 CO_THIRD_PARTY_DECLARED are legacy in a scripts-only forest and are expected to vanish under delta; serialize_codebase_ast.py:6957 likewise
whole-tree identity review (probe_engine_fix1.py) 235 / 93 identity changes introduce nothing, so with the DEFAULT engine the probe must report 0 errors; run it ALSO with baseline="absolute" and report the 235 / 93 (or whatever round 4 left) so the ledger carries both
pytest groups round-4 counts at or above, zero skips

5.5 Done when (round 5)

(1) 5.2 items 1–8 done; (2) 5.3 probes as stated; (3) 5.4 table filled; (4) §8 gates at expected results, uv run python scripts/check_spec_authority.py rc 0 after the spec edit; (5) RTM regenerated (unverified); (6) commits as Mohamed on top of round 4's HEAD, tree clean except hook litter; report with shas, tables, counts, deviations.


Round 6 — round-6 reviewer blockers B1/B2 and must-fixes M1/M2 (orchestrator's picks, 2026-10-07)

Round 5 (7db0f25e1, 47e6b20d2, fc793fef2) executed ADR-0073. The round-6 reviewer confirmed the default, the wiring, 1,059 + 161 tests green, and returned NO-GO on:

6.1 Exact source at fc793fef2

# src/orchestrata_ultimate/refactor/codemod/review_engine.py:212-241  (review)
        mutated = {entry.path: entry.mutated_tree for entry in changes.entries}
        findings = self._run_checks(ws, mutated, {**ws.forest, **mutated})
        if self._baseline == "delta":
            original = {entry.path: entry.original_tree for entry in changes.entries}
            findings = self._delta(
                findings, self._run_checks(ws, original, {**ws.forest, **original})
            )
        if self._include_phase3:
            prolog = (self._prolog if self._prolog is not None else PrologSemanticReview())
            findings.extend(prolog.review(cast("Any", ws), changes))
        return findings
# review_engine.py:328-345  (_delta)
    def _delta(mutated: list[Finding], original: list[Finding]) -> list[Finding]:
        known = Counter((f.path, f.rule, _line_free(f.message)) for f in original)
        introduced: list[Finding] = []
        for finding in mutated:
            key = (finding.path, finding.rule, _line_free(finding.message))
            if known[key] > 0:
                known[key] -= 1
            else:
                introduced.append(finding)
        return introduced
# review_engine.py:400-410  (_line_free)
def _line_free(message: str) -> str:
    text = _LEADING_LINE.sub("", message)
    text = _PAREN_LINE.sub("", text)
    text = _BARE_LINE.sub("line", text)
    return " ".join(text.split())
# src/orchestrata_ultimate/refactor/codemod/report.py:93-102
class Finding:  # frozen dataclass
    severity: Literal["error", "warning"]; rule: str; path: str; line: int | None; message: str
    proof_tree: dict[str, Any] | None = None

# report.py:105-139
class CommitReport:  # frozen dataclass
    success: bool; files_written: tuple[str, ...]; findings: tuple[Finding, ...]
    duration_seconds: float; dry_run: bool; passes_run: tuple[str, ...] = ()
    diffstat: str = ""; correlation_id: str = ""
    def to_json(self) -> str: ...  # serialises the fields above
# src/orchestrata_ultimate/refactor/codemod/workspace.py  (commit, lines 59-109 of the method)
        all_findings: list[Finding] = []
        active = _resolve_reviews(reviews, review_engine, run_review_engine)
        if active:
            op.emit(CodemodEventType.REVIEW_STARTED, {"review_count": len(active)})
            for review in active:
                findings = review.review(self, changes)       # (try/except around it)
                all_findings.extend(findings)
                for finding in findings: op.emit(CodemodEventType.FINDING_EMITTED, {...})
            error_count = ...; warning_count = ...
            op.emit(CodemodEventType.REVIEW_COMPLETED, {"finding_count": ..., "error_count": ..., "warning_count": ...})
        error_findings = [f for f in all_findings if f.severity == "error"]
        if error_findings:
            op.emit(CodemodEventType.COMMIT_ABORTED, {...})
            return CommitReport(success=False, files_written=(), findings=tuple(all_findings), ...)

_source_lines(module, blank=frozenset()) (review_checks.py:118) returns the module's lines with readlines semantics; use it (or a thin _line_text(module, line) beside _line_free) to read the text of finding.line from the right tree.

6.2 The changes

B1. _delta(mutated, original, mutated_trees, original_trees): the key becomes (path, rule, _line_free(message), _line_text(tree_for_path, finding.line)) where _line_text returns the line stripped of surrounding whitespace, or "" when finding.line is None or out of range. Each side reads its OWN tree (mutated_trees[path] / original_trees[path]); findings on paths absent from changes.entries cannot occur (only changed modules are reviewed). Keep the multiplicity Counter. Update the _delta docstring and the module/engine docstrings. Tests in test_review_engine.py: (a) the reviewer's in-place case — API_KEY = «redacted» → API_KEY = "sk-" + 24 alphanumericsvia a realReplaceStringLiteralPass(or the CLI'sreplace-string) gives exactly one introduced error under the default; (b) a prepend above a legacy finding still gives 0 (line shift alone does not change the line's text); (c) a legacy line whose text changes only in whitespace gives 0 (strip); (d) the reviewer's B-mask shape — blank a legacy secret line and append a new secret elsewhere → exactly one introduced error. In tests/scripts/test_codemod_cli.py: the reviewer's CLI case (replace-string old=PLACEHOLDER new=sk-…) → rc 1 under the default, file unchanged with --apply`.

B2. New InMemoryReviewEngine.review_detailed(ws, changes) -> ReviewOutcome (frozen dataclass in review_engine.py: introduced: tuple[Finding, ...], legacy: tuple[Finding, ...]); review() becomes return list(self.review_detailed(ws, changes).introduced) so the ReviewPass protocol is unchanged. Under absolute, legacy == () and introduced is everything. In commit(): when a review in active is an InMemoryReviewEngine, call review_detailed, extend all_findings with introduced only (the veto set), collect legacy into legacy_findings, and emit each legacy finding as FINDING_EMITTED with an extra "legacy": True key; REVIEW_COMPLETED gains "legacy_count". CommitReport gains legacy_findings: tuple[Finding, ...] = () (after correlation_id, defaulted, additive) and to_json serialises it as "legacy_findings" with the same shape as findings. Both return CommitReport(...) sites in commit() pass it. Tests: the two tests that asserted an empty report (test_default_commit_writes_when_the_only_error_finding_is_legacy and tests/scripts/test_codemod_cli.py::test_run_default_baseline_is_delta_and_a_legacy_error_does_not_abort) now assert findings == () AND the legacy error present in legacy_findings (and in the JSON); absolute → legacy_findings == (); run_review_engine=False → legacy_findings == (). The event test in test_review_engine_commit_wiring.py (TST-110-026) asserts the legacy: True payload for a legacy finding. Record this as contract note D28 in the plan ledger cell ("CommitReport.legacy_findings additive field; engine review_detailed; orchestrator adds the contract JSON entry at ship-prep") — do NOT edit the contract JSON.

M1. review_engine.py module docstring (lines 12-14) and requirements.md:111 (REQ-110-035 row) say delta is the default (ADR-0073) and absolute the opt-in.

M2. tests/scripts/test_codemod_cli.py: test_run_default_baseline_aborts_when_the_pass_introduces_an_error — real temp repo, replace-string old=hello new=<sk- key> on a clean line → rc 1 dry-run and with --apply, file bytes unchanged, baseline: "delta" in the report.

C1 / C4 / records. Plan S3 ledger cell: replace the ROUND 5 whole-tree figures with the measured ones above (and say "measured by the round-6 reviewer at fc793fef2"); add "ROUND 6" with this round's measurements (6.3); add carried items C4 and the import os as x observation. Docs docs/codemod-review-engine.md: the delta paragraph states the key (path, rule, line-free message, stripped line text), the in-place shape it now catches, the remaining masking shape (removed legacy finding plus identical text AND identical line text elsewhere in the same file), and that legacy findings appear under legacy_findings without vetoing.

6.3 Expected measurements after round 6

probe at fc793fef2 expected after
reviewer's CLI case (scratchpad/r6rev/clirepo, replace-string old=PLACEHOLDER new=sk-…, default) rc 0, findings: [] rc 1, one SF_EVAL_EXEC error; --apply leaves the file unchanged
inject_probe.py case B-mask (default engine) 0 errors 1 error (the appended secret)
r5_probe_delta.py prepend / append (default) 0 / 0 0 / 0 (unchanged: line text did not change)
gateway dry run (docstring-sweep old=X new=Y, default) rc 0 rc 0, and the report's legacy_findings holds the config.py:59 error
scripts dry run (old=Args: new=Arguments:, default) rc 0, 0 errors rc 0; legacy_findings carries the 32 + 1 legacy errors; the DOCSTRING lines the sweep edits must NOT re-fire as introduced unless a finding sits on them — report any that do, with the rule
whole-tree identity review, default engine 0 0
whole-tree, absolute 235 / 93 (measured) unchanged
pytest groups (zero skips) 93 / 71 / 20 / 55 / 161 at or above

6.4 Done when (round 6)

(1) B1 and B2 implemented as in 6.2 with their tests; (2) M1, M2 done; (3) every 6.3 row at its expected value, with the scripts-dry-run re-fire check reported; (4) §8 gates at expected results (ast-sync first for gate.py run), ruff/black/pyright clean, coverage ≥ the round-5 figures (review_engine.py 100%, workspace.py ≥ 91%, scripts/codemod.py ≥ 97%, report.py measured); (5) ledger, docs, D28 note written; RTM regenerated (unverified); (6) commits as Mohamed on top of fc793fef2, tree clean except hook litter; report with shas, the 6.3 table filled, pytest counts, deviations.

Round 7 — round-7 reviewer findings (orchestrator's picks, 2026-10-07)

Base: 7397f2c35 (round 6 landed in ac8188445, eb44e2a5e, 7397f2c35). The round-7 reviewer closed B1, B2, M1, M2 and the eight verification items, re-measured the whole tree under absolute at 235 errors in 93 files / 12,786 warnings and delta 0, and returned NO-GO on ONE blocker: a pre-existing S1 test that pins the exact REVIEW_COMPLETED payload and now sees the key round 6 added. Regression over all of tests/refactor/codemod/ plus tests/scripts/test_codemod_cli.py (reviewer's groups): 1,068 passed, 1 failed, 0 skipped; tests/verification/review/ 161 passed. Round 6's groups (93 / 71 / 20 / 55 / 161) never included test_observability.py; this round's done-when runs every module.

7.1 Exact source at 7397f2c35

Failing test (tests/refactor/codemod/test_observability.py:945-985, TestWorkspaceCommitObserverComposition.test_commit_event_sequence_and_payload_via_debug_panel_ndjson), the assertion at lines 969-973:

        assert lines[0]["payload"] == {"review_count": 1}
        assert lines[1]["payload"] == {
            "finding_count": 0,
            "error_count": 0,
            "warning_count": 0,
        }
        assert lines[2]["payload"] == {"file_count": 0, "dry_run": True}

Producer (src/orchestrata_ultimate/refactor/codemod/workspace.py, inside CodemodWorkspace.commit, the REVIEW_COMPLETED emit near line 712): the payload is {"finding_count": ..., "error_count": ..., "warning_count": ..., "legacy_count": len(legacy_findings)}. Read it with:

.venv/bin/python scripts/serialize_codebase_ast.py source refactor.codemod.workspace.CodemodWorkspace.commit --no-daemon

Failure text from the reviewer's run: Left contains 1 more item: {'legacy_count': 0}.

Spec events table, specs/110-codemod-engine/spec.md:2310-2311:

| `FINDING_EMITTED` | After a review pass produces a finding | `severity`, `rule`, `path`, `line`, `message` |
| `REVIEW_COMPLETED` | After all review passes complete | `finding_count`, `error_count`, `warning_count` |

7.2 The changes

7.3 Done when (round 7)

(1) R7-B1 applied; (2) spec rows amended; (3) C6 written, C5 sentence reworded, C-a/C-b/C-c recorded, docs sentence for C-b added; (4) ledger ROUND 7 cell written; (5) the FULL regression, every module of tests/refactor/codemod/ in groups under the 300 s cap (the reviewer's runner is /tmp/claude-1001/-home-mohamed/42ea036c-e296-4b26-b447-2f612e9dd49a/scratchpad/r7rev/groups.sh; copy it to your own scratch dir and point S there), plus tests/scripts/test_codemod_cli.py and tests/verification/review/: expected 1,069 passed / 0 failed / 0 skipped + 161; (6) ruff/black clean on the changed files; check_spec_authority.py rc 0; (7) commits as Mohamed on top of 7397f2c35, no AI attribution, no "should", tree clean except hook litter (restore docs/CODEBASE_MAP.md docs/CODEBASE_MAP_FULL.md by name if a hook regenerates them); report with shas and the group counts.