Repository navigation
Fail CI on new yes/no prompts in the installers - #8094
Conversation
#7016 added an "Open Unsloth Studio in your default browser after launch? [Y/n]" question to the interactive install and had to be reverted in #8040. Nothing stopped it landing, so add an allowlist guard over install.sh, install.ps1, studio/setup.{sh,ps1} and scripts/uninstall.{sh,ps1}. Two text passes per script: literal [Y/n] markers, and interactive read sites (read off /dev/tty or -p, Read-Host, PromptForChoice, ReadKey). The second is what catches #7016's shape, where the marker was assigned to _browser_hint a line above the printf. Findings are keyed by normalised question text rather than line number, and checked against APPROVED_PROMPTS, which holds the four prompts in the tree today: "Start Unsloth Studio now?" on both installers, plus the two elevation consent prompts in install.sh and studio/setup.sh. Anything else fails with the file, line, question and the exact allowlist line to add if the prompt is intended, so the decision lands in the diff instead of in the installer unnoticed.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5d1bd6a806
ℹ️ 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".
| or _nearby_question(lines, index, direction = 1) | ||
| or f"<yes/no marker with no question: {text.strip()}>" | ||
| ) | ||
| found.setdefault((script, question), (script, line_number, question)) |
There was a problem hiding this comment.
Preserve prompt occurrences before allowlist validation
When a second prompt reuses approved wording in the same script—for example, another Start Unsloth Studio now? question earlier in install.sh—setdefault collapses it with the existing occurrence before validation. The guard therefore still passes even though the installer gained an additional blocking question; the allowlist needs to constrain occurrence counts or otherwise retain each prompt site rather than deduplicating solely by normalized text.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Reproduced the collapse, but not taking it. The regression class here is new wording: #7016 added a differently worded question, which the guard catches. A second byte-identical 'Start Unsloth Studio now?' earlier in install.sh is not a shape a contributor writes. Pinning occurrence counts in the allowlist would also work against the guard's other requirement, which is not failing on legitimate edits: the count churns whenever a prompt is hoisted into a helper, duplicated across a TAURI_MODE branch, or moved into a retry loop. That trades a shape nobody writes for CI failures on ordinary refactors.
Two review findings on the prompt guard. install.sh downloads and runs scripts/install_rocm_wsl_strixhalo.sh on the automatic WSL path, with no TTY, so a question added there stalls a piped install exactly like the one this guard exists to stop. Scan the scripts/install*.sh helpers as well, and widen the coverage glob so the next one has to be registered too. All three are prompt-free today, so the allowlist is unchanged. The read pass also missed `read -p "Q "` and `read -rp "Q "`: `read\s+` ate the only space, leaving nothing for the whitespace anchor in front of `-p`, so only the two-token `read -r -p` form matched. Match `-p` as an option word instead, bundled or not. The existing test passed on a fixture that carried a literal [Y/n], which the marker pass caught, so the broken branch was masked; the new cases have no marker. Bounding the scan at ; | & at the same time stops a `mkdir -p` later on the line being read as a prompt.
studio/setup.sh:2461 runs scripts/build_whisper_cpp.sh when the prebuilt whisper.cpp is unavailable, under run_quiet_no_exit, where a question would hang with its own prompt swallowed. Scan it. Naming helpers by hand only ever covers the ones we thought of, which is how this one and the WSL bootstrap were both missed, so read them back out of the entry points instead: every scripts/*.sh or .ps1 an installer or setup script references now has to be in SCANNED_SCRIPTS. Those two are the only ones today, and both are prompt-free, so the allowlist is unchanged. Also detect [Console]::ReadLine() and ReadKey in the PowerShell pass. They block exactly like Read-Host and can take their question from a variable, out of the marker pass's reach. Neither installer reads that way today and no [Console]:: write site matches, so the baseline scan is unchanged.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5233286b27
ℹ️ 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".
| them back out of the entry points: whatever they reach, the guard scans.""" | ||
| referenced = { | ||
| f"scripts/{match.group(1)}" | ||
| for script in ENTRY_POINTS |
There was a problem hiding this comment.
Traverse references from scanned helper scripts
When a scanned helper such as scripts/build_whisper_cpp.sh starts invoking a second-level helper such as scripts/build_whisper_deps.sh, this coverage check still passes because references are collected only from ENTRY_POINTS, while prompt detection only reads files already in SCANNED_SCRIPTS. I checked the workflow coverage: Backend CI runs this test for scripts/** changes, but the test cannot discover that transitive helper, so an interactive prompt there remains invisible. Traverse helper references recursively, or at least inspect every scanned script.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Right, fixed in 4d83af5. The reference check now takes every scanned script as a source instead of only the four entry points, which closes over the whole chain: once a helper is listed, whatever it reaches has to be listed too. Referenced set is unchanged today (build_whisper_cpp.sh, install_rocm_wsl_strixhalo.sh, and the two uninstallers), and I confirmed the check is load-bearing by dropping build_whisper_cpp.sh from SCANNED_SCRIPTS and watching it fail.
| "scripts/install*.sh", | ||
| "scripts/uninstall*.sh", | ||
| "scripts/uninstall*.ps1", |
There was a problem hiding this comment.
Include PowerShell installer helpers in discovery
When a PR adds a standalone helper such as scripts/install_windows.ps1, Backend CI runs because it watches scripts/**, but this discovery set omits the file: it includes scripts/install*.sh and PowerShell uninstallers, but not scripts/install*.ps1. The guard therefore passes without requiring the new installer to be added to SCANNED_SCRIPTS, allowing a PowerShell yes/no prompt to go uninspected.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, fixed in 4d83af5: scripts/install*.ps1 was missing from the glob list. A standalone PowerShell helper that no entry point references would not have been caught by the reference check either, so the static glob is the only thing covering that case. Nothing on disk matches it today, so the scanned set and the allowlist are unchanged.
The reference check only read the four entry points, so a helper that grows a helper of its own was invisible. Every scanned script is a source now, which closes over the whole chain: once the first helper is listed, whatever it reaches has to be listed too. The static globs also covered scripts/install*.sh but not the PowerShell half, so a standalone scripts/install_windows.ps1 that no entry point references would not have been required in SCANNED_SCRIPTS. Both leave the scanned set as it is today, so the allowlist and the baseline scan are unchanged.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4d83af58ce
ℹ️ 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".
| ) | ||
|
|
||
| # A `scripts/<helper>` mention is an invocation, quoted or behind a path prefix. | ||
| _HELPER_REF = re.compile(r"scripts/([A-Za-z0-9_.-]+\.(?:sh|ps1))") |
There was a problem hiding this comment.
Recognize sibling-relative helper references
When a scanned helper invokes another helper through a sibling-relative path such as "$SCRIPT_DIR/build_whisper_deps.sh", _HELPER_REF does not match because it requires the literal scripts/ prefix. Consequently, test_helpers_the_installers_invoke_are_scanned passes while the newly invoked helper—and any blocking prompt in it—remains outside SCANNED_SCRIPTS. The fresh evidence beyond the earlier traversal finding is that the new all-SCANNED_SCRIPTS traversal still filters every reference through this prefix-specific regex; recognize basename/sibling helper invocations as well.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fair, fixed in 3537418. Helper references no longer need the scripts/ prefix, since a helper invoking a sibling writes it out of its own directory. To keep that from turning every filename in a log message into a required entry, a name only counts once it resolves to a real script beside the one naming it or in scripts/. Nothing new resolves today, so the scanned set is unchanged.
| # The scan stops at `;|&`, since a `mkdir -p` later on the line is another command. | ||
| _POSIX_READ = re.compile( | ||
| r"(?:^|[\s;&|(])read\s+(?![a-zA-Z_]+=)" | ||
| r"(?:-[a-zA-Z]*p(?=[\s\"']|$)|[^\n;|&]*?(?:<\s*/dev/tty|\s-[a-zA-Z]*p(?=[\s\"']|$)))" |
There was a problem hiding this comment.
Treat bare POSIX reads as interactive sites
When a local installer adds the common pattern printf "Continue with installation? " followed by read -r reply, this regex does not recognize the read because it has neither -p nor a literal /dev/tty redirection, and the question has no marker for the other pass to find. The new test therefore reports no prompt even though the read blocks when ./install.sh is run from a terminal (and consumes installer input in the piped form), so direct reads from inherited stdin need to be classified separately from explicitly redirected file and loop reads.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed, fixed in 3537418, and this is the biggest of the five. A question printed with no marker and answered by a plain unredirected read is the commonest prompt shape there is, and it went straight through. An unredirected read takes the terminal the installer inherited, so it blocks the same way. Loop and pipeline reads are excluded since they are fed by their done or their pipe, and I pinned the shape to options then variable names at end of line in command position, which was needed: a looser rule matched the word read inside the uninstaller's heredoc of prose. No new hits anywhere in the scanned tree.
| r"(?:-[a-zA-Z]*p(?=[\s\"']|$)|[^\n;|&]*?(?:<\s*/dev/tty|\s-[a-zA-Z]*p(?=[\s\"']|$)))" | ||
| ) | ||
| _PWSH_READ = re.compile( | ||
| r"Read-Host|PromptForChoice|Console\]::(?:In\.)?Read(?:Line|Key)|ReadKey\s*\(", re.IGNORECASE |
There was a problem hiding this comment.
Detect blocking Console.Read calls
When a PowerShell installer prints an unmarked confirmation question and reads one response character with [Console]::Read(), _PWSH_READ misses the site because the expression only accepts ReadLine and ReadKey. Since there is no [Y/n] marker to trigger the literal pass, this blocking prompt is invisible to the guard; include Console.Read() alongside the other console input APIs.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 3537418: [Console]::Read joins ReadLine and ReadKey. Same family, and leaving it out after taking the other two would have been arbitrary.
| for text in candidates: | ||
| if _looks_like_question(text): | ||
| normalised = normalise_question(text) | ||
| if normalised: | ||
| return normalised |
There was a problem hiding this comment.
Validate every conditional prompt candidate
When one read site serves conditional messages and the branch nearest the read prints the approved Start Unsloth Studio now? question, this loop returns that first match and never validates an earlier branch such as Enable telemetry?; the read is then deduplicated under the approved key and the new question passes CI. This is distinct from the rejected byte-identical occurrence case: the fresh evidence is that differently worded questions at the same /dev/tty read are collapsed because _nearby_question returns only the nearest candidate, so all reachable question strings need validation.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed, fixed in 3537418. A read site now validates every question in reach rather than only the nearest, so one read serving a branch each no longer hides the unapproved branch behind the approved one. I checked this costs nothing on the current tree: all four existing read sites still resolve to exactly one question each, so no new allowlist entries.
| def _is_comment(line: str) -> bool: | ||
| """Whole-line `#` comment. Inline ones need a parser to tell from a `#` inside | ||
| a string, and a false positive only costs an allowlist entry.""" | ||
| return line.lstrip().startswith("#") |
There was a problem hiding this comment.
Ignore PowerShell block comments
When a scanned .ps1 file documents an example such as Read-Host "Enable telemetry? [Y/n]" inside a <# ... #> block comment, _is_comment treats the example as executable because its line does not start with #. The guard then fails CI and asks for an allowlist entry for a prompt that cannot run, so PowerShell scanning needs to track block-comment regions rather than recognizing only single-line comments.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Good catch, fixed in 3537418. Not hypothetical either: studio/setup.ps1 opens with a <# ... #> comment-based help block, so a documented Read-Host example there would have failed CI over a prompt that cannot run. Block regions are blanked for .ps1 files, keeping the line count so reported line numbers still line up.
Five gaps from review, none of which changes what the scan finds in the tree today. The read pass only knew about -p and /dev/tty, so the commonest prompt of all, a question printed with no marker and answered by a plain unredirected read, went straight through. An unredirected read takes the terminal the installer inherited, so it blocks the same way. Loop and pipeline reads are fed by their done or their pipe, and the shape is pinned to options then variable names at end of line in command position, so the word read in a heredoc of prose is not mistaken for one. A read site now validates every question in reach rather than only the nearest. One read can serve a branch each, and approving the closest was enough to wave the other branch through under an allowlisted key. PowerShell: [Console]::Read() joins ReadLine and ReadKey, and <# ... #> blocks are blanked. studio/setup.ps1 opens with comment-based help, so a documented Read-Host example there would have failed CI over a prompt that cannot run. Helper references no longer need the scripts/ prefix, since helpers invoke each other out of their own directory. A name only counts once it resolves to a real script beside the one naming it or in scripts/, so a filename mentioned in a message is still ignored.
There was a problem hiding this comment.
💡 Codex Review
unsloth/.github/workflows/cross-platform-parity-ci.yml
Lines 23 to 24 in 3537418
When a PR adds a root installer such as install_linux.sh or install_windows.ps1, test_every_installer_script_is_scanned would discover it, but this workflow never runs because its path filter names only the two existing root installers. I also checked .github/workflows/studio-backend-ci.yml, which likewise watches only those exact root names plus scripts/**, and Core does not watch root installers, so the new file can merge with an uninspected prompt; use root install*.sh and install*.ps1 filters matching the discovery patterns.
ℹ️ 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".
| return bool(_PWSH_READ.search(line)) | ||
| if _POSIX_READ.search(line): | ||
| return True | ||
| return "<" not in line and "|" not in line and bool(_BARE_READ.search(line)) |
There was a problem hiding this comment.
Do not treat fallback operators as pipeline input
When an unmarked prompt uses a normal fallback such as read -r reply || reply=n, the detector returns no prompt: _POSIX_READ does not apply without -p or /dev/tty, and this branch rejects the line merely because || contains |. The fresh evidence beyond the earlier bare-read report is that the newly added fallback explicitly conflates || with a pipeline, so an inherited-stdin read that still blocks or consumes piped installer input remains invisible.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Right, my own false positive from the previous round, fixed in 3b202a7. Excluding any line containing a pipe threw out read -r reply || reply=n, which is the house style for an EOF default everywhere else in install.sh and still blocks. Only a real pipeline counts now, and the bare-read shape allows a || or && tail.
| lines.append("") | ||
| in_block = "#>" not in line | ||
| continue | ||
| if powershell and "<#" in line and "#>" not in line.split("<#", 1)[1]: |
There was a problem hiding this comment.
Strip single-line PowerShell block comments
When a PowerShell file contains a one-line block comment such as <# Read-Host "Enable telemetry? [Y/n]" #>, this condition is false because the text after <# already contains #>, and the unchanged line is subsequently reported as an executable prompt. The fresh evidence beyond the earlier block-comment report is that the new state machine handles only comments whose opener and closer are on different lines, so valid inline documentation can still fail CI and encourage a bogus allowlist entry.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, fixed in 3b202a7: inline <# ... #> spans are stripped before the opener check, so a one-liner no longer falls through to the scan as code.
|
|
||
| # Stripped so a question built from a format string keys the same as a literal. | ||
| _FORMAT_NOISE = re.compile( | ||
| r"%[-#0 +]*\d*(?:\.\d+)*[sdfxbq%]|\\[nrte]|\$\{?[A-Za-z_][A-Za-z0-9_]*\}?" |
There was a problem hiding this comment.
Preserve semantic substitutions in approved prompt keys
When approved wording is extended through interpolation, such as printf "Start Unsloth Studio %s now? [Y/n]" "and enable telemetry", stripping every format conversion and variable reference normalizes the new question to the already approved start unsloth studio now?. Both the marker pass and the nearby-read pass therefore accept it, allowing a materially new preference question to bypass the guard; only substitutions known to supply the yes/no marker should be discarded.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Taken, fixed in 3b202a7, though with a different remedy than suggested. Keying only off substitutions that supply the marker would need the guard to know which is which. Instead a substitution normalises to a placeholder rather than vanishing, so printf "Start Unsloth Studio %s now?" keys as start unsloth studio now? and does not collapse onto the approved question. A substitution at the end of the string still normalises away, since that is the [Y/n] hint the marker pass has already read, which keeps the #7016 shape keying cleanly.
| if _is_interactive_read(line, powershell): | ||
| for question in _questions_for_read(lines, index): | ||
| found.setdefault((script, question), (script, line_number, question)) |
There was a problem hiding this comment.
Detect shell select confirmation loops
When an installer uses the shell builtin select, for example PS3="Continue with installation? "; select reply in Yes No; do ..., it blocks for a yes/no choice but contains neither a recognized marker nor a read command, so this scan records no prompt. Such a confirmation can consequently be added without failing CI; treat select and its associated PS3 question as an interactive input site.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 3b202a7. select is the other shell builtin that blocks for an answer, so it belongs with read, Read-Host and the console reads. Its PS3 question needed no extra work: the assignment sits above the loop and the existing nearby scan already reads it. I am drawing the line at builtins, though. External TUI programs such as whiptail, dialog and zenity are an open-ended list and none of them appears anywhere in these scripts.
| _LOOP = re.compile(r"\b(?:while|until|for)\b") | ||
|
|
||
| _PWSH_READ = re.compile( | ||
| r"Read-Host|PromptForChoice|Console\]::(?:In\.)?Read(?:Line|Key)?\b|ReadKey\s*\(", |
There was a problem hiding this comment.
Ignore PowerShell input API names inside strings
When an installer prints an ordinary diagnostic such as Write-Host "Read-Host is unavailable on this terminal", _PWSH_READ.search(line) treats the API name inside the quoted message as an actual input call and reports an unlabelled interactive read. This makes harmless status or error text fail CI even though it cannot block; input APIs need to be recognized only in executable command context rather than anywhere in the raw line.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, fixed in 3b202a7. Quoted text is blanked before the read test, so a message naming Read-Host is not a read while an actual Read-Host call, which sits outside the string, still is.
Five more from review, all of them shapes the previous round created or left behind. The scan of the tree is unchanged. Two were my own false positives. Excluding any line containing a pipe threw out `read -r reply || reply=n`, which is the house style for an EOF default and still blocks; only a real pipeline counts now. And the PowerShell pass matched an API name anywhere on the line, so a message saying Read-Host is unavailable read as a prompt. Quoted text is blanked before the read test, which also covers a single-line <# ... #> block, where the previous state machine only handled an opener and closer on different lines. Normalising away every substitution meant printf "Start Unsloth Studio %s now?" keyed as the approved question. Substitutions become a placeholder instead, so spliced wording is a new question, while one at the end still normalises away since that is the marker hint the other pass already read. select is the other builtin that blocks for an answer, and its PS3 question is picked up by the existing nearby scan.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3b202a7899
ℹ️ 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".
| # Options then variable names to end of line, in command position, so the word | ||
| # `read` in a heredoc of prose is not a prompt. | ||
| _BARE_READ = re.compile( | ||
| r"(?:^|[;&(])\s*read(?:\s+-[a-zA-Z]+)*(?:\s+[A-Za-z_][A-Za-z0-9_]*)+" |
There was a problem hiding this comment.
Accept valid option arguments in bare read detection
When an unmarked prompt is followed by a valid inherited-stdin read such as read -r -n 1 reply or read -r -t 10 reply, this pattern does not match because it permits only alphabetic option tokens and treats neither numeric option arguments nor bundled forms like -rn1 as valid. The marker pass also has nothing to find, so these common single-character or timed confirmation reads can be added without failing the guard.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, fixed in 7b2a7d2: option arguments are accepted, so read -r -n 1 reply, read -r -t 10 reply and the bundled read -rn1 reply all count. A one-character or timed confirmation is still a confirmation. I re-ran the scan over every scanned script to confirm the looser shape adds no hits, since this is the pattern that previously matched the word read inside the uninstaller's help text.
| # A helper filename, with or without its `scripts/` prefix: sibling invocations | ||
| # such as "$SCRIPT_DIR/build_deps.sh" carry no prefix. Resolved against the repo | ||
| # before it counts, so a name that is not a real script is ignored. | ||
| _HELPER_REF = re.compile(r"([A-Za-z0-9_.-]+\.(?:sh|ps1))") |
There was a problem hiding this comment.
Preserve subdirectories when resolving helper references
When a scanned script invokes a nested helper such as "$SCRIPT_DIR/helpers/build_deps.sh", this regex captures only build_deps.sh; the resolver consequently checks the caller's directory and scripts/, but never helpers/build_deps.sh. Fresh evidence after the sibling-relative fix is that directory components are still discarded, so a real nested helper containing an interactive prompt remains outside SCANNED_SCRIPTS while the coverage test passes.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 7b2a7d2. The capture keeps its subdirectory and resolves by full path as well as by name, so a nested helper is found while a URL, whose captured path resolves nowhere, still matches the local copy by name. A lookbehind keeps a leading $SCRIPT_DIR out of the captured path, which the naive version swallowed.
| _SELECT = re.compile(r"(?:^|[;&(])\s*select\s+[A-Za-z_][A-Za-z0-9_]*\s+in\s") | ||
|
|
||
| _PWSH_READ = re.compile( | ||
| r"Read-Host|PromptForChoice|Console\]::(?:In\.)?Read(?:Line|Key)?\b|ReadKey\s*\(", |
There was a problem hiding this comment.
Recognize PSHost ReadLine input
When a PowerShell installer prints an unmarked question and reads the response with $Host.UI.ReadLine(), _PWSH_READ does not match because ReadLine is accepted only through the Console]:: branch. Fresh evidence beyond the earlier Console-read fix is that the standard PowerShell host input API remains uncovered, allowing this blocking prompt shape to pass the guard.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 7b2a7d2: $Host.UI.ReadLine joins the console reads. Still anchored on the receiver rather than matching a bare ReadLine, so a StreamReader over a file is not mistaken for a prompt.
| - 'scripts/install_gemma4_mlx.sh' | ||
| - 'scripts/install_qwen3_6_mlx.sh' | ||
| - 'scripts/install_rocm_wsl_strixhalo.sh' |
There was a problem hiding this comment.
Trigger the guard for newly named root installers
When a PR adds a root installer such as install_linux.sh or install_windows.ps1, test_every_installer_script_is_scanned is designed to reject it until registered, but this workflow enumerates only the current filenames and no other workflow that runs this test has a root install* path trigger (Backend CI also lists only install.sh, install.ps1, and scripts/**). Consequently the guard never runs on that PR, so use root installer globs in the workflow filters rather than enumerating only existing scripts.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Best catch of the round, fixed in 7b2a7d2. The coverage check is written to refuse an unregistered root installer, but the workflow enumerated filenames, so on the PR adding install_linux.sh the check that rejects it would never have run. All the installer paths are globs now, which is also shorter than the list it replaces.
The coverage check refuses an unregistered root installer, but the workflow enumerated filenames, so adding install_linux.sh would not have run the check that rejects it. Its paths are globs now, which is also shorter than the list it replaces. Bare reads accept option arguments, so read -r -n 1 reply and read -r -t 10 reply count: a one-character or timed confirmation is still a confirmation. $Host.UI.ReadLine joins the console reads, kept anchored so a StreamReader over a file is not mistaken for a prompt. Helper references keep their subdirectory and are resolved by full path as well as by name, so a nested helper is found while a URL still resolves to the local copy. The lookbehind keeps a leading $VAR out of the captured path. The scanned set, the allowlist and the scan of the tree are all unchanged.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7b2a7d24c0
ℹ️ 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".
|
|
||
| # A helper filename, with or without its `scripts/` prefix: sibling invocations | ||
| # such as "$SCRIPT_DIR/build_deps.sh" carry no prefix. Resolved against the repo |
There was a problem hiding this comment.
Recognize assignment-prefixed shell reads
When an installer prints an unmarked question and uses the common shell form IFS= read -r reply, neither read pattern matches because _BARE_READ requires read itself to begin the command while _POSIX_READ only covers -p or /dev/tty. Fresh evidence after the earlier bare-read fix is that this assignment-prefixed inherited-stdin form still makes find_prompts() return no prompts, even though it blocks on a terminal or consumes piped installer input; allow leading assignment words before read.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 9d876d7: leading assignments are allowed before read, so IFS= read -r reply counts. The loop exclusion still holds, which matters because the two existing while IFS= read loops in install.sh and build_whisper_cpp.sh are the shape this could most easily have false-positived on. Re-ran the tree scan to confirm no new hits.
| if powershell and in_block: | ||
| lines.append("") | ||
| in_block = "#>" not in line | ||
| continue |
There was a problem hiding this comment.
Preserve code after PowerShell block-comment terminators
When a multiline PowerShell comment closes on the same physical line as executable code, such as #> $reply = Read-Host "Enable telemetry? [Y/n]", this branch blanks the entire line rather than only the comment prefix, so the real prompt is never scanned. Fresh evidence beyond the previous block-comment fixes is the executable suffix after a multiline terminator; retain and scan the text following #>.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 9d876d7: the terminator branch keeps whatever follows #> on the line instead of blanking the whole line.
| # A helper filename, with or without its `scripts/` prefix: sibling invocations | ||
| # such as "$SCRIPT_DIR/build_deps.sh" carry no prefix. Resolved against the repo | ||
| # before it counts, so a name that is not a real script is ignored. | ||
| _HELPER_REF = re.compile(r"(?<![$\w])((?:[A-Za-z0-9_.-]+/)*[A-Za-z0-9_.-]+\.(?:sh|ps1))") |
There was a problem hiding this comment.
Traverse installer Python helpers too
When a directly invoked Python helper adds a prompt, it remains outside this closure because helper references are restricted to .sh and .ps1; for example, both studio/setup.sh and studio/setup.ps1 execute studio/install_python_stack.py. A change such as input("Enable telemetry?") in that helper is neither discovered by this test nor covered by the workflow's path filters, even though it blocks the same Studio update, so include invoked Python helpers and their input APIs in discovery and scanning.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Verified and fixed in 9d876d7. studio/setup.sh:1010 runs python "$SCRIPT_DIR/install_python_stack.py", and following the references turns up four such helpers: install_python_stack, install_llama_prebuilt, install_node_prebuilt and install_whisper_prebuilt. All four are scanned now, with input, getpass and confirm as the read APIs. None has a prompt today. One boundary worth recording: references are followed out of shell, PowerShell and batch scripts only, not out of Python. A shell script naming a file runs it, a Python file naming one imports it, and following imports walked straight into unsloth/models/_utils.py, which is library code rather than an installer.
| # in turn is scanned too (`unsloth studio update` runs setup.sh, which builds | ||
| # whisper.cpp; install.sh fetches and runs the WSL bootstrap), since a question | ||
| # down there stalls the same install. | ||
| ENTRY_POINTS = ("install.sh", "install.ps1", "studio/setup.sh", "studio/setup.ps1") |
There was a problem hiding this comment.
Scan the Windows batch setup entry point
The repository already exposes studio/setup.bat as a Windows setup launcher, but it is absent from ENTRY_POINTS, the on-disk discovery globs, and the workflow path filters. If that launcher gains a blocking batch prompt such as choice /M "Enable telemetry?" or set /P, changing it will not run this workflow and even a manual guard run cannot inspect it; register the batch entry point and recognize CMD input commands.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 9d876d7. studio/setup.bat is a five-line shim that hands off to setup.ps1, but it is a Windows entry point and it was neither scanned nor globbed. It is in ENTRY_POINTS now, with set /p and choice as the read commands and REM and :: as comments.
studio/setup.sh runs four helpers with `python <helper>.py`, the first being install_python_stack.py at setup.sh:1010, and studio/setup.bat is the Windows launcher. An input() or a set /p in any of them blocks the same Studio update, so scan them: input, getpass and confirm for Python, set /p and choice for batch, with REM and :: treated as comments. Helper references follow .py and .bat now, but only out of shell, PowerShell and batch scripts. A shell script naming a file runs it, a Python file naming one imports it, and following imports walked straight into unsloth/models/_utils.py, which is library code, not an installer. Also: `IFS= read -r reply` is one command, not an assignment, so leading assignments are allowed before read; and a `#>` terminator sharing its line with code no longer blanks the code. All five newly scanned files are prompt-free, so the allowlist and the scan of the tree are unchanged.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9d876d74d8
ℹ️ 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".
| # `read` in a heredoc of prose is not a prompt. | ||
| _BARE_READ = re.compile( | ||
| r"(?:^|[;&(])\s*(?:[A-Za-z_][A-Za-z0-9_]*=\S*\s+)*" | ||
| r"read(?:\s+(?:-[a-zA-Z0-9]+|\d+))*(?:\s+[A-Za-z_][A-Za-z0-9_]*)+" |
There was a problem hiding this comment.
Handle Bash read calls that rely on REPLY
In Bash-based entry points such as studio/setup.sh, read -r is valid and stores the response in $REPLY. _BARE_READ requires at least one explicit variable name after the options, while _POSIX_READ only recognizes -p or /dev/tty, so an unmarked printf "Continue? " followed by read -r produces no prompt and allows a new blocking yes/no question to pass the guard.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, fixed in 3a23234: the variable list is optional now, so read -r on its own counts and the answer lands in $REPLY. Nothing in the tree uses that form today, so this closes a gap rather than changing the scan.
| # A helper filename, with or without its `scripts/` prefix: sibling invocations | ||
| # such as "$SCRIPT_DIR/build_deps.sh" carry no prefix. Resolved against the repo | ||
| # before it counts, so a name that is not a real script is ignored. | ||
| _HELPER_REF = re.compile(r"(?<![$\w])((?:[A-Za-z0-9_.-]+/)*[A-Za-z0-9_.-]+\.(?:sh|ps1|py|bat))") |
There was a problem hiding this comment.
Preserve backslash-delimited helper subdirectories
When a PowerShell or batch installer invokes a nested helper using the native Windows form such as $PSScriptRoot\helpers\setup_extra.ps1, this regex captures only setup_extra.ps1 because its directory group accepts / but not \. The resolver then checks only the caller directory, repository root, and scripts/ by basename, never the actual nested path, so the helper-coverage test passes while prompts in that helper remain unscanned. Fresh evidence beyond the earlier forward-slash subdirectory fix is that Windows-delimited paths still lose all directory components.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 3a23234. Backslashes are accepted and normalised, which the tree already needed: install.ps1 and scripts/uninstall.ps1 both write .\scripts\uninstall.ps1 in their usage text. A venv path such as Scripts\Activate.ps1 still resolves nowhere and is ignored.
| lines.append(line.split("<#", 1)[0]) | ||
| in_block = True | ||
| continue | ||
| lines.append("" if _is_comment(line) else line) |
There was a problem hiding this comment.
Ignore input examples inside Python docstrings
When a scanned Python helper documents an example such as reply = input("Enable telemetry? [Y/n]") inside a triple-quoted docstring, blank_comments leaves that line unchanged and both the marker and input passes treat it as executable. A documentation-only edit therefore fails CI for a prompt that can never run and encourages a bogus allowlist entry; Python scanning needs to blank triple-quoted string regions while preserving line numbers.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 3a23234, and this one is live rather than theoretical: install_python_stack.py alone has 152 triple-quote delimiters, so a documented example is a realistic way to hit it. Docstring regions are blanked with the line count kept, matching the block-comment handling for .ps1.
|
|
||
| # The Python helpers setup runs, and the batch launcher. | ||
| _PY_READ = re.compile(r"(?<![.\w])input\s*\(|getpass\.getpass\s*\(|confirm\s*\(") | ||
| _BAT_READ = re.compile(r"\bset\s+/p\b|\bchoice\b", re.IGNORECASE) |
There was a problem hiding this comment.
Restrict batch input detection to command position
When setup.bat prints a diagnostic such as echo choice /M "Enable telemetry?" is not supported here, _BAT_READ matches the word choice anywhere on the line and reports the quoted text as an interactive prompt even though no input command executes. This makes harmless batch status or documentation text fail CI; as with the PowerShell detector, choice and set /p need to be recognized only in executable command context.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, fixed in 3a23234: set /p and choice are matched in command position only, the same treatment the PowerShell detector got.
| `set /p`, or plain inherited stdin. Redirected and loop reads consume a file, not | ||
| a person. Quoted text is blanked first, so a message naming `Read-Host` is not | ||
| one.""" | ||
| code = _QUOTED.sub('""', line) |
There was a problem hiding this comment.
Preserve executable PowerShell string subexpressions
When a PowerShell installer embeds input in an expandable string, for example Write-Host "Response: $(Read-Host 'Enable telemetry?')", the $() subexpression executes and blocks, but replacing the whole quoted region with "" removes the Read-Host call before _PWSH_READ runs. With no literal yes/no marker, find_prompts returns nothing and the new question passes the guard. Fresh evidence after the quoted-message fix is that PowerShell double-quoted strings may contain executable subexpressions rather than only inert message text.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, and it was my own regression from the previous round: blanking quoted text to stop a message naming Read-Host reading as a prompt also blanked the subexpressions, which execute. Fixed in 3a23234. $(...) is kept, and a string quoted inside one is now offered as the question, so the site keys on the real wording instead of falling back to an unlabelled read.
| "install*.ps1", | ||
| "studio/setup*.sh", | ||
| "studio/setup*.ps1", | ||
| "studio/setup*.bat", |
There was a problem hiding this comment.
Discover root batch installers
When a root Windows launcher such as install.bat is added, this discovery list ignores it because batch coverage is limited to studio/setup*.bat; the cross-platform workflow likewise includes only studio/setup*.bat, and Backend CI enumerates only the existing root install.sh and install.ps1. The PR adding that installer therefore runs no prompt guard that can require registration, allowing any blocking question in it to land unseen. Fresh evidence after registering studio/setup.bat is that the resulting batch discovery and workflow coverage remain scoped only to that Studio path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 3a23234: install*.bat joins the discovery globs and the workflow paths, for the same reason install_linux.sh did last round.
Six from review. Three are false positives or blind spots the previous round's own fixes created. Blanking quoted text to stop a message naming Read-Host from reading as a prompt also blanked $(...) subexpressions, which execute: PowerShell prompts from inside an expandable string. Those are kept now, and a string quoted inside one is offered as the question, so the site keys on the real wording rather than an unlabelled read. Batch reads are matched in command position only, so echoing the word choice in a message is not a prompt. Python docstrings are blanked, keeping the line count, since a documented input() example cannot run and the scanned helpers are full of triple-quoted text. read -r with no variable name is valid and puts the answer in $REPLY, so the variable list is optional. Helper references accept backslashes and normalise them, the tree already writing .\scripts\uninstall.ps1 that way. Root install*.bat joins the discovery globs and the workflow paths, for the same reason install_linux.sh did. Scan of the tree is unchanged.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3a23234793
ℹ️ 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".
| "studio/install_llama_prebuilt.py", | ||
| "studio/install_node_prebuilt.py", | ||
| "studio/install_python_stack.py", | ||
| "studio/install_whisper_prebuilt.py", |
There was a problem hiding this comment.
Scan the native diffusion installer
studio/install_sd_cpp_prebuilt.py is omitted even though studio/backend/core/inference/sd_cpp_backend.py imports and runs its install() function automatically when sd-cli or sd-server is missing. A future input() confirmation in that installer would therefore block a first-use backend request while this guard still passes; include it in SCANNED_SCRIPTS and installer discovery.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not on the reasoning given, but the file is scanned as of f9ef29b. sd_cpp_backend.py importing an installer at first use is the running app fetching a prebuilt, not the install path, and treating that as in scope would pull in everything the backend lazily installs. What does put it in is simpler: it is named studio/install_sd_cpp_prebuilt.py and sits beside the four helpers already scanned, so studio/install_*.py is globbed, which covers it and install_manifest.py. Both are prompt-free, so nothing changes in the scan.
| for script in SCANNED_SCRIPTS: | ||
| if script.endswith(".py"): | ||
| continue |
There was a problem hiding this comment.
Follow helpers launched from Python installers
The final implementation still skips every Python source during helper traversal, while the scanned studio/install_python_stack.py actually executes the checked-in studio/backend/requirements/single-env/patch_metadata.py via subprocess.run at line 4157. This is fresh evidence beyond the earlier direct-Python-helper fix: a prompt added to that second-level script remains unscanned and can stall setup, so Python-launched repository helpers must participate in the closure too.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Verified and fixed in f9ef29b. install_python_stack.py:4157 runs [sys.executable, str(SINGLE_ENV / "patch_metadata.py")], so it is an invocation rather than an import. Python sources are traversed again: the reason they were skipped was that following them reached unsloth/models/_utils.py, and that reference turns out to be in a comment, with the others in docstrings, so blanking those removed the cause. patch_metadata.py builds its path from a variable and cannot be resolved from the text, so it is listed explicitly. I did not add repo-wide resolution of a helper by basename, which was the other way to reach it: it also picks up sitecustomize.py and build artifacts.
| _BARE_READ = re.compile( | ||
| r"(?:^|[;&(])\s*(?:[A-Za-z_][A-Za-z0-9_]*=\S*\s+)*" | ||
| # No variable name at all is valid: the answer lands in $REPLY. | ||
| r"read(?:\s+(?:-[a-zA-Z0-9]+|\d+))*(?:\s+[A-Za-z_][A-Za-z0-9_]*)*" | ||
| r"(?:\s*(?:\|\||&&).*)?\s*$" |
There was a problem hiding this comment.
Recognize bare reads in shell conditionals
When an unmarked question is followed by the common conditional form if read -r reply; then, _BARE_READ rejects the line because it permits neither the leading if nor the trailing ; then; _POSIX_READ also does not apply without -p or /dev/tty. That read still blocks on inherited stdin, but find_prompts() returns no prompt, allowing the new question through.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in f9ef29b: a read can be the condition of an if, so that prefix and the ; then tail are allowed.
|
|
||
| # The Python helpers setup runs, and the batch launcher. | ||
| _PY_READ = re.compile(r"(?<![.\w])input\s*\(|getpass\.getpass\s*\(|confirm\s*\(") | ||
| _BAT_READ = re.compile(r"(?:^|[&(]|\bdo\b)\s*(?:set\s+/p\b|choice\b)", re.IGNORECASE) |
There was a problem hiding this comment.
Allow batch echo-suppression prefixes
Batch files commonly prefix individual commands with @, but _BAT_READ does not accept it. Consequently @choice /M "Enable telemetry?" or @set /p reply="Continue?" executes and waits for input while producing no finding when the source contains no explicit yes/no marker; recognize @ before these commands.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in f9ef29b: @ suppresses the echo of a command without stopping it running, so it is allowed before set /p and choice.
| def _blank_strings(line: str) -> str: | ||
| """Blank quoted text so a message naming an input API is not one. A `$(...)` | ||
| subexpression is kept: it executes, and PowerShell really does prompt from | ||
| inside an expandable string.""" | ||
| return _QUOTED.sub(lambda m: m.group(0) if "$(" in m.group(0) else '""', line) |
There was a problem hiding this comment.
Preserve executable Python f-string expressions
For Python helpers, blanking every quoted region also removes executable f-string expressions. For example, print(f"Answer: {input('Enable telemetry?')}") blocks for input but _blank_strings erases the input() call before _PY_READ runs, and without a literal yes/no marker the guard reports nothing; Python f-string expressions need to be retained or parsed separately.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, fixed in f9ef29b, and it is the same mistake as the PowerShell subexpression: an f-string field executes, so blanking the string blanks the call. Both are kept now, and a string quoted inside one is offered as the question so the site keys on the real wording.
| ) | ||
|
|
||
| # The Python helpers setup runs, and the batch launcher. | ||
| _PY_READ = re.compile(r"(?<![.\w])input\s*\(|getpass\.getpass\s*\(|confirm\s*\(") |
There was a problem hiding this comment.
Detect reads from Python standard input
When a scanned Python installer prints an unmarked question and reads the answer with sys.stdin.readline() or sys.stdin.read(1), _PY_READ recognizes none of those standard blocking APIs. The installer can therefore stall waiting for a yes/no response while find_prompts() returns no prompt; include terminal reads through sys.stdin alongside input() and getpass().
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in f9ef29b: sys.stdin.read and sys.stdin.readline block like input(), so they are matched.
| ) | ||
|
|
||
| # The Python helpers setup runs, and the batch launcher. | ||
| _PY_READ = re.compile(r"(?<![.\w])input\s*\(|getpass\.getpass\s*\(|confirm\s*\(") |
There was a problem hiding this comment.
Exclude Python confirm definitions from read detection
Because the confirm\s*\( alternative is unanchored, non-executing declarations such as def confirm(value): are classified as interactive reads and produce an <unlabelled read: ...> failure. A Python installer adding an ordinary helper or callback with that name will therefore fail CI despite never reading user input; restrict this alternative to actual calls to known confirmation APIs.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, my own bug, fixed in f9ef29b. The confirm alternative was unanchored, so an ordinary def confirm(value): read as an unlabelled interactive read and failed CI. Only real confirmation APIs count now.
| # `||` is a fallback, not a pipeline: `read -r reply || reply=n` still blocks. | ||
| piped = "|" in code.replace("||", "") | ||
| return "<" not in code and not piped and bool(_BARE_READ.search(code)) |
There was a problem hiding this comment.
Ignore reads inside file-redirected loop bodies
For a multiline file loop such as while true; do followed by read -r line and then done < "$manifest", the read line itself contains neither < nor |, so this local check reports it as an interactive read even though its stdin is the manifest. This makes a normal non-interactive installer loop fail CI; the detector needs to account for enclosing loop redirections rather than inspecting only the physical read line.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, fixed in f9ef29b. The check only ever saw the read line, so a body whose redirection sits on the done three lines below looked interactive. Loop bodies closed by a redirected done are excluded now. Latent rather than live, since nothing in the tree writes that shape today, but it would have failed CI on an ordinary installer loop.
Seven from review, one declined. Three were mine. `confirm\s*\(` was unanchored, so an ordinary `def confirm(value):` failed CI as an unlabelled read; only real confirmation APIs count now. `_blank_strings` erased f-string fields along with inert text, though a field executes exactly like the PowerShell subexpression fixed last round, so both are kept and a string quoted inside one is offered as the question. And a `read` in a loop body whose redirection sits on the `done` three lines below looked interactive, since the check only ever saw the read line; block bodies with a redirected `done` are excluded now. Python sources are traversed again. They were skipped because following them walked into unsloth/models/_utils.py, but that reference is in a comment and the ones like it are in docstrings, so blanking those fixed the cause. install_python_stack:4157 runs patch_metadata.py with sys.executable, and that path is built from a variable, so it is listed rather than discovered. studio/install_*.py is globbed, which covers install_sd_cpp_prebuilt.py and install_manifest.py. Also: a read can be the condition of an `if`, sys.stdin.read and readline block like input(), and `@` in batch suppresses the echo of a command without stopping it running. Declining repo-wide resolution of a helper by basename: it picks up sitecustomize.py and build artifacts. The scan of the tree is unchanged.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f9ef29bf3a
ℹ️ 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 not opened: | ||
| continue | ||
| start = opened.pop() | ||
| if "<" in line or "|" in line: |
There was a problem hiding this comment.
Keep loop reads interactive when piping loop output
When a loop's output is piped, such as while ...; do printf "Enable telemetry? "; read -r reply; done | tee install.log, the pipe consumes the loop's stdout but does not supply its stdin, so the read still blocks on inherited input. This condition nevertheless marks the whole loop body as redirected whenever the done line contains |, causing the guard to skip the prompt. Fresh evidence beyond the earlier file-redirection report is that the new exclusion treats an output pipeline as though it fed the loop's reads.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, my own bug from last round, fixed in 24d1c7d. A pipe on the done consumes the loop's output and supplies nothing to its stdin, so only an input redirection excludes a body now.
| opener = min((i for i in (line.find('"""'), line.find("'''")) if i != -1), default = -1) | ||
| if opener == -1: | ||
| return line, "" | ||
| head, delimiter = line[:opener], line[opener : opener + 3] | ||
| rest, delimiter = _outside_docstring(line[opener + 3 :], delimiter) |
There was a problem hiding this comment.
Preserve executable triple-quoted f-string fields
When a Python installer uses a triple-quoted f-string such as print(f"""Answer: {input('Enable telemetry? ')}"""), _outside_docstring removes the entire string before input detection even though the field executes and blocks. Fresh evidence beyond the ordinary f-string fix is that every triple-quoted region is now treated as a docstring regardless of its prefix or expression context, allowing this prompt to pass the guard.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, fixed in 24d1c7d: an f prefix on a triple-quoted string means its fields execute, so the line is code and is kept rather than blanked as a docstring.
| r"read(?:\s+(?:-[a-zA-Z0-9]+|\d+))*(?:\s+[A-Za-z_][A-Za-z0-9_]*)*" | ||
| r"(?:\s*;?\s*then\b.*|\s*(?:\|\||&&).*)?\s*$" |
There was a problem hiding this comment.
Detect bare reads followed by another shell command
When an unmarked question is followed by read -r reply; echo done, the read still blocks on inherited stdin, but _BARE_READ only permits then, ||, or && after the variable list and otherwise anchors at end of line; _POSIX_READ also does not apply without -p or /dev/tty. Fresh evidence beyond the conditional-read fix is the ordinary semicolon-separated command form, which still lets a new prompt pass undetected.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 24d1c7d: a semicolon-separated command may follow the read. Safe to allow now that heredoc bodies are blanked, which was the shape that made me anchor at end of line in the first place.
| def find_prompts(script: str, source: str) -> list[tuple[str, int, str]]: | ||
| """Return (script, line_number, normalised question) for every prompt site.""" | ||
| lines = blank_comments(source, script).splitlines() | ||
| redirected = _redirected_loop_bodies(lines) |
There was a problem hiding this comment.
Ignore shell commands documented inside heredocs
When an installer help heredoc contains an example line such as read -r reply, blank_comments leaves the heredoc body in the executable line stream and _BARE_READ reports it as an unlabelled interactive read. A documentation-only edit therefore fails CI even though the command cannot execute, so heredoc regions need to be excluded while preserving their line numbers.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 24d1c7d, and it is what made the rest of this round safe: heredoc bodies are blanked, keeping the line count, so allowing a bare read to be followed by another command no longer flags the read -r reply in the uninstaller's own help text. Writing that turned up a worse bug in my first attempt. The opener matched the <<< here-string inside install.sh's printed profile marker, so everything after line 3424 was blanked and the sanctioned Start Unsloth Studio prompt vanished from the scan. test_approved_prompts_all_still_exist caught it. <<< is excluded now and openers are read from code rather than from inside strings.
| _PY_READ = re.compile( | ||
| r"(?<![.\w])input\s*\(|getpass\.getpass\s*\(|click\.confirm\s*\(|sys\.stdin\.read(?:line)?\s*\(" | ||
| ) |
There was a problem hiding this comment.
Detect directly imported getpass calls
When a Python installer uses the common from getpass import getpass form and then calls getpass() after printing an unmarked question, this pattern does not match because it accepts only getpass.getpass(). Fresh evidence beyond the added sys.stdin coverage is that another explicitly supported blocking API remains uncovered under its normal direct-import spelling, allowing the prompt through.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 24d1c7d: the direct-import spelling is matched alongside getpass.getpass.
| _PY_READ = re.compile( | ||
| r"(?<![.\w])input\s*\(|getpass\.getpass\s*\(|click\.confirm\s*\(|sys\.stdin\.read(?:line)?\s*\(" | ||
| ) | ||
| _BAT_READ = re.compile(r"(?:^|[&(]|\bdo\b)\s*@?\s*(?:set\s+/p\b|choice\b)", re.IGNORECASE) |
There was a problem hiding this comment.
Recognize batch prompts used as conditional commands
When a batch installer uses a valid single-line conditional such as if exist config choice /M "Enable telemetry?", choice executes and waits for input but _BAT_READ accepts only the start of a line, (, &, or do before the command. Fresh evidence beyond the command-position and @ fixes is that batch if command position is still omitted, so an unmarked conditional prompt passes the guard.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 24d1c7d: a single-line if body counts as command position. I kept it anchored on the line starting with if rather than allowing the command anywhere after one, so echoing the word choice in a message is still not a prompt.
Six from review, two of them mine. `done | tee install.log` pipes the loop's output, not its input, so its reads still take the terminal. Only an input redirection excludes a loop body now. A triple-quoted f-string was blanked as a docstring even though its fields execute, so an f prefix keeps the line. Heredoc bodies are blanked, keeping the line count. That is what makes the rest safe: a bare read may now be followed by another command, which without this would have flagged the read -r reply in the uninstaller's help text. Writing that turned up a worse bug in my own first attempt at it. The heredoc opener matched the `<<<` here-string inside install.sh's printed profile marker, so everything after line 3424 was blanked and the sanctioned Start Unsloth Studio prompt disappeared from the scan. The allowlist-still-exists check caught it. `<<<` is excluded and openers are read from code rather than from inside strings. Also: getpass imported directly, and batch prompts as the body of a single-line if. The scan of the tree is unchanged, and replaying it over the last 25 revisions of the five main scripts finds no false positive and never loses a known prompt.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 24d1c7d166
ℹ️ 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".
| match = _HEREDOC.search(_blank_strings(line)) | ||
| if match: | ||
| terminator = match.group(1) |
There was a problem hiding this comment.
Parse inline comments before opening heredocs
When an ordinary shell line has an inline comment mentioning heredoc syntax, such as : # example uses <<EOF, this search treats the comment as a real opener and blanks every subsequent line until a matching terminator—or the rest of the file if none exists. Any real interactive prompt later in the installer is then invisible to the guard, so heredoc detection must ignore shell comment text before updating terminator.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, fixed in 490ffd8, and I gave it a structural backstop rather than another patch. Openers are read from code with inline comments removed, and an opener whose terminator never arrives now blanks nothing at all. Blanking to end of file is the failure mode that silently blinds the scan for everything after it, which is what the <<< here-string did last round, so it should not be reachable from any opener.
| r"read(?:\s+(?:-[a-zA-Z0-9]+|\d+))*(?:\s+[A-Za-z_][A-Za-z0-9_]*)*" | ||
| r"(?:\s*(?:;|\|\||&&).*)?\s*$" |
There was a problem hiding this comment.
Accept non-integer arguments to shell read options
Fresh evidence beyond the integer option-argument fix is that valid blocking forms such as read -r -t 0.5 reply, read -r -t "$TIMEOUT" reply, and read -r -d 'x' reply still do not match: the option-argument grammar accepts only digits or identifier-like variable names, while quoted arguments are blanked to "". With an unmarked question printed beforehand, find_prompts() returns nothing and the new prompt passes the guard.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 490ffd8: option arguments may be fractional or quoted, so read -r -t 0.5 reply and read -r -t "$TIMEOUT" reply both count.
| # Only an input redirection feeds them: `done | tee` pipes the output. | ||
| if "<" in line: | ||
| inside.update(range(start, index)) |
There was a problem hiding this comment.
Distinguish auxiliary file descriptors from stdin redirection
Fresh evidence beyond the output-pipeline fix is a loop ending with done 3<config: this opens descriptor 3 but leaves stdin unchanged, so an ordinary read -r reply in the body still blocks on inherited input. Checking only for any < marks the entire body redirected and suppresses that prompt; the exclusion should apply only when the loop actually redirects fd 0, while still handling reads explicitly consuming another descriptor.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 490ffd8: a loop body is excluded only when the done redirects stdin. done 3<config opens a spare descriptor and leaves the reads on the terminal.
| found.setdefault((script, question), (script, line_number, question)) | ||
|
|
||
| if index not in redirected and _is_interactive_read(line, script): | ||
| for question in _questions_for_read(lines, index): | ||
| found.setdefault((script, question), (script, line_number, question)) |
There was a problem hiding this comment.
Preserve separate occurrences of approved prompts
When a second Start Unsloth Studio now? [Y/n] prompt is added to install.sh, both sites collapse into one dictionary entry keyed only by (script, question), and the surviving entry is already allowlisted. The new blocking prompt therefore passes CI without any allowlist diff; keep prompt occurrences distinct, or separately assert the approved occurrence count, so approval of one site cannot authorize duplicates elsewhere in the same installer.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Same item as the one declined in the first round, and the answer has not changed. The regression class is new wording; a byte-identical second copy of an approved question is not a shape a contributor produces, and pinning occurrence counts churns the allowlist whenever a prompt is hoisted into a helper or moved into a branch.
| - 'studio/setup*.bat' | ||
| - 'studio/install_*.py' |
There was a problem hiding this comment.
Glob newly named Studio shell setup entry points
Fresh evidence beyond the root-installer path fix is that a new studio/setup_linux.sh or studio/setup_windows.ps1 is discovered by test_every_installer_script_is_scanned, but this workflow globs only Studio batch launchers and later enumerates the two existing shell filenames. A PR adding either new setup entry point therefore does not run the test designed to reject it; add matching studio/setup*.sh and studio/setup*.ps1 path filters for both pull requests and pushes.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 490ffd8, same delivery hole as the root installers two rounds back: studio/setup*.sh and studio/setup*.ps1 are globbed in both filters, so a PR adding studio/setup_linux.sh runs the check that rejects it.
| "studio/setup*.bat", | ||
| "install*.bat", | ||
| "studio/install_*.py", |
There was a problem hiding this comment.
Discover root Python installers
After adding Python prompt scanning, a new root entry point such as install.py remains absent from both this on-disk discovery list and the workflow path filters. A PR can therefore add that installer with an input() confirmation without running the guard or being rejected as unregistered; include root install*.py alongside the existing shell, PowerShell, and batch installer patterns.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 490ffd8: install*.py joins the discovery globs and the workflow paths.
| if script.endswith(".bat"): | ||
| return bool(_BAT_READ.search(code)) |
There was a problem hiding this comment.
Exclude file-redirected batch reads
When a batch installer reads a file with the normal form set /p version=<VERSION.txt, _BAT_READ classifies it as an interactive prompt even though stdin comes from the file. This makes a non-interactive configuration read fail CI as an unlabelled prompt; apply the redirected-input exclusion to batch commands as well as shell reads.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 490ffd8: a batch line with an input redirection is reading a file, so set /p version=<VERSION.txt is not a prompt.
| def _blank_strings(line: str) -> str: | ||
| """Blank quoted text so a message naming an input API is not one. A `$(...)` | ||
| subexpression or an f-string field is kept: those execute, and both PowerShell | ||
| and Python really do prompt from inside a string.""" | ||
| return _QUOTED.sub(lambda m: m.group(0) if _EXECUTES.search(m.group(0)) else '""', line) |
There was a problem hiding this comment.
Preserve expressions only in expandable strings
When a harmless diagnostic contains code-like text in a non-executable string, such as PowerShell's single-quoted 'Example: $(Read-Host "Enable telemetry?")' or Python's ordinary "Example: {input('Enable telemetry?')}", _EXECUTES causes the entire string to survive blanking even though neither expression runs. The subsequent API scan reports a prompt and fails CI, so expression retention must verify the language-specific expandable-string prefix or quote type rather than relying only on the string contents.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, my own bug, fixed in 490ffd8. Keeping a string because it contained
| text = _SUBSTITUTION.sub("<var>", text) | ||
| text = re.sub(r"\s+", " ", text).strip() | ||
| # A trailing one is the `[Y/n]` hint the marker pass already read. | ||
| text = _TRAILING_SUBSTITUTION.sub("", text) |
There was a problem hiding this comment.
Retain trailing substitutions in allowlist keys
When an approved prompt is changed to Start Unsloth Studio now? $UNSLOTH_EXTRA_PROMPT [Y/n], the trailing variable is removed from the normalized key, so the result still matches the existing approval even though the variable can append another runtime question such as telemetry consent. The middle-interpolation protection does not cover this suffix case; only the actual marker argument should be omitted, rather than deleting every trailing substitution.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Declining. The trailing-substitution rule exists because a substitution at the end of a prompt string is the marker hint, which is how the #7016 shape keys cleanly. The suggested alternative, omitting only the actual marker argument, needs the guard to know which substitution is the marker, and that is not decidable from the text. Middle interpolation is already covered, and appending a variable that smuggles a second question is deliberate evasion rather than the accident this guard is for. Both would also be visible in the installer diff.
| for candidate in ( | ||
| path.parent / reference, | ||
| REPO_ROOT / reference, | ||
| path.parent / name, | ||
| REPO_ROOT / "scripts" / name, |
There was a problem hiding this comment.
Resolve helper directories assembled in variables
When an installer uses the common shape $HELPER_DIR="$SCRIPT_DIR/helpers" followed by "$HELPER_DIR/setup_extra.sh", the regex captures only setup_extra.sh and these candidates check the caller directory, repository root, and scripts/, never the real helpers/ directory. The coverage test therefore passes while a prompt in that invoked helper remains unscanned; helper discovery must resolve path variables or otherwise derive the invoked checked-in path instead of relying on the literal basename.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Declining. Resolving $HELPER_DIR means evaluating the script rather than reading it, which is a different tool. I already tested the cheaper approximation, resolving a helper by basename anywhere in the repo, and it pulls in sitecustomize.py and build artifacts, so it trades a hypothetical miss for real false positives. What is in place is: literal paths, sibling names, subdirectories in either slash, and traversal out of every scanned script. A helpers/ directory does not exist today, and adding one is a visible change to an installer that a reviewer sees.
Nine from review, three declined. The heredoc handling gets a structural backstop rather than another patch: an opener is read from code with inline comments removed, and an opener whose terminator never arrives now blanks nothing at all. Blanking to end of file is the failure mode that silently blinds the scan for everything after it, which is what the <<< here-string did last round, so it should not be reachable by any opener at all. Three were mine. Keeping a string because it contained $( or a brace field ignored the quote type, so a PowerShell single-quoted diagnostic or a plain Python string with code-shaped text survived blanking and read as a prompt; expansion is judged per language now. The pipeline test looked at the whole line, so the pipe in read -r reply; echo done | tee log was attributed to the read, and the bare-read path runs per command. A loop is only excluded when its done redirects stdin, not when it opens a spare descriptor such as done 3<config. The rest: set /p version=<VERSION.txt reads a file, sys.stdin.buffer reads block like sys.stdin, read option arguments may be fractional or quoted, and install*.py plus studio/setup*.sh and .ps1 join the globs and the workflow paths. Declined: occurrence counts for duplicate approved wording and dropping the trailing-substitution rule, both of which trade a shape nobody writes for allowlist churn on ordinary edits, and resolving helper paths assembled in variables, which needs the text evaluated rather than read. Replaying the scan over the last 25 revisions of ten scanned files, 250 file revisions in all, finds no false positive and never loses a known prompt.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 490ffd8369
ℹ️ 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 python: | ||
| line, in_docstring = _outside_docstring(line, in_docstring) |
There was a problem hiding this comment.
Strip Python comments before tracking triple quotes
When a scanned Python helper contains a whole-line comment such as # opening delimiter is """, _outside_docstring runs before _is_comment, treats the commented delimiter as the start of a multiline string, and blanks all subsequent executable lines until another delimiter appears. A later blocking input() or sys.stdin prompt is therefore invisible to the guard; remove Python comments before updating the triple-quote state.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, fixed in deb2889, together with the PowerShell twin below. Comments are removed before either delimiter is interpreted, and both now get the backstop the heredoc opener already has: an unterminated docstring or block comment puts its lines back instead of blanking to end of file. This is the third language where reading a delimiter out of text blinded the scan the same way, so the backstop matters more than the individual fix.
| if powershell: | ||
| line = _INLINE_BLOCK.sub("", line) | ||
| if "<#" in line: | ||
| lines.append(line.split("<#", 1)[0]) | ||
| in_block = True |
There was a problem hiding this comment.
Ignore PowerShell block markers inside line comments
When a PowerShell helper contains a line comment such as # block comments begin with <#, this branch sees <# before the later whole-line-comment check, enters in_block, and blanks every following line until a #> appears. Consequently a real Read-Host prompt later in the installer can pass undetected; discard line comments before interpreting PowerShell block-comment delimiters.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Same fix as above, in deb2889: a line comment naming <# no longer opens a block, and an unterminated block restores its lines.
| - 'scripts/build_whisper_cpp.sh' | ||
| - 'studio/setup*.bat' | ||
| - 'studio/install_*.py' | ||
| - 'studio/backend/requirements/single-env/patch_metadata.py' |
There was a problem hiding this comment.
Cover every registered helper in workflow paths
In cross-platform-parity-ci.yml, the only workflow that invokes this guard, helper paths are enumerated manually. If a newly invoked helper such as tools/setup_extra.py is added to SCANNED_SCRIPTS, the registration PR runs through the changed caller/test, but a later PR modifying only that helper does not match these filters, so a new prompt in it is never checked. Validate the workflow filters against SCANNED_SCRIPTS or use globs that cover every registered helper.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Good catch, and I took the stronger half of the suggestion in deb2889: the workflow filters are read back and matched against SCANNED_SCRIPTS, so the two lists cannot drift instead of being kept in step by hand. Confirmed load-bearing by dropping the build_whisper_cpp.sh filter and watching it fail. Parsed with a regex rather than yaml because the parity runner installs pytest alone.
| "install*.sh", | ||
| "install*.ps1", |
There was a problem hiding this comment.
Discover root uninstall entry points
When a root uninstaller such as uninstall.sh or uninstall.ps1 is added, these patterns discover only root install* files and uninstallers under scripts/; the workflow filters have the same omission. Such a user-facing removal script can therefore contain a blocking prompt without being registered or causing this guard to run, despite the test's stated coverage of uninstall scripts. Add root uninstall patterns to both discovery and workflow paths.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in deb2889: root uninstall*.sh and uninstall*.ps1 join both the discovery globs and the workflow paths.
| def _looks_like_question(text: str) -> bool: | ||
| """Prose with a question mark, not a `sed`/`-match` pattern that has one.""" | ||
| return "?" in text and not _REGEXY.search(text) |
There was a problem hiding this comment.
Treat marker-backed labels without question marks as prompts
When a shared marker and read serve branches such as printf "Enable telemetry $_hint" and the approved printf "Start Unsloth Studio now? $_hint", this predicate ignores the first label solely because it lacks ?. Both the marker pass and read pass then associate the site only with the approved Studio question, so the new telemetry prompt passes the allowlist unchanged even though Enable telemetry [Y/n] is an ordinary blocking yes/no prompt. Include marker-backed prompt labels without question-mark punctuation when collecting branch candidates.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Declining. A literal label such as Enable telemetry [Y/n] is already caught, by the marker pass rather than the read pass: the string carries the marker, so it keys as enable telemetry and fails the allowlist. What is left is the case in the example, where the marker lives in a variable and the label has neither a marker nor a question mark. Admitting those means treating any nearby message as a candidate key, so an ordinary echo beside a read would start demanding allowlist entries. That trades a two-branch shape nobody writes for churn on ordinary edits.
| r"read(?:\s+(?:-[a-zA-Z0-9]+|[\d.]+|\"\"|''))*(?:\s+[A-Za-z_][A-Za-z0-9_]*)*" | ||
| r"(?:\s*(?:;|\|\||&&).*)?\s*$" |
There was a problem hiding this comment.
Accept trailing comments on bare shell reads
When an unmarked question is followed by a normal read carrying an inline explanation, such as read -r reply # use inherited terminal, _BARE_READ rejects the line because it anchors after the variable list and permits only command separators, while _POSIX_READ does not apply without -p or /dev/tty. The read still blocks on inherited stdin, but find_prompts() returns nothing; strip shell inline comments quote-aware or allow a trailing comment in this pattern.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in deb2889: a bare read may carry a trailing comment. Safe because strings are blanked first, so a surviving # is a comment rather than part of a message.
Five from review, one declined. A comment naming a delimiter was read as one, in Python and in PowerShell, which blanks the rest of the file and takes every prompt in it out of the scan. Comments are removed before either delimiter is interpreted, and both get the backstop the heredoc opener already has: an unterminated docstring or block comment puts its lines back rather than blanking to end of file. This is the third language where reading a delimiter out of text went the same way, so the backstop matters more than the individual fix. The workflow filters are now read back and matched against SCANNED_SCRIPTS, instead of two lists kept in step by hand. Without it a registered helper is only ever checked on the PR that registers it, and a later PR touching only that helper runs nothing. Parsed with a regex since the parity runner installs pytest alone. Root uninstall*.sh and uninstall*.ps1 join the globs, and a bare read may carry a trailing comment. Declining prompt labels with no question mark. A literal `Enable telemetry [Y/n]` is already caught by the marker pass; what is left is a label whose marker lives in a variable, and admitting those means treating every nearby message as a candidate key, which churns the allowlist on ordinary edits. Replaying the scan over the last 25 revisions of all 18 scanned scripts, 450 file revisions, finds no false positive and loses no known prompt.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: deb2889c3c
ℹ️ 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".
| r"read(?:\s+(?:-[a-zA-Z0-9]+|[\d.]+|\"\"|''))*(?:\s+[A-Za-z_][A-Za-z0-9_]*)*" | ||
| r"(?:\s*(?:;|\|\||&&).*)?\s*(?:#.*)?$" |
There was a problem hiding this comment.
Join continued shell reads before matching
When an unmarked question is followed by a line-continued command such as read -r \ and reply on the next line, the shell still executes a blocking read from inherited stdin, but _BARE_READ examines each physical line independently and rejects the backslash. Because _POSIX_READ also does not apply without -p or /dev/tty, find_prompts() returns no finding and allows the new prompt through.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Declining, same as when this was raised in the first round. A backslash-continued read appears nowhere in the tree, the house style being the single-line read -r REPLY </dev/tty, and a continued read that also carries no marker within eight lines is not a shape anyone writes. The cost is not the regex, it is that joining continuations changes what every other pattern sees.
|
|
||
| # The Python helpers setup runs, and the batch launcher. | ||
| _PY_READ = re.compile( | ||
| r"(?<![.\w])(?:input|getpass)\s*\(|getpass\.getpass\s*\(" |
There was a problem hiding this comment.
Recognize explicitly qualified built-in input calls
When a Python installer prints an unmarked question and reads with the standard spelling builtins.input(), the negative lookbehind before input rejects the call because it is preceded by a dot. The marker pass has nothing to detect, so this blocking prompt passes the guard; include builtins.input() alongside direct input().
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Declining. Nobody spells it builtins.input() in an installer, and the lookbehind that excludes it is what keeps ordinary attribute calls such as parser.input() out. This guard is a review aid against a prompt landing unnoticed, not a barrier against someone spelling one unusually on purpose, and either spelling is visible in the installer diff.
|
|
||
| # `select reply in Yes No` is the other builtin that blocks for an answer; its | ||
| # question is the PS3 assignment above it, which the nearby scan already reads. | ||
| _SELECT = re.compile(r"(?:^|[;&(])\s*select\s+[A-Za-z_][A-Za-z0-9_]*\s+in\s") |
There was a problem hiding this comment.
Recognize select after shell conditional keywords
In scanned Bash scripts, a valid single-line conditional such as if enabled; then select reply in Yes No; do break; done; fi still displays PS3 and blocks for input, but _SELECT permits only the start of a command or [;&(] before select. With an unmarked PS3="Continue with installation? ", neither detection pass reports a prompt, so allow command positions following then and else as the bare-read matcher already does.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Declining. select at the start of a line or after a separator is already matched, which is where it is written in practice, including inside an if block. What is missing is only if enabled; then select reply in Yes No; do break; done; fi packed onto one line, and that is not a shape anyone writes in these scripts.
| r"(?:^\s*|[&(]\s*|\bdo\s+)@?\s*(?:set\s+/p\b|choice\b)" | ||
| r"|^\s*@?\s*(?:if|else)\b.*?\s(?:set\s+/p\b|choice\b)", |
There was a problem hiding this comment.
When a batch installer prints an unmarked question and executes pause, the command waits for a keypress and stalls an unattended setup, but _BAT_READ recognizes only set /p and choice. Since the question has no yes/no marker and pause is not classified as an interactive read, find_prompts() returns no finding and the new blocking prompt passes the guard.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Taken, fixed in 14e4f07. pause asks nothing, so it is not a yes/no prompt, but an unattended install stops dead on it just as it would on set /p, and it is a batch builtin rather than an external program, which is the line I drew earlier in this review when declining whiptail and dialog.
It asks nothing, but an unattended install stops dead on it just as it would on set /p, and pause is a batch builtin rather than an external program, which is where I drew the line earlier in this review.
|
Note on scope, after 13 review rounds and 63 items. Where this has got to: the guard scans 18 install, setup, uninstall and helper scripts across shell, PowerShell, batch and Python, and it is now checked in three ways that do not depend on me keeping lists in step by hand.
The most useful thing this review found was not any single missing shape. It was that reading a delimiter out of text (a Two things I am holding the line on, having declined them more than once:
For the same reason I am treating further "recognize this spelling too" items as out of scope unless they come with a shape that exists in the tree, or they fix a false positive. The remaining gaps are deliberate spellings someone would have to choose, and any of them is visible in the installer diff, which is where a reviewer sees it. What is not visible in a diff, and what this exists for, is a plain new question landing in a 200 line installer change. Evidence it stays quiet: replaying the scan over the last 25 revisions of all 18 scanned scripts, 450 file revisions, produces no unapproved finding and never loses one of the four known prompts. Reverted #7016 still fails on both |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 14e4f0748b
ℹ️ 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".
| # Options then variable names to end of line, in command position, so the word | ||
| # `read` in a heredoc of prose is not a prompt. | ||
| _BARE_READ = re.compile( | ||
| r"(?:^|[;&(]|\b(?:if|elif|then|else)\b)\s*(?:[A-Za-z_][A-Za-z0-9_]*=\S*\s+)*" |
There was a problem hiding this comment.
When a shell installer prints an unmarked question and uses the common EOF-safe form if ! read -r reply; then reply=n; fi, the read still blocks on inherited stdin, but this command-position prefix requires read to follow if immediately and does not permit !. _POSIX_READ also does not match without -p or /dev/tty, so the new prompt passes the guard entirely; allow shell negation before a bare read.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 14e70b5. if ! cmd is house style in these scripts, five instances across the shell installers, so a negated read is a natural way to write it.
| "uninstall*.sh", | ||
| "uninstall*.ps1", |
There was a problem hiding this comment.
Discover Python and batch uninstall entry points
Fresh evidence beyond the earlier root-uninstaller fix is that a new root uninstall.py or uninstall.bat is still omitted here, even though the guard supports both Python and batch installers and discovers the corresponding install*.py/install*.bat files. Neither extension is present in the workflow filters either, so such a user-facing removal script can contain a blocking prompt without being rejected or triggering this job; add both uninstall extensions to discovery and both workflow events.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 14e70b5: root uninstall*.bat and uninstall*.py join the globs and both workflow filters, which follows from scanning those two languages at all.
| workflow = (REPO_ROOT / ".github/workflows/cross-platform-parity-ci.yml").read_text( | ||
| encoding = "utf-8" | ||
| ) | ||
| patterns = re.findall(r"^\s*-\s*'([^']+)'\s*$", workflow, flags = re.MULTILINE) |
There was a problem hiding this comment.
Validate each workflow event's path filters separately
Fresh evidence beyond the earlier workflow-coverage fix is that this regex collects quoted entries from the entire YAML, merging pull_request.paths and push.paths. If a scanned helper is later present only in the push filter, this test passes even though a PR modifying only that helper will not run the guard; parse or delimit the two path blocks and require every scanned script to match each event independently.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, and it is a hole in the check I added last round, fixed in 14e70b5. It collected quoted entries from the whole file, so a script present only in the push filter would have passed while pull requests ran nothing. Each event's block is read separately and has to cover the scanned set on its own.
| if not script.endswith((".ps1", ".py", ".bat")): | ||
| lines = _blank_heredocs(lines) |
There was a problem hiding this comment.
Scan executable interpreter heredocs
Fresh evidence beyond the documentation-heredoc fix is an executable body such as python - <<'PY' followed by print('Enable telemetry? '); input(): it really runs and blocks, but an unquoted delimiter causes this branch to blank the body, while a quoted delimiter leaves the body classified as shell so _PY_READ is never applied. With no literal yes/no marker, find_prompts() returns nothing; preserve and scan heredocs passed to Python or another executable interpreter rather than treating every shell heredoc as documentation.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Taking the important half of this, in 14e70b5. An interpreter heredoc runs its body, so blanking it hides real code, which is worse than not having looked: heredoc bodies are only blanked when the opener is not python, node, perl, ruby or osascript. I did not go on to scan the body as Python. Reading it as shell still leaves the marker pass on it, and full multi-language embedding is a different tool. Nothing in the tree uses an interpreter heredoc today.
| for script in SCANNED_SCRIPTS: | ||
| path = REPO_ROOT / script | ||
| source = blank_comments(path.read_text(encoding = "utf-8"), script) | ||
| for match in _HELPER_REF.finditer(source): |
There was a problem hiding this comment.
The helper traversal recognizes only literal filenames with extensions, but scanned installers already load local modules through ordinary imports—for example, studio/install_whisper_prebuilt.py:72 imports prebuilt_core, and studio/install_python_stack.py:35-43 imports backend utility modules. Those modules are absent from SCANNED_SCRIPTS, so adding an input() prompt to an imported function is invisible to this guard and changing that module alone does not trigger this workflow; resolve local Python imports transitively or register and path-filter the imported modules.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Declining, as when this came up before. install_whisper_prebuilt importing prebuilt_core is library composition, not an invocation, and following imports has no natural stop: the first attempt at it reached unsloth/models/_utils.py, which is core library code rather than an installer. The boundary stays at what a script runs. A prompt inside an imported function is also a prompt in ordinary library code, which is a different problem from a question added to setup.
Four from review, one declined. The workflow-filter check I added last round collected quoted entries from the whole file, so a script present only in the push filter would have passed it while pull requests ran nothing. Each event's block is read and required to cover the scanned set on its own. An interpreter heredoc such as `python - <<PY` runs its body, so blanking it hides real code, which is worse than reading it as shell: the marker pass still sees the body this way. Documentation heredocs are blanked as before. Also: `if ! read -r reply` counts, `if ! cmd` being house style in these scripts already, and root uninstall*.bat and uninstall*.py join the globs and the workflow paths now that both languages are scanned. Declining local Python imports. install_whisper_prebuilt importing prebuilt_core is library composition, not an invocation, and following imports has no natural stop: it reached unsloth/models/_utils.py the first time, which is core library code and not an installer. The line stays where it was, at what a script runs.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 14e70b5c06
ℹ️ 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 index not in redirected and _is_interactive_read(line, script): | ||
| for question in _questions_for_read(lines, index): | ||
| found.setdefault((script, question), (script, line_number, question)) |
There was a problem hiding this comment.
Scan executable heredocs using the interpreter language
Fresh evidence after the heredoc fix is that retained bodies are still passed to _is_interactive_read with the outer shell filename. For python - <<'PY' containing print('Enable telemetry? '); input(), script remains install.sh, so _PY_READ is never selected and find_prompts() returns nothing unless the body also has a literal yes/no marker. Track the heredoc interpreter and scan its body using that language's read detector.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Declining, as last round. Not blanking an interpreter heredoc was the part that mattered, since that is what would hide real code; the body is read as shell, so the marker pass still sees it. Selecting a read detector per embedded language is a different tool, and no interpreter heredoc exists in these scripts today.
| if index not in redirected and _is_interactive_read(line, script): | ||
| for question in _questions_for_read(lines, index): | ||
| found.setdefault((script, question), (script, line_number, question)) |
There was a problem hiding this comment.
Keep explicit terminal reads inside redirected loops
When a file-fed loop contains an explicit terminal prompt, such as while ...; do printf "Enable telemetry? "; read -r reply </dev/tty; done < manifest, the read overrides the loop's inherited stdin and still blocks on the user. However, every line in the loop is placed in redirected, and this condition skips even /dev/tty or read -p sites, allowing the new prompt through. Suppress only reads that actually consume the loop input.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, and it is a bug in my own loop exclusion, fixed in 6a41858. Suppressing the whole body also suppressed an explicit read -r reply </dev/tty, which overrides the loop's stdin and still waits on the user. Only the bare-read path is suppressed inside a fed loop now.
| if script.endswith(".bat"): | ||
| # `set /p version=<VERSION.txt` reads the file, not the user. | ||
| return "<" not in code and bool(_BAT_READ.search(code)) |
There was a problem hiding this comment.
Scope batch redirection checks to the input command
When a batch line contains an interactive command followed by an unrelated redirected command, such as choice /M "Enable telemetry?" & set /p version=<VERSION.txt, choice still blocks before the file read, but the presence of any < causes the whole line to be discarded. Since choice supplies its own answer choices at runtime, the source need not contain a literal marker, so both detection passes miss this prompt. Apply the redirection exclusion to the matched set /p or choice command rather than the entire physical line.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, also mine, fixed in 6a41858: the redirection belongs to its own command, as it already did on the shell side, so choice ... & set /p v=<VERSION.txt keeps its prompt.
| in_block = False | ||
| in_docstring = "" | ||
| powershell = script.endswith(".ps1") | ||
| batch = script.endswith(".bat") | ||
| python = script.endswith(".py") | ||
| opened = -1 | ||
| for index, line in enumerate(source.splitlines()): |
There was a problem hiding this comment.
Blank literal PowerShell here-strings before scanning
When documentation or generated text is stored in a single-quoted PowerShell here-string, for example $help = @' followed by Read-Host "Enable telemetry? [Y/n]" and '@, its contents are literal and cannot execute. blank_comments() processes each body line as ordinary PowerShell, however, so either the marker or Read-Host falsely fails CI. The scanned scripts already use this standard here-string syntax for help and embedded source, so track and blank non-executable here-string bodies while preserving line numbers.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct and live rather than theoretical, fixed in 6a41858. scripts/uninstall.ps1 prints its help from a literal here-string at lines 14 to 38, and install.ps1 embeds around 200 lines of launcher source in the expandable form. Literal @' ... '@ is blanked; expandable @" ... "@ is left alone, since it does run.
| "install*.sh", | ||
| "install*.ps1", | ||
| "studio/setup*.sh", | ||
| "studio/setup*.ps1", | ||
| "studio/setup*.bat", | ||
| "install*.bat", | ||
| "install*.py", |
There was a problem hiding this comment.
Discover root setup entry points
When a new root setup entry point such as setup.sh, setup.ps1, or setup.bat is added, these discovery patterns only recognize setup scripts under studio/, and the workflow filters have the same omission. Such a user-facing setup script can therefore introduce a blocking prompt without running this job or being rejected as unregistered. Include root setup patterns in both discovery and the pull-request and push path filters.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 6a41858: root setup*.sh, .ps1 and .bat join the globs and both workflow filters, following install and uninstall.
| # Each event on its own: a filter present only on push leaves pull requests bare. | ||
| for patterns in blocks: | ||
| matchers = [matcher(pattern) for pattern in patterns] | ||
| uncovered = sorted( | ||
| script for script in SCANNED_SCRIPTS if not any(m.match(script) for m in matchers) | ||
| ) |
There was a problem hiding this comment.
Honor negative workflow path patterns
When either event later uses an ordered exclusion such as 'scripts/**' followed by '!scripts/install*.sh', this check still treats every scanned installer as covered because it only asks whether any positive-looking matcher succeeds. GitHub evaluates ! path patterns in order, so the later negative pattern excludes those changes and the prompt guard will not run, despite this test passing (workflow syntax documentation). Model ordered negative patterns when validating each event.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 6a41858: patterns are applied in order and a ! exclusion flips the verdict, matching how GitHub evaluates them. No negative pattern exists in the file today, so this is the check being right about a filter someone adds later.
Five from review, one declined. Four are corrections to my own recent changes rather than new ground. Excluding a file-fed loop body suppressed every read in it, including an explicit `read -r reply </dev/tty` that overrides the loop's stdin and still waits on the user. Only the bare-read path is suppressed there now. The batch check discarded a whole line containing any `<`, so `choice ... & set /p v=<VERSION.txt` lost its prompt; the redirection belongs to its own command, as it already did for shell. The workflow filter check ignored `!` patterns, which GitHub applies in order, so an exclusion added later would have passed it unnoticed. PowerShell literal here-strings are blanked. `@' ... '@` cannot expand, and this is live rather than theoretical: scripts/uninstall.ps1 prints its help from one and install.ps1 embeds source in the expandable form. Expandable `@" ... "@` is left alone, since it does run. Root setup*.sh, .ps1 and .bat join the globs and both workflow filters. Declining scanning an interpreter heredoc body in the interpreter's own language, as last round. Not blanking it is the part that mattered, so real code is never hidden; a full multi-language embedded scan is a different tool.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9d1ec0e0b8
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| "scripts/install*.sh", | ||
| "scripts/install*.ps1", |
There was a problem hiding this comment.
Add scripts Python and batch installer globs
When a new installer helper is added under scripts/ in a language this guard already scans elsewhere, such as scripts/install_extra.py with input() or scripts/install_extra.bat with choice, these discovery patterns skip it, and the workflow paths list has no matching scripts/install*.py/scripts/install*.bat filter either. A PR adding only that file would therefore neither run the prompt guard nor fail test_every_installer_script_is_scanned; include the missing scripts/ Python and batch install patterns in both places.
Useful? React with 👍 / 👎.
| terminator = "" | ||
| continue | ||
| # Openers come from code: not from a string, not from an inline comment. | ||
| code = _blank_strings(line).split("#")[0] |
There was a problem hiding this comment.
Preserve quoted shell heredoc delimiters
Because this blanks quoted strings before looking for the heredoc opener, cat <<'EOF' becomes cat <<"" and _HEREDOC never records the body to blank. In a non-executable help block like the existing scripts/uninstall.sh style, an example containing printf "Enable telemetry? [Y/n]" followed by read -r reply is then scanned as live shell and fails CI even though the heredoc is just documentation; detect quoted delimiters before blanking, or preserve the delimiter token while stripping other strings.
Useful? React with 👍 / 👎.
| if script.endswith(".bat"): | ||
| # `set /p version=<VERSION.txt` reads the file, not the user, but the | ||
| # redirection belongs to that command alone. | ||
| return any("<" not in part and _BAT_READ.search(part) for part in code.split("&")) |
There was a problem hiding this comment.
Treat batch CON redirection as interactive
When a batch prompt explicitly redirects from the console device, for example choice /M "Enable telemetry?" <CON, this check discards the command only because the part contains <. Windows reserves CON for the console device and choice prompts for a key selection, so this is analogous to the shell </dev/tty case and still waits on the user; exempt CON/CONIN$ from the file-redirection skip so these prompts cannot pass unnoticed.
Useful? React with 👍 / 👎.
| return bool(_PWSH_READ.search(code)) | ||
| if script.endswith(".py"): | ||
| return bool(_PY_READ.search(code)) | ||
| if script.endswith(".bat"): |
There was a problem hiding this comment.
Recognize .cmd batch entry points
A Windows command-script entry point named install.cmd or studio/setup.cmd can contain the same blocking choice/set /p prompts as .bat, but this detector only enables the batch read patterns for paths ending in .bat, and the discovery/workflow globs also only list .bat. Such a PR can therefore add a user-facing .cmd installer with choice /M "Enable telemetry?" without being scanned or triggering this job; treat .cmd as batch wherever .bat is handled.
Useful? React with 👍 / 👎.
Summary
#7016 added an
Open Unsloth Studio in your default browser after launch? [Y/n]question to the interactive install, and I had to revert the whole PR in #8040 because of it. An extra question during setup stalls anyone piping the installer into a shell, and the answer is persisted somewhere they will never look for it again. Nothing in CI stopped it landing, so this adds a guard.The only preference setup is allowed to ask about is whether to start Unsloth Studio once the install finishes.
What it does
tests/test_installer_interactive_prompts.pyscansinstall.sh,install.ps1,studio/setup.sh,studio/setup.ps1,scripts/uninstall.shandscripts/uninstall.ps1with two independent text passes, so a prompt cannot slip through by dodging one of them:[Y/n]/[y/N]/(y/n)/yes/nomarkers in a string.readoff/dev/ttyor with-p, PowerShellRead-Host,PromptForChoice,ReadKey.The second pass is what catches #7016's actual shape. There the marker was not next to the question, it was assigned to
_browser_hinta line above theprintf, so a marker-only scan would have keyed off a bare[Y/n]and missed the prompt.Findings are keyed by normalised question text (
" Accept? [Y/n] "becomesaccept?) rather than by line number, so ordinary edits to the installers do not churn the baseline, and are checked againstAPPROVED_PROMPTS, which holds exactly the four prompts in the tree today:install.sh,install.ps1start unsloth studio now?install.sh,studio/setup.shaccept?Anything else fails with the file, the line, the question, a note that this is what #7016 did, and the exact
APPROVED_PROMPTSline to paste if the prompt really is intended:So the guard is an allowlist, not a ban. A deliberate new prompt is still possible, it just has to be an explicit line in the diff that a reviewer sees, rather than a quiet addition inside a 200 line installer change.
Three checks keep the allowlist honest: an entry for a prompt that no longer exists fails, an entry without a reason fails, and a new
install*/setup*/uninstall*script that is not registered inSCANNED_SCRIPTSfails.CI
Runs in
cross-platform-parity-ci.ymlalongside the existing installer parity tests on Ubuntu and Windows. It is pure text scanning, no shell or PowerShell needed, and finishes in about 0.1s. The workflow'spathsfilters gain the two uninstall scripts and the new test file.Testing
ruff checkclean,scripts/lint_workflow_triggers.pyclean.install.shandinstall.ps1: fails on both withopen unsloth studio in your default browser after launch?, and passes the three prompts that were already there. That regression shape is pinned by a self-test for each of sh and PowerShell.Send anonymous usage stats? [Y/n]prompt toinstall.shproduces the message above.read -p,Read-Host, an unlabelled/dev/ttyread, and the negative cases (whole-line comments,readfrom a file,while IFS= read, heredoc reads) so the scan cannot silently stop matching and pass everything.