Files
PaperClipAI/doc
DottaandPaperclip f79264d253 perf(recovery): project current wait facts during action reconciliation (#18793)
## Thinking Path

> - Paperclip manages work and execution for AI agents.
> - Recovery actions keep unresolved work visible and preserve its
owner.
> - Action reconciliation checks whether a durable wait or another live
path has appeared.
> - Its current-wait check collected a complete retry fingerprint
through seven queries.
> - This caller used only the durable-wait flag and reason.
> - This pull request reads those facts in one fresh statement and
shares the existing reason policy.
> - The local service uses less CPU. Fresh mutation guards and full
retry fingerprints stay in place.

## Linked Issues or Issue Description

**What existing behavior does this improve?**
Active recovery action reconciliation.

**Subsystem affected**
server/ — orchestration and recovery.

**Current behavior**
Each admitted source action collects blockers, children, interactions,
approvals, work products, runs and wakes. It sorts and hashes these
records. This caller uses only the durable-wait flag and reason.

**Proposed behavior**
Read three current existence facts in one company-bound statement. Use
the same reason policy as the complete fingerprint collector. Keep child
checks, outside-action checks and mutation services.

**Reason and benefit**
The actual local PostgreSQL service uses less CPU across 8, 32 and
100-action synthetic cohorts. This removes unused work on mostly empty
results. The live workload mix and fleet benefit remain unknown.

**Breaking changes**
No API or schema changes. Query facts now share one statement snapshot.
Scalar issue fields still come from the source cohort read.

**Additional context**
No duplicate projection change was found in the public PR search. The
roadmap has no overlapping core feature. This is a narrow performance
change.

## What Changed

- Add a current durable-wait reader and share reason selection with the
full fingerprint collector.
- Use the reader only in active action reconciliation. Keep the full
collector for retry and child policy.
- Add PostgreSQL regressions for reason priority, scope, board waits,
native holds, healthy children and concurrent decisions.
- Add a manual reproducer and local paired results. Each invocation uses
a unique evidence directory and exclusive output files.

## Verification

- Focused PostgreSQL regressions: 11 passed.
- Separate actual-service proof: 7 passed. Four CPU tests were excluded.
Results, records, semantic relation edges and notifications match the
pinned baseline. Late query facts and a concurrent action decision are
covered.
- Retained primary local paired CPU medians: 8 actions 7.091 → 2.886 ms;
32 actions 21.922 → 8.374 ms; 100 actions 68.384 → 32.718 ms. All nine
CPU and wall pairs improve at these sizes. The data file retains all 72
primary samples and ranges.
- Warm application counts: 81 → 33 queries at 8 actions; 321 → 129 at
32; 1001 → 401 at 100. Rows rise from N to 2N because each EXISTS
statement returns one row.
- See `doc/benchmarks/2026-11-03-active-recovery-projection.md` and its
JSON data for commands, provenance and limits.
- `pnpm -r typecheck` and `pnpm build` passed on head
`f2f8c4a755ac67679d78c6005f420a21a101c1ad`.
- Shipped manual helper smoke with `--proof-only`: 7 passed, 4 timing
tests skipped. All count-proof sample arrays are empty. Unique output
names and cleanup of the three temporary source files were verified.
- Exact-head CI completed with 52 successful checks, three intentional
skips and a successful Snyk status. Greptile completed successfully at
5/5 with no inline findings. The `review` workflow passed commitperclip
dependency and PR quality gates. No separate Paperclip Review check or
verdict was published.

The local `pnpm test:run` attempt passed all six chat shards (1,834
tests), then reported 62 Muse failures and one gateway failure in the
general-server batch. The initial cases each reached the unchanged
15-second timeout. The Muse case was followed by fast failures. After
the full batch breadth and complete CI coverage were established, the
owned known-failed run was interrupted once with SIGINT. Remaining
general-server, serialized and workspace scopes were not completed by
that local invocation. Its interrupted tool exit code is not a pass.
Each initial timeout case then passed in one fresh isolated control. A
single fresh full Muse file passed all 256 tests. Source review found no
changed projection path in either initial case. The original timeout
causes remain unresolved; later passes and green CI do not erase them.

The first reserved CPU run lost its raw files after a harness path error
caused an unintended repeat to overwrite them. Its summary and log
remain historical evidence. The separately retained repeat is the
primary inspectable evidence above. It had no renewed quiet reservation.
The runs are not pooled. The corrected untimed proof and public helper
prevent output replacement. No third CPU run was made.

## Risks

- One statement observes its query facts together. This does not
reproduce every race history of seven concurrent statements.
- Existing action update predicates, issue mutation locks, board
ownership, native reconciliation holds and company guards remain in
place.
- The evidence is a local source service benchmark on macOS and real
PostgreSQL. It is not deployed CPU or request latency acceptance. The
census was startup-adjacent. Conditional scale suggests only a modest
fleet return.
- The original local batch timeout causes remain unexplained. No hosted,
Sentry or OTLP improvement is claimed. No merge or deployment is
requested.

## Model Used

OpenAI `gpt-6.1-sol`, with reasoning, tool use and code execution. The
host did not expose the context window size.

## 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 (focused and isolated
controls; the broad local failure/interruption is described above)
- [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>
2026-11-03 10:13:03 -06:00
..
…
…
…
…
…