Skip to content

[claude-cli] Chunk-failure detail prefers stderr over the JSON envelope error — hook teardown noise masks the real cause #2692

Open

Description

@yotamleo

[claude-cli] Chunk-failure detail prefers stderr over the JSON envelope error — hook teardown noise masks the real cause

Summary

When a claude -p chunk fails under the claude-cli backend, _call_claude_cli
raises with detail = proc.stderr.strip() or cli_error (llm.py, the
proc.returncode != 0 branch). On any Claude Code installation that has
user-configured hooks (e.g. SessionEnd hooks — common for notification/cleanup
setups), a failing session's stderr is dominated by hook teardown messages like:

SessionEnd hook [...] failed: Hook cancelled

so the reported error becomes claude -p exited 1: SessionEnd hook [...] failed: Hook cancelled — while the actual failure cause (e.g. a usage-limit error, an
auth problem) sits unread in the stdout JSON envelope that
_claude_cli_error(proc.stdout) already parses.

Observed impact

On a large docs corpus (~7.9k files), a long unattended run failed 22 of 48
chunks, every one reporting only the SessionEnd hook noise. Diagnosing the real
cause (subscription usage-window exhaustion mid-run) required reconstructing it
from timing, because the envelope error was never surfaced. The failed files
stayed cache-misses and were re-extracted (and re-billed) on the next run.

Suggested fix

Prefer the parsed envelope error when present:

detail = cli_error or proc.stderr.strip() or "(no stderr, no error envelope)"

or include both (f"{cli_error}; stderr: {stderr[:200]}"). The envelope error is
the CLI's own structured report of what went wrong; stderr is where hook/harness
noise lands.

Environment

graphify 0.9.38–0.9.40, Windows 11, Claude Code CLI (subscription auth),
--backend claude-cli, corpus of markdown docs.

Activity

  1. yotamleo commented on Sep 1, 2026

    @yotamleo
    ContributorAuthor

    Status update, since I filed this: #2733 already fixes it (fix(claude-cli): prefer envelope error over stderr on chunk failure), open and mergeable. I'm not opening a competing PR.

    Worth saying that it's better than what I suggested. My proposal was to prefer the envelope and drop stderr; #2733 extracts a _claude_cli_failure_detail(cli_error, stderr) helper that leads with the envelope error and appends a truncated stderr when both are present, so the hook noise stops burying the real cause without the diagnostic being thrown away. It also covers both exit paths — _call_claude_cli and the claude-cli branch of _call_llm — where my report only cited the first. That second site is the one that would have kept the bug alive on labeling calls.

    Nothing further needed from me here; this can close with #2733.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions