Files
PaperClipAI/server
Nicky Leach c55de053f5 perf(wake-queue): skip detailed recovery reads on tasks without history (#22290)
## Thinking Path

> - Paperclip keeps agents from resuming work that still has an
execution owner or a recovery hold.
> - Ordinary board tasks have no recovery record.
> - Admission evaluates two detailed recovery queries for those tasks
while it holds the issue row lock.
> - The source-issue foreign key prevents another transaction from
inserting or moving the first recovery record onto the locked issue.
> - Use one indexed existence check there. Continue to check execution
ownership and apply the complete policy to tasks with history.

## Linked Issues or Issue Description

**What existing behavior does this improve?**

Admitting board assignments and saved task comments.

**Subsystem affected**

Wake-queue’s PostgreSQL adapter for task admission.

**Current behavior**

Admission evaluates detailed recovery predicates even when a locked
board task has no recovery history.

**Proposed behavior**

For a locked board task that did not require writer preservation, check
for any recovery row for that company and task. An empty result skips
the recovery predicates for that call.

**Additional context**

Depends on #22292, which enforces recovery eligibility after wake-queue
acquires the task lock. #22159 and #21459 address separate recovery
lifecycle decisions.

## What Changed

- Preserve the independent ownership and lease check.
- Use the existing detailed recovery logic when history exists. Include
resolved records in the existence check.
- Run the probe after acquiring the issue lock, in its own statement.
Cover both orderings of a concurrent recovery insert and a record moved
onto the issue.

## Verification

At 83d4acd8bf the two query-shape tests failed on the parent and passed
on the new implementation. All 425 tests across five suites passed on
that revision, including all five focused PostgreSQL regressions. A
normal user comment waiting on an uncommitted recovery record creates no
run after the writer commits. Its deferred receipt retains the exact
comment and recovery action. Server TypeScript and the module dependency
check passed. The published head 9783a92ae9 removes six inline comment
lines across both layers. All ten affected application and PostgreSQL
regression tests passed again on that head.

We repeated the whole-admission comparison in both orders after other
local tests finished. Each condition had 34 warmed samples per revision.
With no recovery history, median times fell from 21.45 to 10.35 ms for a
new task, 21.80 to 11.40 ms for one comment, and 44.50 to 22.85 ms for
two serial comments. With one resolved record, median times rose from
20.80 to 22.65 ms, 22.00 to 22.90 ms, and 44.30 to 48.05 ms. All runs
retained the expected receipts and comment IDs.

The isolated blocker read used one fewer statement when history was
empty, and one more when history existed. In 100 paired reads per
condition, the mean empty-history saving was 10.54 ms and the mean
resolved-history cost was 0.18 ms. The latter estimate varied enough to
include zero. The separate post-lock statement sees any recovery insert
that committed while admission waited for the issue lock. These local
timings exclude HTTP and concurrent workload latency.

The full stack passed verification and E2E on 9783a92ae9. [CI
run](https://github.com/paperclipai/paperclip/actions/runs/44461026015)
· [Standard Greptile review,
5/5](https://github.com/paperclipai/paperclip/pull/22290#issuecomment-6999610966)

## Risks

Locked board tasks with recovery history pay one additional indexed
lookup. The adapter owns the issue lock. The proof of absence depends on
the source-issue foreign key and on recovery writers preserving company
identity. The regression checks contention on the source-issue foreign
key and that the next admission sees the new hold.

## 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-19 07:23:03 -08:00
..