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 > - Native agents run in managed sandboxes, and each workspace needs the provider pack (Node, provider CLIs and provider assets) before the provider can start > - The fleet sandbox image has an older provider pack in `/opt`, so the server stages its own pack into each workspace and reuses image files with the same bytes by copying them > - The staged pack is about 3.0 GB of a 10 GiB sandbox disk, and agent tasks on large repositories filled the disk > - About 0.5 GB of that pack is the same bytes stored again under other paths: one OpenCode binary in three packages, one Node binary in two provider runtimes > - This pull request stores repeated bytes once, as hardlinks to one private copy, and copies a path that the image does not have from the same bytes under another image path instead of transferring it > - The benefit is about 550 MB more free disk per workspace, one less large layer to transfer, and a faster staging step ## Linked Issues or Issue Description **What happened?** On staging, agent tasks on the Paperclip monorepo filled their 10 GiB managed sandboxes. In a live fleet sandbox, the workspace's `.paperclip-runtime/paperclip-runner/provider-pack` used 3.0 GB (`node_modules` 1.4 GB, `provider-assets` 1.6 GB). **Expected behavior** A staged pack stores each large file's bytes once. **Steps to reproduce** 1. Use a fleet sandbox whose image pack is older than the server's pack. 2. Start a native run in it. 3. In the staged pack, compare the three OpenCode binaries (`opencode-ai`, `opencode-linux-x64`, `opencode-linux-x64-baseline`) and the Pi and Kimi `node` binaries. They have the same bytes and different inodes. **Paperclip version or commit** `e4b119440e` (master on 2026-11-18). Related: #16493 added the layered reuse. #21784 reuses an image pack that differs only in build provenance. ## What Changed - `provider-pack-layers.ts` (remote reuse step): - A large file whose bytes were already copied privately for another path in this pack is a hardlink to that private copy. - A large file that the image does not have under its own path is copied from an image file with the same bytes under another path, and hashed, instead of being transferred. - Every staged file stays a physical file inside the pack. The image is never linked, because the runner requires pack files and provider asset folders to be physical paths inside the pack (OpenCode launch files, Kimi and Pi installers). ## Verification - `pnpm vitest run src/services/native-runtime/provider-pack-archive.test.ts` (server): 50 passed, with real GNU tar and zstd. New tests: - repeated bytes are one private inode (`nlink` 3), not the image's inode; a path the image lacks comes from an image twin; only the overlay is transferred; the image is unchanged - when the image twin has different bytes, every repeated path is transferred and has the correct bytes - Red/green: the first new test fails on master's code and passes with this change. The second is a safety test and passes on both. - Replay on real fleet sandboxes. I created fresh Daytona sandboxes from the staging fleet snapshot `fleet-sbx-6d5b52eaeeb7`. I used the real file list (paths, sizes, SHA-256) of the current server pack, taken from a live staging workspace. Each replay ran the reuse step, the overlay extraction and the verifier's tree walk. - Disk per workspace, including the layers that are still transferred: 3,033 MB before, 2,484 MB after (−549 MB). - Transfer: the Kimi Node binary layer (126 MB uncompressed) is no longer transferred. - Staging time, same sandbox, alternating order (s): before 5.78, 5.84, 7.39, 7.61; after 5.13, 5.40, 7.04, 6.73. After is faster in all 4 pairs. The reuse step alone: before 2.42–3.59 s, after 1.85–2.99 s. - `pnpm verify`: see the comment below. ## Risks - Repeated bytes share one inode inside the pack. A process that writes one of these binaries also changes its twins. Provider binaries are not written at runtime. - The image is only read, never linked or changed. - No migration, API, or configuration change. ## Model Used Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, used in Claude Code with tool use and code execution (shell, Daytona API, local 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: Claude Opus 5.5 <noreply@anthropic.com>