Files
PaperClipAI/doc/plugins
0b2acfb956 refactor(runner): let the provider decide whether a released Runner relaunches (#22442)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Native Runner sessions can run in a remote environment task that a
plugin provider owns
> - After a turn, the provider can park the Runner, and the next run can
relaunch it from the saved state
> - Core kept its own local record of each released Runner, and the
provider kept its park record too
> - Core lost its copy when the local session directory was not durable.
Then Core restored from a checkpoint although a park existed, and the
turn was slower
> - This pull request makes the provider the only authority on the park.
Core resumes the source from its durable checkpoint, and the provider
answers "resumed" or "unavailable"
> - The benefit is fewer missed relaunches, and less code in Core

## Linked Issues or Issue Description

**What existing behavior does this improve?**

The relaunch of a parked Runner for the next run of a native session.

**Subsystem affected**

Native runtime: `server/src/services/native-runtime`, the Runner control
plane in `packages/paperclip-runner`, and the environment task SDK.

**Current behavior**

Core writes a released-Runner record (source identity, task id and scope
digest) to the local session directory when a release completes. Core
relaunches a parked Runner only when that record exists. Core also
checks the archived Runner state on the provider's relaunch reply. When
the local directory is gone (for example, after the server process
restarts on a new host), Core restores from a checkpoint into a fresh
task, although the provider still has the park.

**Proposed behavior**

Core resumes the source identity from its durable controller checkpoint
on the lease's current task. The provider decides from its own park
record. When no park of that source exists, the provider answers
`unavailable`, and Core starts a fresh task from the saved session, as
it does today for other unavailable answers.

**Reason and benefit**

One record for one fact. Core no longer needs local state to relaunch,
so more runs relaunch. The change removes about 160 lines.

**Breaking changes**

A provider must answer `unavailable` when it has no park for the
requested source. A provider that answers with an error instead makes
the resume fail. The `archivedState` field on a resumed relaunch result
becomes optional. Providers can continue to send it; Core does not read
it.

**Additional context**

Reattach to a live Runner process in the same server is not changed. A
relaunch after a restart still requires the process configuration to
match, because the relaunch reuses the parked launch. A changed
configuration starts a fresh task.

## What Changed

- Removed the local released-Runner record: its writer, its readers, the
scope digest, and the resume and retire callbacks that cleared it.
- Derived the relaunch source from the durable Runner identity. Kept the
check that the task is the lease's current task.
- After a restart, Core takes the released source from the durable
identity for every provider that releases tasks: one that relaunches the
parked Runner, and one that hands it over.
- Added a test that a checkpoint saved with the old released-Runner
record still loads.
- When a restart recovery resumes a released source and the provider
answers `unavailable` with the task stopped and its state saved, Core
now starts a fresh task from the saved session, as it does for a
relaunch. The fallback finishes the old task's startup context before it
inspects the replacement task. An executor test covers this path.
- Updated the SDK source pin in
`tests/runner-e2e/source-sdk-public-inputs.json`.
- Stopped the check of the archived state on the relaunch reply. Removed
`isSettledReleasedRunnerCut` and the resume `settled` hook.
- SDK: a resumed relaunch result no longer requires `archivedState`.
- Updated `doc/plugins/PLUGIN_ENVIRONMENT_TASKS.md` and the tests.

## Verification

- `pnpm run typecheck` in `server` (builds all dependent packages):
pass.
- `pnpm vitest run
src/services/native-runtime/plugin-runner-task.test.ts
src/services/native-runtime/remote-warm-session-recovery.test.ts` in
`server`: 147 passed.
- `pnpm vitest run
src/services/native-runtime/native-session-executor.test.ts -t "releases
settled|accepts only the
attached|released|relaunch|warm|unavailable|recover"` in `server`: 594
passed.
- `runnerd-codex-transport.test.ts` in `packages/paperclip-runner`: 337
passed.
- SDK release and resume tests in `packages/plugins/sdk`: 48 passed.
- `runnerd-codex-transport-release-resume.test.ts -t relaunched` in
`packages/paperclip-runner`: 3 passed. `pnpm run typecheck` in
`packages/paperclip-runner`: pass.
- `tests/runner-e2e/source-sdk-public-inputs.test.mjs`: 13 passed.
- `plugin-runner-release-resume.integration.test.ts -t "completes claude
runs through a retained adopted process"`: pass. I did not run the rest
of the two embedded-Postgres integration suites locally. CI runs them.

## Risks

- A provider that does not answer `unavailable` for a missing park makes
the resume fail. Deploy the provider change first, or in the same deploy
before this Core version takes traffic. This PR and #22443 are one stack
and can ship in one deploy.
- A server restart now relies on the existing unavailable-reuse fallback
to start a fresh task. Tests cover this path.
- Medium risk overall: the change is in the warm-session path. The cold
path is not changed.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`), through Claude Code with tool use
(shell, file edit, code search). Extended thinking on.

## 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

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 10:25:32 -08:00
..