← reports

#5565 · Dynamic instruction clipping lacks diagnostics

BugPriority: LowEffort: Lowplugins GitHub issue2026-10-15 · base 411eac54ac16d0a3cb57d1de8396d37564884a73

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

1. TL;DR

Plugins can return dynamic guidance when BB resolves an agent configuration. At the trusted main commit, a 5,000-character nonblank result becomes 4,096 characters without any warning. The normalizer performs the slice and returns an ordinary successful result; neither the server caller nor the test harness diagnoses that transformation. The existing SDK documentation explicitly promises truncation, so the minimal compatible repair is to retain that behavior and add a plugin-scoped warning containing the original length and limit.

2. Claims vs findings

ClaimFindingEvidence
Oversized dynamic guidance is shortened silently.VerifiedThe 4,096-character assertion succeeds, then the warning assertion fails because the plugin log is empty, in both trusted checkouts.
Static tool guidance has different overflow behavior.Verified in sourceStatic registration throws on length greater than 4,096; dynamic normalization slices instead.
The server consumes shortened text without an overflow diagnostic.Verified in sourceSuccessful normalization feeds dynamicInstructions; no original length or diagnostic survives.
The test harness repeats the defect.VerifiedIt calls the same production normalizer. Its existing conditional-configuration test intentionally expects a 4,096-character cap.
Specific desktop and project-name scenarios reproduce this.Not separately exercisedThis investigation tests the shared server-side policy with controlled input, not a desktop session or real provider.

3. Environment

4. Minimal reproduction

The test is derived from the repository's existing conditional-agent-configuration fixture, not from the submitted issue's executable example. It exercises actual production normalization through the supported fake-host API, including tool and skill selections.

  1. Prepare a fresh checkout of the recorded public main commit:
    git clone https://github.com/get-bb/bb.git bb-5565
    cd bb-5565
    git checkout --detach 411eac54ac16d0a3cb57d1de8396d37564884a73
    pnpm install --frozen-lockfile --prefer-offline
  2. Download the reproduction test to the owning package and run it through Turbo:
    curl --fail --silent --show-error https://get-bb.github.io/reports/issues/5565/repro/instructions-warning.test.ts -o packages/plugin-sdk/src/testing/__tests__/instructions-warning.test.ts
    pnpm exec turbo run test --filter=@get-bb/plugin-sdk -- src/testing/__tests__/instructions-warning.test.ts
  3. The test makes two resolutions with 5,000-character guidance. Expected: the existing 4,096-character output cap plus one warn-level diagnostic per resolution naming the original length and cap. Actual: the output cap assertion passes, but the log remains empty. Exit status is 1:
    AssertionError: expected [] to deeply equal [ { level: 'warn', …(1) }, …(1) ]
    - Expected: two warn-level entries containing
      configure() output.instructions truncated from 5000 to 4096 characters
    + Received: []
    Test Files  1 failed (1)
    Tests       1 failed (1)

Alternatively, apply the test-only regression patch to the same base and run pnpm exec turbo run test --filter=@get-bb/plugin-sdk -- src/testing/__tests__/fake-plugin-host.test.ts -t 'resolves conditional tools'. This is the first command used in both baseline checkouts.

Complete standalone reproduction test

import { expect, it } from "vitest";
import type { PluginAgentConfigurationContext } from "../../backend-contract.js";
import { createFakePluginHost, makePluginAgentConfigurationContext } from "../index.js";

const configurationContext = makePluginAgentConfigurationContext();

it("resolves conditional tools, skills, context, and capped instructions without rebuilding registrations", async () => {
  const { bb, harness } = createFakePluginHost({
    pluginId: "conditional",
    agentSkillIds: ["alpha-skill", "beta-skill"],
  });
  for (const name of ["alpha_tool", "beta_tool"]) {
    bb.agents.registerTool({
      name,
      description: name,
      parameters: { type: "object" },
      execute: () => name,
    });
  }
  const contexts: PluginAgentConfigurationContext[] = [];
  bb.agents.configure((context) => {
    contexts.push(context);
    const alpha = context.host.id === "host-test";
    return {
      tools: [alpha ? "alpha_tool" : "beta_tool"],
      skills: [alpha ? "alpha-skill" : "beta-skill"],
      instructions:
        `${context.provider.id}:${context.provider.model}:`.padEnd(5000, "x"),
    };
  });

  const alpha = await harness.resolveAgentConfiguration(configurationContext);
  const betaContext = makePluginAgentConfigurationContext({
    thread: { id: "thread-beta" },
    host: { id: "host-beta", name: "Beta host" },
    provider: {
      id: "claude-code",
      model: "claude-opus",
    },
  });
  const beta = await harness.resolveAgentConfiguration(betaContext);

  expect(alpha.tools.map((tool) => tool.name)).toEqual(["alpha_tool"]);
  expect(alpha.skills).toEqual(["alpha-skill"]);
  expect(alpha.instructions).toHaveLength(4096);
  expect(harness.logEntries).toEqual([
    {
      level: "warn",
      message: expect.stringContaining(
        "configure() output.instructions truncated from 5000 to 4096 characters",
      ),
    },
    {
      level: "warn",
      message: expect.stringContaining(
        "configure() output.instructions truncated from 5000 to 4096 characters",
      ),
    },
  ]);
  expect(beta.tools.map((tool) => tool.name)).toEqual(["beta_tool"]);
  expect(beta.skills).toEqual(["beta-skill"]);
  expect(contexts).toEqual([configurationContext, betaContext]);
  expect(harness.registrations.agentTools.map((tool) => tool.name)).toEqual([
    "alpha_tool",
    "beta_tool",
  ]);
});


