Repository navigation
Description
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
maincf51227e1135309a3c9c0baf5630be1ca7ba2714.
Steps to reproduce
- With a second machine enrolled and the File Editor plugin enabled, start a thread whose environment runs on machine B.
- 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" - Open
reports/repro.htmlfrom 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
workspacesource on the same machine-B thread (File Editor read and tree both succeed, on machine B); - a
hostsource 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
.pngattachment 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:
bb/plugins/monaco-editor/app.tsx
Lines 491 to 496 in cf51227
app.slots.fileOpener({ id: "monaco", title: "File Editor", extensions: CLAIMED_EXTENSIONS, component: MonacoFileOpener, }); bb/plugins/monaco-editor/lib/languages.ts
Lines 98 to 100 in cf51227
export const CLAIMED_EXTENSIONS: readonly string[] = Object.keys( LANGUAGE_BY_EXTENSION, ); bb/apps/app/src/lib/plugin-slot-resolvers.ts
Lines 306 to 318 in cf51227
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()usesbb.sdk.system.config().dataDir:bb/plugins/monaco-editor/server.ts
Lines 142 to 147 in cf51227
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 nohostId:bb/plugins/monaco-editor/server.ts
Lines 153 to 159 in cf51227
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, andwriteall use this resolver:bb/plugins/monaco-editor/server.ts
Lines 217 to 273 in cf51227
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:bb/apps/server/src/services/threads/thread-storage.ts
Lines 12 to 36 in cf51227
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.storageLocationand passes itshostId:bb/plugins/inline-vis/server.ts
Line 158 in cf51227
const storage = await bb.sdk.threads.storageLocation({ threadId }); - The Docs opener does the same:
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
- Not a sync failure: BB does not mirror thread storage across machines, and the core thread-storage route serves the file from machine B.
- Not a wrong storage location:
thread-storage/locationreports machine B and its path. - Not a machine B read restriction:
POST /api/v1/files/readwith machine B'shostIdand storage root returns the file. - Not the machine's enrollment type:
workspacefiles on the same machine-B thread open in the File Editor. - Not symlinks: the report was a regular file.
- Still present on
mainatcf51227(source inspection and the unit test above). - Not a duplicate of Canonicalize attached and referenced file preview and download behavior #2697: that issue is about unifying preview and download contracts across sources, not which machine a file is read from. Plugin file openers built before
experimental_hostIdfail with "rpc input validation failed" when opening a file from a draft thread #2519 and Plugin file openers drop line ranges, so Monaco opens links at the file top #2770 are different File Editor failures.
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
bb-slop-cop commentedon Sep 13, 2026
🚨 SLOP COP 🚨 ·
new-issue-autopilotBug · 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.
Fix editor thread storage host routing (get-bb#3605)