Skip to content

Migrate app API usage to @bb/sdk - #739

Merged
SawyerHood merged 6 commits into
mainfrom
bb/bb-workflow-skill-check-thr_e4mkfam5y5
Jul 17, 2026
Merged

SawyerHood merged 6 commits into
mainfrom
bb/bb-workflow-skill-check-thr_e4mkfam5y5

Conversation

@SawyerHood

@SawyerHood SawyerHood commented Jul 16, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • replace app API wrapper usage with typed @bb/sdk clients across queries, mutations, dialogs, and workspace flows
  • add missing SDK request fields, browser error exports, structured error bodies, and attachment-copy support
  • preserve query cancellation by threading AbortSignal through SDK read methods
  • reduce the legacy raw-HTTP escape hatch to endpoints without equivalent SDK support

Validation

  • repo-wide typecheck (49 packages)
  • app test suite (1,597 tests)
  • SDK test suite (78 tests)
  • remaining package suites; one unrelated bb-app launcher timeout passed on isolated rerun

Notes

The remaining raw HTTP usage is intentional for binary previews, sidebar bootstrap, voice transcription, provider-CLI NDJSON streaming, and websocket flows without equivalent SDK behavior.

Review follow-up

  • multi-agent review (gpt-5.6-sol finders + adversarial verify + Fable final pass) confirmed two contract issues, fixed in b013d4e29: tabs.get now parses responses with threadTabsResponseSchema, and mutation arg types no longer advertise an ignored AbortSignal (split ThreadActionArgs/ThreadInteractionTargetArgs, regenerated plugin-sdk dts)
  • browser smoke test on a dev instance: spawn/send/timeline, pin/unpin, archive/unarchive, mark unread, stop, persisted thread tabs round-trip, diff panel, and settings/machines/provider screens all pass with zero console errors

@SawyerHood
SawyerHood force-pushed the bb/bb-workflow-skill-check-thr_e4mkfam5y5 branch from 8b4cab8 to 8cb891e Compare July 16, 2026 13:45
SawyerHood and others added 4 commits July 16, 2026 06:47
…check-thr_e4mkfam5y5

# Conflicts:
#	packages/plugin-sdk/bundled-types/bb-plugin-sdk.d.ts
#	packages/sdk/src/areas/projects.ts
#	packages/templates/src/generated/plugin-sdk-dts.generated.ts
…gnal on thread mutations

Parse tabs.get bodies with threadTabsResponseSchema like tabs.update already
does, and split ThreadActionArgs/ThreadInteractionTargetArgs from the
signal-bearing read args (mirroring EnvironmentActionArgs) so mutation
methods no longer accept a signal they never forward.

Co-Authored-By: Claude Fable 5 <[email protected]>
@SawyerHood
SawyerHood merged commit 3d6a61a into main Jul 17, 2026
10 checks passed
@SawyerHood
SawyerHood deleted the bb/bb-workflow-skill-check-thr_e4mkfam5y5 branch July 17, 2026 05:09
ymichael added a commit that referenced this pull request Sep 19, 2026
…3944)

## Human comments

## What was wrong

Reported on Discord: an agent mentions a filename in inline code, bb
auto-links it, and clicking a file that is not in the workspace opens a
preview panel that says `Failed to load file` and nothing else — no
reason, for any kind of failure.

Two independent defects landed on the same blank message.

**Server.** `GET /environments/:id/diff/file` called `host.read_file`
directly and never translated the daemon's error, so a missing file
surfaced as `502 ENOENT` rather than the 404 every `/files/*` route
already returns. The remap lives inside `serveDaemonFileContent`, which
every route returning a `Response` uses and therefore gets for free;
this route returns JSON, builds its own call, and so silently opted out.
It has never had the remap since the route was added in f7d3397
(2026-05-11).

**App.** `resolveSecondaryPanelFilePreviewState` classified not-found
with `error instanceof HttpError && error.status === 404`. That was
correct when written, but #739 (3d6a61a) moved these queries onto the
typed SDK, which throws `BbHttpError` — structurally identical,
different class, so `instanceof` silently answers `false` and never
type-errors. The not-found branch became unreachable and every failure
fell through to a branch that discarded the message.