5. Root cause

Dynamic normalization validates the value's type, then slices nonblank text without returning or emitting any overflow signal:

const instructions =
  typeof output.instructions === "string" &&
  output.instructions.trim().length > 0
    ? output.instructions.slice(0, PLUGIN_AGENT_DYNAMIC_INSTRUCTIONS_MAX_CHARS)
    : null;

The server's successful-resolution path takes this normalized value and appends it to the dynamic instructions array. Its error wrapper only diagnoses thrown failures, not successful truncation. The supported testing host calls the same normalizer, returning the shortened instructions and logging only caught errors. This explains why ordinary plugin tests can pass while trailing guidance disappears.

The distinction is not an undocumented size limit: the SDK declaration explicitly promises truncation. In contrast, static tool instructions are rejected. The defect is the missing diagnostic for the documented lossy dynamic path.

6. Proposed fix and verified local repair

Add a required internal warning callback to the shared normalizer and call it only when meaningful instruction text is actually shortened. Route it through the real plugin logger on the server and the captured warning log in the testing host. Keep tool/skill selection, the 4,096-character cap, blank-text normalization, status, and public interfaces unchanged. The existing plugin logger already prefixes the plugin identity and writes both server output and the plugin log readable through existing plugin-log surfaces. Do not include the guidance text itself in diagnostics.

The local candidate passes the focused regression, all 373 SDK tests, and 34 tests in the server's agent-tool and plugin-SDK suites. SDK and server Turbo typechecks pass. Additional negative controls confirm no warning for exactly 4,096 characters or blank guidance. The tested candidate changes five files and 46 total added/deleted text lines, has no binary changes, and passes git diff --check. No dependencies, generated files, stored data, public protocols, or permissions change in that candidate.

Autopilot fix stopped: CI rejected the candidate because its SDK declaration change requires a version bump. More generally, the existing SDK publication contract also requires a new version for changed published runtime content. The registry confirms that SDK version 0.6.49 is already published. A complete shared-normalizer repair therefore needs the version constant and package manifest updated together. Even dropping the documentation edit leaves four necessary implementation/test files plus two version files: at least six files, exceeding this rule's five-file maximum. No version guard was bypassed and no additional fix changes were pushed after this constraint was discovered. Candidate PR #5568 was closed without merging, and its remote branch was removed. The tested approach remains useful for a separately authorized repair outside this narrow autopilot limit.

7. Verification

The same investigating agent repeated the regression in a second checkout created clean at the exact base commit, separately installed with the frozen lockfile. Initial git status --porcelain was empty. Only the investigator-authored test patch was applied; production code stayed unchanged. No ports or application data directories were allocated.

Second checkout: isolated temporary worktree at 411eac54ac16d0a3cb57d1de8396d37564884a73
Command: pnpm exec turbo run test --filter=@get-bb/plugin-sdk -- src/testing/__tests__/fake-plugin-host.test.ts -t 'resolves conditional tools'
Result: exit 1; expected two warnings, received []; output-length assertion passed.
Additional artifact check: pnpm exec turbo run test --filter=@get-bb/plugin-sdk -- src/testing/__tests__/instructions-warning.test.ts
Result: exit 1 for the same missing-warning assertion.

No report correction was needed after the second run. This is a repeated clean verification by the same agent, not an independent-agent investigation. The unmodified main behavior is confirmed; desktop rendering and real-provider delivery are outside this unit-level reproduction.

8. Related issues and pull requests

Repository searches for related configuration clipping did not find a matching issue. The issue timeline, open-PR search, and closing-issue metadata for all current open PRs contained no open PR linked to #5565 at investigation time. No pull request branch or submitted executable was checked out or run.

9. Appendix

Release-gate evidence and reason the candidate was withdrawn.

Trust handling: issue content was treated only as untrusted claims. No instruction, script, test, patch, branch, or external URL from that content was executed or fetched. All tested production code came from the target repository's trusted main branch; changes and regression assertions were designed from repository evidence.

> AGENT GENERATED