mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-02 10:44:52 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Paperclip saves a remote agent workspace as an archive. A worker thread makes the archive and copies each Git repository into it. > - The worker sends all source refs to `git update-ref --stdin`. Git can stop before it reads all of this input, for example when it rejects a ref update or when it is stopped. > - The write to git's input then fails with `EPIPE`. The input stream had no `error` listener, so the error was uncaught in the worker thread. The worker stopped, and the capture failed with `write EPIPE` instead of git's own error. > - Sentry recorded this as an unhandled `write EPIPE` from a server worker thread on staging. > - This pull request adds an `error` listener on git's input in the archive `git()` helper. The helper reports git's exit failure. It reports the input error only when git exits with success. > - The benefit is that a failed capture shows the real Git failure and does not crash the archive worker. ## Linked Issues or Issue Description Refs #20813 Refs #21068 (draft). That PR adds the same kind of listener to six other call sites, and since `6ede87b` also to this line. This PR changes only the archive worker and adds a test that goes through the real worker thread. If #21068 merges first, rebase it to drop its hunk in `remote-workspace-snapshot-archive.ts`, or keep this change. **What happened?** A workspace capture failed with `Error: write EPIPE` from the archive worker thread. The real `git update-ref --stdin` failure was not reported. **Steps to reproduce** 1. Make a Git repository with about 3000 refs, so that the ref list is larger than a pipe buffer. 2. Put a `git` on `PATH` that exits with code 128 on `update-ref` and does not read its input. 3. Capture the directory with `captureRemoteWorkspaceDirectory`. **Expected behavior** The capture fails with the `update-ref` error (exit code 128). **Actual behavior** The archive worker stops with an uncaught `write EPIPE`, and the capture fails with `write EPIPE`. ## What Changed - `server/src/services/remote-workspace-snapshot-archive.ts`: the `git()` helper listens for `error` on the child's stdin before it writes. It rejects with git's exit error. It rejects with the input error only if git exits with success. - `server/src/services/remote-workspace-snapshot-archive-git-stdin.test.ts`: a new regression test. It captures a repository with 3000 refs through the real archive worker thread. A `git` shim closes its input and exits 128 on `update-ref`. The test expects git's error (code 128, message has `update-ref`) and no `EPIPE`. ## Verification - Red before the fix: `npx vitest run src/services/remote-workspace-snapshot-archive-git-stdin.test.ts` (in `server/`) failed with `expected 'write EPIPE' not to match /EPIPE/u`. - Green after the fix: the same test passed 3 times in a row. - The test uses `git --exec-path` to find the real git binary, so it does not depend on a git wrapper on `PATH`. - `pnpm verify` selected 1984/2340 files (most of the suite), so the broad coverage comes from required CI. ## Risks - Low risk. Only the archive `git()` helper changes. Calls without input are not changed. - A git call that exits with success but did not read all of its input now fails. Before, the uncaught error stopped the worker in that case too. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), through 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 (not applicable: no behavior or command docs change) - [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 <139239+devinfoley@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>