Skip to content

File Editor (monaco-editor) cannot open thread storage for threads on a non-server machine: text files 404 and the tree is empty #3604

Closed

Description

@IlyaM

Summary

With the built-in File Editor (monaco-editor) plugin enabled, thread storage ($BB_THREAD_STORAGE) breaks for any thread running on an enrolled machine other than the server's. The File Editor is the Automatic opener for about 90 extensions, including .html, .md, .txt, .json, .log, and .diff. Every such file clicked in thread storage opens a tab showing HTTP 404: Path does not exist, and the editor's file tree shows thread storage as empty. The plugin looks up thread storage on the server's machine instead of the machine running the thread. BB core resolves the same files correctly: inline-vis renders them and the built-in preview loads them. Expected: the File Editor reads, lists, and saves thread-storage files on the thread's machine.

Versions and environment

  • bb 0.43.0 (npx bb-app), Linux. The server and one host daemon run on machine A.
  • Second enrolled machine B: persistent, provider manual, a Docker devcontainer running the host daemon. Its thread storage root is ~/.bb-machine/thread-storage/.
  • Worktree environment on machine B; provider claude-code 2.1.270. The provider is not involved.
  • File opener preferences at their default (Automatic).
  • Source checked at main cf51227e1135309a3c9c0baf5630be1ca7ba2714.

Steps to reproduce

  1. With a second machine enrolled and the File Editor plugin enabled, start a thread whose environment runs on machine B.
  2. In that thread, write a text file to thread storage:
    mkdir -p "$BB_THREAD_STORAGE/reports" && echo '<h1>hi</h1>' > "$BB_THREAD_STORAGE/reports/repro.html"
  3. Open reports/repro.html from the thread's storage in the thread panel. It opens in the File Editor, the Automatic opener for .html.

Equivalent API calls, run from inside the thread (same auth the app uses):

ENV=$(bb thread show "$BB_THREAD_ID" --json | jq -r .environment.id)
SRC="{\"kind\":\"thread-storage\",\"environmentId\":\"$ENV\",\"projectId\":null,\"threadId\":\"$BB_THREAD_ID\"}"

# BB core thread-storage route: 200
curl -s -o /dev/null -w '%{http_code}\n' \
  "$BB_SERVER_URL/api/v1/threads/$BB_THREAD_ID/thread-storage/files/reports/repro.html"

# File Editor read: 404
curl -s -X POST -H 'content-type: application/json' \
  "$BB_SERVER_URL/api/v1/plugins/monaco-editor/rpc/read" \
  -d "{\"path\":\"reports/repro.html\",\"source\":$SRC}"

# File Editor tree: empty, rooted at the server's data dir
curl -s -X POST -H 'content-type: application/json' \
  "$BB_SERVER_URL/api/v1/plugins/monaco-editor/rpc/tree" \
  -d "{\"source\":$SRC}"

Smallest case: all three are required: the thread runs on a non-server machine, the source is thread-storage, and the file opens with the File Editor. The extension and subdirectory do not matter within the claimed set; a top-level .txt fails the same way.

Did not reproduce with:

  • a thread whose environment runs on the server's machine (File Editor read succeeds);
  • a workspace source on the same machine-B thread (File Editor read and tree both succeed, on machine B);
  • a host source with an absolute path on machine B, from the same thread, even when that path is inside the thread's storage (File Editor read succeeds);
  • inline-vis source="thread-storage" or the built-in thread-storage preview (both render);
  • a .png attachment in the same thread storage (the File Editor does not claim images, so it opens in the built-in preview).

Expected vs actual

Actual, File Editor read (tab content):
HTTP 404: Path does not exist: <server data dir>/thread-storage/thr_…/reports/repro.html

Actual, File Editor tree:
{"ok":true,"result":{"root":"<server data dir>/thread-storage/thr_…","entries":[],"truncated":false}}

Actual, BB core route for the same file: HTTP 200, file content

GET /api/v1/threads/thr_…/thread-storage/location
{"hostId":"<machine B host id>","storageRootPath":"/home/<user>/.bb-machine/thread-storage/thr_…"}

