Skip to content

Ship only SKILL.md frontmatter in the per-turn workspace agent-context read - #8119

Merged
ymichael merged 1 commit into
mainfrom
bb/per-turn-agent-context-skill-frontmatter-only-thr_jiws95vae4
Nov 24, 2026
Merged

ymichael merged 1 commit into
mainfrom
bb/per-turn-agent-context-skill-frontmatter-only-thr_jiws95vae4

Conversation

@ymichael

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Before every turn, and on every slash-menu open, the server makes one host.read_workspace_agent_context RPC. That RPC returned the full text of every project .bb/skills/*/SKILL.md, with a 32 MiB budget. The server only runs parseSkillMetadata on each file to get name and description. It then sends the skill to turn.submit as a workspace-path source, so the provider reads the file from disk itself. Every SKILL.md body made a daemon → server trip and was never used. On the bb repo (9 project skills) that comes to 73 KB per turn. This is finding #4 of the server → daemon RPC audit. I confirmed the call pattern in apps/server/src/services/threads/workspace-agent-context.ts and thread-runtime-config.ts before changing anything.

What changed

Wire change: HOST_DAEMON_PROTOCOL_VERSION 281 → 282.

  • host.read_workspace_agent_context:
    • The kind: "file" project skill entry now carries frontmatter instead of content.
    • projectSkillRead.maxContentBytes is renamed to maxFrontmatterBytes.
  • skillFrontmatterBlock(content) is new in @bb/skill-index/metadata, next to parseSkillMetadata. It returns the file only through its closing --- delimiter. Parsing that block gives the same result as parsing the whole file, because gray-matter's data and the opening-delimiter check depend only on text before the first \n--- after the opener. A file with no --- returns "" and gets the same "must start with a plain --- delimiter" error. An unterminated block returns the whole file, as before.
  • Daemon (command-handlers/workspace-agent-context.ts):
    • It still reads each SKILL.md under the same 10 MiB per-file limit and still reports oversized.
    • It returns only the frontmatter block.
    • The total budget now counts JSON-encoded frontmatter, not file bodies.
    • The daemon does no validation. That stays on the server, so the AGENTS.md boundary holds: the daemon returns raw host data and the server parses it.
  • Server: sends maxFrontmatterBytes: 4 MiB, which is about 1,000 skills × 4 KiB, instead of 32 MiB. It parses skill.frontmatter with the same resolveProjectSkillSourceFromContent. The budget-exceeded warning now names the frontmatter budget.
  • docs/debugging-and-qa.md ("Workspace Context Read Limits") describes the new policy.

Not done (from the report's optional steps): the per-(host, workspace) digest cache and daemon-pushed invalidation. The serial round trip before turn.submit remains; only its payload shrinks.

How you verified

Tests

  • packages/skill-index/test/metadata.test.ts (new): for 16 SKILL.md shapes, the block is a prefix of the file and parseSkillMetadata(block) deep-equals parseSkillMetadata(content). The shapes are plain, CRLF, BOM, ---yaml, an empty block, a ----- closer, a multiline description, unterminated, leading whitespace (closed and unclosed), no opener, no delimiter at all, a ---- opener, invalid YAML, --- only, and empty.
  • apps/host-daemon/.../workspace-agent-context.test.ts: asserts only frontmatter is returned. A new budget case gives each file a 5 KB body to show the body never counts against the budget.
  • Updated the contract fixture and version assertions, plus the server test fakes.
  • pnpm exec turbo run typecheck lint --filter=@bb/host-daemon --filter=@bb/server --filter=@bb/host-daemon-contract --filter=@bb/skill-index
  • turbo run test for @bb/skill-index, @bb/host-daemon (workspace-agent-context), @bb/host-daemon-contract, and @bb/server (thread-runtime-config, public-project-commands, skills/, public-project-workspace-routing).

Real servers, main (af25b0b5a6) vs this branch, same input

Setup:

  • Each build ran as pnpm start --perf-diagnostics on its own fresh data dir under thread storage, never ~/.bb.
  • Each had its local daemon plus a second enrolled daemon (daemon-bundle.mjs, separate data dir) behind a TCP proxy that adds 100 ms each way (200 ms RTT).
  • The proxy decodes WebSocket frames to count host-rpc.requests and response sizes per action.
  • Every project points at the same detached checkout of af25b0b5a6 (9 project skills, 70.6 KB of SKILL.md).
  • Actions: 20× GET /projects/:id/commands?provider=claude-code&hostId=… (slash menu), 1.5 s apart, and 8 real Claude Code (haiku) turns per host via POST /threads/:id/send. Turn timings come from the server's Turn trace log.
action host host RPCs per action (main → branch) agent-context response (main → branch) wall time median / p90 (main → branch)
turn send local 2 → 2 (read_workspace_agent_context, turn.submit) — agent-context RPC 6.7 / 10.4 → 5.5 / 7.4 ms; send → turn.submit sent 35.3 / 45.2 → 34.5 / 49.5 ms
turn send 200 ms RTT 2 → 2 73,022 → 3,331 B (−95%) agent-context RPC 212.9 / 238.9 → 214.9 / 218.1 ms; send → turn.submit sent 251.5 / 272.5 → 253.1 / 279.3 ms
slash menu local same as remote — 32.5 / 69.7 → 20.3 / 27.8 ms
slash menu 200 ms RTT 2 in 16/20 → 15/20 (list_commands, read_workspace_agent_context); plugin.host.call and provider.list_commands join on cache expiry, same on both 73,022 → 3,331 B 220.8 / 423.4 → 225.5 / 427.6 ms
  • Compressed sizes: the proxy connects over loopback, so the server declines WebSocket compression and the byte counts above are uncompressed. With the server's deflate level 1, the captured payloads are 29,078 B (main) and 1,404 B (branch).
  • Output parity:
    • The slash-menu response for the remote host is identical: 87 entries, deep-equal, including every project skill's description.
    • The turn.submit request is 19,755 B on both builds, so the agent gets the same skill sources.
  • Wall time doesn't change: the proxy adds latency, not a bandwidth limit, and the round trip is still serial. What this saves is ~70 KB of tunnel transfer (~28 KB compressed) per turn and per slash-menu open on this repo. It also caps skill-heavy repos at 4 MiB of frontmatter instead of 32 MiB of bodies, and the server no longer JSON-parses the bodies.

AGENT GENERATED

🤖 Generated with Claude Code

@ymichael
ymichael merged commit d12945e into main Nov 24, 2026
52 checks passed
@ymichael
ymichael deleted the bb/per-turn-agent-context-skill-frontmatter-only-thr_jiws95vae4 branch November 24, 2026 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant