mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-05 06:03:51 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Native runs keep a finalization claim. The expired-owner pass (`native-failed-run-owner-release.ts`) settles the claim of a run that already failed, after it proves the old owner stopped. > - A run can fail while its controller on another server still holds that claim. The pass cannot verify a controller in another process space. It holds the task for the board and names the old run. > - When the task has moved on to a newer run, nothing ends that hold. Restart recovery stops at `issue_execution_lock_changed`. Operator containment accepts only the local reason. The active hold also removes the pass's only wake. > - This pull request lets the expired-owner pass release such an owner after the existing bounded wait, with its existing proofs. It also resolves the hold that names the old run. > - The benefit is that the task is not blocked indefinitely. Automatic continuation and the user's Retry work again. ## Linked Issues or Issue Description Refs #19131 (related: it retires `retryable_failure` sources only after a committed successor. It does not cover an `observed` claim whose successor also failed.) **What happened?** A native run failed while its controller on another server still held its finalization claim (phase `observed`). A newer run of the same task started after it. Then: - the expired-owner pass could not verify the foreign controller, so it opened a board-owned `native_restart_recovery_blocked` hold that names the old run; - restart recovery checked the old run every minute and returned `issue_execution_lock_changed` with no write; - operator containment accepts only the local `controller_process_space_unverified` reason, not the remote one; - `nextAbandonedNativeOwnerReleaseAt` excludes rows with an active hold, so the pass had no wake for this row. The user's Retry was refused with `previous_execution_unverified`, and assigned-work wakes were refused every cycle. The task stayed blocked for more than 9 hours. **Expected behavior** An unverifiable lapsed controller is system uncertainty, not a person's decision. When a newer run has taken over the task, the old claim must settle after the bounded wait, and the task must continue on its normal paths. **Steps to reproduce** 1. Make a native run fail while its coordinator stays `observed` with a lease owner from another process space. 2. Clear the task's execution lock and start a newer run of the same task. 3. Run `releaseAbandonedNativeOwners`. It opens the board hold. 4. Before this change: `nextAbandonedNativeOwnerReleaseAt` returns `null`, and later passes never settle the claim or the hold. ## What Changed All changes are in `native-failed-run-owner-release.ts`, in the existing `expired_owner` release: - For a foreign-space owner, the pass now releases the claim when all of these are true: the task's lock is not on the run, a newer run of the task exists, the lease lapsed at least `NATIVE_NAMESPACE_UNVERIFIED_WAIT_MS` ago, the run has no recorded process (PID or group), and the owner is not a finalizer/cleanup owner. Otherwise it keeps the old behavior (surface the board hold, return). - The existing proofs still apply: settled environment lease, no pending Stop, `runProcessMayBeLive` (in-process executions, live controller lease, recorded process), and no accepted result. Only the foreign controller probe is skipped, because a foreign PID is not local evidence. This is the same bounded-wait policy restart recovery uses for unverifiable controllers. - The settlement uses the existing write path: `terminal_failure`, activity entry `native.failed_run_owner_released` (now with `supersededByRunId`), and settlement notifications. It records `successorRunId` and `supersededByRunId`, and resolves (`cancelled`) the board hold whose fingerprint is `native-controller-space:<runId>:…`. - `nextAbandonedNativeOwnerReleaseAt` now also wakes the pass at `leaseExpiresAt + NATIVE_NAMESPACE_UNVERIFIED_WAIT_MS` for such an attended owner. - The first revision changed restart recovery and `native-superseded-retry.ts`. After review, those changes are removed. ## Verification - New `server/src/services/native-runtime/native-superseded-failed-owner.integration.test.ts` (embedded Postgres, real owner-release pass): - Before the fix (master code): `releases the old owner and its hold once the bounded wait has passed` failed. `nextAbandonedNativeOwnerReleaseAt` returned `null` after the hold was raised. - After the fix: 7/7 pass. The claim goes to `terminal_failure` with `successorRunId`. The run keeps `failed` and `native_session_interrupted`. The lock stays `null`. No active hold remains. One activity entry is written, and a later pass does not raise the hold again. - Safety cases (pass before and after): the claim and the hold stay unchanged within the bounded wait, with no newer run, with a recorded run process, with a live run controller lease, while this server executes the run, and while the task's lock is on the run. - Neighbouring suites: `native-failed-run-owner-release.test.ts`, `execution-control-work.test.ts`, `native-restart-recovery-isolation.test.ts` (63 passed with the new file). `heartbeat-native-restart-suspension`, `task-interruption-automatic-path`, `execution-projection`, `native-runner-restart-recovery.integration` (421 passed, 22 skipped). - I did not run the full server typecheck locally because of the sandbox memory limit. CI runs it. ## Risks - Scope: only a foreign-space owner of a run that already ended, when a newer run of the same task exists and the run has no recorded process. Other cases keep their behavior. - Safety: the old controller's stop is still not verified. This follows the existing bounded-wait policy for unverifiable controllers. A newer run already holds the task, so this changes no isolation decision. The release does not start a turn and does not change the task's lock. - Load: one extra indexed query in the release-time calculation. A due row that still cannot be released (for example, an accepted result) makes the pass check at the normal reconciliation interval. - Unchanged: the separate defect where the finish call of a run is not captured (`native_finalization_missing` with `reportedWorkDisposition: yielded`). ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, with tool use and code execution in a Paperclip agent workspace. ## 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 - [ ] 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 - [ ] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>