Files
PaperClipAI/packages/paperclip-runner/src/cli
Nicky LeachandClaude Opus 5.5 de24b28b82 feat(runner): keep harness session state in an optional harness state directory (#22841)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - The Runner starts each agent's harness (ACPX agents and OpenCode)
and keeps a runtime tree for each session
> - All of that tree is in one runtime directory: session records,
conversation history, caches, configuration, temporary homes and the
turn journal
> - Some hosts keep the runtime directory on fast local disk, and keep a
separate durable directory that stays with the work
> - These hosts cannot put the state that a session needs to continue in
the durable directory without also moving large caches and data that the
Runner writes again each launch
> - This pull request adds one optional setting,
`harnessStateDirectory`, for the state that a session needs to continue
> - The benefit is that a host can keep conversations and session
records durable, and keep caches and temporary data local

## Linked Issues or Issue Description

**Is your feature request related to a problem?**
A host can set where the Runner puts its runtime directory. It cannot
set a different location for only the harness state that a later process
needs to continue a session. If a host moves the full runtime directory
to durable storage, it also moves caches, configuration that the Runner
writes again at each launch, temporary homes and the turn journal. These
are large or written frequently, and nothing needs them after the
session.

**Describe the solution you'd like**
An optional setting names a durable directory. The Runner puts only the
state that a session needs to continue in that directory. All other data
stays in the runtime directory. When the setting is not set, nothing
changes.

**Describe alternatives you've considered**
- Move the full runtime directory to durable storage. This moves caches
and data that the Runner writes again each launch.
- Mount local folders over the cache paths. These paths include a
session ID that the Runner makes, so a host cannot know them before the
Runner starts. The folder names are also not a contract.

Related: #12840 (multi-turn remote sessions) and #15406 (Runner task
hooks for environment plugins) touch the same runtime directories. No
open PR or issue duplicates this change.

## What Changed

- The Runner accepts an optional `harnessStateDirectory` setting. A host
gives it as a launch option or as the
`PAPERCLIP_RUNNER_HARNESS_STATE_DIR` environment variable.
- When the setting is set, these folders go below
`<harnessStateDirectory>/acpx/<session>/`: ACPX session records
(`acpx-state`), each agent's home (`<agent>-home`) and XDG data
(`data`).
- When the setting is set, OpenCode's session store (`data`) and its
workspace record go below `<harnessStateDirectory>/opencode/<session>/`.
OpenCode recovery reads the workspace record, so a resume works after
the runtime directory is gone.
- The temporary home, configuration, caches, the ACPX workspace record
and the turn journal stay in the runtime directory.
- Recovery, session reopen, Antigravity probe retirement and the
credential observer look for the state in the new location.
- The Runner refuses a value that is relative, not normalized, missing,
the filesystem root, or reached through a symbolic link. It also refuses
a value that overlaps the workspace. The new folders are private (0700),
and the directory is a protected path for the harness sandbox.
- The ACPX launch descriptor, the sidecar `session.open` parameters and
the runnerd environment allowlists carry the setting only when it is
set.
- The README tells how to use the setting.

## Verification

- `tsc` for `tsconfig.json`, `tsconfig.surfaces.json` and
`tsconfig.test.json`, `check:protocol-types` and `check:acpx-profiles`:
pass.
- Targeted Vitest files for the ACPX sandbox, recovery identity, probe
retirement, the new directory module, the ACPX driver, runtime host,
agent files, the native backend factory, the OpenCode driver, the
OpenCode proxy input, the provider launch and the runnerd transport:
pass.
- Sidecar Vitest files and `node --test
test/acpx-sidecar-contract.test.mjs
scripts/contracts/contract-fingerprints.test.mjs`: pass.
- `cargo fmt --check`, `cargo check --workspace --all-targets` and
`cargo test -p paperclip-runner-core --lib credential_observer`: pass.
- The tests check that:
- The default layout does not change. The tests assert the exact paths.
  - With the setting, only the state folders move.
- A reopen finds the session after the runtime directory is deleted. For
OpenCode, the fake server saves and reloads the session from the session
store, and recovery fails when that state is removed.
  - The Runner refuses each invalid value.
- I did not run the full suite or the Runner integration suites locally.
CI runs them.

## Risks

- When the setting is not set, the layout and the saved descriptors do
not change. Existing hosts see no change.
- A host must enable the setting for new sessions only. A session saved
without the setting does not reattach with it. The Runner refuses it
with the existing "contract changed" error.
- In-process ACPX recovery reads the workspace record from the runtime
directory. If a host loses the runtime directory, that recovery path
fails as it does now. The runnerd ACPX path is not affected, because it
takes the working directory from the descriptor.
- The provider-pack contract digest changes because the Rust descriptor
has a new optional field and the allowlists have a new key. No ACPX
profile version or command digest changes.

> 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`) by Anthropic, in Claude Code, with
tool use (shell, file editing, code search) and extended thinking.

## 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: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 08:58:21 -08:00
..