← reports

#7353 · Preserve the original send failure

Bug Medium priority Low effort cli · GitHub issue · 2026-11-10 · base 7c1353d80729983b86ea1555d18b42407f320406

Verdict: REPRODUCED · Root-cause confidence: high

1. TL;DR

A failed message send can print an unrelated thread-lookup error instead of explaining that the workspace was destroyed. The CLI fetches thread metadata to add a recovery hint after receiving the original HTTP 409 error. If that secondary request fails, its rejection escapes and replaces the original diagnostic. A deterministic command/output regression reproduces this for HTTP 404, HTTP 503, and a rejected transport promise in two clean checkouts at the same trusted main commit.

2. Claims vs findings

ClaimStatusEvidence
A failed recovery-metadata lookup masks the send failure.VerifiedThree failing assertions in each of two clean baseline runs; 19 existing tests pass.
The non-restorable-provider hint lacks a ready command.Verified, static onlyThe branch advises starting a new thread in prose. It does offer a way forward; adding a complete command is a separate convenience change.
A real deletion or server-stop race triggers this path.Not exercised liveEquivalent HTTP failures and connection rejection are injected at the existing CLI transport boundary. No claim is made about race frequency.

3. Environment

4. Minimal reproduction

  1. Clone the trusted repository and select the recorded base:
    git clone https://github.com/get-bb/bb.git bb-7353
    cd bb-7353
    git checkout --detach 7c1353d80729983b86ea1555d18b42407f320406
    pnpm install --frozen-lockfile --prefer-offline
  2. Download the regression patch from this report, save it outside the checkout, and apply it. It only extends the existing command/output test:
    git apply ../regression.patch
    pnpm exec turbo run test --filter=@bb/cli -- src/__tests__/command-output/thread-tell.test.ts
  3. Observe the original send error disappear:
    Expected: Error: HTTP 409: Thread environment is unavailable
    Actual (404): Error: HTTP 404: Thread lookup failed
    Actual (503): Error: HTTP 503: Thread lookup failed
    Actual (transport): Error: Thread lookup connection closed
    Tests: 3 failed | 19 passed (22)

The complete test file includes the existing command registration and transport harness. Added regression:

  it.each([404, 503, "transport"] as const)(
    "bb thread send preserves the send error when the hint lookup fails with %s",
    async (failure) => {
      stubServerApi({
        "v1.threads.:id.$get": async () => {
          if (failure === "transport") {
            throw new Error("Thread lookup connection closed");
          }
          return new Response(
            JSON.stringify({ message: "Thread lookup failed" }),
            { status: failure, headers: { "Content-Type": "application/json" } },
          );
        },
        "v1.threads.:id.send.$post": async () =>
          new Response(
            JSON.stringify({
              code: "thread_environment_unavailable",
              message: "Thread environment is unavailable",
              details: { reason: "destroyed", environmentStatus: "destroyed" },
            }),
            { status: 409, headers: { "Content-Type": "application/json" } },
          ),
      });
      await expect(
        runCommand(["thread", "send", "thread-gone", "hello"], register),
      ).rejects.toThrow("process.exit:1");
      expect(
        vi.mocked(console.error).mock.calls.map((call) => String(call[0])),
      ).toEqual(["Error: HTTP 409: Thread environment is unavailable"]);
    },
  );

5. Root cause

The send catch block and hint builder await a metadata request while already handling an error. The hint builder has no rejection handler around this line:

const { canRestoreEnvironment } = await sdk.threads.get({ threadId });

Consequently throw await withRestoreEnvironmentHint(...) rejects with the lookup failure rather than throwing its original argument. The CLI action wrapper prints that replacement error. The server error constructor confirms the original 409 code, message, and destroyed status used by the regression. This is a diagnostic failure in the CLI, not proof that sending succeeded or that the server lost data.

6. Proposed fix

Make recovery metadata best effort. If the thread request rejects, return the original error unchanged; when it succeeds, retain the existing restore/non-restore hints. This needs no SDK, protocol, data, or permission change. Keep the optional ready-to-run new-thread command out of this minimal defect repair.

7. Verification

The same agent created a second clean clone at the exact recorded commit, checked its clean status, performed a new frozen install, and copied only the authored regression test. The same Turbo command produced the same three intended assertion failures and 19 passing existing cases. This is a repeat clean-checkout verification, not an independent review. No report correction was necessary.

First run log · Second run log. Checkout prefixes are replaced with CHECKOUT_A and CHECKOUT_B in the public artifacts.

8. Related issues and pull requests

No open pull request linked to #7353 was present in the issue timeline or repository PR search during investigation. No separate issue is needed for this confirmed defect.

9. Appendix

The initial full monorepo build encountered an unbuilt Plugin SDK runtime prerequisite. The documented SDK build tasks were run before retrying. This environment setup failure is unrelated to the reproduced CLI assertions; the scoped tests build their upstream generated modules through Turbo.

Issue-provided suggested code and commands were treated as untrusted data, not executed or copied. The regression and repair proposal were derived from the trusted main source and existing test boundary. No live account or user runtime data was accessed.