That second defect is a real regression the report did not mention. For
the workspace preview the symptom was unchanged, because the server was
already returning 502 — but **project file previews** hit a route that
does return a genuine 404, so they showed `File not found.` before
2026-07-16 and `Failed to load file` after. Host file previews regressed
the same way in #2005 (9768d55, 2026-08-20). Thread-storage previews
still fetch through `api.*`, which is why this stayed invisible.

## What changed

- `apps/server/src/routes/environments.ts` —
`.catch(remapDaemonFileRouteError)` on the `diff/file` read. Missing
file → 404, oversized → 413, bad path → 400. No wire change; the daemon
protocol is untouched.
- `apps/app/src/lib/http-error.ts` (new) — `asHttpError` /
`getHttpErrorMessage`, covering both `HttpError` and `BbHttpError`.
`mutation-errors.ts` had a private copy of the message logic and now
imports this one instead (net −20 lines there).
- `apps/app/src/components/secondary-panel/ThreadStorageFilePreview.tsx`
— the 404 check and the message extraction both go through the shared
helpers, so the preview reports the server's reason when there is one
and keeps `Failed to load file` only as a true fallback.
- `apps/app/src/components/secondary-panel/FilePreview.tsx` — `"Preview
not available for <mime>."` moves to a new `unsupported` state. It had
been riding on `kind: "error"`, and the old code inferred `role="alert"`
from *whether a message existed*; once real errors carry messages, every
genuine failure would have silently stopped being announced to screen
readers.

On surfacing daemon text: with the server fix a missing file is a plain
404 and renders `File not found.`, so the daemon's path string no longer
reaches the UI at all. What remains surfaceable are server-authored
bodies (`file_too_large`, `invalid_path`, `host_unavailable`) describing
host-local state the user already owns. Path traversal was checked —
`path=/etc/passwd` resolves under the workspace root and 404s.

## How you verified

Reproduced first, on a built instance from this worktree with a project
checkout containing only `exists.md`. Before the change: `502
{"code":"ENOENT", ...}` and a bare `Failed to load file`. After, in the
running app:

| Click | Result |
| --- | --- |
| `does-not-exist.md` | `File not found.`, path shown in the header, no
`HTTP 404:` prefix |
| `too-big.md` (30 MB) | `File size 31457280 bytes exceeds the 25 MB
limit` |
| `exists.md` | renders normally |

Tests (fail before, pass after — confirmed by reverting `asHttpError` to
`HttpError`-only, which reproduces `expected 'HTTP 404: Path does not
exist: /works…' to be 'File not found.'`, the exact string the browser
showed):

- `apps/server/test/public/public-environments.test.ts` — 2 tests:
ENOENT → 404 with the daemon command asserted, oversized → 413.
- `apps/app/src/components/secondary-panel/FilePreview.test.tsx` — 6
tests across both error classes, the generic fallback, and the
`unsupported` state not being an alert.
- `FilePreview.stories.tsx` — rows for a failure with a reason and for
an unsupported type.

Commands: `turbo run typecheck lint test --filter='...[origin/main]'`.
Typecheck and lint clean (0 errors; the 191 app lint warnings are
pre-existing and none are in the touched lines). Nine
`@bb/integration-tests` and eight `@bb/server` files failed as 60s
timeouts under parallel load, across plugins, install scripts, event
pruning and shared ports — all unrelated to previews, and all pass when
re-run in isolation.

## Not addressed

bb auto-links any inline-code token ending in `.md` without checking it
exists. Confirmed, but deliberately left alone: checking would mean a
host round trip per filename mention during markdown render, and a file
the agent just deleted or is about to create is legitimately
mentionable. With the 404 remap in place a dead link now lands on a
clear `File not found.` Worth its own issue if we want
resolved-vs-unresolved link styling, ideally off a cached workspace
listing rather than a probe per token.

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant