Skip to content

## Salvage agent work before destroying the worktree, and diagnose push rejections #2736

Closed

Description

@propr-dev

Salvage agent work before destroying the worktree, and diagnose push rejections

Context

When an implementation or follow-up run finishes, ProPR commits, pushes and opens/updates the PR, then deletes the worktree (WORKTREE_RETENTION_STRATEGY, default always_delete, in packages/core/src/git/worktreeOperations.ts; containers run with docker run --rm). If the push fails — a GitHub ruleset or secret-scanning push protection rejects it, the installation token expired, a non-fast-forward because someone pushed to the branch, a network error — the work the agent produced is lost with the worktree, and the task fails with a generic message. There is PR publication checkpointing (src/jobs/prPublicationRecovery.ts, migrations add_pr_publication_checkpoint / _completion) and the reconciler marks orphaned tasks failed (src/taskStateReconciler.ts), but nothing preserves the commits themselves when the push is the failing step.

Requirements

  1. Salvage ladder when the final push fails (apply to implementation runs, PR follow-ups, /fix, ultrafix cycles and merge-conflict jobs — every path that pushes from a worktree in src/jobs/):
    1. Retry the push once after refreshing the git credential (installation tokens are short-lived; see packages/core/src/agents/agentGitAccess.ts and the existing token refresh used by fix: refresh GitHub credentials for issue publication).
    2. If it still fails, push the same commits to a rescue ref refs/propr/rescue/<taskId> on the same remote (this succeeds on non-fast-forward failures because the ref is new; it does not help with push-protection rejections).
    3. If that fails, write a git bundle (git bundle create) of the branch to durable local storage under the ProPR data directory (e.g. <data>/rescue/<repo>/<taskId>.bundle), with retention/cleanup consistent with how failed-task worktree retention is handled.
    4. If all of the above fail, keep the worktree (override always_delete for this task) and write .retention-info.json as the failed-task retention path already does.
      Record which rung succeeded in a task timeline event, and include the exact recovery instruction in the task's failure summary and GitHub comment (the rescue ref name, the bundle path, or the retained worktree path).
  2. Push-rejection diagnosis. Parse git's push error output and classify it into at least: push_protection (GitHub secret scanning — include the unblock URL GitHub prints), ruleset_or_branch_protection (rule violations), non_fast_forward, auth (401/403/expired token), network, unknown. Store the classification on the task (a failure_reason detail is fine if a dedicated column is not justified), show it in the task detail UI, in propr task get, and in the GitHub failure comment so a reviewer can act without reading logs. For push_protection, the comment must include the unblock URL verbatim.
  3. Rescue ref hygiene. Provide a maintenance path to delete rescue refs older than N days (default 14) — a daemon maintenance job or a propr maintenance command, whichever matches existing maintenance patterns in docs/docs/operations/maintenance.md. Rescue refs must never be picked up as task branches by the daemon or by branch-naming logic.
  4. Do not change the success path's timing or the worktree lock semantics ("follow-up cleanup finishes before the worktree lock is released").

Documentation

  • docs/docs/operations/maintenance.md and docs/docs/operations/troubleshooting.md: describe the salvage ladder, the rescue ref, the bundle location and how to recover each.
  • docs/docs/architecture/git-management.md: one section on the salvage flow.
  • docs/docs/operations/configuration-reference.md for any new env/settings (rescue retention days, bundle directory).
  • CHANGELOG.md Unreleased entry.

Tests

  • Unit tests for the push-error classifier with real-world sample outputs for each class (secret scanning push protection text with its unblock URL, ruleset violation text, ! [rejected] ... (non-fast-forward), 401/403 text, connection reset).
  • Tests for the salvage ladder using a fake git/remote: step 1 succeeds → no rescue; step 2 succeeds → rescue ref recorded; step 3 succeeds → bundle path recorded; all fail → worktree retained and .retention-info.json written.
  • A test that rescue refs are ignored by the daemon's branch discovery.
  • Run npm run lint, npm run typecheck and the affected suites; keep existing tests passing.

Submitted by @integry through ProPR.

Activity

  1. propr-dev commented on Oct 5, 2026

    @propr-dev
    ContributorAuthor

    🤖 AI processing has started for this issue using claude agent with claude-opus-5-5 model.

    I'll analyze the problem and work on a solution. This may take a few minutes.

    Processing Details:

    • Agent: claude
    • Model: claude-opus-5-5
    • Branch: 2736/claude-opus-5-5-salvage-agent-work-before-20261005-2330-ait
    • Base Branch: main
    • Worktree: issue-2736-20261005-2330-claude-opus-5-5-ait

    🔍 Track Task Execution

  2. added a commit that references this issue on Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions