Files
PaperClipAI/server
0b15b9b2a5 fix: clear watchdog user assignees and isolate reconciliation failures (#17286)
## Thinking Path

> - Paperclip helps people manage AI agents for work.
> - Task watchdogs reuse review issues when a watched subtree stops
again.
> - A finished review can still have a user assignee.
> - Reopening that review for an agent retains the user and fails the
single-assignee check.
> - One failed watchdog also rejects a whole reconciliation batch, so
other watchdogs in that batch are not evaluated.
> - This change clears the prior user, isolates each watchdog failure,
and keeps a failed watchdog as recovery retry debt.

## Linked Issues or Issue Description

**What happened?**

A new stopped fingerprint causes a done, user-assigned watchdog issue to
reopen. The update sets assigneeAgentId but leaves assigneeUserId set.
The issue service returns 422, "Issue can only have one assignee".
Reconciliation rejects, and the remaining watchdogs in the same batch or
ancestor chain are not evaluated. On the reported release this rejection
also aborted startup recovery.

**Expected behavior**

Reopen the reusable issue with only its configured agent assigned. Log a
failed watchdog, continue the other watchdogs, and retry the failed one
through the task-watchdog recovery work.

**Steps to reproduce**

1. Configure a task watchdog and let it create a review issue.
2. Complete the review and assign that completed issue to a user.
3. Change a watched leaf to produce a new stopped fingerprint.
4. Reconcile task watchdogs. Before this change, the operation rejects
with 422.

**Paperclip version or commit**

Reproduced on upstream master at `2cd6eb27c`. The reopen path is
unchanged on current master `629281b1e8a4bae014d682a99aa6cd790508414d`.
Current merge candidate: `66d9c624cd86101e8bf65d05cabc3ed449255e5c`,
integrating that master with the previously published branch head
`681955f972c79a827c5bf2aa3e138fe4b2df69f9`.

Related PRs: #11855 addresses reviewed fingerprint reset, #15063
addresses incomplete subtree scans, and #15067 fences reviews by
configuration revision. #18402 replaced the startup and periodic
recovery sweep with per-watchdog recovery work. This branch now builds
on that design instead of changing server startup. #21670 moved
subsystem notes out of `doc/DEVELOPING.md`, so the recovery note now
lives in `doc/TASK-WATCHDOG.md`. #22831 deleted
`task-watchdogs-scheduler.test.ts` and
`issue-recovery-work-lifecycle.test.ts`, so this branch's regression
tests now live in two focused files.

## What Changed

- Clear assigneeUserId in the existing issue-service update when
reopening for an agent.
- Catch individual watchdog errors in both batch and ancestor
reconciliation. Log identifiers and the error, and return a failed
count.
- Reject the task-watchdog recovery-work check when a watchdog reports
`failed`, as it already does for `incomplete`. The coordinator keeps
that watchdog as retry debt instead of treating the swallowed error as
settled.
- Update the route no-op service and the recovery-work owner type to
match the result contract.
- Add database-backed reassignment, isolation, and reevaluation tests in
`task-watchdogs-reconciliation.test.ts`, and a recovery-work test for
failed-watchdog retry in `task-watchdog-recovery-retry.test.ts`.
- Document the recovery behavior in `doc/TASK-WATCHDOG.md`, under "How a
scan works".
- No server startup changes. The earlier startup and periodic catch
blocks were dropped with the sweep that #18402 removed.

## Verification

Current merge revision (29 November):

- The only conflicts were the two test files that #22831 deleted. This
branch accepts the deletions and moves its four regression tests,
unchanged, into `task-watchdogs-reconciliation.test.ts` (with the
minimal database harness from the deleted suite) and
`task-watchdog-recovery-retry.test.ts` (with the trimmed recovery-work
fixture). The added and removed non-test lines are identical to the 16
November revision.
- Frozen install with declared pnpm 9.15.4 succeeds. The plugin SDK was
rebuilt first; a stale SDK build otherwise fails test collection.
- New suites: **4 passed**. With upstream versions of the four changed
server files, all 4 fail: the reopen rejects with 422 "Issue can only
have one assignee", both reconcile paths reject on the malformed
watchdog, and the recovery check sets no retry wake.
- Related suites `issue-watchdogs-routes` and
`task-watchdogs-incident-fixture`: **14 passed**.
- Server TypeScript: failed with 395 diagnostics, none in changed files.
With upstream versions of the changed files on the same tree and
dependencies, the same 395 diagnostics reproduce exactly. This is
baseline reproduction, not a passing typecheck.
- `git diff --check` passed. Full workspace checks were not repeated;
the historical incomplete-suite and missing-Cargo limitations remain.
- CI and Greptile results from the prior published head do not accept
this revision. Fresh checks are required after publication.

Earlier merge revision (16 November, `681955f9`): 210 focused tests and
20 database-backed recovery tests passed; 370 TypeScript diagnostics
reproduced exactly on the upstream parent.

Earlier merge revision (1 November, `cd37b848`): 192 focused tests and
18 database-backed recovery tests passed. The failed-watchdog retry test
failed without the recovery-work change (1 failed, 12 passed) and passed
with it. 208 TypeScript diagnostics reproduced exactly on the upstream
parent.

Earlier merge revision (27 October, `03cd5fc9`): 89 focused tests passed
in independent QA. 48 TypeScript diagnostics reproduced exactly on the
upstream parent.

Historical initial revision evidence:

- New database regressions on unmodified service: 3 failed, 19 passed.
Failures were the dual-assignee 422 and uncaught assignment validation
failures in both reconciliation entry points.
- New startup regression on unmodified startup code: failed because
startServer rejected. The other 39 tests passed.
- Initial focused suite: 82 passed, 0 skipped: `TMPDIR=/tmp pnpm exec
vitest run server/src/__tests__/task-watchdogs-scheduler.test.ts
server/src/__tests__/server-startup-feedback-export.test.ts
server/src/__tests__/task-watchdogs-classifier.test.ts`.
- Initial server TypeScript passed: `TMPDIR=/tmp pnpm --filter
@paperclipai/server exec tsc --noEmit`.
- `git diff --check` passed.
- Full workspace typecheck and build were attempted. Both stop because
cargo is absent. They are not green.
- Full test suites ended without terminal summaries. They are
incomplete, not green.
- Initial local setup failures: missing plugin-sdk build, missing
embedded PostgreSQL library symlinks, and an overlong tsx IPC temporary
path. Built the workspace dependencies, ran the platform package install
step, and shortened TMPDIR before the successful focused run. These
tests used real PostgreSQL with synthetic data on macOS arm64 and Node
24.22.1.

## Risks

- Watchdog errors no longer abort a reconciliation batch. Operators must
use the error logs, failed count, and recovery-work retry errors to find
an invalid configuration.
- No migration, timer, new privilege, startup change, or live
installation change.
- Existing partial-write delivery behavior is unchanged: a failure after
issue creation/reopening can leave an open same-fingerprint issue that
suppresses a later enqueue. Later reevaluation does not guarantee every
failed delivery retries. The regression proves retry after a pre-write
assignment failure.
- Independent QA reviewed this exact revision before publication. Full
checks remain incomplete; fresh CI is pending publication.

## Model Used

Initial fix and 27 October merge: OpenAI Codex, GPT-6, with reasoning,
shell tools, code editing, and test execution; exact backend model ID
and context window not exposed. 1, 16 and 29 November merges: Claude
Opus 5.5 (`claude-opus-5-5`) in Claude Code, with shell tools, code
editing, and test execution. Independent QA reviews each exact revision
before publication.

## 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
- [x] My branch name describes the change and contains no internal
ticket id or instance-derived details
- [ ] I have run tests locally and they pass — focused tests pass; full
suites ended without terminal summaries
- [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
- [ ] All Paperclip CI gates are green
- [ ] 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>
Co-authored-by: Paperclip <paperclip@localhost>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-05 00:14:53 -08:00
..