Files
PaperClipAI/packages/plugins/sandbox-providers
DottaandPaperclip 89e3c23062 fix(daytona): stream files when export copies cannot fit (#18712)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - A native task must save its files before finalization can release
its writer.
> - Remote workspace capture can produce an archive that fits on the
sandbox disk.
> - Daytona then makes another copy before it downloads that archive.
> - The second copy can run out of space and leave completed work behind
a save hold.
> - This pull request uses the existing bounded stream when that copy
cannot fit.
> - The benefit is a saved archive without a second archive-sized
sandbox allocation.

## Linked Issues or Issue Description

Related: #18644 reduced capture scratch space. #18172 added the
disk-free directory export. #18705 preserves provider checkpoints on a
full disk and reports capture failures. This change handles the later
single-file download copy. It does not depend on #18705 and does not
replace its checkpoint fix.

**What happened?**

A native provider turn returned a successful result and captured its
workspace archive. The Daytona outbound file guard then failed with exit
43 and `No space left on device` while it copied the archive to a
reserved download file. Finalization and file-preservation retries could
not pass this boundary. The workspace kept its writer hold.

**Expected behavior**

Download an existing archive through a confined sandbox process when its
second copy cannot fit. Keep the source and all finalization holds until
the normal save commits.

**Steps to reproduce**

1. Capture a workspace archive in a Daytona sandbox.
2. Leave less free space than the archive needs for another copy.
3. Finalize the task. The outbound single-file guard fails before
download.

**Paperclip version or commit**

Reproduced against `6d72243d8a`. The incident used the native sandbox
runtime. This branch is based on current master.

**Deployment mode**

Cloud with native Paperclip Runner execution and remote workspace
storage.

## What Changed

- Remove partial outbound file copies after a failed snapshot command.
Only copy capacity failures select the stream path. Permission,
confinement, and transport errors still fail.
- Use the existing acknowledged terminal stream to read each file as the
sandbox user. Recheck canonical confinement and regular-file status. Use
a no-follow open. Keep the sandbox disk limit, host free-space reserve,
shared transfer deadline, and bounded teardown.
- Keep host files in private temporary files until the complete batch
has transfer receipts. Never pass a mutable live source to the
privileged download API.
- Add real-file and real-terminal regressions, a disposable Daytona
acceptance case, and workspace verification notes.

## Verification

- Red before repair: a real 5 MiB copy under a controlled file-size
limit failed with exit 43. The same test passes after repair and
compares every source and destination byte.
- The ten capacity cases pass. They cover producer failure after output,
source replacement, stream size limits, permission errors, timeout
teardown, cleanup, and a successful retry. A two-file case completes the
first stream and fails the second. Both old host files stay intact, both
source files survive, and retry saves both files. An isolated
early-publication mutation makes that test fail.
- The initial complete Daytona package suite passes: 537 tests passed, 8
skipped. After the test-only review follow-up, all 60 focused transfer,
stream, and diagnostic tests pass. The package typecheck also passes.
- Real Daytona acceptance passes: an owned Ubuntu 24.04 sandbox stops
and resumes, a copy to `/dev/full` reports ENOSPC, production export
saves the exact archive hash, and a second save after reconnect passes.
The test deletes only its disposable sandbox. This is provider-boundary
acceptance, not a UI journey.
- Assembled finalization acceptance passes with real Postgres and a live
Linux x86_64 Daytona sandbox. The production control-plane port accepts
one fixture result. The production workspace finalizer encounters the
failed copy, saves the files, and commits the task as `done`. A new
database client reads the committed result and exact file hash. The
workspace has no writer or running save, and there is still one run and
one result. No model turn runs. The target resolver is bound to the live
provider fixture. Object storage uses the production encryption and
local-disk service with an S3 admission label; this does not prove an S3
network transfer or a UI journey.
- The live tests used the fixed transfer source with SHA-256
`857b3d8c9ad75170707d95277c17c051ce4582fa79a9c38331d51d2800b36af5`. That
source is identical in this PR head.
- `pnpm -r typecheck` passes locally. The duplicate full local test run
passed all six chat shards before it was stopped during the server lane
in favor of completed current-head CI; a duplicate local build was
skipped. Full current-head CI passes, including typecheck, build,
general and serialized tests, Rust/Runner checks, all eight E2E shards,
and the `ci / e2e` and `ci / verify` aggregate gates.
- Greptile is 5/5 on the current commit with no unresolved review
threads.
- `node scripts/check-maps.mjs` and `git diff --check` pass. Map checks
prove structure only.

## Risks

- The fallback requires the Bash and GNU `dd`/`base64` tools already
required by the existing stream path.
- Terminal streaming is slower than the normal bulk download. It runs
only after a copy capacity failure.
- The workspace capture itself still needs sandbox space. This change
does not fix a full disk before an archive exists.
- The test injects a failed copy sink. It does not exhaust a shared host
disk. No original task was retried, and no deployment or merge is part
of this PR.
- No schema, API permission, writer ownership, or retry-budget change.

## Model Used

OpenAI GPT-6 through Codex, with reasoning, repository inspection, code
editing, shell tools, browser diagnostics, and automated tests. The
exact serving variant and context-window size are not exposed 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
- [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-11-03 06:11:41 -06:00
..