Repository navigation
Description
Summary
When the claude -p subprocess fails, call_haiku raises RuntimeError(f"claude exited {result.returncode}: {stderr}") — but with --output-format json the CLI reports failures as an error JSON on stdout ("is_error": true) and leaves stderr empty. The result is that every subprocess failure logs as the undiagnosable:
[haiku] ERROR: call-haiku error: claude exited 1:
In my case this hid a CLI auth outage for ~7 weeks: the standalone CLI had been logged out (interactive sessions kept working because the desktop app injects its own auth), so every auto-save and consolidation died with the empty message above, now.md went stale, and daily files were never compressed into recent.md/archive.md.
Environment
- remember 0.8.3 (bug still present on
main,pipeline/haiku.pylines 176–178) - Claude Code CLI 2.1.197, macOS (Darwin 25.5.0)
Reproduction
Log the CLI out (or run on any machine where claude auth status reports "loggedIn": false), then run the pipeline:
cd <plugin-dir> && python3 -m pipeline.shell consolidate <staging_dir> <recent.md> <archive.md>
→ RuntimeError: claude exited 1: (empty detail).
Running the same claude -p --output-format json ... command manually shows what actually happened — exit code 1, empty stderr, and on stdout:
{"type":"result","subtype":"success","is_error":true,"result":"Not logged in · Please run /login", ...}Suggested fix (tested)
In call_haiku's non-zero-exit branch, fall back to the stdout JSON's result field when stderr is empty (then raw stdout, capped):
if result.returncode != 0:
detail = result.stderr.strip()
if not detail:
# With --output-format json the CLI reports failures as an error
# JSON on STDOUT (is_error: true) and leaves stderr empty — e.g.
# a logged-out CLI prints {"result": "Not logged in · Please run
# /login"} and exits 1. Surface that message, else every failure
# logs as the undiagnosable "claude exited 1: ".
try:
payload = json.loads(result.stdout)
except json.JSONDecodeError:
payload = None
if isinstance(payload, dict):
detail = str(payload.get("result") or "").strip()
if not detail:
detail = result.stdout.strip()[:500]
raise RuntimeError(f"claude exited {result.returncode}: {detail}")With this patch the log becomes actionable:
RuntimeError: claude exited 1: Not logged in · Please run /login
Two unit tests to go with it (error-JSON-on-stdout, and non-JSON stdout fallback):
@patch("pipeline.haiku.subprocess.run")
def test_call_haiku_nonzero_exit_error_on_stdout(mock_run):
mock_run.return_value = MagicMock(
returncode=1,
stdout=json.dumps({
"type": "result", "subtype": "success", "is_error": True,
"result": "Not logged in · Please run /login",
}),
stderr="",
)
try:
call_haiku("test")
assert False, "should raise"
except RuntimeError as e:
assert "Not logged in" in str(e)
@patch("pipeline.haiku.subprocess.run")
def test_call_haiku_nonzero_exit_non_json_stdout(mock_run):
mock_run.return_value = MagicMock(
returncode=1,
stdout="some plain-text failure banner",
stderr="",
)
try:
call_haiku("test")
assert False, "should raise"
except RuntimeError as e:
assert "plain-text failure banner" in str(e)Full suite passes with the patch applied on 0.8.3 (489 passed, 41 skipped, 98.5% coverage). Happy to open a PR if useful.
🤖 Diagnosed and patched with Claude Code
Activity
fix: keep the OAuth token for the nested call, and report why it fail…
fix: keep the OAuth token for the nested call, and report why it fail…
fix: keep the OAuth token for the nested call, and report why it fail…
fdaviddpt commentedon Jul 25, 2026
Fixed on main (#152), shipping in the next release — together with #131, which is the bug this one was hiding.
The error path now reads stdout: structured field first (
error/result/message, including a nested.message), raw stdout as fallback, stderr appended when present, capped at 500 chars so a large payload isn't dumped into the log on every failure. When both streams really are empty it says(no output on stdout or stderr)instead of trailing off after the colon.Your diagnosis was exactly right, and the sequencing you described is why both went in as one PR: #131 (
CLAUDE_CODE_OAUTH_TOKENstripped as if it were parent-session identity, leaving every nested call unauthenticated) was only identifiable after patching this one. Shipping the credential fix without the diagnostics fix would have left the next auth failure just as silent.Thanks — a 7-week outage hidden behind an empty error string is exactly the kind of thing we can't find from the inside.
— Max
fix: per-tool-call capture on Codex still forked save-session.sh into…
Part of #1011: reduce post-tool-hook.sh no-save forks (#1016)