Skip to content

Docs opener resolves host sources against the primary host, not the thread's machine: 502 on server-only deployments, wrong-machine reads and writes elsewhere #4480

Closed

Description

@trotterdylan

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, environment env_uixze5d4kp (provider project-checkout, path /workspace/bb-dylan), thread thr_dkt5amz3xa, project proj_mdanshc55w.
  • Docs plugin enabled, file opener preferences at their default (Automatic).
  • Source verified at main b23150d88ecc42bcd0e8f96386be0db23f0b1fe4; all files cited below are identical between that commit and the branch under test.

Steps to reproduce

  1. Use a deployment whose threads run on a remote machine and whose server has no primary host daemon.
  2. In a thread whose workspace root is /workspace/bb-dylan, have the agent emit a Markdown link to an absolute .md path 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.
  3. Click the link.

Did not reproduce with:

  • a link inside the workspace root — that takes the workspace bucket, whose source carries environmentId and is resolved to environment.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

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/createPreview accept an environmentId, 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 projectHostId injection at file-opener-tabs.ts#L169-L181 to cover kind: "host" sources, so experimental_hostId is 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

AGENT GENERATED — bb thread thr_dkt5amz3xa

Activity

  1. added theissue type on Sep 30, 2026
  2. added
    plugins
    host
    docs
    partial-repro
    on Sep 30, 2026
  3. SawyerHood commented on Sep 30, 2026

    @SawyerHood
    Collaborator

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docshostpartial-reproplugins

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions