Files
PaperClipAI/server
Nicky Leach 5506359bbb perf(wake-queue): skip recovery lookup when no saved receipt can be adopted (#22279)
## Thinking Path

> - Paperclip assigns tasks and saves input for agents.
> - One admission can adopt previously deferred comments.
> - Admission reads the task's recovery state before creating the run.
> - It repeated that lookup even when there were no deferred receipts to
adopt.
> - Check for scoped receipts first. Verify the recovery hold when at
least one exists.

## Linked Issues or Issue Description

**What existing behavior does this improve?**

Admitting board assignments and saved task comments.

**Subsystem affected**

Server task admission.

**Current behavior**

An empty candidate set triggers a second recovery lookup on the ordinary
assignment and comment paths.

**Proposed behavior**

Check recovery only when the candidate lookup returns rows.

**Additional context**

Builds on #22268 and #22272. Related recovery work in #20163 addresses
terminal tasks.

## What Changed

- Query the same receipt scope under the existing issue lock.
- Keep the handoff owner, receipt order, and reconstruction exception.
- Exercise empty and nonempty exact scopes with an active recovery hold
and verify the lock from a competing database session.

## Verification

162 tests passed across the PostgreSQL wake-queue adapter,
issue-wake-admission, and heartbeat comment batching. A local
occupied-slot benchmark on merged base f0caee6f95 and this change
retained one run and all comment IDs. Warm median statements for
assignment, one comment and two separately posted comments fell from
42/44/86 to 38/40/82 (17 repetitions per case after warmup).

## Risks

A saved receipt behind a recovery hold must remain deferred. The test
uses a real hold and verifies that reconstruction can still adopt the
exact receipt.

## Model Used

OpenAI GPT-6.2 Sol (gpt-6.2-sol) implemented the change. OpenAI Codex
reviewed and qualified it.

## 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
2026-11-18 20:05:15 -08:00
..