fix(workspaces): stop retrying copy-back when a Git operation is in progress (#22844)

## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - After a native run on a remote sandbox, Paperclip copies the
workspace back to durable storage during finalization.
> - The archive capture guard refuses to save a workspace that still has
an unfinished Git operation (such as an unresolved merge or rebase) with
`remote_workspace_archive_git_operation_in_progress`.
> - Finalization treated that refusal as transient and retried three
times, then saved-work recovery treated it as a transient provider error
and retried across its 30-minute window.
> - Nothing finishes or aborts a Git operation in an idle or stopped
sandbox between automatic retries, so every retry fails the same way
while delaying user action.
> - This pull request stops both finalization and saved-work recovery on
the first unfinished Git operation refusal, keeps the accepted result
and retained sandbox intact, and hands the task to the board with a
clear Retry path.
> - The benefit is that tasks stop immediately with an accurate
explanation instead of burning futile retries, and Retry saves the files
and applies the accepted result without another provider turn once the
Git operation is resolved.

## Linked Issues or Issue Description

Refs #20678 (stop retrying copy-back on a full sandbox disk), Refs
#20758 (stop re-saving a retained sandbox whose disk is still full),
Refs #20819 (apply a saved accepted result on Retry instead of a new
turn)

**What happened?**
When an agent finishes a native turn and leaves an unresolved Git
operation (such as a conflicted merge or rebase) in the remote sandbox,
workspace archive capture fails with
`remote_workspace_archive_git_operation_in_progress: finish or abort the
Git operation before saving the workspace`. Finalization retried
copy-back 3 times before ending with
`native_workspace_sync_out_retry_exhausted` ("Saving the workspace
failed after 3 attempts"), and saved-work recovery then classified the
refusal as `export_interrupted` / `retry_transient` (`provider_error`)
and retried across its 30-minute window.

**Expected behavior**
Paperclip recognizes
`remote_workspace_archive_git_operation_in_progress` on the first
failure in both finalization and saved-work recovery. It stops automatic
retries immediately, keeps the accepted result linked and the retained
sandbox intact, names the unfinished Git operation clearly, and exposes
the task's Retry action so the user can save the files and apply the
accepted result without another agent turn once the Git operation is
finished or aborted.

**Steps to reproduce**
1. Run a native task on a remote sandbox and leave a conflicted `git
merge` open before the turn finishes with an accepted result.
2. Observe copy-back fail with
`remote_workspace_archive_git_operation_in_progress: finish or abort the
Git operation before saving the workspace`.
3. Before this change, finalization stays in `retryable_failure` for 3
attempts, and saved-work recovery schedules automatic transient retries
with cause `provider_error`.

## What Changed

- `server/src/services/native-runtime/native-workspace-failure.ts`:
export `REMOTE_WORKSPACE_GIT_OPERATION_IN_PROGRESS_CODE`,
`isWorkspaceGitOperationInProgress()`, and a unified
`workspaceSaveRestCause()` helper (`"sandbox_disk_full" |
"git_operation_in_progress" | null`) used by both finalization and
saved-work recovery as the single source of truth.
- `server/src/services/native-runtime/native-run-finalizer.ts`: use
`workspaceSaveRestCause(failureCause)` to exhaust workspace copy-back on
Attempt 1 for both `sandbox_disk_full` and `git_operation_in_progress`
(keeping `failureCode = native_workspace_sync_out_retry_exhausted`,
accepted result linked, retained sandbox lease preserved, and no new
wakeups), and emit truthful run error and recovery `nextAction` text
without "after 3 attempts" or "Finalization retry budget exhausted."
(net file size change: +1 line).
- `server/src/services/workspace-recovery.ts` &
`server/src/services/system-recovery-state.ts`: use
`workspaceSaveRestCause(error)` so retained saved-work recovery stops on
Attempt 1 for `git_operation_in_progress` with `export_interrupted`,
`retryClass: "user_action_required"`, and cause `{ label:
"git_operation_in_progress", code: null, status: null }`, keeping
unsaved files protected and showing plain-language
`exhaustedSystemRecoveryAction` guidance.
- `ui/src/components/WorkspaceExportRecovery.tsx`: treat
`git_operation_in_progress` alongside `sandbox_disk_full` as a
user-action save rest so the panel surfaces clear status copy and leaves
the task's Retry control available.
- Added red-to-green regression tests across
`server/src/services/native-runtime/native-workspace-failure.test.ts`
(including producer-to-detector redaction round-trip through
`remoteWorkspaceCaptureFailureMessage` and
`remoteWorkspaceFailureCause`),
`server/src/services/native-runtime/native-run-finalizer-telemetry.test.ts`,
`server/src/services/workspace-recovery-warm-handoff.test.ts`, and
`ui/src/components/WorkspaceExportRecovery.control.test.tsx`.

## Verification

- **Red before production edits**:
- Finalizer (`recordNativeFinalizationFailure`), saved-work recovery
(`recoverRetainedWorkspace`), `exhaustedSystemRecoveryAction`, and
`WorkspaceExportRecovery` regressions all failed against unfixed
production code (finalizer stayed `retryable_failure`, recovery stayed
`scheduled`/`retry_transient`/`provider_error`, UI rendered `Recover
saved files` button instead of handing off to task Retry).
- **Green at `6b18fd8b63`** (rebased cleanly onto `origin/master`
`ba63f4f8b2`):
  - `npx tsc --noEmit -p server/tsconfig.json`: pass.
  - `pnpm --filter @paperclipai/ui typecheck`: pass.
- `cd server && npx vitest run
src/services/native-runtime/native-workspace-failure.test.ts
src/services/native-runtime/native-run-finalizer-telemetry.test.ts
src/services/workspace-recovery-warm-handoff.test.ts`: 89/89 pass
(covers producer->detector redaction round-trip, Attempt-1 stop for
git-op-in-progress and disk-full, preserved accepted result, transient
`remote_workspace_archive_changed` & `ECONNRESET` still retrying,
permanent errors still permanent, Retry-while-open resting immediately,
and Retry-after-resolved saving and applying the accepted result without
a new turn).
- `cd ui && npx vitest run
src/components/WorkspaceExportRecovery.control.test.tsx`: 51/51 pass.
- Required GitHub CI supplies the full repo-wide suite on `6b18fd8b63`.
- Environment: local macOS worktree with embedded Postgres fixture for
server integration tests and jsdom for UI tests; live Daytona sandbox
acceptance was not run locally.

## Risks

- Low risk. The terminal finalization code
(`native_workspace_sync_out_retry_exhausted`) and recovery schema
(`export_interrupted` / `user_action_required` with closed-label cause
`git_operation_in_progress`) reuse existing persisted contracts and DB
indexes without any migration.
- Upgrade safety: a run persisted in `retryable_failure` by an earlier
release with `remote_workspace_archive_git_operation_in_progress` stops
on its next attempt; an earlier release reading the new
`git_operation_in_progress` cause passes schema validation and displays
its generic Retry copy.
- Does not modify `remote-workspace-snapshot-archive.ts` or relax any
Git archive safety guard. Unsaved files remain protected in the retained
sandbox and never trigger the `source_unavailable` fallback.

## Model Used

- Gemini 4 Neon (High) (`gemini-4-neon-high`), Google, via Antigravity
with tool use (shell, file edits, test execution).

## 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
- [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
This commit is contained in:
Dotta authored and GitHub committed 2026-11-25 04:34:03 -06:00
1 parent 95ffa0c855
commit 585f58aeba
9 files changed
+333 -39

No files matched your search

@@ -392,6 +392,26 @@ describe("governed retained-file recovery", () => {
expect(api.recover).not.toHaveBeenCalled();
});
it("hands an in-progress Git operation save rest to the task's Retry instead of its own recovery button", async () => {
const gitOp = { ...action, ownerType: "board", evidence: { ...action.evidence, systemRecovery: {
state: "exhausted", preservationOperationIds: [], failure: { code: "export_interrupted",
retryClass: "user_action_required", cause: { label: "git_operation_in_progress", code: null, status: null } } } },
} as unknown as IssueRecoveryAction;
api.inspect.mockResolvedValue(inspection(gitOp));
const owns = vi.fn();
await act(async () => root.render(<QueryClientProvider client={client}>
<WorkspaceExportRecovery action={gitOp} issueId="issue-1" companyId="company-1" onRecoveryControlChange={owns} />
</QueryClientProvider>));
await settle();
expect(button("Recover saved files")).toBeUndefined();
expect(button("Try file recovery again")).toBeUndefined();
expect(owns).toHaveBeenLastCalledWith(false);
expect(owns).not.toHaveBeenCalledWith(true);
expect(container.textContent).toContain("Git operation");
expect(container.textContent).toContain("use Retry to save them");
expect(api.recover).not.toHaveBeenCalled();
});
it("only reports recovered files after the durable preservation receipt is present", async () => {
const recovered = { ...action, evidence: { ...action.evidence, workspaceRecovery: {
...(action.evidence.workspaceRecovery as object), status: "recovered",
+16 -11
View File
@@ -125,12 +125,13 @@ function isRetainedExport(action: IssueRecoveryAction, issueId: string, companyI
&& typeof action.evidence.runId === "string" && action.evidence.runId.length > 0;
}
/** Saved-work recovery ended because the sandbox disk was still full (#20758). */
function isSandboxDiskFullRest(action: IssueRecoveryAction) {
/** Saved-work recovery ended on a deterministic workspace state requiring user action before Retry. */
function userActionWorkspaceSaveRestCause(action: IssueRecoveryAction): "sandbox_disk_full" | "git_operation_in_progress" | null {
const system = asObject(action.evidence.systemRecovery);
const failure = asObject(system.failure);
return system.state === "exhausted" && failure.retryClass === "user_action_required"
&& asObject(failure.cause).label === "sandbox_disk_full";
if (system.state !== "exhausted" || failure.retryClass !== "user_action_required") return null;
const label = asObject(failure.cause).label;
return label === "sandbox_disk_full" || label === "git_operation_in_progress" ? label : null;
}
function isControllerStopRequired(action: IssueRecoveryAction, issueId: string, companyId: string) {
@@ -351,26 +352,30 @@ function RetainedFilesRecovery({ action, issueId, companyId, className, onRecove
const waiting = !failedReceipt && !saved && (restoring || acknowledged || serverAcknowledged);
const unconfirmed = Boolean(pending && !acknowledged && !serverAcknowledged);
const sourceLoading = sourceView.kind === "loading" || sourceView.kind === "reconnecting";
// A save that rested on a full sandbox disk is resumed by the task's Retry,
// which saves the files again and then applies the saved result. Its note
// names Retry, so this panel offers no separate control for it.
const diskFullRest = isSandboxDiskFullRest(current ?? action);
// A save that rested on a deterministic workspace state (such as a full
// sandbox disk or an in-progress Git operation) is resumed by the task's
// Retry, which saves the files again and then applies the saved result. Its
// note names Retry, so this panel offers no separate control for it.
const userActionSaveRest = userActionWorkspaceSaveRestCause(current ?? action);
// A verified source makes this panel the governed recovery path. Otherwise the
// task's own Retry (renewed, re-verified recovery) remains the next action.
const ownsRecoveryControl = canMutate && !diskFullRest && (sourceLoading || Boolean(current && verified && !saved));
const ownsRecoveryControl = canMutate && !userActionSaveRest && (sourceLoading || Boolean(current && verified && !saved));
// `waiting` already excludes a failed accepted request, so the reason stays
// visible after a failed attempt and hides only while recovery is running.
const unverified = Boolean(current && !verified && !saved && !waiting);
return <div className={cn("flex flex-col gap-2 text-sm", className)} data-testid="retained-file-recovery">
<ReportRecoveryControl owns={ownsRecoveryControl} onChange={onRecoveryControlChange} />
<p role="status">{saved ? "Saved files recovered. Task recovery is still being checked."
: diskFullRest && !waiting ? "The sandbox disk was full when Paperclip saved the files. Free space, then use Retry to save them and finish the task."
: userActionSaveRest === "sandbox_disk_full" && !waiting
? "The sandbox disk was full when Paperclip saved the files. Free space, then use Retry to save them and finish the task."
: userActionSaveRest === "git_operation_in_progress" && !waiting
? "A Git operation was still in progress when Paperclip saved the files. Finish or abort it, then use Retry to save them and finish the task."
: failedReceipt ? "File recovery has not finished. The saved source remains protected."
: restoring ? "Recovering saved files. Work remains paused until recovery is verified."
: waiting ? "File recovery is queued. Waiting for verified saved files."
: "The saved files need recovery before work can continue."}</p>
{canMutate ? <>
{current && verified && retryable && !waiting && !diskFullRest && (!pending || unconfirmed && checkedUnconfirmed || confirmedFailedAttempt) ? <Button variant="outline" size="sm"
{current && verified && retryable && !waiting && !userActionSaveRest && (!pending || unconfirmed && checkedUnconfirmed || confirmedFailedAttempt) ? <Button variant="outline" size="sm"
className="self-start" disabled={request.isPending || check.isPending}
onClick={() => request.mutate(confirmedFailedAttempt)}>{request.isPending ? "Requesting file recovery…"
: confirmedFailedAttempt ? "Try file recovery again" : "Recover saved files"}</Button> : null}