mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-09 05:41:56 +02:00
## Thinking Path > - Paperclip manages AI agents and their work. > - The new runner gives agents dedicated tools for common tasks. > - Some API operations and parameters have no dedicated tool. > - Agents need a controlled way to find and use those operations. > - This pull request adds API search and calls through the real server routes. > - Existing tools remain the preferred path. The new tools are disabled by default. > - Paired tests measure correctness, tool choice, cost and time. ## Linked Issues or Issue Description **Subsystem affected** Paperclip Runner contracts, production tool authority and the server API catalog. **Problem or motivation** The runner cannot use much of the API described by the old Paperclip skill. A generic HTTP client would also let agents bypass runner control rules. **Proposed solution** Add `search_api` and `call_api`. Resolve calls from the mounted API catalog. Use server-held, run-bound credentials. Preserve route checks and runner lifecycle rules. Keep the tools disabled until an operator enables selected companies. **Alternatives considered** A dedicated tool for every endpoint would add a large initial prompt. An unrestricted HTTP tool would weaken authorization and replay controls. **Roadmap alignment** This extends the native runner tooling. The repository owner requested this design and implementation. The roadmap and related open PRs were checked. No duplicate API escape-hatch PR was found. ## What Changed - Register two compact fallback tools in canonical contracts and provider projections. - Build deterministic API discovery from OpenAPI, mounted experimental routes and the old skill reference. - Execute bounded JSON, text, file and download requests through authenticated HTTP routes. - Recheck active runs, company access and work modes. Block runner lifecycle, scheduling, credential and approval bypasses. Keep routine annotation collaboration available. - Retain mutation receipts. Report uncertain outcomes without blindly repeating writes. - Add a company rollout gate and a durable eval worker with complete cost accounting checks. - Record child-task creation in the activity log with the agent and run. - Add contract, authorization, file, replay and real runnerd/PRP/HTTP tests. - Document rollout gates and paid coverage limits. The companion eval repository retains immutable attempts and reports. ## Verification - Final app commit `da58370524c3626a744eec20164397c5fb6ba9ef`: all 32 checks passed; the unrelated Storybook visual check was skipped. Greptile 5/5; no unresolved review threads. - Full Linux build and recursive typecheck passed. Repository tests were run by project and serialized shard; all 143 serialized server suites passed. - Runner TypeScript: 1,599 passed, two skipped. Rust release: 451 passing test reports. Conformance and replay parity passed. The required API check passed 837 tests, including runnerd → PRP → authority → real HTTP. - Bindings cannot enable API tools without the explicit deployment flag. Unit and real-authority tests prove the default-off boundary. - The standalone API check builds and stages its own binary. It passed after existing staged and debug binaries were removed from the test container. - UI and CLI tests passed. Initial environment failures (missing jq, Docker overlay file identity, and parallel linker memory pressure) and focused passing reruns are retained. The macOS full runner suite has platform-specific failures; Linux is the qualified full-check platform. - Eval harness: 27 tests passed; existing CI discovery ran 86 tests with two unrelated skips. Credential export rejection is tested against the actual report command. - Luna and OpenRouter Sonnet each passed 60 common-workflow runs: ten workflows, three repetitions per arm, zero unnecessary API fallback. - Sonnet passed 11 selected capability/contract cases after fixes. Gemini passed three smoke cases. DeepSeek exceeded the 120-second limit and remains unqualified. - Luna's two cost flags received focused follow-up. The original flags and a later n=1 latency flag remain visible. Sonnet had no cost or latency increase above 20%. - The catalog contains 785 entries; 58 were exercised across all stages. Most operation probes remain unrun and some need additional fixtures. Authored probes do not establish successful coverage. - Total conservative accounted cost: $9.875960. Active paid-campaign time: 88.16/90 minutes. No missing accounting. Later security and harness fixes have provider-free verification; no paid validation is claimed for those revisions. - Inspect the [qualification report](https://github.com/paperclipai/paperclip-evals/blob/codex/seach-call-api-tools/evals/runner-api-tools/reports/2026-09-07-production/READINESS.md) and [verification record](https://github.com/paperclipai/paperclip-evals/blob/codex/seach-call-api-tools/evals/runner-api-tools/reports/2026-09-07-production/verification.json). ## Risks - This is a broad authenticated API surface. Keep the default-off gate until an operator selects initial rollout companies. - Paid coverage is incomplete. Small regression samples do not prove all workflows are unchanged. - A timeout or server failure can follow a committed mutation. The result reports an unknown outcome and requires state inspection. - The new definitions add prompt tokens. The report retains cost flags and cache variation. - No database migration is required. - Repository rules require code-owner approval before merge. Technical CI and automated review are complete. ## Model Used OpenAI Codex based on GPT-6 assisted with code, tests and review. The exact serving model ID and context window are not exposed in this session. It used reasoning, tool calls and code execution. Eval models: `gpt-5.6-luna` with low reasoning, `openrouter/anthropic/claude-sonnet-5`, `openrouter/google/gemini-3.8-flash`, and `openrouter/deepseek/deepseek-v4-flash-0731`. Attempts retain runtime versions, model identity, usage and source provenance. ## 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 --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
152 lines
8.6 KiB
Markdown
152 lines
8.6 KiB
Markdown
# Runner API escape hatch
|
|
|
|
`search_api` and `call_api` extend the native runner when an available dedicated
|
|
operation cannot express the requested work. Existing tools remain preferred;
|
|
agents do not have to search before using them. Only two tool definitions are
|
|
advertised. The API catalog is returned on demand, never injected into the
|
|
initial prompt.
|
|
|
|
## Controlled rollout
|
|
|
|
The escape hatch is disabled by default. Set
|
|
`PAPERCLIP_RUNNER_API_TOOLS_ENABLED=true` on the server to enable it. For an
|
|
initial company rollout, also set `PAPERCLIP_RUNNER_API_TOOLS_COMPANY_IDS` to a
|
|
comma-separated list of company UUIDs. An unset list allows every company;
|
|
an explicitly empty list allows none. IDs must match exactly.
|
|
|
|
The server always requires the explicit `true` flag, including for server-owned
|
|
bindings. A binding can disable these tools for a baseline eval but cannot enable
|
|
them without operator opt-in. Setting the flag to `false` disables them. The server checks this switch when advertising tools,
|
|
when accepting a call, and immediately before HTTP dispatch after preparing any
|
|
files. Existing dedicated tools remain available. Operators must update the
|
|
environment of each server process and restart it for deployment-level changes;
|
|
this environment switch is not a live settings API.
|
|
|
|
Evaluate selected companies first. Compare success, unnecessary fallback calls,
|
|
cost, and latency against the dedicated-tool baseline before widening. Keep the
|
|
switch disabled if authorization, replay, or cost accounting fails.
|
|
|
|
## Discovery and requests
|
|
|
|
```json
|
|
{"query":"create project","limit":5}
|
|
```
|
|
|
|
Search is deterministic lexical ranking over OpenAPI paths, summaries and the
|
|
old skill reference. It supports task/issue and other terminology, exact
|
|
`METHOD /api/path/{parameter}` lookup, and opaque query/catalog-bound pagination.
|
|
Results include resolved request schemas, response descriptions, authorization
|
|
metadata, work modes, examples where available, and relevant dedicated tools
|
|
with their supported parameters. `limit` defaults to five and is capped at ten.
|
|
|
|
```json
|
|
{"operationId":"PATCH /api/projects/{id}","pathParams":{"id":"PROJECT_UUID"},"body":{"description":"Updated project description"}}
|
|
```
|
|
|
|
The catalog determines method and path. `companyId` is filled from the active
|
|
binding. Scalars and arrays are accepted in `query`. `body` defaults to JSON;
|
|
`contentType` supports text and raw uploads. `files` accepts entries containing
|
|
exactly one authorized `artifactId` or task-workspace `path`, and an optional
|
|
multipart `field`. No arbitrary URL, headers, authentication, or remote file URL
|
|
can be supplied. Routes still validate payloads and enforce permissions.
|
|
|
|
Requests have a 30-second HTTP timeout, 16 KiB URL limit and 10 MiB payload/response
|
|
transfer limit. Responses above 24 KiB and binary responses become company-owned
|
|
assets with retrievable references; text previews are limited to 2,000 bytes.
|
|
All redirects are refused. Oversized or interrupted mutation responses have an
|
|
unknown outcome, requiring inspection before another mutation.
|
|
Mutation responses with HTTP 5xx, HTTP 408, redirects, or malformed JSON also
|
|
retain an unknown outcome. A server may have committed the write before it
|
|
failed to return a valid response.
|
|
|
|
## Authority and replay
|
|
|
|
The server revalidates the active native run, assigned task and actor, then
|
|
creates a server-held agent JWT bound to that company and run. Requests go
|
|
through the actual HTTP router with its authorization, validation and domain
|
|
audit behavior. An additional `runner.api_called` receipt attributes mutations
|
|
to the run even where older route audit events omit that field.
|
|
The run and work mode are checked again after asynchronous file preparation, so
|
|
a stopped run cannot dispatch an upload prepared under its earlier binding.
|
|
|
|
Ask and pre-acceptance Plan permit reads through the escape hatch. Existing
|
|
dedicated-tool exceptions are unchanged. Runner-owned checkout, completion,
|
|
status/assignment transitions, approval decisions and execution-control actions
|
|
cannot be bypassed through generic calls. Routine creation, schedule/trigger
|
|
changes and manual/public routine execution require the existing scheduling
|
|
clients. Direct workspace runtime commands, runtime-slot stop/restart, case
|
|
automation retries and skill test-run controls also require their existing
|
|
execution clients. Gateway session credentials cannot enter generic results.
|
|
Routine metadata remains readable; annotation threads, comments and thread
|
|
resolution remain available through the fallback. API-only ordinary fields, such as a
|
|
task's `billingCode`, remain accessible even when a dedicated tool covers other
|
|
fields on that endpoint.
|
|
|
|
Mutation call IDs reserve a durable receipt in the run's existing `resultJson`
|
|
before dispatch. Replays return the recorded result. Reusing an ID with different
|
|
arguments is rejected. A crash after reservation leaves an unknown outcome and
|
|
never automatically resends the mutation. The limit is 512 mutation receipts per
|
|
run. No database migration is needed.
|
|
|
|
Workspace uploads use the existing workspace resource containment checks,
|
|
no-symlink file opens covering every path component, and bounded descriptor reads.
|
|
Local uploads require Linux or macOS; authorized artifacts work on other hosts.
|
|
Lifecycle-sensitive endpoints require an inline JSON object, so a raw uploaded
|
|
JSON file cannot hide protected fields from policy checks. Artifacts must belong
|
|
to the bound company. Secret-value access, credential management, secret proposals
|
|
and company exports require their existing secure clients. Search describes these
|
|
operations as restricted. `call_api` rejects them before creating a replay receipt
|
|
or making an HTTP request. Safe secret metadata listing remains available.
|
|
Agent credentials are never returned to the model. Streaming, WebSocket, MCP and authentication
|
|
handshakes are documented as protocol operations requiring their existing clients.
|
|
|
|
## Catalog maintenance
|
|
|
|
`runner-api-catalog.ts` builds from the server OpenAPI registry. Experimental
|
|
pipeline, Cases and smoke-lab routes now share their validators with discovery.
|
|
Seven Cases/pipeline route shapes are multiplexed by resource identity: the Cases
|
|
router intentionally forwards unknown resources to the pipeline router. Their
|
|
separate catalog entries explain which resource identifier is required. Registry
|
|
authorization descriptions are documentation; actual route checks are authoritative.
|
|
|
|
Regenerate old-skill enrichment after editing its API reference:
|
|
|
|
```sh
|
|
node scripts/generate-runner-api-reference.mjs
|
|
node scripts/generate-runner-api-reference.mjs --check
|
|
node scripts/generate-runner-experimental-api-metadata.mjs
|
|
node scripts/generate-runner-experimental-api-metadata.mjs --check
|
|
```
|
|
|
|
Mounted-route coverage tests include experimental routes. Three WebSocket mounts
|
|
are explicitly classified in the catalog. Shared protocol-action catalogs,
|
|
provider projections and generated compatibility checks include both tools.
|
|
|
|
## Verification and paid evals
|
|
|
|
The companion `paperclip-evals` worktree contains `evals/runner-api-tools`.
|
|
Its README documents explicit case/model selectors, the cumulative budget ledger,
|
|
fixture reset, progressive batches, and Evalbook generation. No command defaults
|
|
to running the entire paid suite. Capability, forced operation contracts and
|
|
paired common-operation regressions are reported separately.
|
|
|
|
Provider-free integration tests exercise real runnerd → PRP → authority → HTTP,
|
|
route validation and audit, stale bindings, Ask/Plan restrictions, identity
|
|
spoofing, file containment, uncertain mutation receipts and fixture isolation.
|
|
|
|
The Evalbook viewer uses the existing shared viewer and stylesheet on master.
|
|
The report retains actual persisted-state summaries for private local inspection;
|
|
public replay continues to withhold company-state details.
|
|
|
|
The ACPX sidecar includes the upstream terminal-usage accounting correction from
|
|
`origin/codex/evalbook-default-chat-sept6`. Its qualified Claude executable requires
|
|
Linux x64. The first macOS stage records a zero-cost ACPX admission failure. A later user-authorized
|
|
OpenCode/OpenRouter Sonnet profile reached a real HTTP read, but the attempt failed
|
|
on a missing harness completion contract and incomplete terminal accounting. The
|
|
harness contract is corrected. The missing fourth request was subsequently
|
|
recovered from the matching OpenRouter session and generation billing record;
|
|
the original failed attempt remains immutable. New attempts retain an append-only,
|
|
flushed event journal and bounded provider trace outside disposable runtime files.
|
|
Provider-free startup succeeds for OpenRouter Sonnet and DeepSeek. See
|
|
`doc/plans/2026-09-07-runner-api-production-readiness.md` for remaining release gates.
|