Files
PaperClipAI/server
DottaandClaude Opus 5.5 949bc3765c fix(cloud): preserve a settled harness backup whose session is not selected, as offline does (#22647)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - A hosted server copies its Runner harness backups to shared storage
before it moves to a volume-free shape
> - The online pass copies a settled backup only when exactly one task
session selects the backup's native session
> - Some stacks stay blocked with
`native_harness:source_session_not_selected`, but the offline migration
publishes the same backup
> - A selected session whose backup source is not on the disk is
reported with no code at all
> - This pull request applies the offline outcome online with a
selection fence, and names the missing-source case
> - The benefit is that these stacks can move, and the native harness
blocker always says why it remains

## Linked Issues or Issue Description

Refs #19715, #22294

**What happened?**
On staging, two stacks stay ineligible with
`native_harness_backups_require_migration`. Each online pass defers one
backup as `native_harness:source_session_not_selected`. That code means
that no task session, or more than one, points at the backup's native
session.

**Expected behavior**
The online pass gives a settled backup the same outcome as the offline
migration. The offline migration publishes the backup whether or not a
session selects it.

**Steps to reproduce**
1. Keep a sealed backup of a failed native run with a settled
coordinator and a verified lease stamp.
2. Delete the task session that selects it (or add a second one for the
same native session).
3. Run the online pre-copy. It defers the backup as
`source_session_not_selected`. The offline migration publishes it.

**Additional context**
The selection check exists so that publication does not race a change of
the selected session. It does not need exactly one selection for that.

## What Changed

- The settled-source owner records the exact set of task sessions that
select the native session: none, one or several. Publication rechecks
the same set under a share lock. A changed selection keeps the source
local (`source_changed`), as before. The `session_not_selected` reason
is removed.
- The run, coordinator, task, lease, finalization lock and payload
checks do not change.
- After the source walk, the pre-copy lists the selected sessions that
still need a backup. A selected scope with no source on this disk is
reported as `selected_source_absent`. Before, it produced no outcome.

## Verification

- Red (embedded PostgreSQL, real files): `cd server && npx vitest run
src/services/native-runtime/native-harness-online-preservation.integration.test.ts`
failed 4 new tests: unselected and ambiguous sources were deferred, and
a missing selected source produced no outcome.
- Green: the same file passes (20 tests). New tests show that an
unselected or ambiguous source publishes, the run and task sessions do
not change, the backup restores the exact bytes, and a selection that
appears before publication keeps the receipt pending.
- `native-harness-backup-storage.integration.test.ts`: the former
`source_session_not_selected` expectation now expects publication by the
settled-source owner (activity `native_harness_backup_preserved`), not
by the offline owner.
- `npx vitest run` of all 8 files that use these owners (startup gate,
prestage command, filesystem independence, obligations, storage, online
preservation): 240 tests pass.
- `pnpm --filter @paperclipai/server typecheck` passes.
- `pnpm verify` result is in a comment below.

## Risks

- A settled backup of an unselected session now moves to shared storage
online. The offline migration already does this, and the source files
stay on the disk.
- The pre-copy now runs the obligation scan once after the source walk.
This is the same scan that the eligibility read runs.
- Pass deferral codes change:
`native_harness:source_session_not_selected` is gone, and
`native_harness:selected_source_absent` is new.

> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, with tool use and code
execution in Claude Code.

## 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>
2026-11-23 12:51:32 -06:00
..