Skip to content

notebook_validator: read shell the way bash does, and state the torch/torchcodec contract - #10414

Merged
danielhanchen merged 47 commits into
mainfrom
nbval-shell-parsing
Sep 8, 2026
Merged

danielhanchen merged 47 commits into
mainfrom
nbval-shell-parsing

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Split out of #7474, which is 5,503 insertions and too large to review. 3,277 of those are this change: it was reviewed as #10376, but #10376 was stacked on fix/torchcodec-torch211 and squash-merged into that branch rather than into main, so its diff landed inside #7474 instead of its own PR. Its squash commit has a single parent, so it cannot be retargeted; this rebuilds it against main.

What is in here

The shell reader. _split_chained tracks backticks as well as $( ), case arms keep a one-to-one mapping with their pieces instead of falling off the end of a zip, execution prefixes are parsed by each prefix's own option grammar rather than by taking the first pip-looking word, and _split_first_word walks quotes so env TOKEN="a b" pip install git+... is not broken into three words with b" as the executable. Each of those was a way for R-INST-001 to miss a prohibited git+ install on a line bash really would run it on.

The pip replay. _effective_version / _spec_window replace the older bounds reader: PEP 440 specifier sets are intersected rather than read one at a time, --dry-run no longer records an install pip is documented never to perform, a direct archive reference keeps its filename version when a PEP 508 marker follows it, and versions compare with zero-padding so 0.11 and 0.11.0 are one version.

The compatibility contract, in both mirrors: the torch 2.11 row, and the rule that torchcodec 0.12+ is ABI-stable against torch >=2.11 rather than locked to one minor.

Why the contract is here and not in #7474

Two constraints, both mechanical:

  • 49 of the 95 shell-parsing tests observe the replay engine through rule_inst_004_torchcodec_torch, using a torch 2.11 fixture. Landing the parser without the rule means rewriting half the suite to assert on a different vehicle, which would lose more than it saves.
  • test_torchcodec_matrix_matches_notebook_validator asserts _TORCH_TORCHCODEC_MINORS == TORCH_TORCHCODEC as plain dict equality, so the two tables cannot move apart across PRs without going red in between.

So this PR states the contract and enforces it in CI. #7474 keeps everything that acts on it: the installer selector, the wheel-availability tables, index and mirror pinning, NPP, the provenance hint, the packaging extras and the security audit.

Verification

160 passed, 2 skipped across tests/notebooks/ and tests/python/test_torchcodec_torch_compat.py.

test_torch211_rejects_torchcodec_010 is the load-bearing one and is red on main: today the guard says nothing about torch 2.11 with torchcodec 0.10, which is the pairing that fails to load. The other three contract tests are regression guards -- test_torch210_still_rejects_abi_stable_torchcodec in particular pins the ABI floor at 2.11 so the exemption cannot creep downwards.

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

chatgpt-codex-connector Bot commented Sep 7, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-07T19:29:58.775161Z 206632c New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 7, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

- `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.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 7, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 7, 2026
…ase arms

- `env -S'pip install' pkg` is the valid attached spelling of a mandatory operand;
  exact membership missed it, so R-INST-001 saw no install at all.
- pip takes the LAST `@` after the repo path as the revision delimiter, so splitting
  at the first read a traversal resolving outside the allowlist as an allowed repo.
- `--upgrade` moves every named package to the newest available version, so an
  installed release that merely satisfies the range is not where it lands.
- A `case` arm pattern ends in an unbalanced `)`, which is not the substitution's;
  popping on it left the pip call inside `$(case ...)` unscanned.

Four regression tests, each red at the parent commit.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 7, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…tion

- GNU env documents `\\_` in an `-S` operand as a space and it really separates
  (coreutils 9.4: `env -S 'printf [%s][%s] a\\_b'` prints `[a][b]`). bash keeps the
  backslash inside double quotes, so unescaping the operand as an ordinary shell word
  rebuilt `pip install_git+...` and no invocation was seen. Scoped to the operand: a
  trailing argument is bash's to unescape.
- `--upgrade` moves to the newest available release, so an installed version is not
  where it lands. A ceiling with no floor names no landing either, and keeping the
  stale version raised a false R-INST-004 about a release the cell replaces.
- bash's `!` reserved word runs the pipeline and inverts its status, so
  `! ! pip install git+...` still installs; requiring exactly one leading bang matched
  nothing. Covers IPython's `!!` capture form too.

Three regression tests, each red at the parent commit.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 7, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

… 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.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen and others added 2 commits September 7, 2026 12:56
- 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
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen and others added 2 commits September 7, 2026 13:56
- 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
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen and others added 2 commits September 7, 2026 14:34
- 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
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen and others added 2 commits September 7, 2026 15:43
- 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
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen and others added 2 commits September 7, 2026 16:11
- 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
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen and others added 2 commits September 7, 2026 16:55
…-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.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen and others added 2 commits September 7, 2026 17:33
…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.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…, 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.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen and others added 2 commits September 7, 2026 18:53
…ws, undecided marker terms and quoted loop words

Five replay corrections. A function defined behind a body keyword is now matched, so its body
reaches the rules and is still pruned when nobody calls it. A landing an inclusive cap pins to
an excluded release names nothing rather than fabricating the minor. A prerelease landing is
promoted to its stable core only where the window admits that release. A marker term the
oracle cannot answer makes that term unknown rather than the whole marker, so a decisive false
and unknown stays false. A quoted loop word is one literal iteration, so its body certainly
runs.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 6002f89250

ℹ️ 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".

danielhanchen and others added 2 commits September 7, 2026 19:23
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant