Repository navigation
Reduce per-turn overhead with batched workspace reads and skill reuse - #5257
Merged
Merged
Conversation
Adds an opt-in turn trace, recorded only while performance diagnostics are permitted and the experiment is on. The server marks spans along the send path, times every daemon RPC the send awaits, and joins the daemon's own turn.submit spans (returned in the turn.submit result) with the first output batch at event ingest. One `Turn trace` log line per traced send. Bumps HOST_DAEMON_PROTOCOL_VERSION to 231 for the turn.submit result field. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Adds host.read_workspace_agent_context, which returns .bb/AGENTS.md, every .bb/skills/<dir>/SKILL.md, and the shared skills in one reply. The server's runtime configuration and the project command typeahead use it instead of host.list_files followed by batched host.read_file and host.list_skills, and keep assembling instructions and the skill catalog as before. Discovery matches what host.list_files returned: direct, non-hidden, non-symlink skill directories, read with the same workspace containment. SKILL.md files over 10 MB are reported as oversized and skipped with the existing warning, including files over the 25 MB read cap that previously failed the send. Bumps HOST_DAEMON_PROTOCOL_VERSION to 232. Co-Authored-By: Claude Opus 5.5 <[email protected]>
stageInjectedSkillSources re-read and re-hashed every skill tree and ran a full skill-store GC once per tree source on every turn. Collected trees are now remembered per source: tree sources by their content-addressed tree hash, host and workspace path sources by an lstat fingerprint of the skill directory (path, mode, size, inode, mtime, ctime), so an unchanged skill is neither read nor hashed again and an edited one is restaged on the next turn. File digests are computed once at collection. Store GC runs once per staging call that pulled from the store (and once per global skill install), in the background on the store's serial lane, instead of after every tree inside the turn. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
added a commit
that referenced
this pull request
Oct 9, 2026
## Human comments ## What was wrong The combined workspace-context reader introduced in #5257 could read up to 1,000 project skill files concurrently without an aggregate content budget. It also lost excluded-directory filtering and exact-case filename matching on case-insensitive filesystems, and checked containment only when reading individual files. Command lookup unnecessarily read `.bb/AGENTS.md`, allowing an invalid instructions file to break the command catalog. ## What changed - Keep the combined RPC and supply read policy from the server: 1,000 directories, 10 MiB per file, and **32 MiB total JSON-encoded project-skill content**. The aggregate allowance gives several large skills room while bounding retained content; it is a pragmatic starting policy, not a benchmark-derived optimum. Metadata, shared skill discovery, and workspace instructions are outside this content budget, so it is not a whole-response cap. - Read skill files sequentially into bounded buffers, account for JSON escaping, and skip over-budget content with server warnings. Smaller later files can still fit. - Restore excluded-directory filtering and exact-case `SKILL.md` matching. Check root containment before enumeration and file containment before reading; retain symlink skips. - Make instruction reads explicit: command lookup skips them, while turn preparation still reads instructions and reports errors. - Bump `HOST_DAEMON_PROTOCOL_VERSION` from 232 to 233 for required request fields and the budget-exceeded result variant; bump SDK declarations to 0.6.35. Document policy and budget scope in the debugging guide. ## How you verified - Four regression tests failed against the merged implementation for the intended reasons before the fixes: discovery filtering/case, encoded-content budgeting, escaping empty roots, and unnecessary instruction reads. - Focused Turbo tests passed: 8 daemon tests, 46 server tests, and 49 contract tests. Coverage includes encoded-size accounting, admitting smaller later skills, oversized files, symlinks, count limits, command lookup, and runtime configuration. - `pnpm exec turbo run test --filter=@bb/server --filter=@bb/host-daemon --filter=@bb/host-daemon-contract -- src/command-handlers/workspace-agent-context.test.ts test/public/public-project-commands.test.ts test/threads/thread-runtime-config.test.ts test/contract.test.ts` - `pnpm exec turbo run typecheck --filter=@bb/server --filter=@bb/host-daemon --filter=@bb/host-daemon-contract` - Formatting and `git diff --check` passed. No live UI or performance benchmark was run for this follow-up. > AGENT GENERATED Co-authored-by: qa <qa@x>
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
Every send on a warm thread repeated workspace-context RPCs, skill-file reads and hashing, and skill-store cleanup before the provider could start. This added avoidable latency, especially when the execution host was remote.
What changed
host.read_workspace_agent_context { rootPath, sharedSkillRoots }to gather workspace instructions, project skill files, and shared skill discovery in one daemon round trip. The server retains instruction assembly and skill-selection policy. This reduces requests, not file-content payloads: workspace instructions and project SKILL.md contents still return to the server every turn.HOST_DAEMON_PROTOCOL_VERSIONfrom 230 to 232 for the trace fields and new RPC. Bump the plugin SDK package to 0.6.34 because its generated declarations include the updated daemon contract. No database or thread/session lifecycle changes.Workspace context remains freshly read each turn. Watcher-based caching was dropped because delayed change events could let a queued follow-up miss a file edit. Resume-context deduplication was also dropped because measurements showed little benefit. Oversized project SKILL.md files above the old 25 MiB transport cap now receive the same skip-and-warn treatment as other files over the 10 MiB project skill limit, instead of failing the send.
How you verified
pnpm exec turbo run typecheck --filter=@bb/server --filter=@bb/host-daemon --filter=@bb/host-daemon-contractpassed (Turbo cache hits).pnpm exec turbo run test --filter=@bb/server --filter=@bb/host-daemon --filter=@bb/host-daemon-contract -- <changed test paths>passed: 149 server tests, 112 daemon tests (2 skipped), and 49 contract tests across 18 files. Coverage includes trace gating/joining, workspace discovery, skill reuse, in-place edits with unchanged size and mtime, dispatch, and runtime configuration.git diff --check origin/main...HEADpassed.Recorded implementation benchmarks used an instant echo provider, six project skills, workspace instructions, and 20 warm follow-ups per host. The remote daemon ran on an Intel Mac over a tailnet SSH reverse tunnel. These measure BB overhead; network jitter affects remote comparisons. Benchmarks were recorded during implementation and were not rerun while preparing this PR. These figures predate the CI correction that removed metadata-based caching for mutable host files, so they do not establish performance for the final revision. New-thread startup was not measured.