mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-24 05:47:10 +01:00
fix(runner): keep tool catalogs within what a durable run attachment can carry (#22705)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Managed runs start through the Paperclip runner, which records each run's attachment template in a durable control plane > - That template carries the agent's authorized tool catalog, with every tool's JSON schema > - The runner-side catalog check admitted up to 256 tools and 768 KB, but the durable control plane rejects any value over 10,000 canonical JSON nodes, and durable commands cannot exceed about 522 KB > - An agent with Notion and two GitHub connections (about 180 tools) passed the first check and failed every run with `durable_prp_canonical_json_too_large` > - This pull request makes the catalog check honor what the run attachment can carry, and gives controller-built values a node budget that matches the command byte limit > - The benefit is that agents with several large connectors run normally: tools that do not fit move to on-demand search and call instead of blocking the run ## Linked Issues or Issue Description **What happened?** After Notion (77 tools) and two GitHub connections (49 tools each) were connected and installed for the company, every run for an agent failed within seconds with `durable_prp_canonical_json_too_large`, before the model session started. Paperclip retried each run several times. **Expected behavior** An agent with several connectors starts its run. When the full catalog is too large, tools are delivered on demand. **Steps to reproduce** 1. Build an authorized tool catalog that `runnerCodexDynamicToolsFit` admits, for example 250 tools with enum-heavy schemas under 768 KB. 2. Stage it as a run attachment in `DurablePrpControlPlane`. 3. Staging throws `durable_prp_canonical_json_too_large`. ## What Changed - `durable-prp-control-plane.ts`: the canonical JSON node budget is a per-call limit. Runner-sent semantic input keeps 10,000 nodes. Controller-built values (run attachment templates, command digests) use a budget equal to the command byte limit, which already bounds them. New `runAttachToolCatalogFits` checks that a tool catalog canonicalizes and stays within 384 KB, leaving room for the rest of the run attachment. - `runnerd-codex-transport.ts`: `runnerCodexDynamicToolsFit` also requires `runAttachToolCatalogFits`. The server already uses this predicate to choose between direct tools and on-demand tools. - Tests: the densest catalog the fit check admits stages, persists and restores through the control plane; a 180-tool connector catalog under 768 KB no longer fits and moves to on-demand tools. ## Verification - `npx vitest run src/control-plane/durable-prp-control-plane.test.ts` (runner): 232 passed, including the existing runner input `over_node_limit` and `over_depth_limit` cases. - `npx vitest run src/services/native-runtime/assigned-mcp-tools.test.ts` (server): 61 passed. `paperclip-runner-tool-authority.test.ts`: 48 passed. - Red/green: without the change, the control plane test fails with `durable_prp_canonical_json_too_large`, and the server test fails with `expected true to be false` (the oversized catalog was admitted). - `runnerd-codex-transport.test.ts` and `runner-tool-capacity.test.ts` have the same 79 local failures with and without this change (they need built runner binaries). CI runs them. - SDK public input pins: unchanged. ## Risks - Agents whose catalog is between 384 KB and 768 KB now get on-demand tools instead of direct tools. Before this change those runs failed, so no working setup loses direct tools. - Controller-built values get a larger node budget. They are bounded by the command byte limit before they reach the runner, and runner input keeps its strict limit. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), via Claude Code, with tool use. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1363b557b9
commit
b2a12fab49
11 files changed
+278
-43
No files matched your search
@@ -10,7 +10,7 @@ import {
|
||||
ASSIGNED_SCHEMA_ADMISSION_CACHE_ENTRIES, ASSIGNED_SCHEMA_LISTING_BUDGET_BYTES, assignedSchemaAdmissionCacheSize,
|
||||
createAssignedMcpTools, getAssignedMcpGateway, registerAssignedMcpGateway,
|
||||
} from "./assigned-mcp-tools.js";
|
||||
import { admitToolInputSchema } from "../../vendor/paperclip-runner/index.js";
|
||||
import { admitToolInputSchema, runnerCodexDynamicToolsFit } from "../../vendor/paperclip-runner/index.js";
|
||||
import { startOpenCodeMcpBridge } from "../../vendor/paperclip-runner/testing.js";
|
||||
|
||||
vi.mock("../../vendor/paperclip-runner/index.js", async importOriginal => {
|
||||
@@ -256,6 +256,22 @@ describe("assigned MCP runner tools", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("moves a connector catalog the durable run attachment cannot carry to on-demand tools", async () => {
|
||||
const properties = Object.fromEntries(Array.from({ length: 20 }, (_, index) => [`field_${index}`, {
|
||||
type: "string", description: `Connector field ${index} with the provider's own documentation text.`,
|
||||
enum: Array.from({ length: 6 }, (_, value) => `value_${value}`),
|
||||
}]));
|
||||
const descriptors = Array.from({ length: 180 }, (_, index) => ({
|
||||
...descriptor(`connector.operation_${index}`), parametersSchema: { type: "object", properties },
|
||||
}) as ToolGatewayDescriptor);
|
||||
const assigned = await createAssignedMcpTools(fixture(descriptors));
|
||||
const direct = assigned.definitions();
|
||||
expect(direct).toHaveLength(180);
|
||||
expect(Buffer.byteLength(JSON.stringify(direct))).toBeLessThan(768 * 1024);
|
||||
expect(runnerCodexDynamicToolsFit(direct)).toBe(false);
|
||||
expect(assigned.definitions(runnerCodexDynamicToolsFit).map(tool => tool.name)).toEqual([searchName, callName]);
|
||||
});
|
||||
|
||||
it.each([1, 741])("uses bounded on-demand delivery for %i tools even when the direct catalog fits", async count => {
|
||||
const f = fixture(Array.from({ length: count }, (_, i) => descriptor(`app.operation_${i}`)));
|
||||
const direct = await createAssignedMcpTools(f);
|
||||
|
||||
@@ -79,7 +79,7 @@ import { agentDirectoryBusyRetryDelayMs } from "../heartbeat/agent-directory-bus
|
||||
import { NativeExecutionContext } from "./native-execution-context.js";
|
||||
import { NativeStartupCleanupPendingError, clearNativeStartupContext } from "./native-startup-cleanup.js";
|
||||
import { readUnreadSteeredMessages } from "./unread-steered-messages.js";
|
||||
import { coldAdmissionTimeoutMs } from "../../vendor/paperclip-runner/index.js";
|
||||
import { coldAdmissionTimeoutMs, nativeRunAttachReservedBytes } from "../../vendor/paperclip-runner/index.js";
|
||||
import { applyObservabilityEnvironment, type ProviderObservabilityLaunch } from "@paperclipai/adapter-utils/agent-observability";
|
||||
import { museRunnerBroker } from "../muse-runner-broker.js";
|
||||
import { nativeCaseHandoffResult } from "./native-case-handoff.js";
|
||||
@@ -16794,6 +16794,7 @@ async function createRunnerdBackendWithinSessionClaim(
|
||||
input.executionContext?.signal.throwIfAborted();
|
||||
const authority = new PaperclipRunnerToolAuthority(input.db, {
|
||||
apiUrl: resolveLocalRuntimeApiUrl(),
|
||||
runAttachReservedBytes: nativeRunAttachReservedBytes(input.execution),
|
||||
casesEnabled: input.casesEnabled === true,
|
||||
responsibilitiesEnabled: input.responsibilitiesEnabled === true,
|
||||
...(nativeReview ? { nativeReview } : {}),
|
||||
|
||||
@@ -1080,6 +1080,24 @@ describe("PaperclipRunnerToolAuthority", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("moves assigned tools on demand when the run's reserved attachment bytes leave no room for them", async () => {
|
||||
const listToolsForNamedGateway = vi.fn().mockResolvedValue(Array.from({ length: 40 }, (_, i) => ({
|
||||
name: `app.lookup_${i}`, displayName: `Lookup ${i}`, description: "Read a fixture",
|
||||
parametersSchema: { type: "object", properties: { query: { type: "string", description: "Lookup field documentation. ".repeat(80) } } }, risk: "read",
|
||||
})));
|
||||
const assignedMcpTools = await createAssignedMcpTools({
|
||||
gateway: { listToolsForNamedGateway } as unknown as ToolGatewayService,
|
||||
gatewayPublicId: "fixture", bearerToken: "fixture-token",
|
||||
});
|
||||
const binding = { companyId, agentId, issueId, runId, assignedMcpTools };
|
||||
const direct = new PaperclipRunnerToolAuthority(db, binding).definitions().map(tool => String(tool.name));
|
||||
expect(direct.filter(name => name.includes("lookup"))).toHaveLength(40);
|
||||
const reserved = new PaperclipRunnerToolAuthority(db, { ...binding, runAttachReservedBytes: 340 * 1024 })
|
||||
.definitions().map(tool => String(tool.name));
|
||||
expect(reserved.filter(name => name.includes("lookup"))).toEqual([]);
|
||||
expect(reserved).toEqual(expect.arrayContaining(["paperclip_search_assigned_tools", "paperclip_call_assigned_tool"]));
|
||||
});
|
||||
|
||||
it("fits large assigned catalogs alongside workspace and completion tools without dropping task tools", async () => {
|
||||
const listToolsForNamedGateway = vi.fn().mockResolvedValue(Array.from({ length: 224 }, (_, i) => ({
|
||||
name: `app.action_${i}`, displayName: `Action ${i}`, description: "Read a fixture",
|
||||
|
||||
@@ -238,6 +238,7 @@ type Binding = {
|
||||
/** Server-owned suppression for baseline evals; true never overrides operator opt-in. */
|
||||
connectorAssignments?: Pick<ConnectorAssignment, "tools">[];
|
||||
assignedMcpTools?: Awaited<ReturnType<typeof createAssignedMcpTools>>;
|
||||
runAttachReservedBytes?: number;
|
||||
apiToolsEnabled?: boolean;
|
||||
workMode?: "standard" | "planning" | "ask" | "skill_test";
|
||||
casesEnabled?: boolean;
|
||||
@@ -481,7 +482,7 @@ export class PaperclipRunnerToolAuthority {
|
||||
...(this.binding.connectorAssignments ?? []).flatMap((assignment) => assignment.tools)];
|
||||
if (!this.binding.firstPartyOnly && this.binding.assignedMcpTools) definitions.push(READ_TOOL_RESULT_DEFINITION);
|
||||
const assignedTools = this.binding.firstPartyOnly ? [] : this.binding.assignedMcpTools?.definitions((tools) =>
|
||||
runnerCodexDynamicToolsFit([...connectionTools, ...tools, ...definitions])) ?? [];
|
||||
runnerCodexDynamicToolsFit([...connectionTools, ...tools, ...definitions], this.binding.runAttachReservedBytes ?? 0)) ?? [];
|
||||
const all = [...connectionTools, ...assignedTools, ...definitions]
|
||||
.filter(tool => workMode !== "skill_test" || nativeSkillTestToolAllowed(String(tool.name)));
|
||||
return this.binding.museRuntime ? all.filter(definition => MUSE_NATIVE_OPERATIONS.has(String(definition.name))) : all;
|
||||
|
||||
+1
@@ -109,6 +109,7 @@ export const inspectUnclaimedBootstrapState = runner.inspectUnclaimedBootstrapSt
|
||||
export const RUNNER_PRP_PROTOCOL_MIN = runner.RUNNER_PRP_PROTOCOL_MIN;
|
||||
export const RUNNER_PRP_PROTOCOL_MAX = runner.RUNNER_PRP_PROTOCOL_MAX;
|
||||
export const runnerCodexDynamicToolsFit = runner.runnerCodexDynamicToolsFit;
|
||||
export const nativeRunAttachReservedBytes = runner.nativeRunAttachReservedBytes;
|
||||
export const admitToolInputSchema = runner.admitToolInputSchema;
|
||||
export const TOOL_INPUT_SCHEMA_MAX_BYTES = runner.TOOL_INPUT_SCHEMA_MAX_BYTES;
|
||||
export const canonicalToolInputSchema = runner.canonicalToolInputSchema;
|
||||
|
||||
Reference in new issue
Block a user