Reports

#6783 · Command metadata lost during provider translation

BugMedium priorityMedium effortproviders · provider-claude-code · confirmed-repro

Issue · 2026-11-01 · trusted main 916d684ac23d0b0de82c09cfc7553a50287d2188

Verdict: REPRODUCED · Root-cause confidence: high

1. TL;DR

The Claude Code provider drops a command's human-readable description when constructing its command presentation. It also replaces every failed command's exit status with 1, even when the result explicitly reports another status. Replaying provider messages through the real translator and shared event assembler reproduces both losses. The same agent repeated the test in a second clean checkout, with identical results. This is a translation-level reproduction, not a browser or authenticated live-Claude test.

2. Claims vs findings

ClaimFindingEvidence
The command description is discarded.VerifiedA tool-use message with description “Inspect workspace contents” produces presentation.title “ls -a”; the focused test fails.
Failed commands lose their real exit status.VerifiedResult headers reporting 2, 23, 126 and 127 all produce exitCode 1, including structured stdout/stderr metadata.
The user-facing command list lacks this context.Verified at event boundary; live surfaces not runThe event carries the wrong title and code. No screenshot or live CLI session is claimed.

3. Environment

4. Minimal reproduction

  1. Download the regression test, then execute:
git clone https://github.com/get-bb/bb.git bb-6783
cd bb-6783
git checkout --detach 916d684ac23d0b0de82c09cfc7553a50287d2188
pnpm install --frozen-lockfile --prefer-offline
cp /path/to/downloaded/delta-translation.command-metadata.test.ts plugins/provider-claude-code/src/delta-translation.command-metadata.test.ts
pnpm exec turbo run test --filter=bb-plugin-provider-claude-code --force -- src/delta-translation.command-metadata.test.ts

The test feeds ordinary assistant tool-use and user tool-result messages into the repository's existing harness. The command text is never executed. This protects the provider's emitted command-event contract without mocking the translator or adding production seams.

Expected versus actual

Expected title: Inspect workspace contents
Actual title:   ls -a
Expected exit codes: 2, 23, 126, 127
Actual exit codes:   1, 1, 1, 1

Test Files  1 failed (1)
Tests  5 failed | 9 passed (14)

The nine passing controls cover missing/blank/invalid descriptions, absent/malformed/unsafe numeric headers, later output lines, and successful output containing exit-code-like text.

Complete regression test
import { describe, expect, it } from "vitest";
import { createClaudeDeltaHarness } from "./delta-test-harness.js";

