← reports

#7838 · Interaction payload error classification

BugPriority: LowEffort: LowpluginsGitHub issueNovember 19, 2026 · base df9619d8e8aac4aff00c0c3ff9b8ef4e2823e4f2

Verdict: REPRODUCED · Root-cause confidence: high · Reproduction label: confirmed-repro

1. TL;DR

A plugin requesting an input form should receive the same JSON-serializability error whenever encoding its payload fails. Instead, an exception whose message includes 64 KiB escapes unchanged. The normalizer catches its own size-limit exception alongside arbitrary serializer failures, then distinguishes the two by searching the exception text. Two fresh checkouts of the trusted main commit produce identical failing assertions. This is a narrow error-reporting defect, not evidence of a process crash, payload acceptance, or a demonstrated security-boundary bypass.

2. Claims vs findings

ClaimFindingEvidence
Serializer failures mentioning the size threshold escape the normal error mapping.VerifiedA throwing enumerable getter produces the original exception text only when it includes the threshold string. It fails during JSON.stringify, before any size check.
Genuinely oversized JSON still produces the normal size error.Verified65,537-byte ASCII JSON and 65,537-byte UTF-8 JSON both reject; exactly 65,536-byte JSON is accepted.
The specific custom toJSON example demonstrates the defect.Mechanism supported; exact example not executedThe report deliberately uses a newly authored getter-based reproduction, not the issue's script or linked PR test. Both invoke plugin code inside the same native JSON.stringify call.

3. Environment

4. Minimal reproduction

  1. Check out the trusted commit, install its existing dependencies, and build the owning subsystem.
  2. Save the complete test below at the indicated path.
  3. Run the final command. On the unchanged base it exits 1 with two failed and two passed test cases.
git clone https://github.com/get-bb/bb.git bb-repro
cd bb-repro
git fetch origin main
git checkout --detach df9619d8e8aac4aff00c0c3ff9b8ef4e2823e4f2
pnpm install --frozen-lockfile --prefer-offline
pnpm exec turbo run build --filter=@get-bb/plugin-sdk
# Save the test below to packages/plugin-sdk/src/internal/host-policy.test.ts
pnpm exec turbo run test --filter=@get-bb/plugin-sdk -- src/internal/host-policy.test.ts

Complete regression test

import { describe, expect, it } from "vitest";
import { normalizeInteractionRequest } from "./host-policy.js";

describe("interaction request payload validation", () => {
  it.each([
    "encoding failed",
    "encoding failed at 64 KiB",
    "ui.requestInput payload exceeds 64 KiB",
  ])(
    "normalizes serialization failures regardless of their message: %s",
    (message) => {
      expect(() =>
        normalizeInteractionRequest({
          threadId: "thread-test",
          rendererId: "form",
          title: "Form",
          payload: {
            get value(): string {
              throw new Error(message);
            },
          },
        }),
      ).toThrow(new Error("ui.requestInput payload must be JSON-serializable"));
    },
  );

  it("accepts exactly 64 KiB of JSON and rejects larger UTF-8 payloads", () => {
    const request = {
      threadId: "thread-test",
      rendererId: "form",
      title: "Form",
      payload: "a".repeat(65_534),
    };

    expect(normalizeInteractionRequest(request).payload).toBe(request.payload);
    expect(() =>
      normalizeInteractionRequest({
        ...request,
        payload: `${request.payload}a`,
      }),
    ).toThrow(new Error("ui.requestInput payload exceeds 64 KiB"));
    expect(() =>
      normalizeInteractionRequest({
        ...request,
        payload: "\u20ac".repeat(21_845),
      }),
    ).toThrow(new Error("ui.requestInput payload exceeds 64 KiB"));
  });
});

Expected and actual messages

Expected for every serialization failure:
ui.requestInput payload must be JSON-serializable

Actual for a getter throwing "encoding failed":
ui.requestInput payload must be JSON-serializable

Actual for a getter throwing "encoding failed at 64 KiB":
encoding failed at 64 KiB

Actual for a getter throwing "ui.requestInput payload exceeds 64 KiB":
ui.requestInput payload exceeds 64 KiB

The controls include a nonmatching serialization error, the exact ASCII byte boundary including JSON quotes, an ASCII overflow, and a multibyte overflow. This distinguishes exception misclassification from a real byte-limit failure.

5. Root cause

The shared production request normalizer wraps serialization, byte validation, and parsing in a single try/catch. Its catch rethrows any Error whose message includes the limit string:

try {
  const json = JSON.stringify(request.payload);
  if (json === undefined) throw new Error();
  if (Buffer.byteLength(json, "utf8") > PLUGIN_INTERACTION_MAX_PAYLOAD_BYTES) {
    throw new Error("ui.requestInput payload exceeds 64 KiB");
  }
  payload = JSON.parse(json) as JsonValue;
} catch (error) {
  if (error instanceof Error && error.message.includes("64 KiB")) {
    throw error;
  }
  throw new Error("ui.requestInput payload must be JSON-serializable");
}

JSON.stringify can execute getters and custom conversion hooks. Their exceptions are indistinguishable from the normalizer's own size error under that text-based test. An error containing the substring therefore escapes even though no serialized byte count exists. The byte cap itself remains correct.

The live plugin UI request implementation and the testing host both invoke this normalizer. The existing limit is 64 × 1024 bytes. The reproduction targets the actual shared owner directly; it adds no test-only production seam.

6. Proposed fix

Catch only JSON.stringify failures and map them unconditionally to the serializability error. Reject an undefined serialization result explicitly. Run the existing byte-size check afterward, outside the catch, and parse only after the byte check passes. This removes exception-text classification without changing the public API, payload limit, protocol, or persistence.

7. Linked PR review

PR #7840 — closed, not merged

Metadata and diff only were read as untrusted evidence. The diff separates serialization from size validation, which statically addresses the same root cause, and adds a custom-conversion regression plus an oversized-payload control. No correctness finding from that limited static review. Its branch and test were not checked out or run, and its verification claims were not adopted. The report's trusted-base evidence was authored separately. No open linked pull request existed at the time of the duplicate check.

8. Verification

The same agent repeated the reproduction in a second clean temporary checkout, separate from the fix checkout, at exactly df9619d8e8aac4aff00c0c3ff9b8ef4e2823e4f2. Each checkout had its own frozen dependency installation and targeted build. Only the new test was copied into the second checkout; production remained byte-for-byte at the base. No ports or data directories were allocated. This is a repeat verification, not an independent-agent review.

First checkout: exit 1
⎯⎯⎯⎯⎯⎯⎯ Failed Tests 2 ⎯⎯⎯⎯⎯⎯⎯
 FAIL  |@get-bb/plugin-sdk| src/internal/host-policy.test.ts > interaction request payload validation > normalizes serialization failures regardless of their message: encoding failed at 64 KiB
- Expected
+ Received
-   "message": "ui.requestInput payload must be JSON-serializable",
+   "message": "encoding failed at 64 KiB",
 FAIL  |@get-bb/plugin-sdk| src/internal/host-policy.test.ts > interaction request payload validation > normalizes serialization failures regardless of their message: ui.requestInput payload exceeds 64 KiB
- Expected
+ Received
-   "message": "ui.requestInput payload must be JSON-serializable",
+   "message": "ui.requestInput payload exceeds 64 KiB",
 Test Files  1 failed (1)
      Tests  2 failed | 2 passed (4)

Second clean checkout: exit 1
⎯⎯⎯⎯⎯⎯⎯ Failed Tests 2 ⎯⎯⎯⎯⎯⎯⎯
 FAIL  |@get-bb/plugin-sdk| src/internal/host-policy.test.ts > interaction request payload validation > normalizes serialization failures regardless of their message: encoding failed at 64 KiB
- Expected
+ Received
-   "message": "ui.requestInput payload must be JSON-serializable",
+   "message": "encoding failed at 64 KiB",
 FAIL  |@get-bb/plugin-sdk| src/internal/host-policy.test.ts > interaction request payload validation > normalizes serialization failures regardless of their message: ui.requestInput payload exceeds 64 KiB
- Expected
+ Received
-   "message": "ui.requestInput payload must be JSON-serializable",
+   "message": "ui.requestInput payload exceeds 64 KiB",
 Test Files  1 failed (1)
      Tests  2 failed | 2 passed (4)

No report correction was needed: both runs show the same two message-matching failures and passing controls.

Local fix validation

After the smallest owner-boundary fix, all four focused cases pass. The existing Plugin SDK suite passes all 442 tests across 41 files, and the combined Turbo test/typecheck/lint run completes successfully (7 tasks). Formatting and git diff --check pass. The patch changes two files and 72 total text lines (59 additions and 13 deletions), with no binary files, dependencies, generated files, schema, protocol, or storage changes. Production changes account for 23 lines; regression coverage adds 49 lines.

9. Related issues

No additional issue is needed: this report covers #7838 only. The only linked pull request found was the closed, unmerged #7840.

10. Appendix

Issue content and linked PR content were treated as untrusted claims. No issue-provided script, patch, branch, or test was executed. No external issue attachment was fetched.

Raw local logs are retained outside the published repository. Their public, path-free assertion output is included above. The complete test is inline because the reports repository intentionally does not publish raw repro files or logs.

git clone https://github.com/get-bb/bb.git bb-repro
cd bb-repro
git fetch origin main
git checkout --detach df9619d8e8aac4aff00c0c3ff9b8ef4e2823e4f2
pnpm install --frozen-lockfile --prefer-offline
pnpm exec turbo run build --filter=@get-bb/plugin-sdk
# Save the test below to packages/plugin-sdk/src/internal/host-policy.test.ts
pnpm exec turbo run test --filter=@get-bb/plugin-sdk -- src/internal/host-policy.test.ts

Second run: repeat in a newly cloned checkout at the same recorded commit.
After applying the proposed local fix:
pnpm exec oxfmt packages/plugin-sdk/src/internal/host-policy.ts packages/plugin-sdk/src/internal/host-policy.test.ts
pnpm exec turbo run test --filter=@get-bb/plugin-sdk -- src/internal/host-policy.test.ts
pnpm exec turbo run test typecheck lint --filter=@get-bb/plugin-sdk --output-logs=errors-only
git diff --check
git diff --numstat origin/main