Files
PaperClipAI/packages/adapter-utils
Pavel StaykovandClaude Opus 5.5 e35d1819fc fix(acpx): bound session keys so session file names fit NAME_MAX (#22115)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - The shared ACPX engine keeps each agent session in files that ACPX
names after the session key
> - The session key holds two UUIDs, the task key and a fingerprint, so
its length is not bounded
> - When a file name is longer than the NAME_MAX of the file system, the
session cannot start (`acpx_session_init_failed`, `ENAMETOOLONG`)
> - With ACPX 0.12.0, summary-slot task keys exceeded 255 bytes and
failed on all Linux file systems (#17785). With ACPX 0.22.0 they fit,
but only with 6 bytes to spare
> - On eCryptfs (NAME_MAX 143), a UUID task key also fails. Synology
encrypted shared folders use eCryptfs, and self-hosted users often put
the Paperclip home on an NFS export of such a folder
> - This pull request replaces a key that is too long with a
fixed-length digest of that key
> - The benefit is that every session file name fits in 143 bytes, and
keys that fit now stay the same

## Linked Issues or Issue Description

Refs #17785

The ACPX 0.22.0 upgrade (#20770) removed the `.<pid>.<ms>.tmp` suffix
that made the summary-slot names in #17785 longer than 255 bytes. This
change removes the remaining risk: no session file name can be longer
than 143 bytes, whatever the task key is.

The same failure also occurs on eCryptfs with shorter keys. A
self-hosted instance on Kubernetes has `PAPERCLIP_HOME` on an NFS export
of a Synology encrypted shared folder (`namlen=143` in the mount
options). On release `v2026.1106.0` (ACPX 0.12.0), a heartbeat run
failed in `ensure_session`:

```
ENAMETOOLONG: name too long, open '<home>/companies/<company>/acp-engine/agents/<agent>/sessions/paperclip%3A<company>%3A<agent>%3A__heartbeat__%3A<16-hex>.json.<pid>.<ms>.tmp' (acpx_session_init_failed)
```

That name is 147 bytes. ACPX 0.22.0 (on `master` since #20770) writes
the temporary file in a subdirectory, so the heartbeat name now fits.
But other names are still too long:

| Session file name | Bytes |
|---|---|
| Heartbeat key, `<key>.stream.1024.ndjson` | 141 |
| UUID task key, `<key>.json` | 150 |
| UUID task key, `<key>.stream.1024.ndjson` | 164 |
| Summary-slot task key, `<key>.json` | 235 |
| Summary-slot task key, `<key>.stream.1024.ndjson` | 249 |

## What Changed

- `buildSessionKey` measures the URI-encoded key. If the longest session
file name (`<key>.stream.1024.ndjson`) would be longer than 143 bytes,
it returns `paperclip:sha256:<32 hex>`. The digest is the SHA-256 of the
full key, so a digested key has the same scope as the full key.
- A key that fits is not changed. Thus saved heartbeat and `default`
sessions still resume after an upgrade.
- When a resumed run's session key differs from the saved key, the run
result now reports `sessionReset` with the named code
`acpx_session_identity_changed`. Before, it reported the reset only when
`configFingerprint` changed. `isCompatibleSession` already refuses to
resume when the keys differ, so the notice now covers every key change.
This includes the one-time change from a long key to a digest.
- Added `SESSION_KEY_MAX_ENCODED_LENGTH` and tests in
`execute-identity.test.ts`. The tests check that a heartbeat key does
not change, that issue and summary-slot keys become digests that fit in
143 bytes, and that a digest changes when the company, agent, task or
fingerprint changes.
- Added an old-saved/new-resumed test in `execute.test.ts`. It saves
session params with a long key, as the previous release wrote them, and
resumes them with the new code. The run gets the digest key and reports
`acpx_session_identity_changed`. The next run resumes without a reset.

## Verification

- `pnpm --filter @paperclipai/adapter-utils exec vitest run
src/acpx-engine/`: 22 files and 477 tests pass.
- `pnpm --filter @paperclipai/adapter-utils typecheck` passes.
- Without the `buildSessionKey` change, the new test "digests a key
whose file names would exceed the eCryptfs NAME_MAX" fails.
- Without the `sessionReset` change, the new old-saved/new-resumed test
fails.

## Risks

- Previous-release story: saved session params with a key that fits
carry forward unchanged and resume. Saved params with a key that becomes
a digest are reset on purpose: `isCompatibleSession` compares the saved
`sessionKey` with the new key, so the next run starts a new session and
reports `acpx_session_identity_changed`. The saved files under the old
name are not deleted. On a file system with a small NAME_MAX, these keys
could not write their session files before this change, so nothing is
lost. On ext4, a session with a UUID or summary-slot task key resumed
before this change and starts again one time after it.
- A digested key does not show the company, agent or task in logs. The
session directory path and the run context still show the company and
the agent.
- Low risk in other areas. The key format of short keys does not change,
and the code does not parse session keys.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with tool use
(shell, file edits, test runs). A human reviewed the change.

## 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: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-05 04:22:02 -08:00
..

@paperclipai/adapter-utils

Shared utilities for Paperclip adapters: process spawning, environment injection, sandbox/SSH transport, workspace sync, and the round-trip helpers that move code between the local execution-workspace cwd and wherever the agent actually runs.

For the adapter-author guide see docs/adapters/creating-an-adapter.md and the in-repo notes at packages/adapters/AUTHORING.md.

Sandbox bridge deadlines

Command-managed bridge control operations (queue reads, input delivery, setup, and cleanup) have a host-enforced deadline of at most 30 seconds per shell command. A shorter configured timeout still applies. These operations cannot inherit the agent run's hours-long lifetime or wait forever on a provider that ignores its timeout. Long-lived agent session commands keep their own limits.

A control timeout reports a transport failure. It does not prove that the remote command stopped and does not replay an uncertain write. The process session closes failed input delivery and uses its existing shutdown path; normal execution settlement must still verify termination.

Native archive transfer deadlines

Native syncIn and syncOut calls accept an optional minimumTimeoutMs budget. The server validates this budget and extends the worker RPC deadline. Providers can honor this field for file transfers without changing their configuration. Daytona uses the larger of this minimum and its configured timeout. Other providers keep their existing behavior. The minimum is limited to 30 minutes and does not change sandbox lifetimes, stored settings or the timeout for other commands.

The remote-workspace archive path uses the verified capture size for downloads and the local archive size for uploads. Large archives get one second per MiB plus 60 seconds, capped at 30 minutes. Small archives keep the existing provider timeout when that calculation is no greater than five minutes. Archive size, checksum, confinement and host space checks still apply.

An exact retained-sandbox resume keeps its recorded provider timeout and RPC overhead. It uses the normal one-minute fallback only when no timeout was recorded. A five-minute cold restore must not be cut off by that fallback. Resume still targets the recorded allocation and does not acquire a replacement.

No-remote-git contract

The local execution-workspace cwd is the only persistence boundary across runs. No adapter may depend on a git remote for cross-run state.

Adapters that run the agent on a different host should use the SSH round-trip helpers in src/ssh.ts:

  • prepareWorkspaceForSshExecution({ spec, localDir, remoteDir }) — bundles the local cwd (tracked files, dirty edits, untracked additions, and the git history needed to reconstruct it) to remoteDir before the run starts. Runs with no git remote configured.
  • restoreWorkspaceFromSshExecution({ spec, localDir, remoteDir, ... }) — syncs the remote cwd back into localDir after the run, including any new commits the agent created. Also runs with no git remote configured.

prepareRemoteManagedRuntime in src/remote-managed-runtime.ts wraps both calls for adapters that want a per-run remote workspace and an automatic restoreWorkspace() finally hook.

The invariant is pinned by the no-remote-git contract case in src/ssh-fixture.test.ts, which asserts that a remote-only commit propagates to the local worktree through the prepare → restore round-trip with no git remote configured at any point. Do not regress that test.