Repository navigation
notebook_validator: read shell the way bash does, and state the torch/torchcodec contract - #10414
Merged
Merged
Conversation
…/torchcodec contract Rebuilt against main. The shell-parsing work reviewed as #10376 was squash-merged into fix/torchcodec-torch211 rather than into main, so it landed inside #7474's diff instead of its own; this restores it as a standalone change. Carries the compatibility contract with it: the 2.11 row and the 0.12+ ABI-stable rule in both TORCH_TORCHCODEC and _TORCH_TORCHCODEC_MINORS, because 49 of the 95 shell-parsing tests observe the pip replay through R-INST-004 and test_torchcodec_matrix_matches_notebook_validator asserts the two tables are equal. The installer, packaging extras, index pinning, NPP and provenance hints stay in #7474.
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. |
…nd the dry-run seed
- `env -S 'pip install' ARG...` discarded the trailing operands, so R-INST-001 saw an install with no packages. GNU env appends them to the split string. - `python -I -m pip` matched no install rule: PIP_LINE_RE required `-m` immediately after the interpreter, but usage is `python [option] ... [-m mod]`. - `resolved_set` ignored `inv.action`, so a `pip uninstall` left the earlier pin in place and the rules judged a package that is no longer there. - An absent package with a bounded window reported its floor as exact; pip takes the newest release the window admits, so `>=0.10,<0.12` lands on 0.11. - `builtin pip install ...` is "not a shell builtin" and runs nothing, so it is not an exec prefix. Five regression tests, each red at the parent commit.
danielhanchen
added a commit
to danielhanchen/unsloth-staging-2
that referenced
this pull request
Sep 7, 2026
…ase arms - `env -S'pip install' pkg` is the valid attached spelling of a mandatory operand; exact membership missed it, so R-INST-001 saw no install at all. - pip takes the LAST `@` after the repo path as the revision delimiter, so splitting at the first read a traversal resolving outside the allowlist as an allowed repo. - `--upgrade` moves every named package to the newest available version, so an installed release that merely satisfies the range is not where it lands. - A `case` arm pattern ends in an unbalanced `)`, which is not the substitution's; popping on it left the pip call inside `$(case ...)` unscanned. Four regression tests, each red at the parent commit.
…tion - GNU env documents `\\_` in an `-S` operand as a space and it really separates (coreutils 9.4: `env -S 'printf [%s][%s] a\\_b'` prints `[a][b]`). bash keeps the backslash inside double quotes, so unescaping the operand as an ordinary shell word rebuilt `pip install_git+...` and no invocation was seen. Scoped to the operand: a trailing argument is bash's to unescape. - `--upgrade` moves to the newest available release, so an installed version is not where it lands. A ceiling with no floor names no landing either, and keeping the stale version raised a false R-INST-004 about a release the cell replaces. - bash's `!` reserved word runs the pipeline and inverts its status, so `! ! pip install git+...` still installs; requiring exactly one leading bang matched nothing. Covers IPython's `!!` capture form too. Three regression tests, each red at the parent commit.
… exec - The torchao lower-bound scan kept a floor across an uninstall, so R-INST-003 accepted an environment the package had been removed from. - A case arm's unbalanced `)` closed the substitution in an assignment word, so `TOKEN=$(case x in x) printf a;; esac) pip install ...` read as conditional and every rule on unconditional_pip_invocations() skipped the install. - Bare `time` is bash's reserved word (`time [-p] pipeline`); `time -f %e pip install ...` runs a command named `-f`, so consuming GNU time's flags replayed an install bash never performs. An explicit path still reaches the binary. - sudo(8) documents `-D directory`, `-R directory` and `-T timeout`; without them the operand stood as the executable and the pip command behind it was missed. - `exec` replaces the shell, so outer commands after it are unreachable and were being replayed. Its own substitutions still ran, and an exec inside $( ) replaces only that subshell. Five regression tests, each red at the parent commit.
- a group exits with its and-or list's status, so a short-circuited last command no longer speaks for it - a terminator behind then/do/else still ends the line, while a subshell one and an untaken branch do not - a function body is replayed once something calls the function, and stays conditional when it is only defined, named or called on a branch - the pin oracle must retain the packages the rules seed on, not merely parse to something - the snapshot rollback renames preserved copies instead of rewriting them, so a still-full disk cannot strand a mixed generation
- a body word with no compound above it grows every parallel stack, so a compound inside a function no longer pops one that was never pushed - entering a called function removes only the definition from a command's flag; internal guards and compounds still decide for themselves - the call graph is walked to a fixed point, so a function reached only through another called one is replayed too - an unconditional break ends the loop body it sits in, and the line continues after done - a bounded window names its landing whatever the major, so an upgrade into torch 2.11 is resolved rather than left on a 2.10 floor
- break targets the innermost loop, so a nested fi no longer clears it - return ends the function body while the caller carries on - a call resolves against the definition in force at that point - calling a body that ends the shell ends the caller too - a call carries its body's status into the surrounding and-or list - a for loop over a literal non-empty list runs its body - python -c terminates the option list, so -m pip behind one is an argument rather than a module
- a call resolves against the definition complete before it, keyed per definition rather than per name - the negation reserved word survives the reconstruction, so ! false succeeds and the && behind it runs - a closed group's folded status is not overwritten by the last command still in hand, and a function header's parens open no group - an external wrapper reaches no shell function, and a terminating call in a subshell spares the parent - break outside a loop drops nothing, matching what bash does - a dry-run install does not undo a removal
- a false condition derived from that assumption stays conditional, and a terminator reached only through it truncates nothing - an uncalled function body is unreachable rather than conditional, so the all-path rules stop reporting installs the cell cannot run - an assignment, a redirection or the reserved word time still reaches a function; env and nohup still do not - an unfetchable rule-bearing oracle fails colab-diff --strict instead of reporting a pass for a check that never ran
…-false reinstalls Three pip-replay corrections. `--upgrade "x<0.12"` over an installed 0.11 cannot leave the 0.11 line, so the minor is determinate and reporting it unknown hid a pairing every admitted release breaks. An uninstall is matched on the PEP 503 canonical name, so `pip uninstall huggingface_hub` clears the `huggingface-hub` the snapshot is keyed under. A requirement whose marker excludes the interpreter is not an install, so it no longer undoes a removal.
…break levels and substitution calls Six shell-replay corrections. PEP 503 collapses runs of dot, underscore and hyphen alike, so an uninstall now matches whichever spelling the cell used. A for list is found across any shell whitespace, not a literal space around `in`. A keyword can expose a group opener behind it, so `if (pip install ...)` is unwrapped again after `if` comes off. A closed subshell keeps the failure it folded rather than having its last lexical command re-read. `break n` and `continue n` leave the loop they name. A command substitution inherits the parent shell's functions, so its call is resolved against the definitions in force; one the notebook may not expand reaches the body without making anything in it certain.
…, PEP 440 prereleases and pipeline negation Five shell-replay corrections. The pip-succeeds assumption is now tracked by folding the same condition with pip unknown, so a condition that fails whatever pip does stays known and its else keeps the install bash performs. A path-qualified env, nohup or sudo runs the same program the bare word does. A literal return or exit status propagates out of a called function. cmp_versions orders a prerelease below the release it leads up to, as PEP 440 does, so a floor the cell upgrades past no longer looks met. A leading negation covers the whole pipeline rather than its first command.
…ws, undecided marker terms and quoted loop words Five replay corrections. A function defined behind a body keyword is now matched, so its body reaches the rules and is still pruned when nobody calls it. A landing an inclusive cap pins to an excluded release names nothing rather than fabricating the minor. A prerelease landing is promoted to its stable core only where the window admits that release. A marker term the oracle cannot answer makes that term unknown rather than the whole marker, so a decisive false and unknown stays false. A quoted loop word is one literal iteration, so its body certainly runs.
|
Codex Review: Didn't find any major issues. Another round soon, please! 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". |
Comment-only pass over the code this PR changes: multi-line explanations collapsed to one or two lines, review-round banners dropped, docstrings rewrapped. No code changes; 319 passed, 2 skipped.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Split out of #7474, which is 5,503 insertions and too large to review. 3,277 of those are this change: it was reviewed as #10376, but #10376 was stacked on
fix/torchcodec-torch211and squash-merged into that branch rather than into main, so its diff landed inside #7474 instead of its own PR. Its squash commit has a single parent, so it cannot be retargeted; this rebuilds it against main.What is in here
The shell reader.
_split_chainedtracks backticks as well as$( ), case arms keep a one-to-one mapping with their pieces instead of falling off the end of azip, execution prefixes are parsed by each prefix's own option grammar rather than by taking the first pip-looking word, and_split_first_wordwalks quotes soenv TOKEN="a b" pip install git+...is not broken into three words withb"as the executable. Each of those was a way for R-INST-001 to miss a prohibitedgit+install on a line bash really would run it on.The pip replay.
_effective_version/_spec_windowreplace the older bounds reader: PEP 440 specifier sets are intersected rather than read one at a time,--dry-runno longer records an install pip is documented never to perform, a direct archive reference keeps its filename version when a PEP 508 marker follows it, and versions compare with zero-padding so0.11and0.11.0are one version.The compatibility contract, in both mirrors: the torch 2.11 row, and the rule that torchcodec 0.12+ is ABI-stable against torch >=2.11 rather than locked to one minor.
Why the contract is here and not in #7474
Two constraints, both mechanical:
rule_inst_004_torchcodec_torch, using a torch 2.11 fixture. Landing the parser without the rule means rewriting half the suite to assert on a different vehicle, which would lose more than it saves.test_torchcodec_matrix_matches_notebook_validatorasserts_TORCH_TORCHCODEC_MINORS == TORCH_TORCHCODECas plain dict equality, so the two tables cannot move apart across PRs without going red in between.So this PR states the contract and enforces it in CI. #7474 keeps everything that acts on it: the installer selector, the wheel-availability tables, index and mirror pinning, NPP, the provenance hint, the packaging extras and the security audit.
Verification
160 passed, 2 skipped across
tests/notebooks/andtests/python/test_torchcodec_torch_compat.py.test_torch211_rejects_torchcodec_010is the load-bearing one and is red on main: today the guard says nothing about torch 2.11 with torchcodec 0.10, which is the pairing that fails to load. The other three contract tests are regression guards --test_torch210_still_rejects_abi_stable_torchcodecin particular pins the ABI floor at 2.11 so the exemption cannot creep downwards.