describe("Claude command metadata", () => {
  it.each([
    {
      description: "Inspect workspace contents",
      title: "Inspect workspace contents",
    },
    { description: undefined, title: "ls -a" },
    { description: "  ", title: "ls -a" },
    { description: 42, title: "ls -a" },
  ])(
    "preserves the command title for description $description",
    ({ description, title }) => {
      const harness = createClaudeDeltaHarness();
      const started = harness.translate({
        type: "assistant",
        message: {
          role: "assistant",
          content: [
            {
              type: "tool_use",
              id: "command-1",
              name: "Bash",
              input: { command: "ls -a", description },
            },
          ],
        },
        session_id: "metadata-test",
      });
      const completed = harness.translate({
        type: "user",
        message: {
          role: "user",
          content: [
            {
              type: "tool_result",
              tool_use_id: "command-1",
              content: "entries",
              is_error: false,
            },
          ],
        },
        session_id: "metadata-test",
      });
      for (const [events, type] of [
        [started, "item/started"],
        [completed, "item/completed"],
      ] as const) {
        expect(events).toContainEqual(
          expect.objectContaining({
            type,
            item: expect.objectContaining({
              type: "commandExecution",
              command: "ls -a",
              presentation: expect.objectContaining({ title }),
            }),
          }),
        );
      }
    },
  );

  it.each([
    { content: "Exit code 2\nsyntax error", isError: true, exitCode: 2 },
    {
      content: [{ type: "text", text: "Exit code 23\nfailed" }],
      isError: true,
      exitCode: 23,
    },
    {
      content: "Error: Exit code 126\r\nnot executable",
      isError: true,
      exitCode: 126,
    },
    {
      content: "Exit code 127\nnot found",
      isError: true,
      exitCode: 127,
      toolUseResult: { stdout: "", stderr: "not found" },
    },
    { content: "failed", isError: true, exitCode: 1 },
    {
      content: "Exit code 999999999999999999999\nfailed",
      isError: true,
      exitCode: 1,
    },
    { content: "Exit code 2.5\nfailed", isError: true, exitCode: 1 },
    { content: "log line\nExit code 23", isError: true, exitCode: 1 },
    { content: "Exit code 23\nprinted text", isError: false, exitCode: 0 },
    { content: "done", isError: false, exitCode: 0 },
  ])(
    "preserves exit code $exitCode for $content",
    ({ content, isError, exitCode, ...metadata }) => {
      const harness = createClaudeDeltaHarness();
      harness.translate({
        type: "assistant",
        message: {
          role: "assistant",
          content: [
            {
              type: "tool_use",
              id: "command-1",
              name: "Bash",
              input: { command: "ls -a" },
            },
          ],
        },
        session_id: "metadata-test",
      });
      const events = harness.translate({
        type: "user",
        message: {
          role: "user",
          content: [
            {
              type: "tool_result",
              tool_use_id: "command-1",
              content,
              is_error: isError,
              tool_use_result: metadata.toolUseResult,
            },
          ],
        },
        session_id: "metadata-test",
      });
      expect(events).toContainEqual(
        expect.objectContaining({
          type: "item/completed",
          item: expect.objectContaining({
            type: "commandExecution",
            exitCode,
            status: isError ? "failed" : "completed",
          }),
        }),
      );
    },
  );
});

5. Root cause

The Bash parser only constructs command, cwd, background and sandbox metadata; it does not propagate description:

interface ClaudeBashCommand {
  command: string;
  cwd: string | null;
  background: boolean;
  sandboxOverridden: boolean;
}

