mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-12 18:06:11 +02:00
## Thinking Path
> - Paperclip manages AI agent work and keeps a durable record of each
run.
> - Automatic idle sleep must wait for accepted work and provider
cleanup.
> - The current sleep check treats every saved login session as active
work.
> - It also treats every coalesced wake request as pending work.
> - These records can remain after their work and cleanup finish.
> - This pull request checks the cleanup and linked-run evidence before
it treats these records as history.
> - The change lets otherwise idle instances sleep and keeps uncertain
work awake.
## Linked Issues or Issue Description
**What happened?**
A finished login session blocks idle sleep after its provider resource
has been removed. A consumed coalesced wake also blocks sleep after its
linked run finishes.
**Expected behavior**
Finished history should permit sleep when cleanup or run completion is
confirmed. Active work, missing evidence, retry debt, and pending
accounting must still block sleep.
**Steps to reproduce**
1. Create a finished login session with a retained provider reference.
2. Record a successful release for the same resource, company, and
environment.
3. Check idle sleep safety under an owned, quiet admission hold.
4. The current check reports background work. The new check treats the
session as history.
5. Repeat with a finished coalesced wake linked to a finished run in the
same company and agent.
**Paperclip version or commit**
Reproduced on master at 98e3cec78e.
Related work: #15522, #15599, #15629. A search of open and merged
idle-sleep PRs found no duplicate.
## What Changed
- Permit finished login history only after its promotion claim is
cleared. A retained resource reference needs successful cleanup, a
release timestamp, and the same company and environment. Conflicting
cleanup evidence still blocks sleep.
- Permit a finished coalesced wake only after its exact linked run
finishes without a retry or pending cost accounting.
- Keep the lease UUID column unchanged. Convert only valid UUID-shaped
session references so both existing lease indexes remain usable.
- Add real PostgreSQL tests for safe history and missing, active, or
conflicting evidence. Cover text references, UUID references, and
conflicting internal/external matches.
- Document these checks. Image-setup history still blocks sleep because
its terminal state does not confirm cleanup.
## Verification
- `pnpm exec vitest run server/src/__tests__/idle-sleep-safety.test.ts`:
84 tests passed, including the PostgreSQL cases.
- `pnpm -r typecheck`: passed. `pnpm --filter @paperclipai/server
typecheck` also passed after the index fix.
- Full default test coverage was exercised through the supported shard
runner. The initial run was not green. Fixture-permission, local
PostgreSQL startup, socket, route timeout, and Git stress failures
passed controlled rechecks with normal permissions, one database worker,
or isolated runs.
- All route suites, UI/CLI suites, and all shared, database, adapter,
and SDK projects were exercised. One damaged-session recovery test in
`native-session-resume.test.ts` still fails and also reproduces on
unmodified base `98e3cec78e8`. Full-suite green status is not claimed.
- `pnpm build`: passed in an isolated checkout of the initial commit.
The build and full Paperclip CI also passed on final head `d61b489c26b`:
https://github.com/paperclipai/paperclip/actions/runs/38005908398. Both
required branch-protection checks passed. The optional Superagent
security scan is still running and has not returned findings.
- A local PostgreSQL query-plan probe used 10,000 lease rows and 200
finished login rows with mixed internal and external references. The
actual sleep query used both the primary-key and provider-reference
indexes. Execution took 1.63 ms in this synthetic fixture.
- A read-only comparison on a controlled staging instance found login
history as the current check's sole durable-work blocker. The new query
found no durable-work blockers. This comparison did not authorize or
perform provider shutdown.
- The current owned sleep controller refused sleep and released its
hold. The instance remained healthy. Existing backup archives were
unchanged.
## Risks
- Missing schema, missing cleanup evidence, stale claims, and unfinished
linked runs fail closed.
- The change preserves history and provider references. It does not
delete records or release resources.
- Image setup, other durable work, plugin draining, in-flight work, and
backup checks retain their current behavior.
- No schema migration or new API is required.
## Model Used
- OpenAI Codex, GPT-6. Used repository inspection, code execution, and
test tools. The exact deployment model identifier and context-window
size were not exposed in this session.
## 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 the tests for this change locally and they pass. The
broader local baseline failure is described in Verification.
- [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: Paperclip <noreply@paperclip.ing>