Repository navigation
Description
Summary
Clicking an absolute file path in a thread message opens a host-file-preview tab. When the extension is claimed by a plugin fileOpener — the in-tree Docs plugin claims md/mdx/markdown — the open is routed through the plugin instead of the built-in viewer, and the Docs plugin's kind: "host" branch ignores the environmentId on the source. It resolves no host at all, so files.read falls back to the server's primary host.
On a deployment with no primary host daemon (bb server in Kubernetes, all work on machine-provider machines) the tab renders HTTP 502: Local host daemon is not initialized. On a deployment that does have a primary host there is no error: the file is read, and saveOpenedFile writes, on the primary host instead of on the thread's machine.
The sibling File Editor (monaco-editor) plugin already resolves the same source correctly, one line of its resolver apart. Docs is the only in-tree opener with the bug.
Versions and environment
- bb 0.44.0, server deployed in Kubernetes; no local host daemon, so no primary host.
- Threads run on machines from the kubernetes machine provider. Host
host_tu7swxphm7, environmentenv_uixze5d4kp(providerproject-checkout, path/workspace/bb-dylan), threadthr_dkt5amz3xa, projectproj_mdanshc55w. - Docs plugin enabled, file opener preferences at their default (Automatic).
- Source verified at
mainb23150d88ecc42bcd0e8f96386be0db23f0b1fe4; all files cited below are identical between that commit and the branch under test.
Steps to reproduce
- Use a deployment whose threads run on a remote machine and whose server has no primary host daemon.
- In a thread whose workspace root is
/workspace/bb-dylan, have the agent emit a Markdown link to an absolute.mdpath outside the workspace root and outside thread storage — e.g. a sibling checkout on the same machine,/workspace/bb-plugins/plugins/multi-repo/DESIGN.md. - Click the link.
Did not reproduce with:
- a link inside the workspace root — that takes the workspace bucket, whose source carries
environmentIdand is resolved toenvironment.hostId; - the same host path with the Docs opener disabled (built-in viewer resolves the host server-side from the thread's environment);
- the File Editor plugin as the opener for the same host path — its resolver reads
environment.hostId(see Evidence).
Expected vs actual
Actual, in the file tab:
HTTP 502: Local host daemon is not initialized
Expected: the file opens, read from the thread's machine (host_tu7swxphm7).
On a deployment WITH a primary host, actual is worse and silent: the read, and
saveOpenedFile's write, target the primary host's filesystem instead of the
thread's machine. No error is surfaced.
Evidence
1. The link is classified as a host path. thread-local-file-links.ts#L142-L188 tries the workspace root, then the thread-storage root, then falls through to open-host-path. A sibling checkout is neither.
2. The tab is created with hostId: null. For a chat-link open request.hostId is undefined, so the tab is scoped to the thread/environment instead — useThreadFileTabs.ts#L342-L358, and the plugin-side equivalent at file-opener-tabs.ts#L219-L239 with an explicit hostId: null.
3. A plugin opener claims the tab first. useThreadFileTabs.ts#L632-L654 tries createFileOpenerTabForRequest before the built-in tab; with no per-extension preference a claiming plugin wins (plugin-slot-resolvers.ts#L317-L329); Docs claims md/mdx/markdown (plugins/docs/app.tsx#L2416-L2421).
4. The source omits experimental_hostId. file-opener-tabs.ts#L270-L283 spreads it in only when owner.hostId !== null, which is never true for a chat-link open. The projectHostId injection just above (#L169-L181) only patches kind: "workspace" sources with a projectId. The source does still carry environmentId.
5. Docs ignores that environmentId on host sources. plugins/docs/server.ts#L1076-L1093:
if (source.kind === "host") {
if (!isAbsoluteHostPath(filePath)) throw new Error("Host file paths must be absolute");
const normalized = normalizeHostRoot(filePath);
const pathApi = path.win32.isAbsolute(normalized) ? path.win32 : path.posix;
return {
path: normalized,
rootPath: pathApi.dirname(normalized),
hostId: source.experimental_hostId ?? null, // <-- environmentId dropped
};
}
if (source.kind === "workspace" && source.environmentId) {
const environment = await bb.sdk.environments.get({ environmentId: source.environmentId });
...
return { path: ..., rootPath: environment.path, hostId: environment.hostId };
}The workspace branch directly below resolves the environment to a host; the host branch does not. Docs' thread-storage branch is also correct (it resolves via threadId) — host is the only wrong one.
6. The host is then dropped from the request and the server falls back to primary. hostIdArgs(null) returns {} (server.ts#L594-L596), so openFile (#L1957-L1970) and saveOpenedFile (#L1981-L1996) call files.read / .createPreview / .write with no host. Then routes/files.ts#L166-L170:
const resolved = hostId ?? requirePrimaryHostId(deps);requirePrimaryHostId throws ApiError(502, "host_unavailable", "Local host daemon is not initialized") (primary-host.ts#L22-L28) when there is no primary host, and silently returns the wrong host when there is one.
7. The File Editor plugin already does this correctly — plugins/monaco-editor/server.ts#L182-L196 resolves the environment before branching, and its host branch uses environment.hostId:
if (source.environmentId === null) {
throw new Error("This file has no environment to resolve it against");
}
const environment = await bb.sdk.environments.get({ environmentId: source.environmentId });
if (source.kind === "host") {
const api = path.win32.isAbsolute(filePath) ? path.win32 : path.posix;
return {
path: filePath,
rootPath: api.dirname(filePath),
...(environment.hostId ? { hostId: environment.hostId } : {}),
};
}8. This also contradicts the documented SDK contract — app-contract.ts#L455-L471 says host paths "are absolute on the thread's host."
What you ruled out
- Not File Editor (monaco-editor) cannot open thread storage for threads on a non-server machine: text files 404 and the tree is empty #3604 ("File Editor cannot open thread storage for threads on a non-server machine", closed 2026-09-14). Same class of bug — a plugin opener resolving a file on the server's machine instead of the thread's — but a different plugin (monaco-editor, not Docs), a different source kind (
thread-storage, nothost), and a different mechanism (itsthreadStorageRoot()used the server'sdataDir; here the host is simply never resolved). File Editor (monaco-editor) cannot open thread storage for threads on a non-server machine: text files 404 and the tree is empty #3604's "did not reproduce" list explicitly records that ahostsource worked for the File Editor, which matches evidence item 7. That fix did not touch Docs. Worth citing as precedent for the fix shape. - Not Plugin file openers built before
experimental_hostIdfail with "rpc input validation failed" when opening a file from a draft thread #2519 ("Plugin file openers built beforeexperimental_hostIdfail with rpc input validation failed"). That is about bb sending the field to openers whose strict schema rejects it, on the draft-thread/project-routed path. This is the inverse: bb omits the field on a route where it knows the environment, and the opener never resolves a host. Both do point at the same underspecified area ofPluginFileOpenerSource. - Not ThreadChat drops local-file link routing on full-page plugin routes: inline-code file mentions, @thread mentions, and workspace-relative images render dead #4466 / Relative markdown links in plugin-embedded ThreadChat open as broken URLs against the app origin #4438. Those are link routing in
ThreadChaton plugin surfaces — links never become links. Here routing works correctly and the resulting open fails server-side. - Not a path or permission problem. The file is readable on the thread's machine; the built-in viewer opens the same absolute path fine, and the same host path opens fine under the File Editor.
- Not fork-local. All cited files are byte-identical to
origin/mainatb23150d88e.
Suggested fix
Minimal, local to the plugin — make the host branch in plugins/docs/server.ts mirror the workspace branch (or adopt the File Editor's resolve-environment-first shape):
if (source.kind === "host") {
...
const hostId =
source.experimental_hostId ??
(source.environmentId
? (await bb.sdk.environments.get({ environmentId: source.environmentId })).hostId
: null);
return { path: normalized, rootPath: pathApi.dirname(normalized), hostId };
}That fixes the shipped plugin but leaves the hole open for third-party openers: the app knows the environment's host and simply does not pass it. Two broader options:
- Resolve host-side — let
files.read/write/createPreviewaccept anenvironmentId, so a plugin never has to translate an environment into a host. This is the variant that also retires the footgun for everyone. - Populate the field in the app — extend the
projectHostIdinjection atfile-opener-tabs.ts#L169-L181to coverkind: "host"sources, soexperimental_hostIdis always set when known.
Separately, the primary-host fallback at files.ts#L167 is a sharp default for a multi-machine deployment: silently reading and writing a different machine's filesystem when a caller omits the host is hard to notice. Rejecting the ambiguous case, or requiring an explicit opt-in, would fail loudly instead.
Possibly related, same hostId plumbing (happy to split out)
useThreadFileTabs.ts#L502-L527 rewrites any host-file-preview tab with threadId === null to attach the current thread/environment while preserving hostId. But the built-in thread renderer (ThreadDetailView.tsx#L2659-L2683) is purely thread-scoped and never reads tab.hostId, so a plugin-opened tab pinned to host A, once it lands in a thread panel, is read from the thread environment's host B. In the reverse direction, PluginPanelRightPanelHost.tsx#L912-L919 renders null for a tab with hostId === null — a blank panel. Not separately reproduced end-to-end; read from source.
Suggested priority and effort
Medium priority, low effort for the plugin-local fix. Affects every deployment where threads run on a machine other than the server's — a hard 502 when there is no primary host, and silent wrong-machine reads and writes when there is one. Workaround: set the file opener preference for md to the built-in preview, or link paths inside the workspace root.
Checks
- I reproduced this on the latest release or on
main(bb 0.44.0; source verified atmainb23150d88e). - I searched open and closed issues for the same problem. Searches run:
Local host daemon,host_unavailable,file opener,hostId,primary host,experimental_hostId,host-file-preview,docs plugin host,502 file preview. Overlaps addressed above: File Editor (monaco-editor) cannot open thread storage for threads on a non-server machine: text files 404 and the tree is empty #3604, Plugin file openers built beforeexperimental_hostIdfail with "rpc input validation failed" when opening a file from a draft thread #2519, ThreadChat drops local-file link routing on full-page plugin routes: inline-code file mentions, @thread mentions, and workspace-relative images render dead #4466. - Agent-written; thread linked below.
AGENT GENERATED — bb thread
thr_dkt5amz3xa
Activity
SawyerHood commentedon Sep 30, 2026
Verified report: https://get-bb.github.io/reports/issues/4480.html
PARTIALLY REPRODUCED in two clean checkouts at the same main SHA by the same agent. The real Docs RPC handlers omit the environment host; the synthetic primary/remote file fixture reads and edits the primary store. Explicit-host and workspace controls pass. Live HTTP/daemon/browser behavior and the reported 502 remain untested.
Resolve and open Markdown links in one place (get-bb#6756)
Make plugin surfaces prove they use core's path and delete plugin-onl…