Repository navigation
repo_shape.py: load_yaml refuses a YAML file holding a non-UTF-8 byte as REFUSED yaml-unreadable naming the byte, so adopt-project.py check and execute and the validators no longer die with a UnicodeDecodeError traceback and exit 1 on a hand-edited plan or manifest (#192) - #193
Conversation
…te as `REFUSED yaml-unreadable` naming the byte, so `adopt-project.py check` and `execute` and the validators no longer die with a `UnicodeDecodeError` traceback and exit 1 on a hand-edited plan or manifest (#192) `load_yaml` caught `OSError` around `read_text(encoding="utf-8")` and `YamlError` around the parse, and nothing for the decode. `UnicodeDecodeError` is a `ValueError`, and `read_text` raises it after the open has succeeded, so the `OSError` clause never saw it and a plan, manifest or pin with one byte that is not UTF-8 (a raw `0xff` in a leg path, in the issue's probe) escaped every reader as a traceback: exit 1, no `FINDING` or `REFUSED` line, where a missing file is `REFUSED yaml-unreadable` and exit 2. It is now the same code with a detail that names the file, the byte offset and Python's reason (`not UTF-8 at byte 1298 (invalid start byte)`), and a remediation that says the file must be UTF-8 and where to look. Nothing is created: `execute` reads the plan first, so no work directory, local remote or leg exists afterwards. Not chosen: catching it in each reader (about thirty call sites, and `shape-doctor.py` already carries its own `UnicodeDecodeError` clause as the workaround this makes redundant, left alone here); decoding with `errors="replace"` (a fail-closed reader that turned a bad byte into U+FFFD would pass a mangled leg path as a different path); widening the `except` to `ValueError` (it would also swallow a bug). `parse_yaml` and every other module are untouched; no caller relied on the `UnicodeDecodeError`, since each that names it also names `Refusal`. Tests: `tests/test_load_yaml_refusals.py` (new, 11: the four ways a file is not UTF-8, the remediation, and the missing-file, unparsable and non-ASCII-but-UTF-8 neighbours), `tests/test_adopt_execute_refusals.py` (+7: `check` and `execute` each with the byte in a value, in a comment and last in the file, exit 2, `REFUSED yaml-unreadable`, no traceback, nothing made under `--local-remote-dir`; and `cmd_execute` raising the `Refusal`) and `tests/test_manifest_validator.py` (+1: `validate-manifest.py`). 15 of them fail on main at f25d805, with the traceback. 141 passed and 1 skipped in those two files with `tests/test_adopt_plan.py`, 164 passed in `tests/test_shape_doctor.py`, 244 passed in `test_naming_policy.py`, `test_pin_validator.py`, `test_shape_advisory.py` and `test_bump_leg.py`; `render-cli-reference.py --check` ok, `docs/cli.md` unchanged. The full suite was not run. Closes #192 Lane: openreposhape-2 (openRepoShape-2) Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
Sorry @brettheap, you've used your own review budget of 250,000 diff characters for the last 7 days. You can request another review in 6 hours and 9 minutes by commenting |
|
@codex review |
Reviewer's GuideCentralize handling of non-UTF-8 YAML in load_yaml by translating UnicodeDecodeError into a detailed yaml-unreadable Refusal, then verify the behavior directly and through adoption and manifest-validation entry points, including fail-closed execution with no side effects. Sequence diagram for centralized non-UTF-8 YAML refusalsequenceDiagram
participant Command
participant Reader as load_yaml
participant File as YAML file
participant Parser as parse_yaml
Command->>Reader: load_yaml(path)
Reader->>File: read_text(encoding=utf-8)
alt UnicodeDecodeError
File-->>Reader: UnicodeDecodeError(start, reason)
Reader-->>Command: Refusal("yaml-unreadable", path, byte, reason)
else UTF-8 text
File-->>Reader: text
Reader->>Parser: parse_yaml(text)
Parser-->>Reader: YAML value
Reader-->>Command: YAML value
end
Sequence diagram for fail-closed adoption executionsequenceDiagram
participant User
participant Execute as adopt-project.py execute
participant Reader as load_yaml
participant File as bad-plan.yaml
participant Resources as Remote and work resources
User->>Execute: execute --plan bad-plan.yaml --yes
Execute->>Reader: load_yaml(path)
Reader->>File: read_text(encoding=utf-8)
File-->>Reader: UnicodeDecodeError
Reader-->>Execute: Refusal("yaml-unreadable", byte, reason, remediation)
Execute-->>User: REFUSED yaml-unreadable and exit 2
Execute-->>Resources: No resource creation or mutation
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
(lane openRepoShape-2, 2026-10-09T14:19:12Z) Full suite on this head e20b50b, run from a detached worktree in py-bench with git-filter-repo 2.47.0 on PATH, git 2.43: 1667 passed, 1 skipped in 24m (the MedxEHR clone skip, as on main; the count is higher than earlier heads because main f25d805 brought #187's tests). All three OS jobs pass, Sonar passed, Codex found no issues. Log: |
…t-project.py writes a recorded submodule's unprintable character as one, so a submodule named with a no-break space, U+3000, a zero-width space, NEL or U+2028 is held to its row and moving it to the other leg is no longer COMPLIANT (#189) P3-1 of lane openRepoShape-2's review of e167d8b. `_quoted` spelled every character `str.isprintable` refuses as `ascii()` does (`\xa0`, ` `) and a byte that is not UTF-8 as `\xe9`, and `repo_shape._unescape` resolved only `\n \t \" \\`. So the row for `vendor/nb\xa0sp` read back with a literal backslash, named no gitlink, and the doctor called the submodule `kept`; a real adoption of each of six such names, moved to the other leg, stayed COMPLIANT (scratchpad/fix189e/logs/probe-names-dbf8887.log). - scripts/repo_shape.py: `_unescape` also resolves `CODE_POINT_ESCAPES`, YAML's `\xNN`, `\uNNNN` and `\UNNNNNNNN`, with YAML's meaning: the code point, never a byte. One with too few digits, or past U+10FFFF, keeps its backslash, and `\\x41` is still a backslash and `x41`. - adopt-project.py: `_quoted` writes only the escapes those two tables resolve: the named ones for a backslash, a quote, a newline and a tab, and the shortest code-point escape for every other unprintable character. A byte that is not UTF-8 is now `\udce9`, which reads back as the surrogate the path holds, where `\xe9` read back as U+00E9, another name. The doctor reads `project.yaml` with the standard's own `repo_shape` (shape-doctor.py imports it from SHAPE_ROOT/scripts), and the project's own validator with its copy, which `execute` writes from the same standard. PINNED FILE: scripts/repo_shape.py. Every assembly root and every family holder reads `upstream-changed scripts/repo_shape.py` in `update-shape.py check` until its estate re-pins with `apply`, as for #156 and #193; this repository has no digest of it to update. `apply` copies every upstream-changed row together and rolls back if the project's validators go red, so the record's validator never runs beside an older reader. HOW THIS MEETS #199 (fix/adopt-plan-linebreak-names, not on main). #199 adds the same reader to repo_shape.py and more: it also resolves `\r`, and it adds the writer `double_quoted` from the same tables. Whichever lands second takes #199's side of repo_shape.py's escape section, deletes `_quoted`, `_escaped` and `_NAMED_ESCAPES` here, and spells both `submodule_record` fields with `double_quoted`. A record this branch writes reads back unchanged under #199's reader, because both spell by YAML's code points; the one difference is a carriage return, `\x0d` here and `\r` there. Tests: the reader's escape table gains the code points and the cases that must keep their backslash (tests/test_windows_paths.py); the record's round-trip names gain nine unprintable ones and a literal `\x41`, and the non-UTF-8 name now reads back as itself (tests/test_adopt_submodules.py); and the doctor holds six such names, written by `submodule_record`, to their rows: `recorded` in code, MISPLACED (6 paths) once staged in spec (tests/test_shape_doctor.py). Lane: openreposhape-1 (openRepoShape-1) Co-Authored-By: Claude Opus 5.5 <[email protected]>



Lane: openreposhape-2 (openRepoShape-2)
Claim: #192 (comment)
What
scripts/repo_shape.pyload_yamlnow catchesUnicodeDecodeErrorbesideOSErrorand raisesRefusal("yaml-unreadable", "<path>: not UTF-8 at byte <n> (<reason>)", "Remediation: ..."). The remediation says every YAML file the tool reads must be UTF-8, names the byte (counting from 0), and says to re-save the file as UTF-8 or replace that byte. The docstring says why it is its ownexcept:UnicodeDecodeErroris aValueError, andread_textraises it after the open has succeeded, so theOSErrorclause never sees it.parse_yamland every other module are untouched.Not chosen: catching it in each reader (about thirty call sites;
shape-doctor.pyalready carries its ownUnicodeDecodeErrorclause as a workaround, now redundant and left alone); decoding witherrors="replace"(a fail-closed reader must not turn a bad byte into U+FFFD and pass a mangled leg path as a different path); widening theexcepttoValueError(it would swallow a bug). No caller relied on the old exception: each call site that namesUnicodeDecodeErroralso namesRefusal.Why (repro on main)
On main at f25d805, a plan with a raw
0xffin a leg path:Both end, after a traceback through
Plan.loadandload_yaml:with no
FINDINGorREFUSEDline. Nothing is damaged (no leg exists yet), but the contract is that an unreadable input is aREFUSED yaml-unreadableline, a remediation and exit 2, as an unreadable or unparsable file already is. With this change, the same two commands:and
remotes/is not created.Tests
New, 19:
tests/test_load_yaml_refusals.py(new, 11): the function itself. Four ways a file is not UTF-8 (Latin-1é, a UTF-16 byte order mark, a sequence cut off at the end of the file, a bad byte in a comment), each asyaml-unreadablenaming the file, the offset and Python's reason, and each remediation; the missing-file, unparsable and non-ASCII-but-UTF-8 neighbours, so the newexceptis shown not to swallow valid text.tests/test_adopt_execute_refusals.py(+7):adopt-project.py checkandexecuteeach with the0xffin a value, in a comment and last in the file: exit 2,REFUSED yaml-unreadable: <path>:with the offset and a remediation, no traceback;executealso leaves no--local-remote-dir, no--work-dir, no leg and no source branch. Pluscmd_executeraising theRefusalin process.tests/test_manifest_validator.py(+1):validate-manifest.pyon aproject.yamlwith a0xffin a value, besidetest_an_unparsable_manifest_refuses. The doctor has noyaml-unparsabletest to mirror, so the validator it runs is the reader tested.16 of the 19 fail on main at f25d805 with the traceback above; the other three are the neighbours in
test_load_yaml_refusals.py, which pass on both. (The commit message says 15: it was written before the in-processcmd_executetest had been run against main, and that is the sixteenth.)Run on this branch:
test_load_yaml_refusals.py,test_adopt_execute_refusals.py,test_manifest_validator.py,test_adopt_plan.py: 141 passed, 1 skipped (the MedxEHR clone, absent here)test_shape_doctor.py: 164 passedtest_naming_policy.py,test_pin_validator.py,test_shape_advisory.py,test_bump_leg.py: 244 passedpython3 scripts/render-cli-reference.py --check:docs/cli.md is what the generator producesThe full suite was not run here; CI runs it on Linux, macOS and Windows.
Closes #192
🤖 Generated with Claude Code