mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-24 05:47:10 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Agents call connected tools (plugin connectors and remote MCP servers) through the tool gateway, and the runner reports a failed call back to the model > - The runner keeps only a leading stable error code from a failed tool result and drops free text and 5xx errors, so internal diagnostics never reach the model > - The gateway raised every error a connected tool reported about itself as a 502 with the code buried in free text, and stringified an MCP error's content array as "[object Object]" > - So an agent saw only "Paperclip semantic operation failed" for a rate limit, a concurrency refusal or a validation error, and retried blindly > - This pull request re-raises a tool's own error as a 4xx whose message starts with the tool's stable code > - The benefit is that agents see why a tool refused (for example `read_concurrency_limit` or `validation_error`) and can wait or fix their input ## Linked Issues or Issue Description **What happened?** An agent refreshing a tracker ran reads in parallel. The Customer success connector refused all but two at a time with `read_concurrency_limit`, and Notion refused some queries with validation errors. The agent saw "Paperclip semantic operation failed" for every one. Cloud recorded 299 concurrency refusals against 10 completed reads before the run gave up. **Expected behavior** The agent sees the tool's stable error code, for example `Paperclip semantic operation failed: read_concurrency_limit`. **Steps to reproduce** 1. Have an assigned connected tool fail with a tool-reported error (the gateway raises `ToolGatewayHttpError(502, "... (code: read_concurrency_limit, retryable)", "tool_error")`). 2. Call it through the runner's assigned tools. 3. The model receives only the generic failure text. ## What Changed - `server/src/services/native-runtime/assigned-mcp-tools.ts`: a `tool_error` from the gateway, or an `isError` result, is re-raised as a 422 `tool_error` whose message starts with the tool's stable code. The code comes from a plugin's `(code: ...)`, a JSON `"code"` field, or a leading `code:` prefix, with `assigned_tool_error` as the fallback. The message carries no provider free text. - `server/src/services/tool-gateway.ts`: tool error messages use the text of MCP content items instead of `String(array)`. - Tests for each code source and the fallback; the old tests that expected the raw 502 object now cover approval and revocation only. ## Verification - `npx vitest run src/services/native-runtime/assigned-mcp-tools.test.ts`: 63 passed. - The runner's ACPX feedback already keeps a leading `code:` prefix from a failed tool result's text (existing Rust tests), and the Codex driver passes a thrown error's message as that text. ## Risks - Low. Only errors that a connected tool reported about itself change. Approval, revocation and gateway failures are unchanged. The reason code stays `tool_error`. ## 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>