#7790 · ACP command state exceeds the ingest byte budget
Verdict: REPRODUCED · Root-cause confidence: high · reproduction label: confirmed-repro
1. TL;DR
A long command list can disappear before it reaches the composer or CLI. The ACP bridge caps the number of commands, but not the serialized byte size of their descriptions. The server correctly enforces a separate 65,536-byte extension payload limit and replaces the entire oversized state event with a diagnostic. A fresh thread therefore has no provider command state to read. An integration reproduction constructed from trusted main reproduces this in two clean checkouts: 12 commands survive, while 192 commands produce a 155,424-byte state and zero visible commands.
2. Claims vs findings
| Claim | Status | Evidence |
|---|---|---|
| A list below the 500-command cap can still be lost. | Verified | 192 mapped commands become one 155,424-byte payload; the resulting timeline contains no commands. |
| The server rejects the whole state at 64 KiB. | Verified | Stored event is provider/unhandled, with payloadOmitted: true and reason payload is 155424 bytes; the limit is 65536. |
| A smaller list is accepted. | Verified | The same integration case with 12 commands passes in both clean checkouts. |
| Unchanged lists are not republished within a session. | Verified by source | publishThreadState caches the serialized payload before sending and skips an identical payload; no server acceptance acknowledgment controls that cache. |
| The reported installed version, operating system, custom agent, and exact 300-command payload exhibit the symptom. | Not rerun | No issue script or binary was executed. This report tests the trusted main mapping and real server ingestion/projection instead, using independently authored data. |
| An earlier desktop performance report has this exact cause. | Unverified | Similar oversized-payload diagnostics alone do not establish the extension kind or prove duplicate root cause. |
3. Environment
- Public repository
get-bb/bb, fetched from its own origin; trusted main502cf5ae9b61f050ac6d2a7a1b9060f18b339828. - Linux 4.19.0-gvisor; Node.js v22.19.0; pnpm 9.15.0; Vitest 4.1.12; workspace ACP bridge 0.0.1; locked ACP SDK 1.9.0.
- Two separate temporary source worktrees, named
baseandverify, at the same commit. Each harness creates a fresh migrated SQLite connection and a new temporary data directory, cleaned on completion. - In-process HTTP requests exercise the actual server routes. No TCP ports are opened, no production bb data is read, and no real agent is launched.
- Frozen installs completed. Full Turbo builds pass (74 tasks each). The first fresh build hit an unrelated SDK-output ordering failure; retry after the SDK build completed succeeds. No source repair was made for that build failure.
4. Minimal reproduction
- Create a clean checkout and verify its revision:
git clone https://github.com/get-bb/bb.git base cd base git checkout --detach 502cf5ae9b61f050ac6d2a7a1b9060f18b339828 pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build
- Save the independently authored test below as
apps/server/test/internal/issue-7790-provider-commands.test.ts. It calls the production ACP mapper, submits its output through the real internal event route, inspects the real SQLite event storage, and reads the public timeline route. The seeded provider identity is only a harness fixture: corebb/*state schemas are checked for every provider. - Run the focused reproduction through Turbo:
pnpm exec turbo run test --filter=@bb/server -- test/internal/issue-7790-provider-commands.test.ts
- Expected: both cases retain every advertised name. Actual: the 12-command control passes; the 192-command assertion fails with zero commands. The test deliberately exits nonzero on the defective main revision.
Complete reproducible test
import { eq } from "drizzle-orm";
import { events } from "@bb/db";
import { threadScope, THREAD_PROVIDER_COMMANDS_STATE_KIND } from "@bb/domain";
import { groupHostDaemonEvents } from "@bb/host-daemon-contract";
import { threadTimelineResponseSchema } from "@bb/server-contract";
import { describe, expect, it } from "vitest";
import { toThreadProviderCommandsState } from "../../../../packages/provider-bridge-acp/src/session/thread-state.js";
import { internalAuthHeaders } from "../helpers/commands.js";
import { readJson } from "../helpers/json.js";
import {
seedEnvironment,
seedHostSession,
seedProjectWithSource,
seedThread,
} from "../helpers/seed.js";
import { createTestAppHarness } from "../helpers/test-app.js";
describe("issue 7790: ACP command state reaches timeline readers", () => {
it.each([12, 192])("retains %i advertised commands", async (count) => {
const harness = await createTestAppHarness();
try {
const { host, session } = seedHostSession(harness.deps);
const { project } = seedProjectWithSource(harness.deps, {
hostId: host.id,
});
const environment = seedEnvironment(harness.deps, {
hostId: host.id,
projectId: project.id,
});
const thread = seedThread(harness.deps, {
projectId: project.id,
environmentId: environment.id,
providerId: "codex",
status: "active",
});
const advertised = Array.from({ length: count }, (_, index) => ({
name: `reference-${index}`,
description: "Detailed command documentation. ".repeat(24),
}));
const payload = toThreadProviderCommandsState(advertised);
const response = await harness.app.request("/internal/session/events", {
method: "POST",
headers: internalAuthHeaders(harness),
body: JSON.stringify({
sessionId: session.id,
eventGroups: groupHostDaemonEvents([
{
threadId: thread.id,
event: {
type: "thread/extensionState/updated",
threadId: thread.id,
providerThreadId: "repro-session",
scope: threadScope(),
kind: THREAD_PROVIDER_COMMANDS_STATE_KIND,
payload,
},
},
]),
}),
});
expect(response.status).toBe(200);
const timeline = threadTimelineResponseSchema.parse(
await readJson(
await harness.app.request(`/api/v1/threads/${thread.id}/timeline`),
),
);
const rows = harness.db
.select({ type: events.type, data: events.data })
.from(events)
.where(eq(events.threadId, thread.id))
.all();
console.log(
JSON.stringify({
count,
payloadBytes: Buffer.byteLength(JSON.stringify(payload)),
actualCommands: timeline.providerCommands?.length ?? 0,
storedTypes: rows.map((row) => row.type),
diagnostics: rows
.filter((row) => row.type === "provider/unhandled")
.map((row) => JSON.parse(row.data)),
}),
);
expect(timeline.providerCommands ?? []).toHaveLength(count);
expect(timeline.providerCommands?.map((command) => command.name)).toEqual(
advertised.map((command) => command.name),
);
} finally {
await harness.cleanup();
}
});
});
Observed output, first clean checkout (only the failed case's console output is displayed by the configured passed-only reporter):
{"count":192,"payloadBytes":155424,"actualCommands":0,"storedTypes":["provider/unhandled"],"diagnostics":[{"providerThreadId":"repro-session","providerId":"codex","rawType":"extension/state:bb/provider-commands","rawEvent":{"jsonrpc":"2.0","method":"thread/extensionState/updated","params":{"kind":"bb/provider-commands","payloadOmitted":true,"payloadBytes":155424,"reason":"payload is 155424 bytes; the limit is 65536"}}}]}
AssertionError: expected [] to have a length of 192 but got +0
Tests 1 failed | 1 passed (2)
The missing state does not imply command execution itself is broken. This test proves command advertisement loss at the data boundary; browser presentation and a standalone CLI invocation were not run.
5. Root cause
- ACP thread-state mapper, lines 14–31 filters blank names, takes up to 500 commands, and retains complete descriptions/input hints. There is no byte-budget step.
commands.filter((command) => command.name.trim() !== "") .slice(0, MAX_COMMANDS) .map((command) => ({ name: command.name, description: command.description, ... })) - Core command schema, lines 33–42 limits the array to 500, but description length is unrestricted. Thus a count-valid payload need not fit the server's independent byte constraint.
- Session snapshot publisher, lines 2959–2967 sends this mapped payload as
bb/provider-commands. Thread state publication cache, lines 2877–2894 records serialized state and suppresses identical updates. - Server byte budget defines
64 * 1024. Core state validation, lines 134–145 measuresBuffer.byteLength(JSON.stringify(site.payload))and rejects a larger payload, even when its command count is valid. - Ingest replacement, lines 209–241 replaces the event with
provider/unhandled; it does not retain a truncated command-state event. Command projection, lines 51–67 looks for a valid command state and returns null if none exists. - The server head-state reader and CLI commands reader use this provider-command projection. The composer input path receives timeline provider commands. Therefore the absent state explains both reported discovery surfaces.
The root defect is a producer/consumer resource-limit mismatch, not malformed ACP command names and not a reason to weaken ingest validation. On a thread that already had a smaller accepted state, rejection can leave stale earlier commands rather than clearing them; the zero-command result here concerns a fresh thread.
6. Proposed fix
Make the ACP command-state producer respect the existing serialized UTF-8 byte budget before it sends an event. Prefer preserving command names and useful input hints, reducing long descriptions with Unicode-safe truncation and JSON-escape-aware byte measurement; bound the final fallback if non-description content alone exceeds the limit. Preserve unchanged payloads that already fit. Keep the server's rejection boundary intact. Cover multi-byte text, JSON escaping, unusually large names/hints, and ordinary small lists. No fix code is included in this investigation because an open linked PR already covers this work.
Test value: existing ingest tests intentionally reject manually oversized inputs and check small valid core states. This regression crosses the actual ACP mapping/ingestion/projection boundary and exposes the missing producer-side budget. It adds no production export, switch, injected path, or database mock.
7. PR review
PR #7791 — static review only
Open linked PR, reviewed as untrusted metadata/diff at head 4aae2b8cc0a5317e93b75dfadc4baccbb8c133c4. It shares the existing byte-limit constant and fits command descriptions before publication, with a fallback that removes trailing entries if the remaining state is still too large. Its diff includes unit cases and a bridge-level test. This addresses the demonstrated producer-side mismatch while retaining the ingest limit.
No blocking defect was established by this static review. Large input hints, escape-heavy strings, and fallback policy deserve focused review. The branch was never checked out, patched in, or executed; the PR's claimed green tests and runtime correctness are not independently verified here. The only tests executed are this report's trusted-main reproduction and the existing trusted-main ingest suite. No duplicate fix PR is opened.
8. Related issues
#7618 discusses a different desktop performance symptom with oversized provider extension diagnostics. Those diagnostics may share a payload source, but that is not proven here, so this issue is not marked duplicate. Trusted source history records diagnostic-size hardening in commit b35f0e1a91; bounded diagnostics do not make an oversized command state acceptable.
9. Verification
The same agent repeated the reproduction in a second clean detached worktree at the recorded base commit, after a fresh frozen install and successful full build. The clean status was checked before adding only the authored reproduction test. Each case used new temporary harness state; no live ports or provider accounts were involved. This is a second clean run, not an independent-agent check.
git worktree add --detach ../verify 502cf5ae9b61f050ac6d2a7a1b9060f18b339828 cd ../verify pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build pnpm exec turbo run test --filter=@bb/server -- test/internal/issue-7790-provider-commands.test.ts
Second-run output:
{"count":192,"payloadBytes":155424,"actualCommands":0,"storedTypes":["provider/unhandled"],"diagnostics":[{"providerThreadId":"repro-session","providerId":"codex","rawType":"extension/state:bb/provider-commands","rawEvent":{"jsonrpc":"2.0","method":"thread/extensionState/updated","params":{"kind":"bb/provider-commands","payloadOmitted":true,"payloadBytes":155424,"reason":"payload is 155424 bytes; the limit is 65536"}}}]}
AssertionError: expected [] to have a length of 192 but got +0
Tests 1 failed | 1 passed (2)
Both runs produce the same bytes, diagnostic, missing commands, and failing assertion. No correction to the root cause or verdict was needed. A production fix and green-after-fix claim are intentionally absent.
10. Appendix
Relevant existing server tests were also run without production changes:
pnpm exec turbo run test --filter=@bb/server -- test/internal/internal-extension-payloads.test.ts
Test Files 1 passed (1)
Tests 13 passed (13)
Investigation commands additionally included read-only GitHub issue/property/label queries, linked-PR metadata and diff reads, trusted-main source and history inspection, git status --short, and pnpm exec oxfmt on the authored test. Both full builds used pnpm exec turbo run build. Initial test orchestration was canceled to correct the new test's relative import before Vitest ran. No issue-provided program or linked PR code was executed.
Trust boundary: issue content, logs, and linked PR material were treated only as untrusted claims. Reproduction data and test logic were authored from trusted repository code. Raw run logs and the test artifact remain outside this public report repository; the complete sanitized reproduction is inline above, as required by this site's publishing policy.