Repository navigation
Bound thread-storage listings and notify only the changed thread - #7089
Merged
ymichael merged 2 commits intoNov 5, 2026
Merged
Conversation
The daemon reported a thread-storage write as an environment change with only the environment id. The server broadcast it to every client, and the app refetched the storage lists of every cached thread in that environment. The daemon now sends thread-storage-change with the thread id (protocol 262). The server checks the thread belongs to the sending host and sends a thread-level storage-changed change to that thread's detail subscribers only, and the app refetches that thread's storage queries. The thread storage watch target no longer carries an environment id, and thread-storage-changed is no longer an environment change kind. Co-Authored-By: Claude Opus 5.5 <[email protected]>
host.list_files and host.list_paths without a query walked the whole tree and then kept the first limit + 1 entries. The walk now stops once it has limit + 1 paths, which is the same prefix in the same order, so results and truncation are unchanged. Queried listings still walk and cache the full tree for ranking. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
deleted the
bb/thread-storage-change-per-thread-thr_wxx5y5j3nk
branch
November 5, 2026 17:49
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
Perf audit finding #10 (thread-storage file list). Two separate costs:
1. Every unqueried listing walked the whole tree. The thread-storage panel asks for the first 1,000 files with no query (
apps/server/src/routes/threads/data.ts→host.list_files,limit: 1000). On the daemon,listHostFiles/listHostPathsalways calledlistWorkspacePaths, which walks the whole tree (11–17k files in real thread-storage dirs).finalizeListedPathsthen keeps onlylimit + 1entries. The full listing is cached only when the walk took ≥500 ms, so most refetches while an agent writes pay for the full walk again.2. Every storage write refetched the lists of every thread in the environment. When a file changed in a thread's storage, the daemon sent
environment-changewithchange: "thread-storage-changed"and only the environment id (apps/host-daemon/src/app.ts), although its watcher already knew the thread. The server broadcast that to every connected client. The app then refetched the storage queries of every cached thread in that environment (dirtyThreadStorageQueriesForEnvironment). So one agent writing reports or screenshots made every open thread in the same environment re-list its own storage, on every client.What changed
Bounded unqueried listings (daemon only). When a listing has no query, the walk stops once it has
limit + 1paths. The walk is depth-first inreaddirorder, so the bounded walk returns the same prefix in the same order as the full one, andtruncatedis unchanged. Queried listings still walk, cache and rank the full tree.The change is daemon-local: there are no wire changes, no
HOST_DAEMON_PROTOCOL_VERSIONbump and no plugin SDK change. The same path serves every unqueriedhost.list_files/host.list_pathscaller (workspace, project, environment, skills), and each gets identical results.The one part of finding #10 left out is always caching the full listing with watcher invalidation.
Thread-targeted storage notifications.
HOST_DAEMON_PROTOCOL_VERSION261 → 262): sends a newthread-storage-change { threadId }message.thread-storage-changedis removed from the daemon'senvironment-changekinds. The thread-storage watch target dropsenvironmentId, because this message was its only use.notifyDaemonThreadStorageChangechecks that the thread's environment belongs to the sending host and isn't destroyed. It then callshub.notifyThread(threadId, ["storage-changed"]).storage-changedis detail-only, likehistory-compacted, so it goes only to that thread'sthread-detailsubscribers and not to the thread list. It doesn't re-resolve watch targets.storage-changedthread rule (debounced) refetches that thread's storage files, paths and previews. The environment rule,collectCachedThreadIdsForEnvironmentand thegetCachedThreadIdsForEnvironmentcontext are deleted. A released thread-detail watch now catches up by re-marking that thread's storage, not the whole environment's.storage-changedis added toTHREAD_CHANGE_KINDSandthread-storage-changedis removed fromENVIRONMENT_CHANGE_KINDS. These unions are part of the plugin SDK's realtime types (ChangedMessage), so the SDK goes 0.6.124 → 0.6.125. In-repo, the git plugin listed the old kind only to keep its caches, and the github-pr-status test listed it as a no-op. Both are updated.Why the protocol bump and SDK change can't be avoided: the server can't tell from the environment id which thread's storage changed, so the daemon message needs the thread id. Clients can only be told which thread changed through the realtime change message type, and the plugin SDK publishes that type.
How you verified
Bounded listings
The benchmark calls
listHostFileswith the panel's exact command (limit: 1000,includeHidden: false,respectGitIgnore: false, default excludes) on the six largest real dirs in~/.bb/thread-storage. Each call runs in a fresh process, 5 runs per dir. Main and branch use the same checkout with only the daemon files swapped. Medians:Parity: the response hash (
files+truncated) matches main for every static dir. thr_272ubxihy7 is a live thread and its hash changes between runs on either build. Frozen copies of it and thr_cbwjth4yt7 give identical hashes on main and branch (8e315bfdd95a,d4f45e09ef0b).Tests: a new case in
workspace-path-list.test.tschecks that an unqueriedhost.list_pathsat a limit returns exactly the full walk's first entries withtruncated: true, reads fewer directories than the full walk, and returnstruncated: falsewhen the limit equals the tree size. Locallyworkspace-path-list.test.tsandfile-list.test.tspass (32 tests), and@bb/host-daemontypecheck passes. CI runs the full suites.Thread-targeted notifications
Real running servers, main vs branch. I ran source servers from origin/main and from this branch with
pnpm starton fresh data dirs, not a copy of~/.bb. Each had one project and two threads in one environment: A, where files are written, and B, the viewer. Three headless Chrome instances each held one foreground page on the real app: A with the right panel open, B with the right panel open, and home. I wrote 20 files into A's thread storage, one per second, and counted/thread-storage/filesrequests andstorage-changedWebSocket frames per page.Tests:
internal-environment-change.test.ts:thread-storage-changenotifies only the changed thread withstorage-changed, ignores the same message from another host, and never sends an environment change.realtime-cache-effects.test.ts: astorage-changedchange refetches the changed thread's storage preview and not a sibling thread's in the same environment.Commands:
pnpm exec turbo run typecheck --filter='...[origin/main]': 117/117turbo run linton the same filter: 57/57check-plugin-sdk-version.mjsCI runs the full suites.
🤖 Generated with Claude Code