mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-20 18:26:40 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - The server sends unexpected run failures to Sentry as run-failure events. It keeps known, recovered failures local > - The runner stops a native turn when the turn holds too many tool results (`semantic_tool_turn_receipt_limit`). The finalizer then continues the task in a fresh session > - The runner's stop has no recorded cancellation request. So the cancelled run keeps `unknown`, unexpected cancellation provenance, and `reportRunFailure` sends it to Sentry as "Native session cancelled" > - The continuation owns recovery, so this event is noise. The native capacity retry had the same problem, and #19051 and #19320 fixed it with the successor run as the proof > - This pull request uses the same successor-run proof for the tool-receipt-limit continuation > - The benefit is that a continued receipt-limit stop does not make Sentry noise. Exhausted continuations still report ## Linked Issues or Issue Description Refs #19051, #19320 **What happened?** On staging, a native Codex run stopped at its tool-result receipt limit. The finalizer committed the `semantic_tool_turn_receipt_limit` decision and scheduled a fresh-session continuation run (`retryOfRunId` = the stopped run, `scheduledRetryReason` = `semantic_tool_turn_receipt_limit`). The continuation succeeded and the task finished. Sentry still got a run-failure event: `Error: Native session cancelled`, `run_status=cancelled`, cancellation `source: unknown`, `expected: false`. **Expected behavior** A receipt-limit stop that has a scheduled continuation stays local. The continuation reports itself if it fails. A stop with no continuation (exhausted, or the user stopped it) stays reportable as before. **Steps to reproduce** 1. Run a native turn that reaches the semantic-tool receipt limit. 2. Let the finalizer schedule the fresh-session continuation. 3. With `PAPERCLIP_SENTRY_RUN_FAILURES=unexpected`, see that the cancelled run is sent to Sentry. ## What Changed - `server/src/services/run-failure-report.ts`: `isScheduledNativeCapacityRetry` becomes `isScheduledNativeRetry`. It reads the successor run for the lane that can own the run: `native_provider_overloaded` for a failed capacity run (unchanged), and `semantic_tool_turn_receipt_limit` for any other failed or cancelled native run. The query, task binding, setup-phase, signal, and read-failure behavior do not change. - `server/src/services/__tests__/run-failure-report.test.ts`: regression tests with the persisted shape of the staging run, plus negative cases (no successor, other retry lane, other task, no native task, legacy, signal, timed out, setup phase, `all` mode, failed read). - The shared `buildRun` fixture in `run-failure-report.test.ts` now has `createdAt`, like a persisted run row. Without it, the wider scheduled-retry read failed on in-memory test runs and logged a spurious warning. Real report inputs are full database rows, so production code does not change for this. - `server/src/services/native-runtime/native-tool-receipt-limit.integration.test.ts`: the real native executor and finalizer path now also asserts the Sentry outcome. A continued stop sends no report. A cancelled turn without a continuation still sends one. The fixture run now has `startedAt`, as a real started run does. Without it, no cancelled-run report can occur, and the new assertion would prove nothing. ## Verification - Red before the fix: the two new unit cases failed (`captureRunFailure` was called), and the integration assertion failed (`expected [...] to have a length of +0 but got 1`). - Green after the fix: - `npx vitest run src/services/__tests__/run-failure-report.test.ts src/__tests__/run-failure-sentry.test.ts src/__tests__/run-failure-sentry-real-sdk.test.ts src/services/native-runtime/native-provider-overload.integration.test.ts src/services/native-runtime/native-tool-receipt-limit.integration.test.ts src/services/native-runtime/status-arbiter.test.ts` → 383 passed, 13 skipped. - `node scripts/typecheck-layers.mjs` in `server` → no errors. - `pnpm verify` did not finish in the local sandbox in the time limit. The only failures were 3 cases in `server/src/__tests__/archived-nested-repository.test.ts`. They also fail on unchanged `master` in the same sandbox, and they do not use this code. CI runs the full suite. ## Risks - Low risk. The change only removes Sentry events. It does not change run status, task status, retries, or the user's view. - A failed or cancelled native run that is not a capacity failure now does one more indexed read before its report. That read is bounded by company, task, and agent, and it happens only when a report is about to be sent. - A successor with this retry reason exists only when the status arbiter proved the receipt-limit stop from a persisted runner diagnostic. A user Stop refuses the continuation, and an exhausted lane creates none, so these runs still report. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, used through Claude Code with tool use (shell, code search, and test runs). ## 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 - [ ] 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 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: paperclipbugbot <356415228+paperclipbugbot@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>