Repository navigation
Bound ai-accounts stderr drain after the command exits - #1721
Conversation
Architecture-Review: unchanged; the optional account shim keeps command and replay behavior and returns the known exit status if stderr remains open. Co-Authored-By: Codex <noreply@openai.com>
There was a problem hiding this comment.
loopzero primary review by claude on 0a875f98cd32fc1f240b35e754593178c618bf3f, 42.0s: approve (0 critical, 0 important, 3 suggestion)
Settings per native call (launch configuration and CLI claims, not backend attestation):
- Call 1: requested model claude-opus-5-5 (effort medium); CLI-reported model claude-opus-5-5 (effort unknown); configured model claude-opus-5-5 (effort medium)
Native Claude output is retained in the restricted local review receipt.
| t.join() | ||
| t.join(timeout=1) | ||
| if t.is_alive(): | ||
| return code |
There was a problem hiding this comment.
suggestion: A daemon pump still writing at shutdown can abort the interpreter and replace the leader's exit code
When the drain times out, cmd_run returns and sys.exit starts interpreter finalization while the daemon pump thread is still running. If a lingering descendant keeps writing stderr and the pump is blocked inside sys.stderr.buffer.write (for example because whoever reads the wrapper's stderr has stalled), it holds the BufferedWriter lock. During finalization, flush_std_files waits about 1s for that lock and then calls Py_FatalError("could not acquire lock for <stderr> at interpreter shutdown, possibly due to daemon threads"). The process then exits from SIGABRT (status 134) instead of returning the leader's code. That breaks the 'exit status is preserved' acceptance criterion in the same scenario this change targets. This only happens when the stderr consumer stalls, so the window is narrow. Smallest fix: have pump write with os.write(2, chunk) instead of the buffered sys.stderr.buffer, so the daemon never holds an interpreter-level I/O lock. Alternatively, call sys.stderr.flush() then os._exit(code) on the timed-out path.
| assert helper.active('codex') == 'main' | ||
|
|
||
|
|
||
| def test_run_returns_after_leader_exits_with_inherited_stderr(helper): |
There was a problem hiding this comment.
suggestion: No test checks that partial stderr blocks replay
The new test only checks that the wrapper returns exit code 7 when nothing would trigger replay. Nothing checks the third acceptance item: when the drain times out after a retryable exit whose partial stderr already matches USAGE_LIMIT_RE, exhausted must not be called and no second attempt may run. If someone later moves the t.is_alive() check below the retry decision, every test still passes. Add a case to the existing parametrized replay test (or an in-process cmd_run test with exhausted monkeypatched) where the leader prints the usage-limit text, starts a child that holds stderr open, and exits with a retryable code. Assert one run and no call to exhausted.
|
|
||
| def test_run_returns_after_leader_exits_with_inherited_stderr(helper): | ||
| argv = [helper.sys.executable, helper.__file__, 'run', 'claude', '--', helper.sys.executable, | ||
| '-c', 'import subprocess, sys; subprocess.Popen(["sleep", "6"]); sys.exit(7)'] |
There was a problem hiding this comment.
suggestion: The test leaves a sleep 6 process running after it finishes
The grandchild sleep 6 is never reaped or killed, so it outlives the test by several seconds. Under parallel or repeated runs this leaves stray processes behind. A shorter sleep (for example 3s, which still exceeds the 1s drain plus startup and stays under the 5s timeout) shrinks the leak. Running the leader in its own session and killing that process group at teardown would remove it completely.
|
@Mergifyio queue |
✅ Merged into
|
|
No description provided. |
Bound ai-accounts stderr drain after the command exits
Context and goal
Closes #1660
Acceptance
Base
main @ 4e1c0a4
Validation
Recorded for
59f6deab582euv run --group dev ruff check src tests: exit 0uv run --group dev tach check: exit 0uv run --python 3.14 python scripts/check_architecture_docs.py: exit 0scripts/size_budget.sh: exit 0uv run --group dev pytest -q: exit 0Review
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.