Skip to content

Fix Claude conversations blocked by automatic context reporting - #5914

Merged
ymichael merged 3 commits into
mainfrom
bb/explain-thread-thr-3wbmnrdpap-thr_qqz2dhpxud
Oct 20, 2026
Merged

ymichael merged 3 commits into
mainfrom
bb/explain-thread-thr-3wbmnrdpap-thr_qqz2dhpxud

Conversation

@ymichael

@ymichael ymichael commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Automatic Claude context reports ran on the same Claude process that handles user prompts. A stalled token-count request could block that process from consuming the next prompt. BB's five-second report timeout only stopped waiting for the result; it did not cancel the underlying request, so the conversation could remain stuck until manually stopped.

What changed

Keep automatic context breakdowns, but collect them in a separate, non-persisted fork of the saved conversation. The reporter has its own MCP server, disables hooks, and cannot execute tools. A five-second deadline, replacement report, or thread stop closes the reporter. User prompts continue on the live process without waiting for reporting or restarting the conversation.

Remove the live session's context-report method, document the isolation behavior in the provider skill, and keep diagnostic forks from consuming conversation segments in the replay harness. No server/daemon wire contracts change.

How you verified

  • pnpm exec turbo run test typecheck lint --filter=bb-plugin-provider-claude-code — 398 tests passed; typecheck and lint passed.
  • pnpm exec turbo run test typecheck lint --filter=@bb/provider-bridge-protocol — all 314 tests passed, including replay and cross-provider permission contracts; typecheck and lint passed. The permission fixture distinguishes diagnostic forks from the live session.
  • Claude provider parity against the unchanged baseline with an empty allowlist — 13 passed, 0 failed, 1 skipped (model-list).
  • Added a regression proving a blocked automatic report does not stop a follow-up prompt on the same live session, and that replacement/stop closes reporters. The regression fails against the unchanged baseline. The timeout test verifies cancellation after five seconds.
  • Exercised the actual Claude CLI with a local HTTP fixture: user turns completed while token-count requests hung; successful reports still published automatically. Verified that the reporter reads saved history without changing the original transcript or persisting a fork.

AGENT GENERATED

@ymichael
ymichael merged commit 3db407d into main Oct 20, 2026
86 of 87 checks passed
@ymichael
ymichael deleted the bb/explain-thread-thr-3wbmnrdpap-thr_qqz2dhpxud branch October 20, 2026 21:37
ymichael added a commit that referenced this pull request Nov 16, 2026
## Human comments

## What was wrong

bb starts two short-lived Claude Code processes to read session
metadata: the initialization probe
(`plugins/provider-claude-code/src/bridge/initialization-probe.ts:41`)
and the isolated context-usage probe
(`plugins/provider-claude-code/src/bridge/context-usage-probe.ts:26`).
Both load `settingSources: ["user", "project", "local"]` and do not
restrict MCP. So each probe connected to every user, project and plugin
MCP server, and then closed about 1 s later while MCP discovery was
still in progress. The context probe runs at the start of every turn, so
MCP servers saw a dropped connection on every turn (#6655,
[report](https://get-bb.github.io/reports/issues/6655.html)).

## What changed

- `initialization-probe.ts`: adds `strictMcpConfig: true`. The probe
passes no `mcpServers`, so the CLI starts no MCP server.
`probeClaudeUsage` shares this code path.
- `context-usage-probe.ts`: adds `strictMcpConfig: true`. When the
thread has dynamic tools, the bb bridge server is still passed through
`mcpServers`, so those tools are still loaded and counted.
- `__tests__/probe-mcp-isolation.test.ts` (new): with a mocked SDK
`query`, checks that both probes set `strictMcpConfig` and pass no MCP
server except the bb bridge.

In `@anthropic-ai/[email protected]`, `strictMcpConfig` maps to
`--strict-mcp-config`: the CLI uses only the servers given in
`mcpServers` and ignores `.mcp.json`, user settings, plugins and agent
frontmatter (`sdk.d.ts:2403`).

No wire, protocol, CLI or doc change.

Difference from the issue: the issue also suggests reading context usage
from the live session or caching it. #5914 moved away from the live
session because it blocked conversations, so that is not part of this
PR.

## How you verified

- Before the fix (new test on the old probes): `AssertionError: expected
{ cwd: '/tmp/probe', env: {}, ...(3) } to match object {
strictMcpConfig: true }`, 2 of 2 tests fail.
- After the fix: `pnpm exec turbo run lint lint:type-aware typecheck
test --filter=bb-plugin-provider-claude-code` passes, 11 of 11 tasks, 31
test files, 444 tests, 0 lint warnings. `oxfmt --check` passes.
- Real SDK and bundled CLI (Linux x64, outside the repo, temporary HOME
with a user-scope HTTP MCP server on loopback and a fake `count_tokens`
endpoint):
- Old code: both probes connected to the MCP server on every run (`POST
/mcp` twice per probe). Across 10 context-probe runs, the user MCP tool
was reported with 0 tokens and `isLoaded: false` at most, and
`totalTokens` was 1648 every time.
- New code, 3 runs each: 0 MCP requests from either probe. The probes
still returned 5 models, 44 commands and `totalTokens` 1648. With
dynamic tools, `mcp__bb-bridge__probe_tool` was still listed.
- Not verified: macOS, `headersHelper`, a real Anthropic account, and a
run through the bb UI. With a real account, a fast MCP server could in
theory answer before `getContextUsage` and add its tool tokens to the
old number. The new number never includes user MCP tools. No such count
was seen in the runs above.

Fixes #6655

> AGENT GENERATED

---------

Co-authored-by: Michael Yong <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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