Expected: File Editor read, tree, and write use the storage location above, on machine B.

The directory <server data dir>/thread-storage/thr_… does not exist on machine A. BB does not mirror thread storage between machines, so the plugin looks for files on a machine that never had them.

Evidence

Server log on machine A:

{"level":40,"component":"server","msg":"[plugin:monaco-editor] rpc read failed: HTTP 404: Path does not exist: <server data dir>/thread-storage/thr_…/reports/…html"}

bb plugin list shows the same error against [email protected].

Why it hits most thread-storage files by default. The File Editor claims every extension in its language table, and with no per-extension preference, a claiming plugin wins over the built-in preview:

  • app.slots.fileOpener({
    id: "monaco",
    title: "File Editor",
    extensions: CLAIMED_EXTENSIONS,
    component: MonacoFileOpener,
    });
  • export const CLAIMED_EXTENSIONS: readonly string[] = Object.keys(
    LANGUAGE_BY_EXTENSION,
    );
  • const extension = getFileExtension(args.path);
    if (extension === null) return OWNER_REPLACEMENT;
    const preference = args.preference?.[extension];
    if (preference === BUILT_IN_FILE_OPENER_PREFERENCE) {
    return OWNER_REPLACEMENT;
    }
    return resolveReplacement(
    args.registrations,
    (candidate) =>
    candidate.extensions.includes(extension) &&
    (preference === undefined ||
    buildFileOpenerRef(candidate) === preference),
    );

Cause, confirmed in source. The File Editor resolves a thread-storage source from the server's own dataDir and passes no hostId, so files.read, files.listPaths, and files.write all run on the server's machine.

  • threadStorageRoot() uses bb.sdk.system.config().dataDir:
    async function threadStorageRoot(): Promise<string> {
    const override = process.env.BB_THREAD_STORAGE;
    if (override && override.trim().length > 0) return path.resolve(override);
    const { dataDir } = await bb.sdk.system.config();
    return path.join(dataDir, "thread-storage");
    }
  • The thread-storage branch returns { path, rootPath } with no hostId:
    if (source.kind === "thread-storage") {
    if (source.threadId === null) {
    throw new Error("This thread-storage file has no thread");
    }
    const rootPath = path.join(await threadStorageRoot(), source.threadId);
    return { path: path.join(rootPath, filePath), rootPath };
    }
  • read, tree, and write all use this resolver:
    async read({ path: filePath, source }) {
    const target = await resolveTarget(source, filePath);
    const file = await bb.sdk.files.read(target);
    if (file.contentEncoding !== "utf8") {
    return {
    kind: "unsupported" as const,
    reason: "This file is not text",
    };
    }
    if (file.sizeBytes > MAX_EDITABLE_BYTES) {
    return {
    kind: "unsupported" as const,
    reason: `This file is too large to edit (${Math.round(file.sizeBytes / 1024 / 1024)} MB)`,
    };
    }
    return {
    kind: "text" as const,
    content: file.content,
    sha256: file.sha256,
    absolutePath: target.path,
    relativePath: relativeTo(target.rootPath, target.path),
    };
    },
    async tree({ source }) {
    const target = await resolveTarget(source, ".");
    const result = await bb.sdk.files.listPaths({
    path: target.rootPath,
    includeFiles: true,
    includeDirectories: true,
    includeHidden: true,
    limit: MAX_TREE_ENTRIES,
    ...(target.hostId !== undefined ? { hostId: target.hostId } : {}),
    });
    return {
    root: target.rootPath,
    entries: result.paths.map((entry) => ({
    path: entry.path,
    kind: entry.kind,
    })),
    truncated: result.truncated,
    };
    },
    async write({ path: filePath, source, content, expectedSha256 }) {
    const target = await resolveTarget(source, filePath);
    const result = await bb.sdk.files.write({
    ...target,
    content,
    contentEncoding: "utf8",
    expectedSha256,
    });
    return result.outcome === "written"
    ? { outcome: "written" as const, sha256: result.sha256 }
    : { outcome: "conflict" as const, currentSha256: result.currentSha256 };
    },

read and tree were exercised live. write was not. From the source it would target the server's machine too, so saving a new file could place it on machine A instead of the thread's machine; that outcome is unverified.

Other code already resolves this correctly:

  • The server computes storage from the thread host's session dataDir:
    export async function requireThreadStoragePath(
    deps: WorkSessionDeps,
    args: RequireThreadStoragePathArgs,
    ): Promise<string> {
    const session = getLatestSessionForHost(deps.db, { hostId: args.hostId });
    if (session === null) {
    throw new ApiError(
    502,
    "host_unavailable",
    "The host has no known storage location",
    false,
    );
    }
    return path.join(session.dataDir, "thread-storage", args.threadId);
    }
    export async function requireLiveThreadStoragePath(
    deps: WorkSessionDeps,
    args: RequireThreadStoragePathArgs,
    ): Promise<string> {
    const session = await ensureHostSessionReadyForWork(deps, {
    hostId: args.hostId,
    });
    return path.join(session.dataDir, "thread-storage", args.threadId);
    }
  • inline-vis uses bb.sdk.threads.storageLocation and passes its hostId:
    const storage = await bb.sdk.threads.storageLocation({ threadId });
  • The Docs opener does the same:

    bb/plugins/docs/server.ts

    Lines 1034 to 1049 in cf51227

    if (source.kind === "thread-storage") {
    if (!source.threadId) {
    throw new Error("Thread-storage files require a thread ID");
    }
    const relativePath = requireThreadStoragePath(filePath);
    const storage = await bb.sdk.threads.storageLocation({
    threadId: source.threadId,
    });
    if (!isAbsoluteHostPath(storage.storageRootPath)) {
    throw new Error("This thread has no absolute storage path");
    }
    const rootPath = normalizeHostRoot(storage.storageRootPath);
    return {
    path: hostPathApi(rootPath).join(rootPath, ...relativePath.split("/")),
    rootPath,
    hostId: storage.hostId,

Suggested fix

Not submitted as a change. Resolve thread-storage targets the way inline-vis and Docs do:

if (source.kind === "thread-storage") {
  if (source.threadId === null) {
    throw new Error("This thread-storage file has no thread");
  }
  const { hostId, storageRootPath } = await bb.sdk.threads.storageLocation({
    threadId: source.threadId,
  });
  return {
    path: path.join(storageRootPath, filePath),
    rootPath: storageRootPath,
    hostId,
  };
}

This drops threadStorageRoot(), including its process.env.BB_THREAD_STORAGE override. That override points at one thread's own directory, and the resolver then appended the thread id to it.

I checked the fix locally at cf51227. I added a server.test.ts using createFakePluginHost, modeled on plugins/inline-vis/server.test.ts. It stubs threads.storageLocation with a different host and asserts that read, tree, and write receive that host's hostId and storage root.

  • Without the change: 3 failed.
  • With the change: 3 passed, and the plugin's suite passes (37/37).

What you ruled out

Suggested priority and effort (optional): High. With the File Editor enabled and default opener settings, thread storage cannot be browsed or opened for most text files on any thread running on a second machine, and nothing indicates why. Workarounds exist but are not discoverable: inline-vis, "Open with built-in preview" on a timeline file link, or setting each extension to Built-in preview in Settings → File openers. No data loss was observed. Effort: low, a single resolver branch plus a test.

No public link to the bb thread or investigation report is available; the thread ran on a private instance.

AGENT GENERATED

Activity

  1. added theissue type on Sep 13, 2026
  2. added
    plugins
    remote
    confirmed-repro
    on Sep 13, 2026
  3. bb-slop-cop commented on Sep 13, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    Bug · Priority Medium · Effort Low. Applied labels: plugins, remote, confirmed-repro.

    Reproduction report: REPRODUCED, high root-cause confidence. The editor derives thread storage from server-local configuration and omits the owning host ID for read, tree, and save.

    Three routing regression tests failed on trusted main and again in a second clean checkout. PR #3605 fixes the resolver: all 37 tests and typecheck pass; 112 changed lines across two files. Verification covers RPC routing with SDK test doubles, not live two-machine UI or physical writes.

    AGENT GENERATED

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

    confirmed-repropluginsremote

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions