Fix: claude subprocess inherited stdin — leaked the learner's answer key#3
Open
JMCCavender wants to merge 1 commit into
Open
Fix: claude subprocess inherited stdin — leaked the learner's answer key#3JMCCavender wants to merge 1 commit into
JMCCavender wants to merge 1 commit into
Conversation
subprocess.run(capture_output=True) captures stdout/stderr but INHERITS
stdin. With a seekable stdin (heredoc, redirected file), the claude CLI
rewinds fd 0 and reads the learner's entire pending input from position 0
— including lines the REPL already consumed. Every scripted/piped session
therefore leaked all future answers into the tutor's context: gates could
grade against answers not yet given, and openings referenced content the
learner "hadn't said yet" (the real root cause behind the graded-cold-open
symptom previously attributed to prompt framing alone).
Reproduced: a heredoc-fed session where claude echoed back the full
script verbatim, including already-consumed lines. Fixed with
stdin=subprocess.DEVNULL on both _default_invoke and claude_available.
Verified end-to-end with a clean scripted run: cold opens now teach,
a thin answer honestly fails the gate ("Not yet"), a claimed-but-not-
demonstrated skill is held at the gate until demonstrated, and resume →
completion works. Interactive tty use was never affected.
Tests: 69 passing (+1 asserting stdin=DEVNULL is passed).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This was referenced Jul 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The tutor could read the learner's unsent answers
subprocess.run(capture_output=True)captures stdout/stderr but inherits stdin. When MarbleTutor's stdin is seekable (heredoc, redirected file — i.e. any scripted or automated session), theclaudeCLI rewinds fd 0 and reads the entire input from position 0 — including lines the REPL had already consumed.Impact: every piped session leaked the learner's full script — all future answers plus the
/checkcommands — into the tutor's context on every call. Gates could grade against answers not yet given; "cold opens" referenced things the learner hadn't said. This was the true root cause of the graded-before-teaching symptom that #2's prompt fix partially addressed (that fix remains correct and needed — but this was the deeper bug). Interactive tty use was never affected, which is why it hid.Repro (before fix): a heredoc-fed session where claude echoed the full script back verbatim, including the already-consumed
yconfirmation line.Fix:
stdin=subprocess.DEVNULLon_default_invokeandclaude_available, plus a regression test asserting the kwarg.Verified with the first honest end-to-end run:
Tests: 69 passing.
🤖 Generated with Claude Code