Files
PaperClipAI/server/src/services
Devin FoleyandClaude Opus 5.5 fec961b580 fix(workspaces): record why a full-disk read-only capture failed (#19619)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - A remote agent workspace is saved to durable storage after each run.
The save builds a portable archive inside the sandbox.
> - When the sandbox disk is full, #19465 starts one read-only fallback.
The fallback copies a verified source to the controller and seals the
archive there.
> - If that fallback also fails, the code keeps the original disk-full
message and puts the fallback failure in `error.cause`.
> - `remoteWorkspaceFailureCause` reads only the top message. The
recorded copy-back cause and the run error therefore say only "the
sandbox disk is full". The fallback stage and reason are lost.
> - Also, the sandbox inventory script reports every failure as
`unsafe`, and `command()` drops that token. The fallback then says
`reason=operation_failed` for a linked worktree, a budget limit, or an
unreadable file.
> - #20678 later made a transient fallback failure (a dropped
connection) surface as its own cause. Every other fallback failure is
still wrapped in the disk-full error, and that wrapped cause is still
dropped. A staging save on a release with #20678 again recorded only the
bare disk-full message.
> - This pull request keeps the disk-full code and message unchanged. It
appends the fallback's closed-grammar cause to the recorded cause, and
it names the inventory refusal.
> - The benefit is that an operator can see why a full-disk save still
failed (for example `stage=inspect reason=unsafe_source`), so the next
fix targets the real step.

## Linked Issues or Issue Description

Refs #19465
Refs #19543
Refs #20678

**What happened?**

On a release that contains #19465 and #19543, a hosted run finished its
turn, and all three workspace save attempts failed. Each recorded cause
was only `remote_workspace_sandbox_disk_full: the sandbox disk is full;
free space in the sandbox before saving the workspace`. The read-only
fallback ran on each attempt, but the record did not say at which stage
it stopped or why. Later, the existing provider-cache reclaim freed
space and the save completed. The fallback failure itself is still
unexplained, because the record does not contain it.

**Expected behavior**

The recorded cause keeps the disk-full code, so retries and cache
reclaim work as before. It also names the fallback stage, a closed
reason, and a transport label. It never includes paths, file names, or
provider text.

**Steps to reproduce**

1. Create a workspace with a `.git` file (a linked worktree pointer) or
with one unreadable file.
2. Make the normal capture report a full disk, so the read-only fallback
runs.
3. Call `remoteWorkspaceFailureCause` on the capture error.
4. On `master`, the result is only the disk-full message. With this
change, the result ends with `;
remote_workspace_readonly_capture_failed: stage=inspect
reason=unsafe_source transport=provider_error` (or `reason=fs_eacces`).

## What Changed

- `remoteWorkspaceFailureCause`: when the error message is the exact
disk-full message and `error.cause` matches the closed
`remote_workspace_readonly_capture_failed: stage=… reason=… transport=…[
code=…]` grammar (the existing `READONLY_CAPTURE_FAILURE_CAUSE` from
#20678, now also allowing digits in the reason for errno codes), append
that cause after `; `. Other causes are not attached. The thrown
message, the derived code (`remote_workspace_sandbox_disk_full`), and
the disk-full equality checks used by retry and cache reclaim do not
change.
- The sandbox inventory script now writes
`remote_workspace_readonly_capture_budget` for a budget limit and
`remote_workspace_readonly_capture_fs_<errno>` for a filesystem error
code. Other refusals still write
`remote_workspace_readonly_capture_unsafe`. It never writes error text
or paths.
- `command()` accepts only these exact tokens from a failed capture
command, so the fallback can map them.
- The fallback maps `fs_<errno>`, `disk_full` and command timeouts
(`timed_out`) to their own reasons, in addition to the existing
`unsafe_source`, `source_changed` and `budget_exceeded`.
- New test file `remote-workspace-readonly-capture-cause.test.ts` with
four cases: source changed during transfer, linked worktree refusal
before transfer, unreadable file by errno only (no private file name in
the cause), and a cause outside the grammar that is not attached.

## Verification

Rebased onto `master` at `b4cea5b5a4` (2026-11-21). The only conflict
was in `remoteWorkspaceFailureCause`, where #20678 added a direct match
for a thrown read-only cause. Both behaviours are kept, and the PR now
reuses #20678's grammar instead of adding a second regex.

- Red on `master` (`b4cea5b5a4`, with the two source files swapped back
to `master`): three of the four new tests fail, each getting only the
bare disk-full message. The grammar guard test passes on both.
- Green with this change: all four new tests pass.
- From `server/`: `npx vitest run
src/services/remote-workspace-readonly-capture-cause.test.ts
src/services/remote-workspace-readonly-inventory.test.ts
src/services/remote-workspace-transport.test.ts
src/services/native-runtime/native-run-finalizer-telemetry.test.ts`: 213
passed, 6 failed. All 6 are in `remote-workspace-transport.test.ts` and
are environmental in this sandbox:
- `does not run ambient checkout filters…`, `uses trusted SSH rewrites
only for clone…` and `rejects an unsafe restore lock…: directory_shared`
fail the same way with the unchanged `master` source (the sandbox's Git
wrapper blocks clones).
- The other three hit the 15 s test timeout under load. Run alone,
`restores offline partial Git state…` passed twice with this change, and
passed once and failed once with the unchanged `master` source.
- The finalizer telemetry suite (#20678's tests, including "hands a full
sandbox disk to saved-work recovery on the first copy-back failure")
passes. The appended cause keeps the
`remote_workspace_sandbox_disk_full:` prefix, and the saved failure code
still comes from the text before the first `:`.
- A full typecheck was not run locally: `tsc` ran out of memory in this
sandbox. CI typecheck and build must pass.
- Environment: Linux, Node v25.9.0, filtered `pnpm install` of the
server package.

## Risks

- Low risk. The thrown error message and the save failure code do not
change, so retry policy, recovery classification and full-disk cache
reclaim behave as before.
- The run error text ("Last cause: …") becomes longer for this case. It
stays below the 1024-character bound and matches the existing
`readWorkspaceFailureCause` grammar (a test checks this).
- An unreadable or vanished file now reports `fs_<errno>` instead of
`unsafe_source`. That is more exact. Both reasons keep the source
retained and do not produce a receipt.
- No documentation text changed. `doc/execution-semantics.md` says that
transfer failures "retain the original disk-full error", and that stays
true.

## Model Used

- Provider: Anthropic. Model: Claude Opus 5.5 (`claude-opus-5-5`), used
through Claude Code with tool use (shell, file editing, test runner,
GitHub connector). The exact context window is not shown in this
session.

## 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 (the new tests pass; the
two clone-dependent failures also fail on unchanged `master` here)
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes (no
change needed: the documented contract is unchanged)
- [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>
2026-11-20 19:32:44 -08:00
..
…
…
…
…
…