Repository navigation
Conversation
Clicking an auto-linked file that is missing from the workspace showed a bare "Failed to load file" with no reason. Two independent causes: - `GET /environments/:id/diff/file` called `host.read_file` without `remapDaemonFileRouteError`, so a daemon ENOENT surfaced as 502 rather than the 404 every `/files/*` route already returns. Oversized reads had the same problem and now return 413. - The preview state mapper only recognised 404 on `HttpError`, but this preview is fetched through the typed SDK, which throws `BbHttpError`. The not-found branch could never match for workspace previews, and the error branch dropped the message entirely. `asHttpError`/`getHttpErrorMessage` now live in `lib/http-error.ts` and cover both HTTP error classes; `mutation-errors.ts` loses its private copy. The preview mapper reports the server's reason when it has one, and "Preview not available for <mime>." moves to a new `unsupported` state so only real failures are announced as alerts. Verified in the running app: the missing file now shows "File not found." with its path, and the raw daemon message no longer reaches the UI at all. Co-Authored-By: Claude Opus 5 <[email protected]>
ymichael
deleted the
bb/file-preview-shows-failed-to-load-file-with-no-r-thr_ebwu27jpbd
branch
September 19, 2026 07:36
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.
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 fileand nothing else — no reason, for any kind of failure.Two independent defects landed on the same blank message.
Server.
GET /environments/:id/diff/filecalledhost.read_filedirectly and never translated the daemon's error, so a missing file surfaced as502 ENOENTrather than the 404 every/files/*route already returns. The remap lives insideserveDaemonFileContent, which every route returning aResponseuses 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.
resolveSecondaryPanelFilePreviewStateclassified not-found witherror instanceof HttpError && error.status === 404. That was correct when written, but #739 (3d6a61a) moved these queries onto the typed SDK, which throwsBbHttpError— structurally identical, different class, soinstanceofsilently answersfalseand 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 andFailed to load fileafter. Host file previews regressed the same way in #2005 (9768d55, 2026-08-20). Thread-storage previews still fetch throughapi.*, which is why this stayed invisible.What changed
apps/server/src/routes/environments.ts—.catch(remapDaemonFileRouteError)on thediff/fileread. 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 bothHttpErrorandBbHttpError.mutation-errors.tshad 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 keepsFailed to load fileonly as a true fallback.apps/app/src/components/secondary-panel/FilePreview.tsx—"Preview not available for <mime>."moves to a newunsupportedstate. It had been riding onkind: "error", and the old code inferredrole="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/passwdresolves 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 bareFailed to load file. After, in the running app:does-not-exist.mdFile not found., path shown in the header, noHTTP 404:prefixtoo-big.md(30 MB)File size 31457280 bytes exceeds the 25 MB limitexists.mdTests (fail before, pass after — confirmed by reverting
asHttpErrortoHttpError-only, which reproducesexpected '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 theunsupportedstate 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-testsand eight@bb/serverfiles 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
.mdwithout 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 clearFile 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.🤖 Generated with Claude Code