Files
PaperClipAI/packages/paperclip-runner/src
DottaandClaude Opus 5.5 b2a12fab49 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>
2026-11-23 17:27:47 -06:00
..