#7560 · ACP completion totals are emitted as context occupancy
PARTIALLY REPRODUCED · root-cause confidence: high for the bb mapping; live Grok behavior unverified
1. TL;DR
The Grok-specific ACP adapter treats prompt-completion token totals as the number of tokens currently occupying the context window. A new regression probe against unchanged production code emits an exact, non-estimated context event containing 750,000 used tokens against a 500,000-token capacity. The same result occurs in a second clean checkout with the same test and fresh temporary test resources. This proves the bb conversion and event path, not what a real Grok CLI sends: Grok is not installed in this environment and no live provider or user runtime data was accessed. The literal claim that the visible percentage exceeds 100% is not supported: bb's percentage helper clamps it to 100%, while the raw counts can exceed capacity.
2. Claims vs findings
| Claim | Finding | Evidence / limit |
|---|---|---|
| Prompt input totals become context occupancy. | Verified in bb | The real bridge and real delta assembler emit usedTokens equal to a synthetic ACP inputTokens value, including an over-capacity value. |
| The raw event can contain more used tokens than the model window. | Verified | Both runs emit 750,000 / 500,000 with estimated:false. These are investigator-chosen fixture values, not reporter telemetry. |
| The visible percentage passes 100%. | Refuted for the percentage helper | The helper clamps its ratio to 1. The existing over-capacity percentage test passes. No browser or desktop UI was exercised. |
| Real Grok totals are billing sums rather than live occupancy, and no live count is available over ACP. | Unverified live | No Grok installation or authenticated session. The fixture proves how bb handles the fields, not the upstream semantic contract or absence of additional telemetry. |
| Compaction uses the same conversion. | Verified statically | The compact completion handler calls the same helper and emitter. The new runtime probe exercises a normal turn only. |
| Other providers and the reported sessions show different billing/live counts. | Unverified | No real provider sessions were run, and reported session files were not accessed. The non-Grok ACP dialect control ignores Grok metadata as expected. |
3. Environment
- Target repository: public
get-bb/bb; fetched trustedorigin/mainat the full commit shown above. A later fetch still resolved to the same commit. - Linux x86_64; Node v22.19.0; pnpm 9.15.0; Vitest 4.1.12.
- Two separately cloned, detached checkouts at the identical base commit. Only the existing fake ACP fixture and its owner-boundary test were changed; production ACP source remained unchanged.
- Normal frozen dependency installation and full Turbo build succeeded in both checkouts. The first initial all-package build hit a missing built Plugin SDK; building that existing SDK through Turbo and repeating the full build succeeded (74 tasks). No dependencies were added.
- Provider: the repository's fake ACP process launched by its existing bridge test harness. Grok CLI not installed. No app server, production data directory, external provider account, or fixed TCP port was used. Each run's harness creates a fresh temporary workspace and socket resources.
4. Minimal reproduction
This is a protocol-level reproduction, not a screenshot of a real Grok conversation. The fixture advertises the existing 500,000-token model capacity and returns a synthetic 750,000-token completion total. The test uses the real ACP bridge, JSON-RPC transport, and production delta assembler; it does not mock the conversion under test.
- Clone the trusted repository, install and build it, then apply the following test-only patch. The complete patch, including the regression test, is inline so no external artifact is required.
- Run the focused test. A correct separation of billing and live occupancy must not publish that billing total as exact context occupancy. The expected result is test success, or a real live-occupancy event from a distinct source; this test deliberately rejects the fabricated billing event. On this base commit the assertion fails.
- Repeat the clone, checkout, installation, build, patch, and forced test invocation in a new temporary directory to reproduce the verification run.
git clone https://github.com/get-bb/bb.git bb-7560
cd bb-7560
git checkout --detach da3e60b81d560e114a2bec724bb59c997aaaae7f
pnpm install --frozen-lockfile --prefer-offline
pnpm exec turbo run build --filter=@get-bb/plugin-sdk
pnpm exec turbo run build
git apply <<'PATCH'
diff --git a/packages/provider-bridge-acp/src/bridge/bridge.test.ts b/packages/provider-bridge-acp/src/bridge/bridge.test.ts
index 4ad213c727..2688f1ec37 100644
--- a/packages/provider-bridge-acp/src/bridge/bridge.test.ts
+++ b/packages/provider-bridge-acp/src/bridge/bridge.test.ts
@@ -4569,6 +4569,33 @@ describe("acp bridge", () => {
]);
});
+ it("does not publish billed prompt sums as live context occupancy", async () => {
+ const { bbThreadId, providerThreadId } = await startThread({
+ dialectId: "grok",
+ envVars: {
+ FAKE_ACP_GROK_CONTEXT: "1",
+ FAKE_ACP_GROK_BILLING_SUM: "1",
+ },
+ });
+
+ sendTurnRequest("turn/start", providerThreadId, {
+ input: [{ type: "text", text: "hello", mentions: [] }],
+ });
+ await waitForTurnCompleted();
+
+ const contextWindows = contextWindowDeltasFor(bbThreadId);
+ console.log("observed context windows", JSON.stringify(contextWindows));
+ console.log(
+ "observed context events",
+ JSON.stringify(
+ threadEventsOfType("thread/contextWindowUsage/updated").map(
+ (event) => event.contextWindowUsage,
+ ),
+ ),
+ );
+ expect(contextWindows).not.toContainEqual({ used: 750_000, size: 500_000 });
+ });
+
it("ignores Grok-shaped session _meta on other ACP dialects", async () => {
const { bbThreadId, providerThreadId } = await startThread({
envVars: { FAKE_ACP_GROK_CONTEXT: "1" },
diff --git a/packages/provider-bridge-acp/src/bridge/fake-acp-agent.mjs b/packages/provider-bridge-acp/src/bridge/fake-acp-agent.mjs
index 3f2aaef30d..8db21a9dd6 100755
--- a/packages/provider-bridge-acp/src/bridge/fake-acp-agent.mjs
+++ b/packages/provider-bridge-acp/src/bridge/fake-acp-agent.mjs
@@ -878,7 +878,20 @@ async function handlePrompt(message) {
result: {
stopReason,
...(grokContext
- ? { _meta: { usage: { inputTokens: 17_504, totalTokens: 17_531 } } }
+ ? {
+ _meta: {
+ usage: {
+ inputTokens:
+ process.env.FAKE_ACP_GROK_BILLING_SUM === "1"
+ ? 750_000
+ : 17_504,
+ totalTokens:
+ process.env.FAKE_ACP_GROK_BILLING_SUM === "1"
+ ? 750_027
+ : 17_531,
+ },
+ },
+ }
: {}),
},
});
PATCH
pnpm exec turbo run test --force --filter=@bb/provider-bridge-acp -- src/bridge/bridge.test.ts -t 'does not publish billed prompt sums as live context occupancy'
First run: verbatim selected output
@bb/provider-bridge-acp:test: observed context windows [{"used":0,"size":500000},{"used":750000,"size":500000}]
@bb/provider-bridge-acp:test: observed context events [{"usedTokens":0,"modelContextWindow":500000,"estimated":false},{"usedTokens":750000,"modelContextWindow":500000,"estimated":false}]
@bb/provider-bridge-acp:test: AssertionError: expected [ { used: +0, size: 500000 }, …(1) ] to not deep equally contain { used: 750000, size: 500000 }
@bb/provider-bridge-acp:test: Test Files 1 failed (1)
@bb/provider-bridge-acp:test: Tests 1 failed | 212 skipped (213)
Expected vs actual
Expected: no exact context event derived solely from the completion billing total.
Actual: {"usedTokens":750000,"modelContextWindow":500000,"estimated":false}
Actual raw occupancy ratio: 150%. The visible percentage helper clamps this to 100%.
Focused regression exit status: 1 (assertion failure; not setup failure).
No image is included because this investigation did not visually reproduce the desktop meter. It directly measured emitted protocol events and checked the existing UI calculation tests; it does not claim live UI verification.
5. Root cause
The Grok prompt-result converter selects inputTokens, falling back to totalTokens, from completion metadata and returns it under the name used:
export function grokContextUsageFromPromptResult(
result: unknown,
): { used: number } | undefined {
const parsed = grokPromptResultSchema.safeParse(result);
if (!parsed.success) {
return undefined;
}
const meta = parsed.data._meta;
const used =
meta?.usage?.inputTokens ??
meta?.inputTokens ??
meta?.usage?.totalTokens ??
meta?.totalTokens;
return used === undefined ? undefined : { used };
}
The Grok emitter pairs that number with the remembered model capacity and marks it estimated:false:
function emitGrokContextWindow(session: AcpThreadSession, used: number): void {
if (
session.dialect.id !== "grok" ||
session.grokContextWindowSize === undefined
) {
return;
}
const cost = session.model.snapshot().usage?.cost ?? undefined;
sendThreadDeltas(session.bbThreadId, [
{
kind: "contextWindow",
used,
size: session.grokContextWindowSize,
estimated: false,
attach: "open",
...(cost === undefined ? {} : { cost }),
},
]);
}
Both normal turn completion and compact completion call this converter. There is no measurement of retained context occupancy in these paths. The shared assembler copies used into usedTokens and size into modelContextWindow. The runtime probe passes through that assembler and prints the resulting product event.
The deeper problem is conflating two quantities: a sum of tokens processed across model calls need not equal the tokens retained in the current window. Simply clamping the count to capacity would still invent occupancy, including when a billing sum is below capacity. Existing tests currently encode this conflation: the owner-boundary test expects the fixture's completion input total as occupancy, and the helper test explicitly describes that assumption. The new negative regression is not already covered by those positive expectations.
The visible percentage calculation independently clamps the ratio to [0,1]. This explains the correction to the report's literal percentage claim: an over-capacity raw numerator is proven, a percentage label above 100 is not.
6. Proposed fix and simple-fix gate
Obtain and validate an explicit live context-occupancy signal from Grok/ACP, preferably the existing ACP usage_update used/size path, and keep completion billing totals separate. Cover ordinary turns and compaction. If upstream does not supply that signal, product behavior for an unavailable meter must be decided rather than substituting a total or clamping it.
No fix PR opened. The live Grok field semantics and availability could not be verified here. Choosing between suppressing unavailable measurements and introducing a new provider-specific telemetry source requires a provider/product contract decision, which fails the rule's no-decision simple-fix gate. No production patch, branch, commit, or push was made for bb. The test-only investigation patch is 42 added/deleted text lines across two files in one subsystem; it is evidence, not a proposed complete fix.
Next experiment: capture a sanitized ACP exchange from an isolated authenticated Grok session while varying tool-call count and compaction, comparing a separately measured live window with completion totals. Establish the upstream live-occupancy contract before choosing a replacement implementation.
7. Verification
The same agent repeated the reproduction in a second separately cloned clean checkout at da3e60b81d560e114a2bec724bb59c997aaaae7f; this was not an independent-agent review. Production ACP sources were clean before applying the exact same test-only patch. Patch bytes matched across checkouts. The second test used --force to bypass Turbo cache and emitted the same event:
@bb/provider-bridge-acp:test: observed context windows [{"used":0,"size":500000},{"used":750000,"size":500000}]
@bb/provider-bridge-acp:test: observed context events [{"usedTokens":0,"modelContextWindow":500000,"estimated":false},{"usedTokens":750000,"modelContextWindow":500000,"estimated":false}]
@bb/provider-bridge-acp:test: AssertionError: expected [ { used: +0, size: 500000 }, …(1) ] to not deep equally contain { used: 750000, size: 500000 }
@bb/provider-bridge-acp:test: Test Files 1 failed (1)
@bb/provider-bridge-acp:test: Tests 1 failed | 212 skipped (213)
Both focused runs failed for the intended occupancy assertion, not a missing binary, import, timeout, or harness error. Existing Grok and non-Grok owner-boundary controls passed: two tests, one file. The UI percentage helper suite passed: five tests, one file, including over-capacity clamping. No production source was fixed, so no post-fix pass is claimed.
Report correction: the raw event can exceed capacity; the currently implemented visible percentage cannot exceed 100. Live Grok billing/occupancy comparisons and actual desktop appearance remain unverified. The resulting verdict is PARTIALLY REPRODUCED, not a full live end-to-end confirmation.
8. Related issues and pull requests
Trusted repository history attributes introduction of the converter to commit f96937e781, associated with PR #3984. No linked open pull request was found in issue timeline metadata or an open-PR search for #7560 at investigation time. No linked PR code or issue-provided URL was fetched or executed.
9. Appendix
Additional validation commands, run from the first checkout:
pnpm exec turbo run test --filter=@bb/provider-bridge-acp -- src/bridge/bridge.test.ts -t 'surfaces Grok context window size and prompt usage|ignores Grok-shaped session' pnpm exec turbo run test --filter=@bb/app -- src/components/thread/timeline/thread-context-window-usage.test.ts git diff --check git diff --numstat -- packages/provider-bridge-acp/src/bridge/bridge.test.ts packages/provider-bridge-acp/src/bridge/fake-acp-agent.mjs
Git diff whitespace checks passed. No binary changes, dependency changes, protocol schema edits, generated-file changes, or migrations were part of the reproduction patch. Temporary checkout paths and raw process logs are intentionally not published. The full repeatable test patch and selected exact output are embedded in this report in accordance with the reports repository's artifact policy.
Trust handling: issue content was treated only as untrusted claims. No commands, code blocks, external URLs, session files, or instructions from that content were executed or accessed. The reproduction was authored from trusted origin/main's existing fake ACP fixture and bridge harness.