export function parseClaudeBashCommand(
  input: unknown,
): ClaudeBashCommand | null {
  const parsed = bashArgsSchema.safeParse(input);
  if (!parsed.success) {
    return null;
  }
  const command = toOptionalString(parsed.data.command);
  if (!command) {
    return null;
  }
  const background = claudeBackgroundFlagSchema.safeParse(input);
  const sandboxOverride = claudeSandboxOverrideFlagSchema.safeParse(input);
  return {
    command,
    cwd: toOptionalString(parsed.data.cwd) ?? null,
    background:
      background.success && background.data.run_in_background === true,
    sandboxOverridden:
      sandboxOverride.success &&
      sandboxOverride.data.dangerouslyDisableSandbox === true,
  };

Command presentation always uses the raw command as its title. Classification forwards only the parsed metadata.

export function commandPresentation(args: {
  command: string;
  background: boolean;
  sandboxEscaped: boolean;
}): DeltaPresentation {
  const presentation = withTitle(
    {
      label: args.background
        ? {
            pending: "Starting background command",
            completed: "Started background command",
          }
        : { pending: "Running command", completed: "Ran command" },
      icon: { glyph: "Terminal" },
    },
    presentationTitle(args.command),
  );

Terminal close fields derive exitCode solely from the boolean error flag:

function terminalCloseFields(
  shape: DeltaItemShape,
  outputText: string | undefined,
  isError: boolean,
): Pick<
  Extract<ThreadDelta, { kind: "item.close" }>,
  "exitCode" | "aggregatedOutput" | "resultText"
> {
  switch (shape.type) {
    case "command":
      return {
        exitCode: isError ? 1 : 0,
        ...(outputText === undefined ? {} : { aggregatedOutput: outputText }),
      };
    case "fileRead":
    case "search":
    case "delegation":
      return {};
    default:
      return outputText === undefined ? {} : { resultText: outputText };
  }

The completion path has the original result content but never parses its exit-status header. Output extraction prefers structured stdout/stderr, so parsing only the displayed output would still miss some headers. A trusted recorded transcript also contains a real failed-command header with code 2 (fixture).

Deeper rendering constraint

The shared timeline renderer deliberately excludes command rows from its presentation-title path and then selects raw command text. Consequently, merely preserving the description in the provider presentation does not make it visible in command titles. Both UI and CLI text formatting rely on this shared title builder (renderer; CLI formatting).

function mapExecutionTitle(row: TimelineExecutionWorkRow): TimelineTitle {
  const status = displayStatus({
    approvalStatus: row.approvalStatus,
    status: row.status,
  });
  const isCommand = row.workKind === "command";
  if (
    row.presentation &&
    status !== "waiting" &&
    status !== "denied" &&
    !isCommand
  ) {
    return presentedTitle({
      presentation: row.presentation,
      status,
      startedAt: row.startedAt,
      completedAt: row.completedAt,
    });
  }
  const content = isCommand
    ? row.command
    : formatToolCallCommand(row.toolName, row.toolArgs);

6. Proposed fix and stopped local candidate

Preserve the optional provider description using the existing presentation title, retaining raw command data and its fallback title. Parse only a leading failure-result exit-code header, validate it as a safe integer, and keep the existing 0/1 fallback. Read the original result text independently of aggregated stdout/stderr. A complete user-visible repair also needs a shared renderer change, with UI/CLI regression coverage and preservation of command approval behavior.

A local provider-only candidate touched four files and 172 total text lines (168 additions, 4 deletions), including the 140-line regression test. The focused test failed before and all 14 cases passed after. Lint and typecheck passed. The 27 relevant existing-plus-regression files passed all 320 tests. The full package run still had six pre-existing environment-dependent failures in discovery and bridge permission tests; the unchanged second checkout reproduced the same six failures in addition to the five new regression failures. They were not modified.

No fix was pushed and no PR was opened. The candidate was stopped when end-to-end inspection proved that a complete repair must span the provider and shared-rendering subsystems, violating this automation's one-subsystem simple-fix limit. Its passing tests only establish the candidate's translation behavior, not a complete user-visible repair.

7. Verification

The same agent created a second clean temporary checkout at 916d684ac23d0b0de82c09cfc7553a50287d2188, performed a separate frozen install, copied only the newly authored test, and ran the exact focused Turbo command with --force to bypass test caching. Result: the identical five intended assertion failures and nine passing controls. Production files were unchanged. No report correction was necessary; this is a repeated check, not independent verification.

Root-cause excerpts above were read directly from the recorded commit with git show. All linked artifacts are actual saved outputs. A later end-to-end static review corrected the initial provider-only fix proposal: command rendering ignores that presentation title, so the candidate is incomplete and stopped. No live UI/CLI verification or screenshots are claimed. The general verification inventory also reports pre-existing unmapped diagnostics CLI drift; that unrelated documentation was not changed.

8. Related issues and pull requests

No linked open PR was found in issue cross-reference metadata or the repository's open-PR search for 6783 before the fix. Related issue searches found no matching duplicate; installation and permission issues concern different paths.

9. Appendix

Issue text was treated as untrusted hypotheses. Its proposed actions and implementation suggestions were not executed. The test and patch were authored from trusted repository code and recorded fixtures.

Additional validation commands

pnpm exec turbo run test --filter=bb-plugin-provider-claude-code
pnpm exec turbo run test --filter=bb-plugin-provider-claude-code -- --exclude src/bridge/__tests__/bridge.test.ts --exclude src/bridge/provider-maintenance.discovery.test.ts
pnpm exec turbo run lint typecheck --filter=bb-plugin-provider-claude-code
git diff --check
git diff --numstat origin/main

Generated by SlopCop. No dependency was added. Report artifacts omit private home paths.