Repository navigation
Description
Summary
Extension payloads rejected for exceeding the 65,536-byte limit are still persisted in full inside provider/unhandled diagnostics. Rejection prevents the extension update but does not bound the retained payload, so repeated rejected snapshots accumulate large hidden history.
Expected behavior is a bounded diagnostic with the rejection reason, extension kind, original UTF-8 payload byte count, and event provenance.
Versions and environment
- Production evidence came from BB desktop and CLI 0.46.1 on macOS 27.0.1, using a local SQLite database.
- Local API reproduction used source commit
b143a22860944a96bf183605dfb0ffe58b1de283, which the GitHub API reported asmainduring this investigation. - Local runtime was Node v24.15.0 on macOS 27.0.1.
- The reproduction uses the existing test-app harness, a real migrated SQLite database, and a synthetic provider. No external agent CLI, private plugin, or production payload is required.
Steps to reproduce
-
Check out commit
b143a22860944a96bf183605dfb0ffe58b1de283with the repository development dependencies available. -
Apply the regression-only suggested patch below.
-
Run:
pnpm exec turbo run test --filter=@bb/server -- test/internal/internal-extension-payloads.test.ts
The new cases POST oversized extension item and state events to /internal/session/events. Each payload contains 131,072 copies of é, so UTF-8 byte count differs from character count. The test reads the persisted event through the real database and checks provenance before checking the diagnostic size.
This reproduces the ingest and persistence defect on current source. It is not a desktop loading reproduction or a latency benchmark.
Expected vs actual
Expected: replace the rejected event in the same batch slot with a diagnostic no larger than a documented byte budget. The suggested regression uses 65,536 bytes as that budget. Keep useful diagnosis and provenance without a complete oversized payload.
Actual output from the local run:
bounds persisted diagnostics for an oversized item payload
AssertionError: expected 262452 to be less than or equal to 65536
bounds persisted diagnostics for an oversized state payload
AssertionError: expected 262437 to be less than or equal to 65536
Tests 2 failed | 9 passed (11)
The rejected input payloads were 262,160 and 262,157 UTF-8 bytes. The larger values in the failures measure UTF-8 JSON.stringify output of the persisted diagnostic data, including its metadata. The existing nine tests passed, including valid extension events and ownership checks.
Evidence
The original investigation is bbthread://thr_tvsrr4kgtd. This follow-up is BB-3 in bbthread://thr_apydtjqzvy.
The source trace contains read-only SQL output from an affected thread:
sequence reason
116541 payload is 252784 bytes; the limit is 65536
116542 payload is 252784 bytes; the limit is 65536
116543 payload is 255852 bytes; the limit is 65536
In a bounded sample of the most recent 128 provider/unhandled rows, 62 rejected extension state snapshots occupied 15,598,043 stored characters. This is SQLite sum(length(data)), not a byte measurement or a total-history census. The other 66 sampled records were different diagnostic types.
The trace records the sample query and output at sequence 1381 and the three rejection reasons at sequence 1458. The sample grouped the latest 128 rows by rawType, rawEvent.method, and message type. A sanitized equivalent is:
WITH sample AS (
SELECT data
FROM events
WHERE thread_id = :affected_thread_id AND type = 'provider/unhandled'
ORDER BY sequence DESC
LIMIT 128
)
SELECT
json_extract(data, '$.rawType') AS raw_type,
json_extract(data, '$.rawEvent.method') AS method,
count(*) AS sample_events,
sum(length(data)) AS stored_characters
FROM sample
GROUP BY raw_type, method
ORDER BY stored_characters DESC;These historical measurements were verified against the captured command outputs, not remeasured on the live production database. Private payloads and custom plugin identifiers are excluded.
Source evidence at the reproduced commit:
- Size validation and unconditional fallback payload copy.
- Valid events pass through, rejected events become fallback diagnostics.
- Existing ingest regression tests.
Observed mechanism: validateSite rejects oversized JSON, but toUnhandledEvent assigns site.payload directly to rawEvent.params.payload. Ownership and declaration failures can also return before the size check, so a fix limited to the size-rejection branch would miss those oversized inputs.
Retaining these payloads increases diagnostic storage and the data available to later hidden-history scans. This issue does not claim a measured loading-time improvement from the proposed change.
What was ruled out
- The payload-size guard is present and fires. The defect is retention after rejection, not failure to reject.
- The synthetic API reproduction requires no producer event-volume change, live provider, or timeline query.
- Searched open and closed issues for extension payloads, rejected payloads, extension diagnostics,
toUnhandledEvent, and65536. No matching retention issue was found. - provider-claude-code: unknown custom entry type agent-session-bridge-state floods sdk/unknown log #2319 concerns provider parsing and repeated unknown custom entries, not oversized rejected extension payloads.
- Thread-list goal lookup repeatedly scans unrelated extension history and stalls the server #5234 concerns a thread-list state-history query. This issue concerns the ingest fallback and requires no query change.
- No historical cleanup or deletion is proposed. This prevents new oversized fallback copies; existing stored history would remain.
Proposed fix
Keep the repair in toUnhandledEvent in apps/server/src/internal/extension-payloads.ts:
- Measure the original serialized payload in UTF-8 bytes for every rejection path.
- For an oversized payload, omit the full
params.payload. Keep an explicit omission marker and original byte count, such aspayloadOmitted: trueandpayloadBytes. - Preserve the reason and extension kind, plus provider identity, original event method, scope, parent tool-call association, and envelope ordering.
- Enforce a documented serialized diagnostic byte budget. Any payload preview, validator-derived reason, or unusually long identifier must fit that budget with an explicit truncation marker where needed. Do not replace the full payload with another unbounded serialized copy.
- Keep valid extension events unchanged. Preserve existing small rejection payloads where they fit the diagnostic budget.
A payload-only condition does not by itself prove a total diagnostic bound. In particular, extension-kind validation currently checks syntax without a length bound, and schema validator messages can be large. The implementation must account for those fields without changing ingest protocol semantics.
This is a proposed repair, not an implemented or validated production fix. Producer event-volume reduction, timeline-query changes, and historical data deletion are out of scope.
Regression tests needed
The suggested patch adds the primary failing integration regression at the real ingest/persistence boundary for both item and state events. It checks reason, kind, original byte count in the reason, scope, provider provenance, parent association for items, and a serialized diagnostic bound.
Before landing a production fix, also cover:
- Oversized payloads rejected for ownership or missing schema before size validation.
- The core thread-state validation path.
- Payloads at the 65,536-byte acceptance boundary and one byte over it.
- A large validator reason and an unusually long kind, so metadata cannot defeat the diagnostic budget.
- Explicit omission and original-byte-count metadata in the final diagnostic format.
Retain the existing valid-event, small-schema-rejection, and ownership tests. The proposed patch intentionally stays red until the fix exists.
Local checks completed:
- Focused ingest suite, nine existing tests passed and two new size regressions failed as shown above.
pnpm exec turbo run typecheck --filter=@bb/serverpassed.pnpm exec oxfmt --check apps/server/test/internal/internal-extension-payloads.test.tspassed.git diff --checkpassed.
Suggested patch
This is the complete local diff. It adds regression tests only and makes no production-code change.
diff --git a/apps/server/test/internal/internal-extension-payloads.test.ts b/apps/server/test/internal/internal-extension-payloads.test.ts
index 56810911..966483bf 100644
--- a/apps/server/test/internal/internal-extension-payloads.test.ts
+++ b/apps/server/test/internal/internal-extension-payloads.test.ts
@@ -346,6 +346,55 @@ describe("extension payload ingest validation", () => {
}
});
+ it.each([
+ ["item", extensionItemEvent, "objective"],
+ ["state", extensionStateEvent, "status"],
+ ] as const)(
+ "bounds persisted diagnostics for an oversized %s payload",
+ async (surface, makeEvent, field) => {
+ const { harness, session, thread } = await setup();
+ try {
+ const payload = { [field]: "é".repeat(128 * 1024) };
+ const payloadBytes = Buffer.byteLength(JSON.stringify(payload));
+ const response = await post(harness, session.id, [
+ turnStarted(thread.id),
+ makeEvent(thread.id, payload),
+ ]);
+ expect(response.status).toBe(200);
+ const rows = storedRows(harness, thread.id);
+ expect(rows.map((row) => row.type)).toEqual([
+ "turn/started",
+ "provider/unhandled",
+ ]);
+ expect(rows[1]).toMatchObject({
+ scopeKind: surface === "item" ? "turn" : "thread",
+ turnId: surface === "item" ? "turn-1" : null,
+ data: {
+ providerThreadId: "prov-1",
+ providerId: PROVIDER_ID,
+ rawType: `extension/${surface}:${GOAL_KIND}`,
+ ...(surface === "item" ? { parentToolCallId: "parent-1" } : {}),
+ rawEvent: {
+ method:
+ surface === "item"
+ ? "item/started"
+ : "thread/extensionState/updated",
+ params: {
+ kind: GOAL_KIND,
+ reason: `payload is ${payloadBytes} bytes; the limit is 65536`,
+ },
+ },
+ },
+ });
+ expect(
+ Buffer.byteLength(JSON.stringify(rows[1]!.data)),
+ ).toBeLessThanOrEqual(EXTENSION_PAYLOAD_MAX_BYTES);
+ } finally {
+ await harness.cleanup();
+ }
+ },
+ );
+
it("stops accepting a kind once its plugin's registration is disposed", async () => {
const { harness, session, thread } = await setup();
try {AGENT GENERATED
Activity
bb-slop-cop commentedon Oct 21, 2026
🚨 SLOP COP 🚨 ·
new-issue-autopilotplugins,threads.confirmed-repro.provider/unhandleddata. Early rejection paths and unbounded metadata also evade a total diagnostic limit.origin/maincheckouts produced the same nine byte-bound failures; ten tests passed, including all nine existing cases. Server typecheck passed. The independently authored regression is inline in the report.Bound rejected extension payloads in fallback diagnostics (get-bb#7431)