Files
PaperClipAI/tests
Devin FoleyandPaperclip 158613ef81 Permit idle sleep with proved passive remote workspaces (#23335)
## Thinking Path

> - Paperclip runs agent work and retains its files after a run ends.
> - Remote workspaces save those files in a durable archive.
> - The idle inventory still treats every remote workspace row as active
work.
> - A saved archive or an unused setup reservation can then keep an idle
instance awake.
> - This PR adds a read-only proof in the remote workspace owner and
uses it in the existing idle check.
> - The proof keeps active work and uncertain recovery awake and
preserves all retained data.

## Linked Issues or Issue Description

**What happened?**

A retained `cloud_sandbox` workspace blocks idle sleep after its archive
commits and its allocation is released. The passive workspace check only
accepts local directories and git worktrees. An unused reservation can
also remain after a bootstrap failure that started no provider work.

**Expected behavior**

An idle instance can sleep when existing receipts prove that its remote
files are saved or that a setup reservation was never used. Missing,
foreign, contradictory, and unfinished state must keep blocking sleep.

**Steps to reproduce**

1. Save a remote workspace and finish its snapshot operation.
2. Release its allocation with the matching stop receipt, or retain no
allocation.
3. Keep the workspace row and inspect idle safety. Before this change,
the row still reports work.

Related: remote workspace storage in #18403. No duplicate open
sleep/workspace PR was found.

## What Changed

- Add a pure SQL proof for a committed, scoped archive and its completed
source operation. Require the stored encryption scheme and correctly
shaped IV, tag, and ciphertext. An unchanged save can reuse an older
snapshot.
- Require exact release evidence for a retained location and every
allocation of an unused reservation. Unused reservations require an
ended legacy bootstrap, an explicit no-provider-work result, no live
controller or retry, and no native finalization. A pristine reservation
cannot carry retained recovery-file references.
- Apply that proof through the existing passive workspace check. Keep
runtime configuration, commands, due cleanup, reopen fences, and every
independent run, lease, and recovery check.
- Add PostgreSQL regression cases and describe the proof in the
idle-safety documentation. The existing shared database fixture keeps
the tests in one suite instead of adding another database startup.
- Correct two pre-existing receipt browser assertions uncovered by
required CI. Plain comments have supported keyed retries since October
28; the older tests assumed one POST even when receipt reads lose the
race to backoff. Assert exact request identity and payload across
retries, one saved comment, and preservation of the next draft.

## Verification

- Receipt CI follow-up, Node 25.6.1 on macOS: the full
`board-attachment-receipts.spec.ts` passed twice with four Chromium
workers (28/28). Both corrected cases passed with delayed issue reads
after reproducing both old failures under the same delay. `node
scripts/typecheck-test-projects.mjs --reuse-declarations tests/e2e` and
the focused test-budget check passed. Only browser assertions changed
after the 323-test server verification.
- Node 25.6.1 on macOS: `pnpm --filter @paperclipai/server typecheck`
passed.
- Final revision: `pnpm exec vitest run
server/src/__tests__/idle-sleep-safety.test.ts
server/src/__tests__/idle-sleep-diagnostics.test.ts`: 323 passed. Both
suites used real embedded PostgreSQL. An earlier run also selected the
remote-workspace lifecycle suite; its 16 cases were skipped because its
external test database was not configured.
- Red-green: the new saved-workspace regression failed before the first
proof. Both unused-reservation cases failed before that proof was added.
The focused regressions passed after the changes. Empty key material and
a foreign allocation bound to an unused writer were also reproduced
red-green during review.
- `pnpm verify --explain` returned the documented exit 2 because the
documentation path requires broader CI. Required CI will supply that
coverage; a full local repository run was not substituted.
- After rebasing onto current `master`, the focused passive-state tests
and server typecheck passed again.
- `git diff --check` and a staged secret/PII scan passed.
- The previous revision (`078e60f`) received Greptile 5/5 with its
key-format thread resolved. [Initial
CI](https://github.com/paperclipai/paperclip/actions/runs/46536659729)
failed in a Rust executable fixture (`ExecutableFileBusy`) and a browser
receipt assertion. The targeted rerun passed Rust but failed the
companion receipt test. Both browser assertions expected one POST,
contrary to the documented keyed retry contract. A scratch fault fixture
delaying issue reads by 1.6 seconds reproduced both old failures
(`Expected: 1 / Received: 2`); both revised cases passed under the same
delay. The delay fixture is kept outside the branch. Final head
`97269b3420387b28fda5f35f69a6b9ed45d5bb54` is merge-ready: all required
gates passed, 81 checks succeeded and four were skipped by workflow
policy, Greptile is 5/5 on this head, and the one review thread is
resolved. GitHub reports `MERGEABLE` / `CLEAN`. The skipped
external-database local cases and earlier failed attempts remain
recorded above.
- No provider suspension, external wake, deployment, or cost-saving
result is claimed from these local checks. The proof adds no provider
call, recurring scan, or extra database round trip. It runs within the
existing bounded, read-only snapshot.

## Risks

This expands automatic sleep eligibility for proved passive remote
state. A proof error could stop an instance with unfinished work. The
new cases cover dirty or foreign authority, missing or malformed
snapshot key material, incomplete operations, foreign or unverified
leases, active ownership, retry state, and retained recovery references.
The SQL checks the stored key format; archive decryption and object
verification remain with the restore owner. The existing owned hold,
generation checks, runtime probes, and final host authorization still
apply. The change does not delete files, clear reservations, rewrite
history, create receipts, change schedules, or add a migration. Revert
the remote-provider predicate to restore the previous refusal behavior.
Hosted stop/wake qualification remains part of deployment acceptance.

## Model Used

OpenAI GPT-6.1-sol with xhigh reasoning through Codex in T3 Code.
Tool-assisted implementation, source review, and PostgreSQL
verification.

## 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 described the issue in-PR following the bug report template
- [x] I have not referenced internal/instance-local Paperclip issues or
links
- [x] My branch name describes the change and contains no internal
ticket id or instance-derived details
- [x] I have run relevant tests locally and they pass; skipped
external-database cases are stated above
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation
- [x] I have considered and documented risks
- [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

- Final revision [ci /
e2e](https://github.com/paperclipai/paperclip/actions/runs/46539276027/job/142275047883):
passed.

- Final revision [ci /
verify](https://github.com/paperclipai/paperclip/actions/runs/46539276027/job/142275348382):
passed.

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-11-30 17:29:31 -08:00
..