Skip to content

Let the stdout guard read writes, not flushes - #11576

Merged
danielhanchen merged 2 commits into
mainfrom
fix/stdout-guard-reads-writes-not-flushes
Sep 22, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
fix/stdout-guard-reads-writes-not-flushes

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

tests/python/test_install_python_stack.py::TestProgressLineNotes::test_no_direct_stdout_writes fails on main (be072ee2f) and in Repo tests (CPU, studio):

AssertionError: install_python_stack.py:[10982] write to sys.stdout directly; only _progress()/_end_progress_line() may, everything else uses _safe_print()

Line 10982 came in with #11566. It flushes stdout and stderr before the installer reruns the new version of itself:

# The child writes to the same descriptors, so anything still buffered here would land
# after its output.
sys.stdout.flush()
sys.stderr.flush()

That flush is correct and needed. The guard exists so nobody copies _progress()'s sys.stdout.write idiom and glues text onto the progress bar (its docstring says so). A flush emits no characters and cannot do that. The matcher listed flush only as the second half of that idiom. It now matches write only; the product is unchanged.

Verification

  • TestProgressLineNotes: 14 passed (1 failed on main).
  • Sabotage: changing line 10982 to sys.stdout.write("") fails the test at that line.

test_no_direct_stdout_writes flags sys.stdout.write and sys.stdout.flush outside
the progress helpers, and has failed on main since #11566, which flushes stdout
and stderr before rerunning the installer it just installed. That flush is
needed: the child writes to the same descriptors, so anything still buffered
would land after its output. A flush emits nothing and cannot glue text onto
the progress bar, which is what the guard exists for. It now matches write
only; a direct write on the same line still fails it.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

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

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-22T18:40:12.084869Z e617fb9 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

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

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: e617fb9215

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 4a955d2 into main Sep 22, 2026
38 of 43 checks passed
@danielhanchen
danielhanchen deleted the fix/stdout-guard-reads-writes-not-flushes branch September 22, 2026 19:40
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
* Let the stdout guard read writes, not flushes

test_no_direct_stdout_writes flags sys.stdout.write and sys.stdout.flush outside
the progress helpers, and has failed on main since unslothai#11566, which flushes stdout
and stderr before rerunning the installer it just installed. That flush is
needed: the child writes to the same descriptors, so anything still buffered
would land after its output. A flush emits nothing and cannot glue text onto
the progress bar, which is what the guard exists for. It now matches write
only; a direct write on the same line still fails it.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant