mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-06 23:20:53 +01:00
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - Hosted `claude_local` runs use the ACPX engine. Paperclip gives each
run its runtime MCP servers (for example the `paperclip-assigned` tool
gateway) as ACP `mcpServers` entries.
> - Claude's default MCP tool timeout is far longer than a run. ACP
`mcpServers` entries have no per-server timeout field. So the agent
waits on an MCP call until the call answers.
> - Hosted error reports show runs that end with "Run exceeded the
adapter execution timeout (sandbox)". The stop-time diagnostics from
#15962 show the problem: the agent went silent about 50 seconds into the
run, three tool calls of ACP kind `other` stayed pending, and nothing
ended them until the 4h sandbox backstop.
> - The gateway bounds the remote provider call (10s default, 60s max).
But other steps on the gateway `tools/call` path have no deadline: DB
queries, row locks and pool acquisition, the credential steps before the
provider timer starts, and the stdio child exit wait. One stuck step
holds the agent turn for hours.
> - This pull request gives the agent's MCP client a deadline:
`MCP_TOOL_TIMEOUT` for ACP Claude runs that receive runtime MCP servers.
> - The benefit is that a stalled gateway call becomes an MCP error that
the model can see. The turn continues and does not spend the full 4h
execution budget.
## Linked Issues or Issue Description
- Refs #15962 (diagnostics that identified the silent turn with pending
tools)
- Refs #15448, #15456, #15850 (related gateway timeout and
connection-health work; this PR does not overlap with them)
**What happened?**
A hosted `claude_local` run sent parallel MCP tool calls. No call
answered. The run stayed silent for about 4 hours. Then the sandbox
execution timeout ended it with "Run exceeded the adapter execution
timeout (sandbox)".
**Expected behavior**
A stalled MCP call ends with an error after a bounded time. The agent
sees the error and continues.
**Steps to reproduce**
1. Start an ACP `claude_local` run that has runtime MCP servers.
2. Make the gateway `tools/call` request stall (for example, hold a lock
that the request needs).
3. See that the run stays silent until the adapter execution timeout.
**Paperclip version or commit**
`master` at 976cdc7.
## What Changed
- Add `ACPX_CLAUDE_MCP_TOOL_TIMEOUT_MS` (15 minutes) in
`acpx-engine/constants.ts`. The value has wide headroom over the
gateway's longest legitimate wait (60s provider calls, 2 minutes of
approval preparation, and the 10-minute connection cap proposed in
#15850).
- The ACPX engine sets `MCP_TOOL_TIMEOUT` in the agent env for Claude
when the run has runtime MCP servers. If the adapter `env` already sets
`MCP_TOOL_TIMEOUT`, the engine keeps that value. Other agents and runs
without MCP servers do not change.
- Add an engine test for the bound, the no-server case, the user
override, and a non-Claude agent.
- Document the client-side deadline in `doc/MCP-RUNTIME-OPERATIONS.md`.
## Verification
- `npx vitest run src/acpx-engine/` in `packages/adapter-utils`: 21
files, 423 tests pass.
- The new test fails without the env assignment (`expected undefined to
be '900000'`), and passes with it.
- `npx tsc --noEmit -p packages/adapter-utils`: passes.
- The env reaches Claude through the same per-session env path as
`ANTHROPIC_MODEL`. `claude-agent-acp` merges this env into the Claude
SDK env.
## Risks
- A legitimate MCP call that takes longer than 15 minutes now fails. No
gateway path is designed to wait that long. Operators can set
`MCP_TOOL_TIMEOUT` in the adapter `env` to change the value.
- The value also applies to other MCP servers in the same Claude
session, for example servers in user settings. The same override is
available.
- Warm sessions get the env when the agent process starts again. The env
is not part of the session fingerprint, so this change does not reset
resumable sessions.
- This PR does not fix the server-side step that stalls. It bounds the
effect on the run. Server-side deadlines on the gateway `tools/call`
path (DB lock and statement timeouts, a request-level deadline, SIGKILL
escalation for stdio children) are possible follow-ups.
## Model Used
- Claude Opus 5.5 (`claude-opus-5-5`) through Claude Code, with tool use
and code execution. It read the repository, traced the gateway path,
edited the code, and ran the tests.
## 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: devinfoley <devinfoley@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
61 lines
3.0 KiB
TypeScript
61 lines
3.0 KiB
TypeScript
export const DEFAULT_ACP_ENGINE_AGENT = "claude";
|
|
export const DEFAULT_ACP_ENGINE_MODE = "persistent";
|
|
export const DEFAULT_ACP_ENGINE_PERMISSION_MODE = "approve-all";
|
|
export const DEFAULT_ACP_ENGINE_NON_INTERACTIVE_PERMISSIONS = "deny";
|
|
export const DEFAULT_ACP_ENGINE_TIMEOUT_SEC = 0;
|
|
export const DEFAULT_ACP_ENGINE_WARM_HANDLE_IDLE_MS = 0;
|
|
|
|
// The bound on the ACP startup handshake (`runtime.ensureSession()`). This
|
|
// deadline is separate from, and much smaller than, the whole-adapter
|
|
// execution timeout: it bounds only the handshake, not the agent turn. A real
|
|
// handshake completes in a few seconds; this value gives it generous room
|
|
// before the host gives up and reports a closed timeout code.
|
|
export const ACPX_HANDSHAKE_TIMEOUT_MS = 60_000;
|
|
|
|
// How often the host polls the duplex control-channel disposition while the
|
|
// handshake is in flight. The read is a cheap, non-mutating getter, so a
|
|
// short interval costs nothing while giving the host near-immediate notice
|
|
// of a channel loss.
|
|
export const ACPX_HANDSHAKE_TRANSPORT_POLL_MS = 250;
|
|
|
|
// The bound on how long the host waits, after a latched terminal sandbox
|
|
// duplex-channel loss, for the agent to answer the `turn.cancel()` request.
|
|
// `cancel()` only asks the agent to end the turn; it does not end the turn by
|
|
// itself. An agent that stopped answering never honors it, so this deadline
|
|
// is the host-side bound that ends the run without the agent's help. It is
|
|
// much smaller than the whole-adapter execution timeout.
|
|
export const ACPX_DUPLEX_LOSS_CANCEL_DEADLINE_MS = 30_000;
|
|
|
|
// The per-call deadline Claude applies to MCP tool calls (`MCP_TOOL_TIMEOUT`)
|
|
// when Paperclip attaches runtime MCP servers. Claude's own default is far
|
|
// longer than a run, so a gateway call that never answers holds the turn until
|
|
// the 4h sandbox backstop ends the run. The gateway bounds each provider call
|
|
// at 60s and approval preparation at 2 minutes; this leaves wide headroom over
|
|
// both.
|
|
// On expiry Claude returns an MCP error to the model and the turn continues.
|
|
// A user-configured `MCP_TOOL_TIMEOUT` still wins.
|
|
export const ACPX_CLAUDE_MCP_TOOL_TIMEOUT_MS = 15 * 60 * 1000;
|
|
|
|
// The closed ACP `ToolKind` enum. Run diagnostics may report these labels for
|
|
// pending tool calls; tool titles, names, and inputs never leave the run.
|
|
// Any other reported kind is collapsed to "unknown".
|
|
export const ACP_TOOL_KINDS = [
|
|
"read", "edit", "delete", "move", "search", "execute", "think", "fetch", "switch_mode", "other",
|
|
] as const;
|
|
|
|
export const ACPX_ADAPTER_AGENT_IDS = {
|
|
claude_local: "claude",
|
|
codex_local: "codex",
|
|
gemini_local: "gemini",
|
|
kimi_local: "kimi",
|
|
custom_acp: "custom",
|
|
} as const;
|
|
|
|
export type AcpxAdapterType = keyof typeof ACPX_ADAPTER_AGENT_IDS;
|
|
export type AcpxAgentId = (typeof ACPX_ADAPTER_AGENT_IDS)[AcpxAdapterType];
|
|
|
|
export function acpxAgentIdForAdapterType(adapterType: string | null | undefined): AcpxAgentId | null {
|
|
if (!adapterType) return null;
|
|
return ACPX_ADAPTER_AGENT_IDS[adapterType as AcpxAdapterType] ?? null;
|
|
}
|