Files
PaperClipAI/packages/paperclip-runner/src/drivers/tool-input-error.test.ts
T
DottaandClaude Opus 5.5 52817dff55 fix(runner): name missing tool fields and what the call included (#21252)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Agents act through Paperclip tools, and the runner validates each
tool call against its input schema
> - When a call is invalid, the runner returns an "Invalid tool input"
error to the model
> - For a call that left out required fields, that error was a list of
JSON Schema messages such as `/ must have required property 'kickoff'`
> - A model sent `paperclip_create_case` with only
`workflow_document_text` for about 5 minutes, believed it had sent every
field, and never replied to the person
> - This pull request makes the error name the missing fields, the
fields the call did include, and a short example of the missing fields
> - The benefit is that a model can see its own mistake and correct the
call on the next attempt

## Linked Issues or Issue Description

**What happened?**
In the paid chat eval `cases.create-case` (OpenCode with
`openrouter/deepseek/deepseek-v4.1-flash-1017`), the agent called
`paperclip_create_case` about 20 times with only
`workflow_document_text`. Each call returned `Invalid tool input: / must
have required property 'idempotencyKey'; / must have required property
'caseType'; ...`. The model's reasoning said that the other fields were
being stripped. It never created the case and never replied.

**Steps to reproduce**
1. Validate `{ "workflow_document_text": "..." }` against the
`create_case` input schema.
2. Read `toolInputError(validator)`.

**Expected behavior**
The error says which required fields are missing, says that the call
included only `workflow_document_text`, and shows a short example of the
missing fields.

## What Changed

- `packages/paperclip-runner/src/drivers/tool-input-error.ts`: for
missing top-level required fields, the error now says `missing required
fields: idempotencyKey, caseType, title, kickoff.`, `This call included
only: workflow_document_text.`, and a placeholder example built from the
schema, such as
`{"idempotencyKey":"<idempotencyKey>",...,"kickoff":{"toAgentId":"<toAgentId>","phase":"<phase>","instructions":"<instructions>"}}`.
Other validation errors follow after `Also:`. Field-description guidance
is unchanged.
- `packages/paperclip-runner/src/drivers/opencode/mcp-bridge.ts` and
`runner-tool-bridge.ts`: pass the call arguments to the error builder.
Only argument names are read; values are never echoed.
- `packages/paperclip-runner/src/drivers/tool-input-error.test.ts`: a
test on the real `create_case` schema and a test that other errors still
follow the missing fields.
- The `create_case` schema is not flattened. The model also left out the
flat fields (`idempotencyKey`, `caseType`, `title`), so nesting was not
the cause, and `kickoff` is shared with `handoff_case`.

## Verification

- `cd packages/paperclip-runner && npx vitest run
src/drivers/tool-input-error.test.ts
src/drivers/opencode/mcp-bridge.test.ts
src/drivers/opencode/opencode-server-driver.test.ts` passes (115 tests).
The two new tests fail on master.

## Risks

- Low risk. Only the error text for invalid calls changes. Validation
and dispatch are unchanged. The example is bounded to 600 characters and
the field lists to 12 names.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, with tool use and code
execution in Claude Code.

## 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
- [x] All Paperclip CI gates are green
- [x] 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-12 20:06:48 -06:00

49 lines
3.0 KiB
TypeScript

import { Ajv2020 } from "ajv/dist/2020.js";
import { expect, it } from "vitest";
import { toolInputError } from "./tool-input-error.js";
import { createCaseAction } from "../protocol-actions/case-data.js";
it("leaves ordinary validation errors unchanged and excludes guidance from unrelated scopes", () => {
const validate = new Ajv2020({ allErrors: true }).compile({ type: "object", required: ["id", "child"], properties: {
id: { type: "string", description: "Root ID guidance" },
child: { type: "object", required: ["id"], properties: { id: { type: "string", description: "Nested guidance" } } },
} });
validate({ id: 9, child: {} });
expect(toolInputError(validate)).toBe("Invalid tool input: /id must be string; /child must have required property 'id'");
expect(toolInputError(undefined)).toBe("Invalid tool input.");
});
it("bounds and deduplicates direct missing-property descriptions", () => {
const properties = Object.fromEntries(["a", "b", "c", "d", "e"].map(key => [key, { type: "string", description: key === "b" ? "a".repeat(1100) : key.repeat(1100) }]));
const validate = new Ajv2020({ allErrors: true }).compile({ type: "object", required: Object.keys(properties), properties });
validate({});
const result = toolInputError(validate);
expect(result).toContain("a".repeat(1000));
expect(result).toContain("c".repeat(1000));
expect(result).toContain("d".repeat(1000));
expect(result).not.toContain("e".repeat(1000));
expect(result).not.toContain("a".repeat(1001));
});
it("names the missing create_case fields, what the call included, and a short example", () => {
const validate = new Ajv2020({ allErrors: true, strict: false }).compile(createCaseAction.live.descriptor.inputSchema);
const input = { workflow_document_text: "Investigate, then verify." };
expect(validate(input)).toBe(false);
const result = toolInputError(validate, input);
expect(result).toContain("missing required fields: idempotencyKey, caseType, title, kickoff.");
expect(result).toContain("This call included only: workflow_document_text.");
expect(result).toContain('Missing fields example: {"idempotencyKey":"<idempotencyKey>","caseType":"<caseType>","title":"<title>","kickoff":{"toAgentId":"<toAgentId>","phase":"<phase>","instructions":"<instructions>"}}');
expect(result).not.toContain("must have required property");
});
it("keeps other validation errors after the missing fields", () => {
const validate = new Ajv2020({ allErrors: true }).compile({ type: "object", required: ["id", "count"], properties: {
id: { type: "string" }, count: { type: "integer" }, child: { type: "object", required: ["id"], properties: { id: { type: "string" } } },
} });
const input = { child: {} };
validate(input);
expect(toolInputError(validate, input)).toBe(
'Invalid tool input: missing required fields: id, count. This call included only: child. Send every required field together in one call, alongside the fields you already sent. Missing fields example: {"id":"<id>","count":0} Also: /child must have required property \'id\'',
);
});