Repository navigation
notebook_validator: read shell prefixes, backticks and case arms the way bash does - #10376
danielhanchen merged 34 commits into
Conversation
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. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ae587c9687
ℹ️ 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".
| """ | ||
| prefixed = False | ||
| while True: | ||
| parts = text.split(maxsplit = 1) |
There was a problem hiding this comment.
Preserve quoted words while stripping shell prefixes
When an execution prefix contains a quoted value with whitespace, such as !env NOTE="hello world" pip install git+https://example.com/pkg.git or !NOTE="hello world" pip install ..., splitting on raw whitespace leaves the command as !world" pip install .... parse_pip_line then rejects it, so R-INST-001 and the compatibility rules miss an installation that the shell actually executes. Tokenize prefixes with shell quoting semantics rather than str.split.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Below the bar for a change. The miss needs a prefix assignment whose value contains whitespace (env NOTE="hello world" pip install git+...); the forms notebooks actually use, !pip install git+... and a plain env VAR=x pip install git+..., are caught today. Adding shlex tokenization to the prefix stripper buys the exotic case and puts a second quoting parser next to the one in parse_pip_line, which is where quoting bugs on this branch have come from.
| bodies.append(command[i + 2 : j - 1 if depth == 0 else j]) | ||
| i = j | ||
| elif ch == "`": | ||
| j = command.find("`", i + 1) |
There was a problem hiding this comment.
Skip escaped delimiters when closing backticks
When a legacy backtick substitution contains an escaped backtick before a later pip command, Bash keeps scanning to the actual closing delimiter, but find treats the escaped character as the close. The extracted body is therefore truncated and a subsequent pip install git+... inside that substitution is never inspected by R-INST-001. Scan for the next unescaped backtick instead.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Below the bar. This needs an escaped backtick inside a legacy backtick substitution that itself contains a later pip install. Backtick substitution is already rare in notebooks, and nested escaping inside one is not input this validator will meet. Failing open here costs a miss on a cell nobody writes.
|
@codex review |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a525a12112
ℹ️ 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".
| i += 1 | ||
| continue | ||
| # `$( )` and backticks expand inside double quotes; `<( )` and `>( )` do not. | ||
| opens = command.startswith("$(", i) or ( |
There was a problem hiding this comment.
Treat parameter-expansion substitutions as conditional
When a command substitution occurs in a parameter-expansion word, such as !X=ok; echo ${X:-$(pip install "torchcodec==0.13")}; pip install "torch==2.12", Bash does not evaluate the substitution because X is set. This scan nevertheless extracts the inner pip command as unconditional, so _effective_version records torchcodec 0.13 and R-INST-004 misses the actual incompatible torch 2.12 / torchcodec 0.11 result. Preserve the parameter-expansion condition when emitting nested substitution bodies.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Below the bar. ${X:-$(pip install ...)} with X set is a construct no notebook contains, and modelling parameter-expansion conditionality would mean tracking variable assignment state through the scanner to decide whether a default word is evaluated. That is a large amount of new machinery, in the part of this file that has produced the most defects, for an input that does not occur.
| quote = ch | ||
| buf.append(ch) | ||
| i += 1 | ||
| elif ch in ")}" and in_substitution: |
There was a problem hiding this comment.
Keep parentheses from closing parameter expansions
Fresh evidence after the earlier ${...} fix is that a literal parenthesis in the fallback word still pops the parameter-expansion grouping here. For example, Bash treats !echo ${X:-a)b||pip install git+https://example.com/pkg.git} as one echo argument and never executes pip, but _split_chained exposes the text after ) as a conditional pip command and R-INST-001 rejects the clean notebook. Only } should close a ${...} grouping.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Below the bar, though I agree only } should close a ${...}. The trigger is a literal ) inside a parameter-expansion fallback word (${X:-a)b||pip install git+...}), which is not something a notebook install cell contains. I would rather not add another special case to the grouping stack for it; the false positive is unreachable in practice.
| elif ceiling is not None and cmp_versions(current, ceiling) >= 0: | ||
| current, exact_known = landing, True |
There was a problem hiding this comment.
Preserve exclusive upper bounds for compatibility checks
When an installed ABI-stable codec is explicitly downgraded with an exclusive cap, for example Colab torch 2.12 / torchcodec 0.13 followed by pip install "torchcodec<0.12", pip necessarily leaves a pre-0.12 codec that this rule considers incompatible with torch 2.12. Because a cap-only window has no landing, this assignment clears the codec version and the early return in R-INST-004 suppresses the error. Retain the proven <0.12 property even when the exact release below the ceiling is unknown.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Below the bar, and the fix is not derivable here. R-INST-003/004 run offline (only R-INST-002 consults PyPI), so for a cap-only window the replay cannot name the release just below the ceiling. You are right that <0.12 proves the codec is pre-0.12, but representing that needs a third state, known-below-X, whose only consumer is the ABI branch, while every lockstep row still needs a minor it would not have. The current behavior fails safe: a miss, not a false error on a clean notebook.
| tails[-1] = False | ||
| buf_conditional = any(tails) |
There was a problem hiding this comment.
Mark the right side of
&& as conditional
A command after && runs only when the preceding and-or list succeeds, but this branch clears the conditional state and feeds the command to unconditional_pip_invocations. For example, !false && pip install "torchcodec==0.13"; pip install "torch==2.12" leaves the Colab codec at 0.11, yet the replay records 0.13 and suppresses the R-INST-004 incompatibility. Keep the && tail conditional for effective-version replay while still allowing reachability rules such as R-INST-001 to inspect it.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Below the bar. !false && pip install "torchcodec==0.13" is a construct notebooks do not contain, and the effective-version replay would need a per-command reachability state that R-INST-001 must then deliberately ignore. That split (conditional for replay, unconditional for reachability) is exactly the kind of dual-meaning flag this file has been bitten by.
Two things at once, because the merge is what forced the question. The shell-parser rewrite in scripts/notebook_validator.py is now unslothai#10376. It was 865 of this branch's ~2950 added lines, drove all nine review rounds here, and shares no code with the torchcodec pin this PR is named for. Its three open P1 items from the 2026-09-02 round are fixed there, with a test each that is red against the parser as it stood at 75a808c. What stays here is the torchcodec change: the "2.11": {"0.11"} row and the ABI-stable rule in unsloth/import_fixes.py, the audio-torch211 extra in pyproject.toml, _select_torchcodec_spec and the 13b install step in studio/install_python_stack.py, the dropped flat pin in extras-no-deps.txt, and the security-audit.yml coverage for every installable torchcodec line. scripts/notebook_validator.py is main's version plus one line, the "2.11" row, which test_torchcodec_matrix_matches_notebook_validator asserts against _TORCH_TORCHCODEC_MINORS. unslothai#10376 carries the same row, because rule_inst_004_torchcodec_torch lives in that file and its update depends on _effective_version and _marker_environment from the rewrite, so the rule could not be separated from the parser. That one line will conflict trivially, with identical content, whichever merges second. tests/python/test_torchcodec_torch_compat.py keeps the 24 cases that are actually about torchcodec, import_fixes and install_python_stack; the 77 that exercise the parser went to unslothai#10376 with it. Merge conflicts, both resolved toward this branch's intent: studio/install_python_stack.py, the torchcodec wheel predicate. Main reworded the comment; this branch had rewritten the condition to name the platforms that HAVE a wheel, which is a fix rather than a rewording -- listing the ones that do not missed every Linux architecture past Arm, ppc64le and s390x among them. Kept this branch's. scripts/notebook_validator.py, resolved by taking main's file and adding the one row, per the split above. The progress denominator did not repeat its earlier trap: main is 12/13, this branch adds the torchcodec step, and base_total is 13 if IS_WINDOWS else 14. Local runs: test_torchcodec_torch_compat.py 24/24, and 3459 passed / 5 skipped / 3 failed across it plus tests/studio/install and tests/notebooks. The three are test_managed_node_runtime.py::test_managed_dir_fallback_honors_override and its two siblings, which fail identically on a clean checkout of main (7ba00bb) and which this branch does not touch.
Caught by Codex on the split commit, and introduced by it. Adding
"2.11": {"0.11"} to main's TORCH_TORCHCODEC without the matching
short-circuit made rule_inst_004_torchcodec_torch report torch 2.11 against
torchcodec 0.12 through 0.15, all of which upstream supports, at error
severity. Before the row existed the lookup missed and the rule stayed silent,
so the row was strictly worse than no row for those notebooks.
import_fixes.py and install_python_stack.py both carry this exemption already;
the validator's copy went to unslothai#10376 with the parser rewrite, because there it
is entangled with _effective_version. This is the standalone version of the
same rule, which is what the row needs to be correct on its own.
Lockstep below the floor is unchanged: 2.11 with 0.10 still reports, and torch
2.10 with 0.12 still reports, since the exemption is torch >=2.11 only.
tests/notebooks and test_torchcodec_torch_compat.py: 76 passed, 2 skipped. The
new case is red without the short-circuit.
2360bb4 to
7c25d73
Compare
|
Retargeted this onto #7474 and rebased. When I split the parser out of #7474, this branch kept the torchcodec compat table's Reverting the rule to The rebase also picks up the compat matrix correction from #7474 (torch 2.6 allows only torchcodec 0.2; torch 2.5 only 0.1) so the two copies of the table stay identical. Conflicts were in
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7c25d73eab
ℹ️ 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".
| if token in operand_flags: | ||
| operand = tail.split(maxsplit = 1) | ||
| rest = operand[1].strip() if len(operand) > 1 else "" |
There was a problem hiding this comment.
Preserve the command encoded by env -S
When a notebook uses GNU env -S, such as !env -S pip install git+https://example.com/pkg.git, the operand is the command rather than metadata to discard. env --help defines -S as “process and split S into separate arguments,” so this invocation executes pip, but this branch consumes pip and leaves install ...; parse_pip_line then finds no invocation and R-INST-001 misses the prohibited source. Parse the -S payload into the command being executed instead of handling it like the operands of -u or -C.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The env -S semantics are right and I checked env --help, but this is below the bar as a change. A notebook that wants a git+ install writes !pip install git+...; env -S pip install git+... is not a form that appears, and treating -S as a command payload means parsing its split rules as a third quoting dialect in this file.
| elif cap is not None and cmp_versions(current, cap) > 0: | ||
| current, exact_known = cap, True # `<=V` allows V, so V is what pip picks |
There was a problem hiding this comment.
Apply caps to versions represented by inexact floors
When an absent package is first installed through a broad floor and then capped, current is only a lower-bound representative, so comparing that representative to the cap can incorrectly treat the second install as a no-op. For example, after pip uninstall torchcodec, pip install "torchcodec>=0.10" resolves the newest codec, and a following pip install "torchcodec<=0.11" downgrades it to 0.11; with torch 2.12 this is incompatible, but the replay retains (0.10, inexact) because 0.10 is not above the cap, and R-INST-004 emits nothing. Account for exact_known == False when applying a later cap rather than assuming the stored floor is the installed version.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Below the bar. The sequence needs an uninstall, then a broad floor, then a cap, on one package in one notebook. More to the point the outcome you describe is not derivable offline: after pip install "torchcodec>=0.10" the replay cannot know which release the index returns, so it cannot know whether a later <=0.11 downgrades it. Guessing would make the lockstep rows, which are error severity, fire on versions we never established.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 510fed7ac4
ℹ️ 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".
| if inv.action == "uninstall": | ||
| current = None # removed; a later install can put it back | ||
| continue | ||
| if not pins and not replaced_unnamed and _forces_resolution(inv.flags): |
There was a problem hiding this comment.
Re-resolve bounded requirements under upgrade flags
When the installed version already satisfies a bounded requirement, this condition checks _forces_resolution only when pins is empty, so --upgrade incorrectly leaves the old version in the replay. The inspected python -m pip install --help defines --upgrade as upgrading specified packages to the newest available version; therefore, with torch 2.10 / torchcodec 0.10, pip install --upgrade "torchcodec<0.12" resolves a 0.11 codec, but _effective_version retains 0.10 and R-INST-004 misses the incompatible pairing. Apply forced resolution to bounded windows as well.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Below the bar for the same reason. --upgrade does force resolution, and I agree the bounded-window case skips that check, but the finding you expect cannot be derived: with pip install --upgrade "torchcodec<0.12" the replay would have to know 0.11 is the newest release under the cap, and it has no index. Marking it merely moved-to-unknown suppresses the rule anyway, so the outcome is the same miss, with more machinery. Fails safe rather than reporting a version we never resolved.
…way bash does Split out of #7474. That PR is a torchcodec/torch 2.11 pin; this parser rewrite rode along with it and has since driven every one of its nine review rounds while sharing no code with the pin. Separating them makes each reviewable and revertable on its own. Carries the rewrite as it stood at 75a808c plus fixes for the three P1 defects from the 2026-09-02 round, which were still open. Each one let R-INST-001 miss a `git+` install that bash really would run, and in each case the neighbouring form was already caught, which is what makes them defects rather than gaps. A prefix operand can be spelled like the command. `env -u pip pip install git+...` unsets the variable `pip` and runs the second one, but the executable was located by searching for the first pip-looking word, which selected the operand and produced `pip pip install ...` -- rejected by PIP_LINE_RE, so nothing was collected at all. Prefixes now consume their own options and operands positionally, per a small per-prefix table of the flags that take a separate argument, so the executable is whatever word survives. Backticks were not tracked as substitutions. `_split_chained` knew about quotes and `(`/`{` but never a backtick, so the `;` in ``echo `pip install git+...; echo ok` `` split the line and handed `_substitution_bodies` an unmatched fragment it cannot read. The `$( )` form was handled correctly throughout, which isolates it. There is now a backtick state folded into `in_sub()`, checked before the quote branch because backticks expand inside double quotes. `zip(out, commands)` was not one-to-one. `commands` dropped pieces that unwrapped to empty while `out` kept them, so every later pair slid by one and `zip` stopped at the shorter list. A `case` emits an empty piece per `;;` and its `esac` unwraps to "", so a two-arm `case` left `out` at 5 against `commands` at 2 and the arm holding the substitution was never scanned. Empty pieces are now carried through the pairing and filtered after it. One adjacent defect the same trace exposed: `_unwrap_shell_group` ended with `rstrip(")}")`, which also ate the `)` closing a `$( )` when no `(` had been stripped. Only a grouping bracket is stripped now; a lone `}` from a group that spanned a separator still is, which `_final_bracket_closes_substitution` tells apart. Five tests, all red against the parser at 75a808c and green here, each paired with the control form that already passed. tests/notebooks is 119 passed / 2 skipped; ruff clean. The `"2.11": {"0.11"}` torchcodec row appears here too, because `rule_inst_004_torchcodec_torch` lives in this file and its update depends on `_effective_version` and `_marker_environment` from this rewrite. #7474 adds the same row on its side to keep `test_torchcodec_matrix_matches_notebook_validator` green, so that one line will conflict trivially, with identical content, whichever merges second.
The git+ allowlist, install-cell discovery and pip-skip cases exercise the rewritten parser rather than the torchcodec pin, so they belong here too, along with the _one_cell_notebook helper they share. #7474 keeps only the 24 that are actually about torchcodec, import_fixes and install_python_stack. tests/notebooks: 131 passed, 2 skipped.
…oth oracles
Three from the first Codex round on this branch. All three reproduce, and the
first is the one that matters most: it is a false positive, so it rejects a
clean notebook rather than missing a dirty one.
${X:-a||pip install git+...} is one word to bash. `${` was pushed onto the
groupings stack as a plain brace group, so the `||` inside the fallback word
was read as a control operator and _split_chained manufactured a conditional
pip command that never runs. R-INST-001 then failed the notebook over an echo.
`${` is now tracked the way `$(` already was. A $( ) inside an expansion does
run and is still read; a real { } group still splits on its own separators.
pip install "x<=V" on an absent package installs V. _effective_version treated
a cap-only requirement as leaving the package absent, so uninstall followed by
a capped reinstall came back None and R-INST-004 said nothing about exactly the
downgrade it exists to catch. A cap now names the landing version, since pip
takes the highest release the requirement allows. An exclusive ceiling still
names nothing, because which release sits below it depends on the index.
os-info stopped being human-only when this rewrite gave _marker_environment
its Python version, but notebooks-ci.yml still refreshed pip-freeze alone. On
a Colab Python rotation that judges a fresh package set against the previous
image's Python. The pre-lint step now refreshes both with --all, which writes
nothing unless it fetched every oracle, so the fallback is the committed pair
and is at least self-consistent. The comment above COLAB_STRICT_ORACLE claimed
os-info feeds no rule; it does now, and says so.
Three tests, red at the parent, green here. tests/notebooks: 134 passed, 2
skipped. ruff clean, workflow YAML parses.
- The interpreter alternative only accepted `-m pip`, but unsloth_nb_pip_magic rewrites `(pip|uv)` after the module flag and uv's pip-compatible interface is spelled `uv pip <action>`. So `!python -m uv pip install git+...` matched _PIP_CELL_RE, yielded no invocation, and R-INST-001 missed a prohibited source the notebook runs. The tool is now decided by matching `uv pip` as a word pair, so an interpreter path containing "uv" is still plain pip. - The static-with-pypi job installed only pip, and _requirement_applies falls back to "applies" when it cannot import Marker. The daily lint was therefore replaying every environment-marked requirement, including the ones Colab's pip skips, which is the question the refreshed Python-version oracle exists to answer. packaging is now declared there. Also merges the base branch and carries its torch-replay, provenance and Windows-shell tests against this branch's API.
|
@codex review |
…x/notebook-validator-shell-parsing # Conflicts: # scripts/notebook_validator.py # tests/python/test_torchcodec_torch_compat.py
…x/notebook-validator-shell-parsing # Conflicts: # scripts/notebook_validator.py # tests/python/test_torchcodec_torch_compat.py
tests/test_source_read_encoding.py forbids reading a checked-in file with the platform default encoding, since it breaks on Windows the moment that file gains a non-ASCII byte. The four notebooks-ci.yml reads added by this PR were missing it.
|
@codex review |
|
@codex review |
|
Codex Review: Didn't find any major issues. 👍 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". |
…x/notebook-validator-shell-parsing # Conflicts: # scripts/notebook_validator.py
Compress the explanatory blocks to their load-bearing content: 331 added comment lines down to 287 across the files this PR owns. No behaviour change; the full suite still passes.
…/torchcodec contract (#10414) * notebook_validator: read shell the way bash does, and state the torch/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. * Move the pip-replay tests beside the code they describe * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Guarded installs, substitutions in words, nested backticks, env -S, and the dry-run seed * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * notebook_validator: fix five shell-replay parsing gaps - `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. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * notebook_validator: attached env -S, VCS revision split, --upgrade, case 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. * notebook_validator: env -S escapes, ceiling-only upgrades, shell negation - 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. * notebook_validator: uninstall floors, case arms in words, time, sudo, 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. * notebook_validator: and-chains, interpreter operands, ${ } words, bare exec - `A && B` succeeds only when both did, so an intervening command that is not modelled as succeeding ends the assumption. Holding it once any pip command had appeared replayed an unreachable install and suppressed R-INST-004 on the pair really installed. `||` still carries the list, since one branch is enough. - `python --help` documents `-W arg` and `-X opt`; accepting only self-contained option tokens before `-m` let `python -W ignore -m pip install git+...` through. - bash keeps `TOKEN=${TOKEN:-a b}` as one assignment word. Tracking only $( ) ended the word at the space and left `b}` as the supposed executable. - `exec` with no utility only makes its redirections permanent and the shell carries on, so `exec >/tmp/log; pip install git+...` must not be truncated. Regression from the exec hand-over added in the previous round. Four regression tests, each red at the parent commit. * notebook_validator: -mpip, exec behind a prefix, X+= and leading redirections - `python -mpip install ...` is a valid CPython invocation, and \b finds no boundary between the m and the p, so cell discovery never even matched the cell. - `command exec pip ...` hands the shell over exactly as `exec pip` does; testing the raw first word answered `command` and replayed the unreachable install. - `PATH+=:/opt/bin pip install ...` is an assignment prefix (bash runs the child with the appended value), not a command, so the word stood as the executable. - A simple command may put its redirections before the command name, so `>/tmp/log pip install ...` and `FOO=1 2>/dev/null python -m pip ...` both run pip. Four regression tests, each red at the parent commit. * notebook_validator: compound bodies, removed dependencies, PEP 440 prereleases - An if/while/for body kept its condition only on the piece carrying the `then` or `do`, so a second command in the body replayed as an install bash never performs. Tracked per open compound now, until its fi/done/esac. - Uninstalling what a --no-deps install needs is the broken state R-INST-002 and R-INST-005 exist to catch, but resolved_set drops the package and both read that as missing data and fell silent. A removal is now told apart from never having been mentioned, and is reported. - PEP 440 orders `2.11.0rc1` and `0.12.0.dev1` BELOW 2.11 and 0.12; cmp_versions reads dotted digits only, so the prerelease number lifted them above the ABI floors and approved a pairing outside the ABI-stable contract. Fixed in the validator and in the mirrored runtime hint in import_fixes. Three regression tests, each red at the parent commit. * notebook_validator: prefixed pip, conditional exec, case arms, branching ${ } - `_piece_is_pip` stripped the notebook bang AFTER the prefixes, so `!env X=1 pip install ...` matched no prefix name and the && after it went conditional. - A hand-over inside a compound body was declared unconditionally, dropping the reachable install after the closer; the body condition counts there too. - A substitution inside a body took only the separator-level flag, so its install replayed as certain in a body bash never runs. - Every command between `case` and `esac` sits in some arm and only one arm runs; no body keyword opens the level, so it is active from the word itself. - `_removed_by_cell` answered on the first uninstall it met, claiming the cell removes a dependency a later install puts straight back. - `${name:-$(pip install ...)}` is expanded on one branch of the parameter's state, so it is a path the notebook may take, not one it certainly does. - `colab-diff --strict` passed on a missing snapshot that carries a rule-bearing key, leaving marker evaluation silently replaying every requirement. - The dependency-removal test used the live PyPI path, so it asserted nothing wherever the network is blocked; stubbed like its neighbours. Seven regression tests, each red at the parent commit. * notebook_validator: pipeline exec, substituted sources, hyphenated prereleases - `exec` under `|` or `&` runs in a subshell and the parent shell reaches the next command, so the list must not be truncated there. - A substitution's closing bracket was kept as part of a git+ source, so an allowlisted URL passed through `$(printf %s ...)` was reported as prohibited. - A strict oracle key absent from BOTH parses left them equal, so the no-drift return fired while marker evaluation silently replayed every requirement. - PEP 440 spells the same prerelease `2.11.0rc1`, `2.11.0-rc1` and `2.11.0.rc1`; normalise_version cut everything from the hyphen, so the hyphenated form cleared an ABI floor it sits below. - `true` and `:` always succeed, so an `&&` after one is always reached; treating every non-pip command as a probe dropped the install behind them. - `n<&word` duplicates an input descriptor, but only `>&` was exempt, so `0<&1 pip install ...` was split into something that reads as no pip at all. Six regression tests, each red at the parent commit. The os-info fixture now carries the Python line the real oracle has, since its absence is the drift the strict check exists to catch. * notebook_validator: decisive torch floors, dry runs, negation, groups, wrapped exec - An inexact torch floor is still decisive when NO release at or above it can take the codec: `torch>=2.11` with `torchcodec==0.10` fails on every candidate. - A dry run makes no environment changes, so it places no lower bound; the floor scan read it and R-INST-003 preferred a version the cell never installs. - A strict oracle key has to hold a value its consumer can READ, not merely exist: `Python version 3.14` keeps the key and disables marker evaluation. - `!` inverts the pipeline's status, so `! false && pip install ...` always runs the install while `! pip install x && ...` does not. - A group exits with its LAST command's status, so `(pip install x) && pip install y` reaches y; closing the group discarded that and marked y conditional. - `env exec true` asks env to launch a program called exec, which does not exist, so the parent shell carries on. Only prefixes bash resolves in-process keep the builtin's meaning. Six regression tests, each red at the parent commit. * Read fallbacks, case selectors and unreachable bodies as bash runs them - a || fallback behind a command that cannot succeed always runs - a case selector is expanded before any arm is chosen - env --help / command -v print and exit, so nothing is unwrapped past them - a body whose test can never succeed is unreachable, not conditional - refresh-colab --all skips an advisory oracle it cannot fetch instead of failing, and refuses to acknowledge a rule-bearing payload the rules cannot read - the missing-pip-snapshot check gets its own fixture instead of reusing a function-scoped one that had already been mutated * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fold the whole and-or list, and stop at exit as well as exec - || reachability is decided by the folded status of the entire left-hand list, so true || false || pip skips and false && true || pip runs - an unconditional exit ends the command list the way exec does - the Colab Python version keeps its prerelease suffix, which is what python_full_version markers compare against - an exclusive floor survives as an inexact bound instead of being discarded, so whole-range compatibility checks can still run * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Replay the branch a known test actually takes, and read function bodies - a constant test names its branch: an if true body is replayed as unconditional, and an if false else branch stays reachable - the exclusion fallback is checked against the whole specifier window, not just the ceiling it was derived from - a name() { ... } body is exposed to the rules instead of hiding behind its header, restoring the git+ source R-INST-001 caught on main * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Carry arm outcomes through elif, and land the oracle set as a unit - an elif whose earlier arms all certainly failed is reached, and its own constant test decides the branch; else runs when every arm failed - refresh-colab --all restores the committed snapshot if any write in the set fails, so a mixed generation is never exposed - an inexact prerelease codec floor admits the stable release above it, so torchcodec>=0.12.0rc1 no longer reads as a pre-ABI pin * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fold whole conditions, and stop reading commands the shell never runs - a condition is its whole and-or list, folded before the body is judged, and until inverts the result rather than the first piece - a pip test keeps its failure branch, so the else R-INST-001 must see survives while the then body keeps the pip-succeeds assumption - the non-executing privilege-escalation and interpreter modes (-v/-l, -h/-V) run no command, so nothing is unwrapped past them - a terminator inside a brace group ends the line; a subshell one does not - a function body stays conditional past its own separators - an escaped or quoted brace does not close a parameter expansion * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Carry a closed group's status, and read prerelease windows as ranges - a group folds its exit status into the list that contains it, so { false; } || pip install x reaches the install - a window whose floor is a prerelease lands on the minor rather than on the prerelease, which PEP 440 sorts below the ABI floor - the .git suffix is stripped case-insensitively, so an allowlisted repository spelled .GIT still matches * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Replay a called function, and read a group's status off its list - 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 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Keep the compound stacks aligned, and enter a call without clearing it - 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 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Scope break and return to what they leave, and resolve calls in order - 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 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Resolve calls per definition, and keep the negation word intact - 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 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Never cut a path on the pip-succeeds assumption - 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 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Read an upgrade under a ceiling, canonical uninstall names and marker-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. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Read PEP 503 names, tab-delimited for lists, groups behind keywords, 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. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Read pip-decided conditions, path-qualified prefixes, return statuses, 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. * Read definitions behind keywords, excluded landings, prerelease windows, 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. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Tighten the comments in the shell-parsing work 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. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: danielhanchen <[email protected]>
…orch minor (#7474) * torchcodec: cover torch 2.11 in the compatibility guard and pin per torch minor install.sh's CUDA branch allows torch>=2.4,<2.12.0 and the cu12x/cu13x wheel indexes top out at torch 2.11.0, so a fresh NVIDIA install lands on torch 2.11. studio/backend/requirements/extras-no-deps.txt pinned torchcodec==0.10.0, which upstream pairs with torch 2.10 exactly, and torchcodec publishes no Requires-Dist: torch, so pip cannot notice. The guard that exists to catch this, _torchcodec_version_mismatch_hint, looks the torch minor up in _TORCH_TORCHCODEC_MINORS and returns None on a miss, and the table had no "2.11" row: it was silent on precisely the version where the mismatch now happens. Add the 2.11 row (mirrored into scripts/notebook_validator.py), add an audio-torch211 extra pinning the 0.11 line, and select torchcodec at install time from the venv's torch minor instead of a flat pin. A requirements file cannot branch on the installed torch version, so _select_torchcodec_spec follows the existing _select_torchao_spec pattern. It runs after the final torch repair, which can still move torch onto another minor. torchcodec 0.11 is the release upstream pairs with torch 2.11 exactly and the newest one published on the cu128 index install.sh resolves torch 2.11.0 from, since 0.12 dropped CUDA 12.8. From 0.12 torchcodec is ABI stable against torch >= 2.11, so that half of the matrix is open ended and cannot be written as a finite set of minors; both checkers now exempt torchcodec >= 0.12 on torch >= 2.11 rather than flagging a combination upstream supports, and torch 2.12+ installs take the open >=0.12.0 floor instead of the 2.11-only 0.11 line. Also bump the installer step total for the new step and keep torchcodec inside the security audit set now that it no longer comes from a requirements file. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * torchcodec: warn when torch outruns the last lockstep row The ABI-stable branch clears torch >= 2.11 paired with torchcodec >= 0.12, but everything else fell through to the lockstep matrix, which has no row past torch 2.11. So torch 2.12 or 2.13 with torchcodec 0.10 or 0.11 hit `allowed is None` and returned no hint at all, even though upstream pins 0.11 to torch 2.11 exactly and 0.10 to torch 2.10 exactly. torchcodec ships no `Requires-Dist: torch`, so pip cannot catch it either and the user only sees a raw "Could not load libtorchcodec" at first use. Split the lookup into three cases: a torch minor below the table stays silent as before, a torch minor with a row keeps the existing per-minor pin and audio-torch2xx extra hint, and a torch minor at or past the ABI-stable floor with no row now points at `torchcodec>=0.12.0`. Mirror the same three-way split in scripts/notebook_validator.py's R-INST-004 so the two stay in step, and cover both with tests plus a regression test that torch below the table still produces no finding. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Read explicit lower bounds in the torchcodec notebook rule * Tighten the torchcodec comments * Order the version bounds and restore the torchcodec 0.10 audit input * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Replay upper bounds in invocation order too * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Clear the effective version when a cell uninstalls the package * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Keep an absent package unknown instead of pinning it to its floor * Split chained pip commands and read compatible-release floors * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Respect shell quoting, or-chains and compatible-release ceilings * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Read each requirement as one version window * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Stop at shell comments, resume after or-lists and replay exclusions * Treat a hash after a control operator as a comment * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Keep escaped separators and merge repeated requirements * Resume after and-or lists, name only single-minor windows and read wheel installs * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Do not name a floor when the exclusion leaves several minors * Keep or-fallbacks visible to the other rules and stop naming exclusive floors * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Treat an open floor as a floor and skip conditional pins when seeding * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Unwrap shell groups and keep rule 002 in step with the seed * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Bound the minor with an inclusive cap and recheck exclusions after the move * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Name the iterator that skips fallbacks and move off an exclusive endpoint * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Keep a grouped fallback conditional to its closing delimiter * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Read whole lines for the git ban, pad the minor boundary, and stop guessing torch * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Scope the git allowlist per source and audit every selector line * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Match git sources by repository and scan the torchcodec lines apart * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Track fallbacks per group, land on an inclusive cap, and drop a version on upgrade * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Treat every resolution-forcing flag like an upgrade * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Flag the command in hand and read compound-only lines * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Tell a shell test from a body and read the arguments shlex produced * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Read git sources only from the pip commands on a line * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Evaluate environment markers and expand bundled short flags * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Find compound pip commands when discovering install cells * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Split on single control operators and filter the torchao floor by marker * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Match git repositories exactly, glue discovery lines and filter the no-deps rules * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Split keywords on any whitespace, comment after a bracket, decline unknown markers * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Read pip commands inside case arms * Respect shell quoting when finding a case-arm label * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Read pip in substitutions, escaped case patterns and marker literals * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Name the platforms with a torchcodec wheel and read prefixed or embedded pip commands * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Read substitutions the way the shell does * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Match git sources case-insensitively and read prefixes, redirections and quoted process forms * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Exempt the ABI-stable codec line from the new 2.11 validator row Caught by Codex on the split commit, and introduced by it. Adding "2.11": {"0.11"} to main's TORCH_TORCHCODEC without the matching short-circuit made rule_inst_004_torchcodec_torch report torch 2.11 against torchcodec 0.12 through 0.15, all of which upstream supports, at error severity. Before the row existed the lookup missed and the rule stayed silent, so the row was strictly worse than no row for those notebooks. import_fixes.py and install_python_stack.py both carry this exemption already; the validator's copy went to #10376 with the parser rewrite, because there it is entangled with _effective_version. This is the standalone version of the same rule, which is what the row needs to be correct on its own. Lockstep below the floor is unchanged: 2.11 with 0.10 still reports, and torch 2.10 with 0.12 still reports, since the exemption is torch >=2.11 only. tests/notebooks and test_torchcodec_torch_compat.py: 76 passed, 2 skipped. The new case is red without the short-circuit. * Port the other half of the ABI rule to the validator, and pin the two together Third instance of the same mistake, and the reason for the second half of this commit. The ABI rule has two halves: exempt torchcodec 0.12+ once torch is >=2.11, and reject a pre-0.12 codec once torch is past the last lockstep row. I ported the exemption in the previous commit and left the rejection behind, so the validator went silent on pairings import_fixes reports: torch 2.12.0 + torchcodec 0.11.1 -> validator silent, guard reports torch 2.13.0 + torchcodec 0.10.0 -> validator silent, guard reports Both are broken: 0.11 is built against torch 2.11 exactly, and the table has no row past 2.11, so nothing was left to catch them. Adding the inverse floor before the unknown-minor return makes the validator agree with the guard again. The new test compares the two checkers pair by pair over the whole matrix rather than asserting either one in isolation. Every bug in this area so far has been half a rule living in one checker and not the other -- three times now, twice in the last two commits -- and a parity test is the thing that fails on the next half-port instead of waiting for review to catch it. test_torchcodec_torch_compat.py and tests/notebooks: 77 passed, 2 skipped. The parity case is red without the inverse floor. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Close the third checker into the consistency net There are three checkers, not two: import_fixes' runtime guard, the notebook validator's R-INST-004, and install_python_stack's _select_torchcodec_spec. The parity test in the previous commit covered the first two, which is where the three half-ports happened, and left the installer tied to the matrix only by test_select_torchcodec_spec_matches_compat_matrix. That test iterates _TORCH_TORCHCODEC_MINORS.items(), so it only asks about torch minors that HAVE a row. A minor past the last row is exactly where the ABI half-port hid, so the one blind spot the existing coverage had is the one that has already been exploited once. This asks the question that matters instead, over torch 2.5 through 2.14: for every codec the installer's own spec admits, is the runtime guard silent? In other words, can the installer ever install something it will then complain about. It cannot today. Not red at the parent -- the installer and the guard already agree, so this is a guard against the next divergence rather than a fix for a past one. I checked it can fail rather than assuming: giving torch 2.11 the 0.10 line makes it red, which matters because the parity test I added an hour ago passed for the wrong reason on its first draft. 27 passed in test_torchcodec_torch_compat.py, 77 with tests/notebooks. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * torchcodec: never install a line this platform has no wheel for, and never let it end the install Simulated the install rather than reasoned about it, over 176 cells of {linux x86_64, linux aarch64, linux ppc64le, win amd64, win arm64, macOS 14, macOS 13, Intel Mac} x torch 2.4..2.14 x {py3.10, py3.13}, resolving every selected spec against the live PyPI index. Twelve cells could not resolve, and because step 13b called pip_install(), whose failure path is run(check=True), each was an aborted Studio install rather than a skipped audio extra. Windows on torch 2.5, 2.6 or 2.7. Those select >=0.1.0,<0.3.0 / >=0.2.0,<0.4.0 / >=0.3.0,<0.6.0, and torchcodec published no win_amd64 wheel before 0.7.0. Reachable rather than theoretical: the cu118 index tops out at torch 2.7, so this is any Windows box on an older driver. Before this branch such a host installed the flat torchcodec==0.10.0 pin and got a mismatched-but-present codec; after it, the install died. A silent degradation became a hard failure. macOS below 14 on torch 2.12+. That selects the ABI-stable >=0.12.0 line, and 0.12.0 moved the wheel from macosx_11_0 to macosx_14_0. Not reachable from a default install today, since the constraint caps macOS at torch 2.11, but it is one ceiling bump away and a user-supplied torch reaches it now. Three changes. _torchcodec_spec_is_installable() asks, before installing, whether this host published a wheel in the window this torch selects, from a table of the three transitions that exist: win_amd64 from 0.7.0, manylinux aarch64 from 0.11.0, and macOS arm64 moving its floor 11.0 -> 14.0 at 0.12.0. A no means skip, which is what such a host got before this step existed. The step now uses pip_install_try(), not pip_install(). The table above cannot predict a yanked release, an offline mirror, or a platform tag added or dropped upstream after this ships, and none of those should end an install over an optional audio extra. That is the rule the extras-no-deps torchcodec filter twenty lines up already states; this step was the one place breaking it. Linux aarch64 is no longer excluded outright. It had no wheel at 0.10, which is when that list was written, but 0.11.0 added manylinux_2_28_aarch64 and every release since kept it. Since selecting 0.11 on torch 2.11 is the point of this branch, excluding aarch64 denied audio to exactly the hosts the new row serves. audio-torch211 in pyproject.toml carries the same marker change; the older extras top out at 0.10 and still exclude it. Same 176 cells after: 0 unresolvable, 0 skipped-where-a-wheel-exists, and 84 clean attempts against 76 before, the extra 8 being the recovered aarch64 cells. Five new tests plus a rewritten gating test, all six red against the parent. 3467 passed / 5 skipped across test_torchcodec_torch_compat.py, tests/studio/install and tests/notebooks; the 3 failures are test_managed_node_runtime.py, which fails identically on clean main. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * torchcodec: pin the compat matrix to upstream's published table Verified our three copies of the torch <-> torchcodec matrix against the table published in the torchcodec README and on PyPI. Two rows were wrong, in all three copies, and had been since they were written: torch 2.6 allowed torchcodec 0.3, which upstream builds against torch 2.7 torch 2.5 allowed torchcodec 0.2, which upstream builds against torch 2.6 Release dates corroborate the upstream table: 0.3.0 shipped 2025-04-24, one day after torch 2.7, and 0.2.0 shipped 2025-02-05, a week after torch 2.6. In the runtime guard this only cost a missed report. In the installer it was live: pip takes the highest version in the window, so `>=0.2.0,<0.4.0` on torch 2.6 resolved to 0.3 and `>=0.1.0,<0.3.0` on torch 2.5 resolved to 0.2. The installer was producing exactly the mismatch this module exists to prevent. The existing parity tests could not catch this. They compare our tables against each other, which passes just as happily when all of them are wrong in the same way. Added two tests that pin the matrix and the installer windows to a literal transcription of the upstream table instead, and one that asserts what pip would actually resolve each window to, not merely which versions the window admits. Narrowing the windows then exposed a second defect that the extra width had been masking. The gate modelled the platform wheel axis but not the interpreter one, and torchcodec's Python range moves three times across the lines we select from (0.1 stops at 3.12; 0.8 drops 3.9). With torch 2.5 pinned to the 0.1 line, a Python 3.13 host has no wheel at all, where before the window reached 0.2 and its cp313 wheels. Added _TORCHCODEC_PYTHON_WINDOWS and taught _torchcodec_spec_is_installable to check it, so such a host skips audio rather than attempting an install that cannot resolve. The wheel-vs-gate test now sweeps interpreters as well as hosts: 8 hosts x 5 Python versions x 11 torch minors, each cell asserting the gate's answer equals whether a wheel really exists. All 440 agree, and a live re-run against the PyPI index reports 165 clean attempts, 275 correct skips, and zero of either failure mode. Both bad rows predate this PR and are present on main. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Install torchcodec from the resident torch's index, and honor requested codec ranges Two review findings on this PR, both in code the PR itself adds. Pin the torchcodec index to the torch build (P1). torchcodec is published per accelerator exactly the way torch is: PyPI carries one default flavor and the rest live at download.pytorch.org/whl/<tag>, as +cu126 / +cu128 / +cu130 local versions. Step 13b installed it unpinned, so a cu126 or cu128 venv took PyPI's default and got a codec built against another CUDA, which cannot dlopen. Upstream's install docs say to pass --index-url and match the torch build, and docker/Dockerfile already pins cu128 by hand with a comment saying why. The pin is skipped for torch 2.5 and 2.6. Those select torchcodec 0.1 and 0.2, which were published to PyPI only, so pinning would turn today's behavior into a guaranteed skip on the oldest venvs. rocm and xpu stay unpinned for the same reason. An untagged torch also stays unpinned: it is PyPI's own build, whose counterpart is PyPI's default codec. That is the opposite reading from _torch_flavor_tag, which maps untagged to cpu for the Windows repair path. The indexes line up with the compat matrix, which is why pinning never starves a supported host: cu128 stops at torch 2.11 and its torchcodec stops at 0.11, exactly the pair the matrix maps 2.11 to; cu130 starts at torch 2.9 and its torchcodec starts at 0.8, the pair for 2.9. Asserted over every reachable (index, torch minor) cell. Honor a requested torchcodec range in R-INST-004 (P2). resolved_set only overrides the oracle on an exact `==`, so a cell asking for `torchcodec>=0.12.0,<0.13.0` still read as Colab's preinstalled 0.11 and the rule reported a mismatch pip would never produce. R-INST-004 is error severity, so this failed CI on correct notebooks. Both bounds matter: a floor above the oracle and a ceiling that rules it out each mean pip has to move. The rule still fires where pip really does leave a mismatch: an exact wrong pin, a bare torch upgrade that leaves the oracle codec in place, and a floor that is itself incompatible with the requested torch. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Read codec ranges in order, skip marked ones, and cap the audio extras Three review findings on the previous round. The range reader took the highest floor and lowest ceiling across every pip invocation in the cell, which is not what pip does. `torchcodec>=0.12.0` followed by `torchcodec<0.12.0` ends on a pre-0.12 codec, but intersecting produced a 0.12 that was never installed and R-INST-004 then missed the mismatch. Only the last invocation that constrains the package decides. It also used the bounds of requirements carrying a PEP 508 marker. pip skips a requirement whose marker is false, so `torchcodec>=0.12.0; python_version < '3.10'` on the 3.13 image leaves the preinstalled 0.11 in place. This branch has no oracle for the image's interpreter, and evaluating the marker against the runner would move the answer between machines, so a marked requirement is left alone: the cell is judged on the preinstalled version, which is what it was judged on before this reader existed. The audio extras had a Python floor and no ceiling. torchcodec publishes no sdist, so on an interpreter past its last cp tag pip fails the whole install rather than skipping audio, and requires-python is open-ended at >=3.9. Capped each extra where its codec line actually stops: the 0.6/0.7 line at 3.13, the rest at 3.14, matching _TORCHCODEC_PYTHON_WINDOWS. Asserted by evaluating the real markers rather than by string match. * Do not judge a codec the cell moved somewhere only the index names, and pin the index in the remedy A ceiling-only request excludes the installed version without naming a replacement: `pip install "torchcodec<0.10.0"` on the 0.11 image downgrades to whatever the index has under 0.10. The reader returned the excluded oracle, so R-INST-004 reported the exact pairing the cell had just ruled out and a clean notebook failed on torch 2.9 with the image's 0.11. It now returns unknown and the rule falls silent, which is the honest answer offline. A floor still names where the install lands, so those cases keep resolving and keep being judged. The runtime mismatch hint also told users to install from the default index while the installer had just started pinning the torch one. Following it on a cu126 or cu128 venv reinstalls a codec built for another CUDA, which is the failure the hint exists to clear. It now carries the same --index-url the installer would use, under the same rules: nothing for an untagged torch (PyPI's own build), nothing for rocm or xpu, and nothing for the 0.1 and 0.2 lines, which were published to PyPI only. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Match pip on requirement names, and stop judging an uninstalled codec Two more false positives from the range reader, both errors on notebooks pip resolves fine. Names are compared case-insensitively by pip (PEP 503), and parse_spec already lowercases for that reason, but the reader used its own case-sensitive regex. `TorchCodec>=0.12.0` therefore moved nothing and the cell was judged on Colab's 0.11. Reading the name through parse_spec fixes it and drops the duplicate pin-parsing regex at the same time. An uninstall also left the oracle in place, so `pip uninstall -y torchcodec` followed by a torch 2.12 install reported a codec that is no longer installed. The branch this PR adds is what made it visible; the parent stayed silent because it had no post-table row to reach. The reader now tracks whether the last invocation naming the package was an uninstall and returns unknown if so. Putting the codec back incompatibly is still reported, so this is not a blanket mute. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Read ~= and <=, drop the unpinnable remedy, and replace a wrong-index codec Three follow-ons, all on code this PR introduced. The range reader knew only >= and <. `torchcodec~=0.12.0` is a two-sided bound (PEP 440: >=0.12.0,<0.13.0) and `<=V` names its own landing version, so both requests moved the codec while the reader kept the image's 0.11 and R-INST-004 reported the version pip had already replaced. The mismatch hint offered `pip install 'unsloth[audio-torch211]'` as an alternative even where the direct command needed --index-url. An extra cannot carry an index: the marker picks the version, not the index, and putting --index-url on the whole command would resolve unsloth itself from the torch index. So on a +cuNNN or +cpu venv that alternative hands back the same unloadable wheel the warning is about, and it is now offered only where no pin is needed. Three existing tests asserted the extra on a +cu128 host; their point was that the hint names the MATCHING extra, so they keep that assertion on an untagged host and now also assert the pinned command on the tagged one. Pinning the index only helped a fresh install. A codec already inside the selected window satisfies the requirement, so pip and uv skip it and the pin fetched nothing, leaving the wrong-accelerator wheel the pin exists to replace. Provenance is readable from the version, since the torch indexes carry a +cuNNN / +cpu local tag and PyPI forbids one, so a missing or different tag now forces the reinstall and says so. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Land a bounded codec window on its newest candidate, not its floor pip resolves a window to the newest release it admits, not the lowest, so `torchcodec>=0.8,<0.11` on torch 2.9 installs the 0.10 line, which 2.9 does not support. Modelling the landing as the floor read that as 0.8, called it compatible, and the finding disappeared. The ceiling names the landing minor without an index: `<0.11` can only land in 0.10. Which patch inside that minor is unknowable offline, and these rules compare minors, so that is enough. This also subsumes the ceiling-only case fixed earlier: `torchcodec<0.10.0` now reads as 0.9 rather than as unknown, which is both more precise and the same verdict. Only 0.N ceilings are modelled. `~=0.12` implies `<1`, which names no minor, and that falls back to the floor as before. * Replay codec installs in order, and honour > and patch-level ceilings Three fixes to the requested-version replay behind R-INST-004: - _highest_minor_below decremented the minor for any exclusive ceiling, so `<0.10.5` modelled as 0.9 even though it still admits 0.10.0 through 0.10.4. Only a ceiling on a minor boundary excludes that whole minor. A torch 2.9 cell pinning `torchcodec<0.10.5` was silently passing. - `>V` was parsed and then dropped, so `torchcodec>0.11.0` kept the very 0.11.0 the request excludes and R-INST-004 rejected a torch 2.12 notebook. It is now a floor that excludes itself; which release pip picks instead is only in the index, so the replay declines to name one rather than guessing. - The bounds came from the LAST invocation naming the package, but pip does not reinstall something that already satisfies the new requirement, so `>=0.12.0` followed by the broader `>=0.10.0` ends on the 0.12. The sequence is now replayed in order against what the previous command left, carrying exact pins through so a reinstall after an uninstall restores a version. Each of the three new tests is red at the parent commit. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Replay != exclusions when resolving the codec version PEP 440 version exclusion inverts `==`, so `torchcodec!=0.11.0` makes pip replace the image's 0.11.0 and `!=0.11.*` rules out the whole minor. The operator dispatch ignored `!=` entirely, so the replay kept the excluded version and R-INST-004 rejected a torch 2.12 notebook that pip resolves to an ABI-stable codec. Exclusions are now recorded per invocation. One that covers the installed version forces a move, and one that covers the landing the window would otherwise name clears it, since which release pip picks instead is only in the index. An exclusion naming something else leaves the version alone, so a genuine mismatch is still reported. Test is red at the parent commit. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Zero-pad version comparisons, keep open floors inexact, honour a pinned mirror - cmp_versions compared raw digit tuples, so `0.11` sorted below `0.11.0` even though PEP 440 pads the shorter release segment. That discarded the ceiling-derived minor for `torchcodec>0.11.0,<0.12.0` and R-INST-004 skipped a real torch 2.12 mismatch. It now pads both sides. - An open `>=` floor was recorded as the version pip lands on, but pip takes the newest release above it, so `torchcodec>=0.11.1` on torch 2.12 resolves to the ABI-stable line and the rule reported a mismatch that never happens. The replay now returns (version, exact) and R-INST-004 uses an inexact answer only where every version at or above it agrees, so `torch==2.10` with `torchcodec>=0.12.0` is still reported. - _torchcodec_index_url rebuilt a public download.pytorch.org URL from the local tag even when UNSLOTH_TORCH_INDEX_URL pinned a mirror. The --index-url that follows also makes _install_env_for_cmd drop inherited index configuration, so an authenticated or air-gapped host lost audio outright. An explicit pin now wins, as it does for the torch repair helpers. Each of the three new tests is red at the parent commit. The three test_managed_node_runtime failures in the wider run reproduce at the PR head without these changes. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Apply exclusions to a bounded landing, and name a mismatched codec build - The ceiling-derived landing ignored exclusions, so `torchcodec>=0.8,<0.11,!=0.10.*` came back as 0.10 and R-INST-004 reported against a line the cell had already ruled out. An exclusion covering the landing now clears it, since where pip drops to instead is only in the index. - `>=V` followed by `>V` left the floor inclusive, because the second bound moves it nowhere and the comparison only accepted a strictly greater one. `>=0.10,>0.10,<0.12` therefore read as "0.10 is fine" when pip must move above it, suppressing a real mismatch. The two intersect to `>V`. - _index_flag recommended the public download.pytorch.org URL even when UNSLOTH_TORCH_INDEX_URL pinned a mirror, so following the warning fails on an air-gapped host or bypasses the configured artifact source. It now reads the same override the installer does. - A cu128 venv holding PyPI's default torchcodec has the right VERSION and still cannot dlopen, so the version hint returned None and audio was disabled with nothing said. A provenance hint now names it, emitted only once the load has actually failed, so a working pairing never warns. Each of the four new tests is red at the parent commit. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Do not print a configured index that may carry credentials The install status line printed _codec_index verbatim. That was harmless while it was always a public download.pytorch.org URL, but honouring UNSLOTH_TORCH_INDEX_URL means it can now be an authenticated mirror whose credentials live in the userinfo or a query token, and this line goes straight to the terminal and the CI log rather than through _redact_install_output, which only covers captured pip output. It now displays _strip_index_url_credentials(_codec_index) while the installer still receives the exact URL. The runtime hints added alongside had the same leak, and there is no redactor in import_fixes.py. They now emit the variable rather than its value, so the pasted command still works for whoever configured the mirror and nothing is written down. Both new tests are red at the parent commit. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Let the last pip verb decide, and follow a configured PyTorch mirror - The uninstall flag matched `pip uninstall` anywhere in an invocation's raw text, but one logical line can chain both verbs. This branch does not split on `&&`, so `pip uninstall -y torchcodec && pip install torchcodec==0.10.0` was one invocation, read as a removal, and the exact reinstall it also captured was thrown away. The LAST pip verb now decides, so a line that really does end on a removal still clears the package. - UNSLOTH_PYTORCH_MIRROR replaces the base every other index in install_python_stack is built from, but the codec pin was a literal download.pytorch.org URL, so an air-gapped host could not fetch it and a corporate one silently bypassed its artifact source. It now uses _PYTORCH_WHL_BASE, and an explicit UNSLOTH_TORCH_INDEX_URL still wins. - The runtime remedy does the same, naming the variable rather than its value so a mirror carrying credentials is not written into a warning. Each of the three new tests is red at the parent commit. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Replay torch too, and stop the codec hint overstating its case - Only torchcodec was replayed, so `pip install "torch>=2.12.0"` left torch at the image's 2.11 and R-INST-004 judged a pairing the cell had already moved away from. Torch now goes through the same helper, and an inexact torch declines to pick a table row rather than guessing one. - The provenance hint asserted that differing local tags were why the codec failed to load. All they establish is that the two wheels came from different indexes: torchcodec is published per accelerator on every line, 0.12 included, so the mismatch stays possible there, but the load can equally have failed on a missing libavutil that no reinstall repairs. It now says "may be" and names FFmpeg as the other candidate. - The remedy printed POSIX `"$VAR"` everywhere. PowerShell is Studio's supported Windows shell and does not expand it, so the command pasted there produced an empty --index-url. It now emits `$env:VAR" on Windows. Each of the three new tests is red at the parent commit. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Attribute each package to the pip command that names it A chained line arrives here as one invocation carrying every package, because this branch has no shell splitter. A single verb for the whole line is wrong in both directions: taking the first threw away a reinstall on the right of an `&&`, and taking the last cleared torch and torchcodec for `pip install torch==2.10.0 torchcodec==0.12.0 && pip uninstall -y torchaudio`, where a third package was the one removed and the incompatible pair stayed installed. Each pip command now owns the packages that appear inside its own span, which runs to the next pip verb. A reinstall after an uninstall of the same package still lands, and an uninstall that really does come last still clears it. Test is red at the parent commit. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Respect ||, attribute by token, pin the remedy window, install NPP - The per-command scanner replayed the right side of `||`, which runs only when the left FAILS. The rules read a cell as the shell runs it on a working host, so `install codec==0.10 || install codec==0.12` now ends on 0.10. `&&` and `;` both still run. - Attribution used substring membership, so `pip install torch && pip uninstall -y torchaudio` put torch in the uninstall span and read it as removed. Each span is tokenised now. - The provenance remedy suggested a bare `torchcodec`. The accelerator indexes carry the whole line, so on torch 2.9 that installs 0.11 and trades a wrong-accelerator build for a wrong-version one. It now pins the window the table allows, or the ABI-stable floor past the table. - torchcodec's CUDA build dlopens libnppicc and libnppc, and NPP is not in torch's dependency set, so the --no-deps install from a cuNNN index reported success and then failed to import. docker/Dockerfile pairs nvidia-npp-cu12 with the same wheel; the installer now does too, with the major taken from the index leaf so cu13x asks for cu13. Fail-soft, like the codec install itself. Each of the four new tests is red at the parent commit. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * notebook_validator: read shell prefixes, backticks and case arms the way bash does (#10376) * notebook_validator: read shell prefixes, backticks and case arms the way bash does Split out of #7474. That PR is a torchcodec/torch 2.11 pin; this parser rewrite rode along with it and has since driven every one of its nine review rounds while sharing no code with the pin. Separating them makes each reviewable and revertable on its own. Carries the rewrite as it stood at 75a808c5c plus fixes for the three P1 defects from the 2026-09-02 round, which were still open. Each one let R-INST-001 miss a `git+` install that bash really would run, and in each case the neighbouring form was already caught, which is what makes them defects rather than gaps. A prefix operand can be spelled like the command. `env -u pip pip install git+...` unsets the variable `pip` and runs the second one, but the executable was located by searching for the first pip-looking word, which selected the operand and produced `pip pip install ...` -- rejected by PIP_LINE_RE, so nothing was collected at all. Prefixes now consume their own options and operands positionally, per a small per-prefix table of the flags that take a separate argument, so the executable is whatever word survives. Backticks were not tracked as substitutions. `_split_chained` knew about quotes and `(`/`{` but never a backtick, so the `;` in ``echo `pip install git+...; echo ok` `` split the line and handed `_substitution_bodies` an unmatched fragment it cannot read. The `$( )` form was handled correctly throughout, which isolates it. There is now a backtick state folded into `in_sub()`, checked before the quote branch because backticks expand inside double quotes. `zip(out, commands)` was not one-to-one. `commands` dropped pieces that unwrapped to empty while `out` kept them, so every later pair slid by one and `zip` stopped at the shorter list. A `case` emits an empty piece per `;;` and its `esac` unwraps to "", so a two-arm `case` left `out` at 5 against `commands` at 2 and the arm holding the substitution was never scanned. Empty pieces are now carried through the pairing and filtered after it. One adjacent defect the same trace exposed: `_unwrap_shell_group` ended with `rstrip(")}")`, which also ate the `)` closing a `$( )` when no `(` had been stripped. Only a grouping bracket is stripped now; a lone `}` from a group that spanned a separator still is, which `_final_bracket_closes_substitution` tells apart. Five tests, all red against the parser at 75a808c5c and green here, each paired with the control form that already passed. tests/notebooks is 119 passed / 2 skipped; ruff clean. The `"2.11": {"0.11"}` torchcodec row appears here too, because `rule_inst_004_torchcodec_torch` lives in this file and its update depends on `_effective_version` and `_marker_environment` from this rewrite. #7474 adds the same row on its side to keep `test_torchcodec_matrix_matches_notebook_validator` green, so that one line will conflict trivially, with identical content, whichever merges second. * Move the parser's own tests across with it The git+ allowlist, install-cell discovery and pip-skip cases exercise the rewritten parser rather than the torchcodec pin, so they belong here too, along with the _one_cell_notebook helper they share. #7474 keeps only the 24 that are actually about torchcodec, import_fixes and install_python_stack. tests/notebooks: 131 passed, 2 skipped. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Keep parameter expansions literal, land a cap-only install, refresh both oracles Three from the first Codex round on this branch. All three reproduce, and the first is the one that matters most: it is a false positive, so it rejects a clean notebook rather than missing a dirty one. ${X:-a||pip install git+...} is one word to bash. `${` was pushed onto the groupings stack as a plain brace group, so the `||` inside the fallback word was read as a control operator and _split_chained manufactured a conditional pip command that never runs. R-INST-001 then failed the notebook over an echo. `${` is now tracked the way `$(` already was. A $( ) inside an expansion does run and is still read; a real { } group still splits on its own separators. pip install "x<=V" on an absent package installs V. _effective_version treated a cap-only requirement as leaving the package absent, so uninstall followed by a capped reinstall came back None and R-INST-004 said nothing about exactly the downgrade it exists to catch. A cap now names the landing version, since pip takes the highest release the requirement allows. An exclusive ceiling still names nothing, because which release sits below it depends on the index. os-info stopped being human-only when this rewrite gave _marker_environment its Python version, but notebooks-ci.yml still refreshed pip-freeze alone. On a Colab Python rotation that judges a fresh package set against the previous image's Python. The pre-lint step now refreshes both with --all, which writes nothing unless it fetched every oracle, so the fallback is the committed pair and is at least self-consistent. The comment above COLAB_STRICT_ORACLE claimed os-info feeds no rule; it does now, and says so. Three tests, red at the parent, green here. tests/notebooks: 134 passed, 2 skipped. ruff clean, workflow YAML parses. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Drop the duplicate ABI constants left by the restack My conflict resolution when rebasing onto #7474 kept both sides of the constants block, so TORCHCODEC_ABI_STABLE_TORCH and _CODEC were each defined twice. The values are identical, so the later pair wins and nothing misbehaves -- which is exactly why the test suite stayed green and only the duplicate-definition lint caught it. Deleted the second copy. Also escaped the backslash in the escaped-separator test's literal. `"\;"` is not a valid Python escape, so it raised a SyntaxWarning; `"\;"` is the same string with the intent stated. * Treat a top-level extra marker as false, and a pip mention as not an install Two review findings, both false positives on R-INST-004 / R-INST-003, which are error severity and so fail notebook CI on clean notebooks. `extra` is only bound while resolving a selected extra's dependency metadata. A requirement handed straight to pip has the known empty value, so `extra == "foo"` is definitively false and pip drops the requirement. Confirmed against pip: $ pip install --dry-run --no-deps "certifi; extra == 'foo'" Ignoring certifi: markers 'extra == "foo"' don't match your environment Omitting it from the marker environment made _requirement_applies conservatively replay such requirements, so `pip install "torch==2.12.0; extra == 'foo'"` was judged against the Colab baseline and reported a mismatch. A cell can also look like an install and run none: `!echo "pip install foo"` matches the install-cell regex but executes no pip. The compat rules then resolved nothing and compared the oracle against itself, so R-INST-003 reported Colab's own peft/torchao pair as an error in the notebook. A notebook with no install cell at all was always skipped; the lookalike now behaves the same. The cell stays discovered, so the per-cell forbid-pattern rules still inspect it. * Drop the narrow codec-range helper this PR's replay supersedes #7474 fixes R-INST-004's range handling with _effective_requested_version, which re-reads the cell text and takes the highest floor it finds. This PR replaces that with _effective_version, a full replay that walks the invocations in order and tracks whether the version it lands on is exactly known. The rebase kept both, so the replay ran and the narrower helper then overwrote its answer, losing invocation order: `torchcodec>=0.12` followed by `torchcodec==0.11.1` resolved back to 0.12 and the real mismatch went unreported. Three of this PR's own tests caught it. Removed the superseded helper and its bounds parser; _effective_version covers every case they did, which the torchcodec compat suite asserts. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Run notebooks CI when the marker oracle rotates _marker_environment reads the image's Python out of colab_os_info.gpu.txt, which makes that snapshot rule-bearing: an OS-only refresh changes which requirements the validator replays. The pull_request path filter listed only the pip freeze, so such a PR skipped the lint and smoke jobs its change affects. Added the OS snapshot beside it. * Pair the marker oracle with the pip snapshot it is judging Both halves of one mismatch, introduced when _marker_environment started reading the image's Python out of colab_os_info.gpu.txt. The path was hard-coded to scripts/data, so `lint --colab-pin` pointing at a snapshot captured anywhere else evaluated markers against this repo's committed os-info: a different image's interpreter than the packages being judged. The oracle directory now follows the pin. The scheduled job had the same split from the other side. It refreshed only colab_pip_freeze.gpu.txt and then linted, so after a Colab Python rotation it judged freshly refreshed packages with the previous image's interpreter, skipping requirements that apply or replaying ones that do not. The PR-time step already refreshes both with --all --snapshot-dir; the cron now matches it. * Match the repo's kwarg spacing in the new oracle test pre-commit's ruff-format-with-kwargs hook writes `encoding = "utf-8"`; the test I added used the tight form, which is what turned the hook red. * Parse python -m pip, gate compat replay on unconditional installs Three fixes: - PIP_LINE_RE now accepts pip's own recommended `python -m pip` form. The cell regex already selected such a cell, so the invocation list came back empty and R-INST-001 missed a prohibited `git+` install outright. The unused _PIP_WORD_RE that recognised the prefix but was wired to nothing goes away with it. - The whole-notebook compatibility rules now run only when the merged cell has an UNCONDITIONAL pip invocation. `!command -v uv || pip install foo` parses to a conditional one, so the rules replayed nothing and compared the Colab oracle against itself, reporting the base image's own peft/torchao pair against an unrelated notebook. R-INST-001 still sees the conditional path: it runs per cell, before this gate. - os-info drift in its Python line now fails `colab-diff --strict`. _marker_environment reads that line, so it is rule-bearing, but with only the pip freeze named strict a Colab interpreter bump behind an unchanged package set left the cron green and the committed version stale. The rest of os-info, and all of apt-list, stay advisory. Each of the three new tests is red at the parent commit. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Recognise expanded interpreter forms, and gate exception coverage on a real pip run - PIP_LINE_RE only accepted a literal `python*` executable, so `!{sys.executable} -m pip install ...` and `!/usr/bin/python3 -m pip ...` matched _PIP_CELL_RE, yielded no invocation, and slipped past R-INST-001 and every compatibility replay. The interpreter alternatives are now kept in step with docker/unsloth_nb_pip_magic.py, which rewrites the same spellings at runtime. _unwrap_shell_group also stripped a leading `{` unconditionally, leaving `sys.executable}` as the executable. `{` opens a shell group only as its own token, so it is stripped only when whitespace follows; a real `{ pip install x; }` group still unwraps. - rule_l12_exceptions_coverage consumed the raw cells install_cells returns, with no parsed-invocation gate. A documentation-only line such as `!echo "pip install peft"` therefore drew a blocking R-EXC-001 for a policy clause the notebook has no install to carry. cmd_lint already gates on an invocation; this path now does too. Also carries the base branch's PEP 440 zero-padding fix for cmp_versions and its pinned-mirror fix for the torchcodec index, with tests against this branch's API. Each new test is red at the parent commit. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Parse python -m uv pip, and give the cron lint the packaging it needs - The interpreter alternative only accepted `-m pip`, but unsloth_nb_pip_magic rewrites `(pip|uv)` after the module flag and uv's pip-compatible interface is spelled `uv pip <action>`. So `!python -m uv pip install git+...` matched _PIP_CELL_RE, yielded no invocation, and R-INST-001 missed a prohibited source the notebook runs. The tool is now decided by matching `uv pip` as a word pair, so an interpreter path containing "uv" is still plain pip. - The static-with-pypi job installed only pip, and _requirement_applies falls back to "applies" when it cannot import Marker. The daily lint was therefore replaying every environment-marked requirement, including the ones Colab's pip skips, which is the question the refreshed Python-version oracle exists to answer. packaging is now declared there. Also merges the base branch and carries its torch-replay, provenance and Windows-shell tests against this branch's API. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Name the encoding on the workflow reads in the new tests tests/test_source_read_encoding.py forbids reading a checked-in file with the platform default encoding, since it breaks on Windows the moment that file gains a non-ASCII byte. The four notebooks-ci.yml reads added by this PR were missing it. * Tighten the comments added by this PR Compress the explanatory blocks to their load-bearing content: 331 added comment lines down to 287 across the files this PR owns. No behaviour change; the full suite still passes. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> * Skip dry runs, intersect the cap with the ceiling, keep quoted words and markers * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Tighten the comments added by this PR * Move the pip-replay tests to the validator suite in #10414 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Read the codec's provenance from its metadata rather than by importing it An unloadable wheel usually raises while torchcodec/__init__ imports its decoders, and Python drops a module whose initialisation raised, so importing it again in the hint just repeated the exception and returned None. The accelerator mismatch went undiagnosed in exactly the case the hint exists to name. The installer's metadata carries the version and needs no native library; an import is still the fallback for a layout the metadata cannot describe. * Collapse the repeated torchcodec guard tests into parametrized tables The module asserted the same shape ten times over for the runtime guard, parsed the audio extras' markers twice, and repeated the wheel-gate scaffolding across four platform tests. Every fact it checked is kept, now as case tables: - one parametrized guard test over 19 (torch, torchcodec) pairs, replacing ten near-identical bodies - one gate table for the audio extras covering both the platform and the Python ceiling, plus a check that a newly added extra cannot slip through untested - one anchor table for the wheel gate's documented transitions - an autouse fixture clearing the index environment, so a developer's own UNSLOTH_TORCH_INDEX_URL cannot decide what the suite asserts Also drops test_select_torchcodec_spec_matches_compat_matrix, which loops the guard matrix that test_compat_matrix_matches_the_published_upstream_table already pins to the literal the stronger installer test below it loops. 1,261 lines to 1,132, 76 tests. Verified by breaking each collapsed behaviour in turn (the ABI floor, the ABI codec floor, the aarch64 marker, the Python ceiling, the macOS 14 floor, the 0.1 Python window, and adding an ungated extra) and confirming the tables still fail. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: oobabooga <[email protected]>
Split out of #7474, which is a torchcodec/torch 2.11 pin. The parser rewrite in
scripts/notebook_validator.pyrode along with that PR and has since driven every one of its nine review rounds, while sharing no code with the pin itself. Separating them makes each reviewable and revertable on its own, and stops a compatibility fix waiting on a shell-parsing arms race.This carries the rewrite as it stood at
75a808c5c, plus fixes for the three P1 items from the 2026-09-02 round, which were still open when I split.The three defects
Each let
R-INST-001return no finding for a line bash really would run the prohibitedgit+install on. In each case the neighbouring form was already caught, which is what makes them defects rather than gaps in coverage.A prefix operand can be spelled like the command.
env -u pipunsets the variable namedpipand then runs the secondpip. The executable was located with_PIP_WORD_RE.search(), which takes the first match, so it selected the operand and producedpip pip install ...-- rejected byPIP_LINE_REon itsinstall|uninstallgroup, so the invocation was never collected at all.Prefixes now consume their own options and operands positionally, driven by a small per-prefix table of which flags take a separate argument, with
--ending the options and--unset=NAMEhandled inline. The executable is whatever word survives.Backticks were not tracked as substitutions.
_split_chainedknew about quotes and(/{but never a backtick, andin_sub()was defined purely off the groupings stack. So the;inside`pip install git+...; echo ok`reached the top-level separator branch, split the line, and left_substitution_bodiesan unmatched fragment it bails on. The$( )spelling of the same shape was caught throughout, which isolates it:There is now a backtick state folded into
in_sub(), checked before the quote branch since backticks expand inside double quotes and only single quotes make them literal.zip(out, commands)was not one-to-one.commandsdropped any piece that unwrapped to empty whileoutkept them, so every later pair slid by one andzipstopped at the shorter list. Acaseemits an empty piece per;;and itsesacalso unwraps to"", so a two-armcasegaveout5 entries againstcommands2, and the arm carrying the substitution was never handed to_substitution_bodiesat all -- not merely mispaired, but off the end. Empty pieces are carried through the pairing now and filtered after it.One adjacent defect the same trace exposed:
_unwrap_shell_groupended withstripped.rstrip(")}"), which also ate the)closing a$( )when no(had been stripped, leavingecho $(pip install git+...unbalanced even once the piece was reached. Only a grouping bracket is stripped now. A lone}from a group that spanned a separator still strips, which is why this needs_final_bracket_closes_substitutionrather than simple bracket counting -- I tried the counting version first and it broke exactly that case.Verification
Five tests, one per item plus one for the bracket strip, each paired with the control that already passed. All five are red against the parser at
75a808c5cand green here:tests/notebooksis 119 passed / 2 skipped at head, which includes the 64 validator tests moved over from #7474's test file. ruff clean on both changed files.One overlap with #7474
The
"2.11": {"0.11"}torchcodec row is in this file too, becauserule_inst_004_torchcodec_torchlives here and its update depends on_effective_versionand_marker_environmentfrom this rewrite -- so the rule change could not be separated from the parser change. #7474 adds the same one line on its side to keeptest_torchcodec_matrix_matches_notebook_validatorgreen. Whichever merges second will conflict on that single line, with identical content on both sides.