Repository navigation
Conversation
…hify-Labs#2554) `claude -p` reports API failures in the stdout JSON envelope with `is_error` set and an empty stderr, and on a rate limit it can exit 0. Both call sites decided success from `returncode` and read the cause from `stderr` only, so three failures went unreported: a non-zero exit printed a bare "exited 1:" with no cause; a zero exit fed "API Error: Rate limit reached" to the JSON parser, where the empty parse read as truncation and adaptive retry bisected the chunk against an outage that could not succeed; and `_call_llm` returned that same string as the model's reply, letting community labeling and the dedup tiebreaker persist it into graph.json as a label. `_claude_cli_error` reads the envelope's `is_error` flag instead of inferring failure from the exit code. On a non-zero exit stderr keeps priority so a genuine CLI crash still reports its own diagnostics, with the envelope text as the fallback; on a zero exit the flag now raises. Failing fast is intended: `extract_corpus_parallel` already catches per-chunk exceptions and continues. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
There was a problem hiding this comment.
Graphify reviewed this change.
Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).
Graphify review — findings
This PR adds error detection for the claude -p CLI backend by introducing a new _claude_cli_error helper that inspects the stdout JSON envelope for an is_error flag and extracts the CLI's error text. It wires this check into both _call_claude_cli and _call_llm so that error envelopes raise RuntimeError (including when the CLI exits 0 or reports errors only in stdout rather than stderr), and enriches the existing non-zero-exit error message with the envelope detail as a fallback. New tests in test_claude_cli_backend.py cover the error-envelope scenarios for both entry points across zero and non-zero exit codes.
No blocking issues surfaced. 2 lower-confidence candidates did not survive cross-model review.
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 657 functions depend on the 207 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
_call_claude_cli()— 28 callers, 9 callees - worse:
_call_llm()— 9 callers, 17 callees
Verification — 657 functions in the blast radius were not formally verified this run (proofs are advisory here).
Gate & verification
graphify gate
PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.
Advisory (not blocking):
- verification_scope: 428 function(s) in the blast radius were not formally verified this run
· 2 more finding(s) on lines outside this diff (see the check run).
…e errors; bump to 0.9.37 (#2543, #2554) #2543 (adopts PR #2546, thanks @michaelxer): a failed extraction is no longer stamped in the incremental manifest as up-to-date, so graphify update retries it instead of skipping it forever; a manifest already poisoned by the old behavior is healed on the next run; genuinely unchanged files are not re-processed. Extended to the watch save_manifest paths too. #2554 (adopts PR #2555, thanks @annieyii): the claude-cli backend now inspects the stdout envelope for an is_error result (e.g. a rate limit returned with exit code 0) and raises it on both the zero and non-zero exit paths, instead of parsing it as an empty success and bisecting against a live rate limit. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…e errors; bump to 0.9.37 (Graphify-Labs#2543, Graphify-Labs#2554) Graphify-Labs#2543 (adopts PR Graphify-Labs#2546, thanks @michaelxer): a failed extraction is no longer stamped in the incremental manifest as up-to-date, so graphify update retries it instead of skipping it forever; a manifest already poisoned by the old behavior is healed on the next run; genuinely unchanged files are not re-processed. Extended to the watch save_manifest paths too. Graphify-Labs#2554 (adopts PR Graphify-Labs#2555, thanks @annieyii): the claude-cli backend now inspects the stdout envelope for an is_error result (e.g. a rate limit returned with exit code 0) and raises it on both the zero and non-zero exit paths, instead of parsing it as an empty success and bisecting against a live rate limit. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Fixes #2554
Problem
claude -preports API failures in the stdout JSON envelope (is_error: true) with an empty stderr, and on a rate limit it may exit 0. Both call sites inllm.pydecide success fromreturncodeand read the cause fromstderronly, so three failures go unreported:claude -p exited 1:with nothing after the colon."API Error: Rate limit reached"to_parse_llm_json; the empty parse reads as truncation and adaptive retry bisects the chunk, re-issuing requests that are still being refused._call_llmreturns that same string as the model's reply, so community labeling and the dedup tiebreaker can writeAPI Error: Rate limit reachedintograph.jsonas a label.Change
_claude_cli_error(stdout)returns the envelope'sresulttext whenis_erroris set, and""otherwise, including when stdout will not parse, so the existing "unparseable JSON envelope" error still takes precedence.Both call sites (
_call_claude_cli,_call_llm) then:stderron a non-zero exit and fall back to the envelope text, so a genuine CLI crash or spawn failure still reports its own diagnostics;Failing fast is intended here:
extract_corpus_parallelalready catches per-chunk exceptions and continues, so each chunk now reports the real cause instead of silently bisecting during an outage.Relationship to #1864
#1864 found the same root cause and fixes A via
proc.stdout.strip()[-500:]. It has not landed;llm.py:1541onv8still reads stderr only.This PR is a superset: it also covers B and C, which occur on a zero exit that #1864's non-zero branch never reaches, and it surfaces the envelope's
resultfield rather than a 500-character tail of raw JSON. Happy to rebase onto #1864 instead if the author would rather extend that PR.Verification
Four tests added to
tests/test_claude_cli_backend.py, following the file's existingMagicMock+patch("subprocess.run")convention, so CI needs noclaudebinary:test_nonzero_exit_surfaces_envelope_error_when_stderr_emptytest_raises_on_error_envelope_with_zero_exittest_call_llm_raises_on_error_envelopetest_call_llm_nonzero_exit_surfaces_envelope_errorEach was written and observed failing before the implementation.
Four unrelated failures in
tests/test_ollama_retry_cap.pyare pre-existing on my machine and come from the optionalopenaipackage not being installed (ModuleNotFoundError: No module named 'openai'raised bymonkeypatch), not from this change.Against a live rate-limited account: