mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-29 06:50:43 +01:00
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work.
> - Before a run starts, Paperclip copies each selected skill version
from skill package storage into a local cache.
> - Skill package reads share small I/O queues for each process. Each
queue has 2 active permits and 32 waiting slots.
> - Each read started its 180-second deadline before it waited for a
permit. A read that waited behind other transfers used up its deadline
in the queue.
> - On a busy host, a run then failed before its agent started with
"Failed to materialize the selected skill version: The operation was
aborted due to timeout". The next run did the same cold read and failed
the same way.
> - This pull request starts each transfer deadline when the queue
grants the permit.
> - The benefit is that a cold skill read under load waits for its turn
and then gets its full transfer deadline.
## Linked Issues or Issue Description
**What happened?**
A staging host had a burst of 21 run failures in 15 minutes. All runs
were in one company, and each failed with "Failed to materialize the
selected skill version: The operation was aborted due to timeout". The
runs woke at the same time after a provider usage limit reset. The skill
cache was cold.
**Expected behavior**
A run that waits for a skill package I/O permit gets the full 180-second
deadline for its own transfer. Time spent in the queue must not count
against that deadline.
**Steps to reproduce**
1. Make the skill package cache cold for three companies.
2. Stall the archive reads of two companies, so that they hold both
storage permits.
3. Resolve the runtime skills of the third company. Its reads now wait
in the queue.
4. Wait longer than the transfer deadline, then release the stalled
reads.
5. On `master`, the third company's skill resolves as missing with the
timeout message. Its own transfer would take milliseconds.
**Paperclip version or commit**
`master` at 7a2ee0da1c.
## What Changed
- `withPackageIo` now creates the transfer deadline after it grants the
permit, and gives the action that signal. A queued wait stops only when
the caller cancels.
- Manifest loads, isolated package reads, warm package materialization,
durable verification, cached version reads and single-file reads no
longer start a deadline before they queue. Each transfer still has the
same 180-second deadline.
- The cold-response permit gets no deadline of its own. That permit only
bounds decoded responses until cleanup. The storage transfer inside it
still has its deadline.
- An isolated read now gives its consumer the transfer signal. The
cached file reads inside that consumer use it.
- Package uploads (`prepare`) are not changed.
- Added the regression test `starts package transfer deadlines after
queued storage waits`.
## Verification
- `pnpm --filter @paperclipai/server exec vitest run
src/__tests__/skill-package-store.test.ts -t "starts package transfer
deadlines"`
- With this change: passes.
- With `master`'s `skill-package-store.ts`: fails. The skill resolves as
missing with "Failed to materialize the selected skill version: The
operation was aborted due to timeout".
- Related suites: `skill-package-store`, `skill-package-upload`,
`skill-version-cache`, `skill-version-retention`, `runtime-skill-cache`,
`company-skills-runtime-concurrency`,
`company-skills-runtime-selection`, `managed-skill-content`,
`skill-repository-package`, `skill-version-cache-lock`,
`skill-package-work`, `skill-package-storage-migration`,
`skill-package-storage-migration-postgres` and `skill-package-recovery`.
235 of 236 tests pass.
- The only failure is `bounds and validates archives, binaries, paths,
executable modes, and corruption`. It also fails on unchanged `master`
in the same sandbox, because the sandbox `umask` is `077`. It is not
related to this change.
- A timing probe with 20 concurrent cold resolves in one company and 4
other cold companies failed on `master` and passed with this change.
## Risks
- A queued read can now wait longer before it fails. The wait is still
bounded, because each queue has at most 32 waiting reads and every
active transfer has its own deadline. A full queue still returns "Skill
package storage is busy; retry shortly." immediately.
- After a cold fill is published, cache trimming is no longer bounded by
the fill's deadline. Trimming keeps its own 10-second limit, and each
storage check inside it has its own transfer deadline.
- If a manifest read times out, the store now tries the saved legacy
contents or the restore recipe before it fails. Before, the timeout
stopped it before those fallbacks. Both fallbacks are already
authoritative sources for the same manifest.
- Low risk otherwise. The change is limited to `skill-package-store.ts`.
## Model Used
- Claude Opus 5.5 (`claude-opus-5-5`), in Claude Code with tool use and
code execution.
## 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
- [ ] 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
Related: #22310 changes `skill-package-runtime.ts` and the same test
file. It does not change these deadlines.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: paperclipbugbot <356415228+paperclipbugbot@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>