fix(claude-cli): deliver extraction instructions in the user turn (fixes infinite bisection on Claude Code >= 2.1) - #1611
Closed
javargasm wants to merge 1 commit into
Conversation
The claude-cli backend passed the extraction schema via --system-prompt with
only the raw file dump in the user turn, assuming a replacement system prompt
is the model's sole authority. Claude Code >= ~2.1 (verified on 2.1.197) does
not honour that: it still layers in the local coding-agent context
(CLAUDE.md/AGENTS.md in cwd, skills, MCP) and, given a user turn that is just a
file with no request, replies conversationally ("I see the file, but there's no
actual request attached"). That prose parses to zero nodes/edges, so
_response_is_hollow flags it as truncation and the adaptive-retry path bisects
the chunk indefinitely (94 -> 47 -> 23 -> ...), never converging and never
writing graph.json.
Move the full extraction schema plus an explicit imperative into the user turn
and drop --system-prompt, so the CLI emits the JSON object directly. The
<untrusted_source> prompt-injection guardrails are carried verbatim; model
override, --add-dir image handling, timeout, and token accounting are untouched.
Collaborator
|
Merged into |
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.
Summary
The
claude-clibackend can hang on an infinite chunk bisection under newer Claude Code CLIs (>= ~2.1, verified on 2.1.197), sographify extract --backend claude-clinever writesgraph.json._call_claude_clidelivered the extraction schema via--system-promptand put only the raw file dump in the user turn, on the assumption that a replacement system prompt is the model's sole authority. Claude Code >= 2.1 does not honour that: it still layers in the local coding-agent context (CLAUDE.md/AGENTS.md in cwd, skills, MCP) and, given a user turn that is just a file with no request, replies conversationally:That prose parses to zero nodes/edges, so
_response_is_hollowflags it as truncation and the adaptive-retry path bisects the chunk indefinitely (94 → 47 → 23 → …), never converging and never writinggraph.json. The run ends inall semantic chunks failed for backend 'claude-cli'.Observed log:
Fix
Move the full extraction schema plus an explicit imperative into the user turn and drop
--system-prompt, so the CLI emits the JSON object directly. The<untrusted_source>prompt-injection guardrails are carried verbatim (the schema text is unchanged; only its delivery channel moves). Model override (GRAPHIFY_CLAUDE_CLI_MODEL),--add-dirimage handling, timeout, and token accounting are untouched.Why not other approaches
Verified empirically before landing this:
--model haikufails the same way.--setting-sources ""/--tools ""/--mcp-config '{}'break auth (Not logged in) or hang.Moving instructions into the user turn is the only approach that makes the CLI emit JSON.
Verification
graph.jsonwith no bisection: e.g.38 nodes / 38 edges,3468 / 11390,679 / 1334,3723 / 7302.test_uses_system_prompt_not_append(which asserted the old behaviour that caused this bug) is updated to assert instructions ride in the user turn.--system-promptabsent from argv; schema + imperative + source present in stdin;<untrusted_source>guardrails preserved.pytest tests/test_claude_cli_backend.py tests/test_llm_parser.py tests/test_llm_backends.py→ 116 passed.Notes
est. cost (~claude-cli): $0.0000line is unaffected by this change, but note extraction runs on the Claude Code plan (Opus by default);GRAPHIFY_CLAUDE_CLI_MODEL=haikureduces that.