## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work.
> - It keeps a session for each agent. Some agents use the same session
for many runs.
> - The session compaction feature rotates a session when it grows too
large.
> - The rotation function asks the adapter registry for a limit for each
adapter type.
> - The registry gave hermes_local a policy where all limits were 0.
> - The function read those 0 values and decided that no limit exists.
It never rotates.
> - So a new hermes agent starts with no rotation limit unless someone
adds a manual override.
> - hermes does not compress its own context well on large sessions. Its
compression stops.
> - A stalled compression uses half of the run budget and the run then
fails.
> - This pull request gives hermes_local its own rotation policy with
real limits.
> - The benefit is that every new hermes agent is protected by default.
## Linked Issues or Issue Description
No public GitHub issue exists for this defect. This is the defect
report.
**What happened?**
The registry marks `hermes_local` as `nativeContextManagement:
"confirmed"`. It gives the type `ADAPTER_MANAGED_SESSION_POLICY`. Every
limit in that policy is 0. The function
`hasSessionCompactionThresholds()` returns false for it. The server then
never rotates the session.
**Expected behavior**
A new `hermes_local` agent should start with working rotation limits. A
developer should not need to add
`runtimeConfig.heartbeat.sessionCompaction` to each agent by hand.
**Steps to reproduce**
1. Create an agent with adapter `hermes_local`. Do not set any session
policy.
2. Call `resolveSessionCompactionPolicy("hermes_local", undefined)`.
3. Read `hasSessionCompactionThresholds(result.policy)`.
4. The result is `false`. The server returns `rotate: false` on every
wake.
**Agent adapter(s) involved**
`hermes_local`. The change does not affect `claude_local`,
`codex_local`, or `acpx_local`.
**Relevant logs or output**
hermes reports this in its own log:
```
run_agent: Context compression made no progress for 300.0s (total wait 300.0s, ceiling 600.0s); continuing without compression
```
The session row records the same event:
```
compression_failure_error: backoff:stall_interrupted:strategy=lean:msgs=1297:tokens=346650
```
On one measured fleet, 52 unarchived hermes sessions reached 400 or more
messages. They hold 33,894 messages and 854,572,069 cumulative input
tokens.
**Additional context**
On that fleet, agents that have a manual override rotate correctly
today. This change only protects agents that are created after it lands.
## What Changed
- Add `HERMES_SESSION_COMPACTION_POLICY` to
`packages/adapter-utils/src/session-compaction.ts`.
- Point
`ADAPTER_SESSION_MANAGEMENT.hermes_local.defaultSessionCompaction` at
that policy.
- Add a test file with four cases. It covers the default, the other
adapters, an agent override, and a full opt out.
The new policy is:
```ts
const HERMES_SESSION_COMPACTION_POLICY: SessionCompactionPolicy = {
enabled: true,
maxSessionRuns: 12,
maxRawInputTokens: 500_000,
maxSessionAgeHours: 168,
};
```
`maxSessionRuns` and `maxSessionAgeHours` work together across cadences.
An agent that runs about four times a day reaches 12 runs in about three
days. A daily agent reaches the 168 hour limit first.
`maxRawInputTokens` compares only the latest run. For hermes it is a
backstop. `maxSessionRuns` is the limit that acts first.
## Verification
Run these commands from the repository root.
```bash
pnpm install --frozen-lockfile
pnpm --filter @paperclipai/plugin-sdk build
npx tsc --noEmit -p packages/adapter-utils
npx vitest run packages/adapter-utils/src/__tests__/session-compaction.test.ts \
packages/shared/src/validators/adapter-registry.test.ts \
server/src/__tests__/adapter-registry.test.ts
```
Results on master at commit `043f2514e`:
| Check | Result |
| --- | --- |
| `tsc --noEmit` in `packages/adapter-utils` | clean |
| `packages/adapter-utils/src/__tests__/session-compaction.test.ts` | 4
passed |
| `server/src/__tests__/adapter-registry.test.ts` | 33 passed |
| `packages/shared/src/validators/adapter-registry.test.ts` | 4 passed |
CI runs the full suite. It uses `pnpm test:run:general`, the serialized
server shards, `typecheck:build-gaps`, `build`, and the end to end
tests.
One test fails in the sandbox. It is
`heartbeat-workspace-session.test.ts` →
`assertGitWorktreeBaseWorkspaceReady` → `marks a proven non-Git local
path as an owner configuration conflict without changing the failure`.
The same test fails on unmodified master. It does not relate to this
change.
## Risks
The change is low risk. It does not alter a shared default.
- Only `hermes_local` changes. The shared
`ADAPTER_MANAGED_SESSION_POLICY` is unchanged.
- A hermes agent that runs about four times a day rotates after about
three days. Its context is then rebuilt from a handoff note.
- Any agent can still set `runtimeConfig.heartbeat.sessionCompaction`
and override the policy.
- Any agent can set `enabled: false` and stop rotation.
- There is no migration. No stored data changes.
Reviewers should compare this change with PR 3905. That PR is open. It
sets limits for `codex_local`. It edits the same file. The two changes
touch different adapter keys.
## Model Used
The original fix was written with Anthropic Claude Opus 4.8. It used a
1M context window.
The change was later moved onto current master by an OpenClaw agent
runtime. That runtime used the model `minimax-portal/MiniMax-M3`. It
used shell access, git, the GitHub API, and the test runner. It did not
use a separate reasoning mode.
## Related and Prior Work
- PR 3905 is open. It sets limits for `codex_local`. This change does
the same job for `hermes_local`.
- PR 7902 is closed. It tried to stop unbounded session growth in the
shared policy. That approach would rotate adapters that compress
correctly. This change gives hermes its own policy instead.
## 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
- [ ] 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
- [ ] I will address all Greptile and reviewer comments before
requesting merge
---------
Co-authored-by: ruai-engineering-lead <engineering-lead@ruah.innovations>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Head of Engineering <engineering@ruah-innovations.local>
@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) toremoteDirbefore the run starts. Runs with nogit remoteconfigured.restoreWorkspaceFromSshExecution({ spec, localDir, remoteDir, ... })— syncs the remote cwd back intolocalDirafter the run, including any new commits the agent created. Also runs with nogit remoteconfigured.
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.