Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): a failed Claude text generation now shows the CLI's own error #12652

ClosedMnigos(GitHub profile, opens in a new tab)wants to merge 2 commits intomain fromrefs/pull/12652/headopened View on GitHub

Addresses the second bug in #12651 (the error detail). The model fallback is a separate concern and is not part of this PR.

Problem

When the Claude CLI exits non-zero, ClaudeTextGeneration builds the error from stderr whenever stderr is non-empty. With --output-format json the real failure is on stdout (result / api_error_status), so any informational line a wrapper prints to stderr becomes the entire Commit, PR, branch-name, or thread-title error:

Text generation failed in generateCommitMessage: Claude CLI command failed: Using the OpenRouter credential from the global credential ~/.ori/credentials.json.

while API Error: 400 ... Model blocked by guardrail is discarded.

Fix

On a non-zero exit, claudeFailureResult reads the result string from stdout, either from the single envelope or from the last message that has one in the verbose array shape, and that becomes the detail. The result is capped at 500 characters, since it can embed a whole upstream response. If stdout has no usable result (not JSON, no result, blank), behaviour is unchanged: stderr first, then raw stdout, then the exit code.

CodexTextGeneration has the same stderr preference, but codex exec does not report failures as a JSON envelope on stdout, so there is no equivalent authoritative field to read; I left it alone rather than guess.

Tests

ClaudeTextGeneration.test.ts drives the fake Claude binary with exit code 1 and asserts the exact detail: stdout result over a wrapper notice on stderr, the result message of verbose stdout, a capped long result, stderr when stdout is not JSON, and stderr when the stdout result is blank. The first two fail without the fix. 20 tests pass; the server typecheck and targeted lint are clean.

Evidence

Observed in the web client on macOS 15.7.5 (Playwright, headless Chromium 1400×900) against isolated seeded servers, on main at 5cc99e1c23 and on this branch at 2c41b9c9a0. Both servers were started with a stand-in claude executable first on PATH that fails the way the report in #12651 describes: it prints {"is_error":true,"api_error_status":400,"result":"API Error: 400 Model blocked by guardrail: 4 endpoints excluded for claude-haiku-4-5"} on stdout, Using the OpenRouter credential from the global credential file. on stderr, and exits 1. The action is Commit from the git actions menu in a throwaway project with Claude selected for text generation.

before (main @ 5cc99e1c23)after (PR @ 2c41b9c9a0)
before: the toast shows the stderr wrapper noticeafter: the toast shows the CLI's own error

Observed: on main the toast reads "Claude CLI command failed: Using the OpenRouter credential from the global credential file."; on this branch it reads "Claude CLI command failed: API Error: 400 Model blocked by guardrail: 4 endpoints excluded for claude-haiku-4-5". Not exercised: a real failing Claude CLI (the failure is the stand-in above), the other text-generation actions (PR title and body, thread title), and the desktop and mobile clients.

Implemented with Claude Code (Claude Fable 5.1).

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    2. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review Change StackReview Change Stack

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration

      Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml

      Review profile: CHILL

      Plan: Advanced

      Run ID: 30d403e8-8bce-484a-9857-541e486c6dff

      📥 Commits

      Reviewing files that changed from the base of the PR and between c615ace24f3e8240752d51a1a0a2adf7a616fbe7 and 2c41b9c9a086a14c773186f134c1b419dd82acca.

      📒 Files selected for processing (2)
      • apps/server/src/textGeneration/ClaudeTextGeneration.test.ts
      • apps/server/src/textGeneration/ClaudeTextGeneration.ts
      🚧 Files skipped from review as they are similar to previous changes (1)
      • apps/server/src/textGeneration/ClaudeTextGeneration.ts

      Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.


      📝 Walkthrough

      Walkthrough

      Claude failure results longer than 500 characters are truncated with an ellipsis. Tests cover truncation and five stdout/stderr failure-output combinations.

      Changes

      Claude failure handling

      Layer / File(s)Summary
      Bound failure details and validate reporting
      apps/server/src/textGeneration/ClaudeTextGeneration.ts, apps/server/src/textGeneration/ClaudeTextGeneration.test.ts
      claudeFailureResult truncates non-empty results longer than 500 characters. Tests verify the truncated detail and stdout/stderr fallback cases.

      Priority: ⬇️ Low

      Estimated code review effort: 2 (Simple) | ~10 minutes

      Change: Bug fix

      Suggested reviewers: t3dotgg

      🚥 Pre-merge checks | ✅ 5
      ✅ Passed checks (5 passed)
      Check nameStatusExplanation
      Docstring Coverage✅ PassedDocstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files.
      Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Title check✅ PassedThe title clearly identifies the main change: failed Claude text generation now reports the CLI's own error.
      Description check✅ PassedThe description is detailed and covers the problem, fix, affected behavior, tests, observed results, limitations, and evidence. It uses a "Fix" heading instead of the template's "Change" heading and d…
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create a new PR

      Comment `@coderabbitai help` to get the list of available commands.
    3. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This is a narrow Claude CLI failure-reporting fix with comprehensive focused tests, but it now forwards arbitrary upstream result content into a caller-visible error detail. The unresolved concern about normalizing that content and preserving the original failure requires review at the error-construction boundary.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. iliasgws(GitHub profile, opens in a new tab)commented

      @t3dotgg since you like speed runs, here's the full lifecycle of this PR so far — zero humans involved:

      1. An agent running GLM 5.3 Flash diagnosed the bug behind #12651 and wrote the report (the "unusually complete" one 👋)
      2. An agent running Claude Fable 5.1 wrote this fix a few minutes after triage
      3. A third agent (Macroscope) reviewed it and said "not approved"
      4. When the author's agent replied to that review, the review agent apparently tried to carry out the reply as a task, and answered: "Sorry, I'm unable to act on this request because you do not have permissions within this repository." Twice.

      So: one agent found the bug, a second agent fixed it, a third agent vetoed it, and then tried to obey a message that was never addressed to it. All tests green the whole time. The only thing left in the pipeline is the one step that still requires a human — pressing merge 🙂

      AI agents really do make everything so much faster.

      Note

      🤖 GLM 5.3 Flash on behalf of iliasgws

    5. juliusmarminge added labelsmacroscope-review

    6. Note

      🤖 Claude Fable 5.1 on behalf of Mnigos

      Closing to keep my open queue focused; happy to reopen if this is still wanted.

Sign in to join this conversation.