Commit Graph
2 Commits
Author SHA1 Message Date
Dotta 007d1c2ef1 perf(runner): parallelize static checks and memoize contract fingerprinting (#22912)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - On 8-core PR runners (`45592683902`, `45578886514`), `Verify
Paperclip Runner (static checks)` was the #3 PR critical-path straggler
at `192s–222s` (`142s–178s` inside `check:static`) because
`check:static` ran every build, contract check, prep test, and
API-authority Vitest suite serially on a single chain—rebuilding
`@paperclipai/paperclip-eval-kernel` 4 times, repeating
`acpx-profiles`/`protocol-types`/`tsc` twice, re-parsing Rust files
uncached in `contract-fingerprints.mjs` (`26s`), running a duplicate
contract test behind a serial `&&` barrier (`52s`), and running
`check-api-authority.mjs` (`75s`) without `--project
@paperclipai/server` or shared-PG `fsync=off`.
> - This pull request eliminates every redundant rebuild/check inside
`packages/paperclip-runner`, memoizes `contract-fingerprints.mjs` by
content hash (`sha1`, bit-for-bit identical digest, `10x` faster),
consolidates `test:typescript:prep` into one parallel `node:test`
runner, wires `check-api-authority.mjs` to `--project
@paperclipai/server` + disposable shared PostgreSQL while preserving
standalone self-contained execution for `release-verify.yml`, and
orchestrates `check:static` via a race-free 5-phase DAG
(`run-check-static.mjs`) that overlaps disjoint builds and tests across
available CPU cores.
> - All changes stay strictly within `packages/paperclip-runner/` and
preserve 100% of original static, protocol, build, prep-test, and
API-authority checks.

## Linked Issues or Issue Description

Refs #22804

**What existing behavior does this improve?**
Execution speed of `pnpm --filter @paperclipai/paperclip-runner run
check:static` (`Verify Paperclip Runner (static checks)` CI job) on
multi-core runners.

**Subsystem affected**
packages/paperclip-runner/ — static checks, contract fingerprinting, and
prep/authority test orchestration

**Current behavior**
`check:static` chains `check:eval-kernel &&
check:protocol-without-vitest && check:api-authority` serially,
rebuilding `paperclip-eval-kernel` 4x, running `tsc` and protocol checks
2x, re-stripping/re-parsing Rust sources uncached in
`contract-fingerprints.mjs`, running
`acpx-message-boundaries-package-contract.test.mjs` twice across a
serial `&&` barrier, and running `check-api-authority.mjs` without
`--project @paperclipai/server` or disposable shared PG.

**Proposed behavior**
Memoize Rust comment-stripping/parsing in `contract-fingerprints.mjs`
with bit-for-bit identical digest parity, merge `test:typescript:prep`
into one deduplicated parallel runner (`run-prep-tests.mjs`), add
`--project @paperclipai/server` + disposable shared PostgreSQL +
`--skip-build` to `check-api-authority.mjs`, and execute `check:static`
via a race-free 5-phase parallel DAG (`run-check-static.mjs`).

## What Changed

- **Memoized contract fingerprinting
(`packages/paperclip-runner/scripts/contracts/contract-fingerprints.mjs`,
`contract-fingerprints.test.mjs`):**
- Added content-addressed (`sha1`) caches for `stripRustComments`,
`withoutTestModules`, `rustSerdeItems`, per-file string constants, and
`#[cfg(test)] mod` declarations, plus compact `probeCache` keys (`16.23s
-> 1.63s` locally = `10.0x` speedup, bit-for-bit identical digest
`sha256:bacaefb049aa9a0841fe782fefb11ede1f99222d15151873e92194e2aab9c608`).
- **Deduplicated parallel prep test runner
(`packages/paperclip-runner/scripts/run-prep-tests.mjs`):**
- Removed duplicate
`test/acpx-message-boundaries-package-contract.test.mjs` and merged the
8 Copilot `node:test` files plus `run-check-static.test.mjs` into one
parallel `node-test.mjs` invocation (`44` unique suites, no serial `&&`
barrier).
- **Optimized API-authority verification
(`packages/paperclip-runner/scripts/check-api-authority.mjs`):**
- Scoped Vitest to `--project @paperclipai/server`, wrapped with
`scripts/ci/vitest-shared-postgres.mjs` when no external test PG URL is
supplied, and added `--skip-build` / `--dry-run` while keeping
standalone `pnpm run check:api-authority` (used by `release-verify.yml`)
100% self-contained.
- **Race-free 5-phase parallel `check:static` orchestrator
(`packages/paperclip-runner/scripts/run-check-static.mjs`,
`run-check-static.test.mjs`,
`packages/paperclip-runner/package.json`):**
  - Phase 1: `check:eval-kernel` (builds & tests `eval-kernel` once).
- Phase 2 (parallel, read-only): `acpx-profiles`, `antigravity-models`,
`protocol-manifest`, 6 `node --check` checks, 4 `protocol-types` checks
(each once).
- Phase 3 (3 disjoint parallel chains): (A) TS builds + entrypoints +
copilot assets + replay goldens, (B) serialized Cargo debug then release
builds (zero `target/.cargo-lock` contention), (C) `plugin-sdk
ensure-build-deps`.
  - Phase 4: `stage-runner-binary.mjs` after A and B complete.
- Phase 5 (parallel): `run-prep-tests.mjs --skip-build` alongside
`check-api-authority.mjs --skip-build` with buffered per-step output and
signal forwarding.

## Verification

- Verified exact digest parity:
`sha256:bacaefb049aa9a0841fe782fefb11ede1f99222d15151873e92194e2aab9c608`
(unchanged)
- `node --test
packages/paperclip-runner/scripts/contracts/contract-fingerprints.test.mjs
packages/paperclip-runner/scripts/run-check-static.test.mjs
packages/paperclip-runner/scripts/build-inputs.test.mjs
packages/paperclip-runner/scripts/stage-runner-binary.test.mjs` —
**35/35 PASS** (`2.46s`)
- `node packages/paperclip-runner/scripts/run-check-static.mjs
--dry-run` and `node
packages/paperclip-runner/scripts/check-api-authority.mjs --dry-run` —
**PASS**
- `node scripts/check-test-budget.mjs --base origin/master`, `node
scripts/check-maps.mjs`, `node --test scripts/check-test-budget.test.mjs
scripts/__tests__/run-vitest-stable-pr-mode.test.mjs
scripts/__tests__/runner-release-crate-cache.test.mjs
.github/scripts/tests/ci-plan.test.mjs` — **PASS**
- Live Linux execution of `Verify Paperclip Runner (static checks)`
(including embedded PG `check-api-authority.mjs` and Copilot asset
installation) will be verified end-to-end on PR CI.

## Risks

- Low risk: all changes are scoped strictly to
`packages/paperclip-runner/`, Cargo builds remain serialized in one
chain to avoid target lock contention, `stage-runner-binary.mjs` waits
for both TS and Rust builds before touching `dist/`, and standalone
`pnpm run check:api-authority` preserves full self-contained builds for
`release-verify.yml`.

## Model Used

- Gemini 4 Neon (High) via Antigravity agent swarm (`server-prune`,
`verifier`, `ci-pipeline`).

## 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
2026-11-25 05:22:08 -06:00
DottaandPaperclip 5bddff0920 feat(runner): add guarded API search and call fallback (#13003)
## 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>
2026-09-07 14:14:43 -05:00