mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-26 10:07:24 +01:00
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:
1 parent
95ffa0c855
commit
585f58aeba
9 files changed
+333
-39
No files matched your search
@@ -930,8 +930,9 @@ describeEmbeddedPostgres("native run finalizer / status decision committer — a
|
||||
expect(run?.error).toMatch(/sandbox disk is full/);
|
||||
expect(run?.error).not.toMatch(/after 3 attempts/);
|
||||
// The export hold owns the next step; no provider turn is requested.
|
||||
expect(await db.select().from(issueRecoveryActions).where(eq(issueRecoveryActions.sourceIssueId, fixture.issueId)))
|
||||
.toEqual([expect.objectContaining({ status: "active", ownerType: "board", cause: "native_workspace_sync_out_retry_exhausted" })]);
|
||||
const actions = await db.select().from(issueRecoveryActions).where(eq(issueRecoveryActions.sourceIssueId, fixture.issueId));
|
||||
expect(actions).toEqual([expect.objectContaining({ status: "active", ownerType: "board", cause: "native_workspace_sync_out_retry_exhausted" })]);
|
||||
expect(actions[0].nextAction).not.toMatch(/Finalization retry budget exhausted/);
|
||||
expect(await db.select({ id: agentWakeupRequests.id }).from(agentWakeupRequests)
|
||||
.where(eq(agentWakeupRequests.agentId, agentId))).toEqual(wakeupsBefore);
|
||||
});
|
||||
@@ -949,6 +950,61 @@ describeEmbeddedPostgres("native run finalizer / status decision committer — a
|
||||
expect(failure).toMatchObject({ phase: "retryable_failure", failureCode: "native_workspace_sync_out_failed" });
|
||||
});
|
||||
|
||||
it("stops copy-back on the first unfinished Git operation failure and keeps the accepted result", async () => {
|
||||
const gitOpCause = "remote_workspace_archive_git_operation_in_progress: finish or abort the Git operation before saving the workspace";
|
||||
const fixture = await seedNativeRun();
|
||||
await driveToCompleteResult(fixture);
|
||||
const [accepted] = await db.select().from(nativeRunResults).where(eq(nativeRunResults.runId, fixture.runId));
|
||||
expect(accepted).toBeDefined();
|
||||
const wakeupsBefore = await db.select({ id: agentWakeupRequests.id }).from(agentWakeupRequests)
|
||||
.where(eq(agentWakeupRequests.agentId, agentId));
|
||||
const failure = await recordNativeFinalizationFailure({
|
||||
db, runId: fixture.runId, error: new Error("native_workspace_sync_out_failed"),
|
||||
projectRunStatus: true, failureScope: "workspace", failureCause: gitOpCause,
|
||||
});
|
||||
expect(failure).toMatchObject({
|
||||
phase: "terminal_failure",
|
||||
failureCode: "native_workspace_sync_out_retry_exhausted",
|
||||
nextAttemptAt: null,
|
||||
});
|
||||
const [coordinator] = await db.select().from(nativeRunFinalizations).where(eq(nativeRunFinalizations.runId, fixture.runId));
|
||||
expect(coordinator.failureDetail).toMatchObject({
|
||||
recoveryOwner: { kind: "board" },
|
||||
workspaceFinalizeAttempt: 1,
|
||||
failureCause: gitOpCause,
|
||||
});
|
||||
expect(coordinator.resultId).toBe(accepted.id);
|
||||
expect(await db.select().from(nativeRunResults).where(eq(nativeRunResults.runId, fixture.runId))).toEqual([accepted]);
|
||||
const run = await readRunError(fixture.runId);
|
||||
expect(run).toMatchObject({ status: "failed", errorCode: "native_workspace_sync_out_retry_exhausted" });
|
||||
expect(run?.error).toMatch(/Git operation is still in progress/);
|
||||
expect(run?.error).not.toMatch(/after 3 attempts/);
|
||||
const actions = await db.select().from(issueRecoveryActions).where(eq(issueRecoveryActions.sourceIssueId, fixture.issueId));
|
||||
expect(actions).toEqual([expect.objectContaining({
|
||||
status: "active",
|
||||
ownerType: "board",
|
||||
cause: "native_workspace_sync_out_retry_exhausted",
|
||||
wakePolicy: null,
|
||||
})]);
|
||||
expect(actions[0].nextAction).toMatch(/Git operation/);
|
||||
expect(actions[0].nextAction).not.toMatch(/Finalization retry budget exhausted/);
|
||||
expect(await db.select({ id: agentWakeupRequests.id }).from(agentWakeupRequests)
|
||||
.where(eq(agentWakeupRequests.agentId, agentId))).toEqual(wakeupsBefore);
|
||||
});
|
||||
|
||||
it("keeps transient workspace archive change failures on their bounded retry", async () => {
|
||||
const fixture = await seedNativeRun();
|
||||
await db.insert(nativeRunFinalizations).values({
|
||||
runId: fixture.runId, companyId, issueId: fixture.issueId, phase: "observed", attempt: 1,
|
||||
});
|
||||
const failure = await recordNativeFinalizationFailure({
|
||||
db, runId: fixture.runId, error: new Error("native_workspace_sync_out_failed"),
|
||||
projectRunStatus: true, failureScope: "workspace",
|
||||
failureCause: "remote_workspace_archive_changed",
|
||||
});
|
||||
expect(failure).toMatchObject({ phase: "retryable_failure", failureCode: "native_workspace_sync_out_failed" });
|
||||
});
|
||||
|
||||
it("does not attach a finalization error to a provider-succeeded run when provider retries are exhausted", async () => {
|
||||
const fixture = await seedNativeRun();
|
||||
await db.update(heartbeatRuns).set({ resultJson: { prpRunTerminalState: "succeeded", finalizationFailureCount: 2 } })
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { notifyNativeEnvironmentSettlement } from "../native-environment-settlement-notifications.js";
|
||||
import { isContextCompactionRun } from "../context-compaction.js";
|
||||
import { REMOTE_WORKSPACE_SANDBOX_DISK_FULL_CODE } from "../remote-workspace-transport.js";
|
||||
import { isWorkspaceGitOperationInProgress, workspaceSaveRestCause } from "./native-workspace-failure.js";
|
||||
import { notifyExternalAgentSettlement } from "../../modules/external-agents/index.js";
|
||||
import { notifyNativeRecoveryNotices } from "../native-recovery-notice-notifications.js";
|
||||
import { resolveCommittedNativeRecoveryNotices } from "./native-recovery-notices.js";
|
||||
@@ -324,11 +324,19 @@ export function readWorkspaceFailureCause(value: unknown): string | null {
|
||||
|
||||
function terminalFinalizationFailureMessage(failureCode: string, failureScope: "provider" | "workspace" | undefined,
|
||||
failureCause?: string | null) {
|
||||
if (failureCode === "native_workspace_sync_out_retry_exhausted" && isSandboxStorageExhausted(failureCause)) {
|
||||
const saveRestCause = failureCode === "native_workspace_sync_out_retry_exhausted"
|
||||
? workspaceSaveRestCause(failureCause)
|
||||
: null;
|
||||
if (saveRestCause === "sandbox_disk_full") {
|
||||
return "Saving the workspace stopped because the sandbox disk is full. The agent's result is kept, and Paperclip "
|
||||
+ "saves the files again from the retained sandbox without repeating the agent's work; follow the run's recovery "
|
||||
+ `action if that cannot free enough space. Last cause: ${failureCause}`;
|
||||
}
|
||||
if (saveRestCause === "git_operation_in_progress") {
|
||||
return "Saving the workspace stopped because a Git operation is still in progress in the workspace. "
|
||||
+ "The agent's result is kept; finish or abort the Git operation before saving the workspace. "
|
||||
+ `Last cause: ${failureCause}`;
|
||||
}
|
||||
if (failureCode === "native_workspace_sync_out_retry_exhausted") {
|
||||
// This code also covers local-directory and plugin workspaces, so the
|
||||
// message stays general and defers to the recovery action's next step.
|
||||
@@ -434,16 +442,6 @@ export async function endSupersededNativeFinalizationRuns(db: Db, runIds?: reado
|
||||
return ended;
|
||||
}
|
||||
|
||||
/**
|
||||
* A full sandbox disk stops every copy-back the same way: the archive is built
|
||||
* in that sandbox, and nothing frees space between finalizer attempts. It is
|
||||
* recognised on the first failure and handed to saved-work recovery, which can
|
||||
* reclaim the retained sandbox's inactive provider cache before saving again.
|
||||
*/
|
||||
function isSandboxStorageExhausted(failureCause: string | null | undefined) {
|
||||
return typeof failureCause === "string" && failureCause.startsWith(`${REMOTE_WORKSPACE_SANDBOX_DISK_FULL_CODE}:`);
|
||||
}
|
||||
|
||||
const NATIVE_FINALIZATION_RETRY_LIMIT = 3;
|
||||
/**
|
||||
* Contention while applying a saved, accepted, provider-succeeded result is
|
||||
@@ -595,9 +593,11 @@ async function recordRetryableFailure(input: {
|
||||
let finalizationFailureCount = input.failureScope === "workspace"
|
||||
? null
|
||||
: readFinalizationFailureCount(input.run.resultJson) + 1;
|
||||
const nonRetryableWorkspaceCause =
|
||||
input.failureScope === "workspace" && workspaceSaveRestCause(failureCause) !== null;
|
||||
const budgetExhausted =
|
||||
input.permanent === true ||
|
||||
(input.failureScope === "workspace" && isSandboxStorageExhausted(failureCause)) ||
|
||||
nonRetryableWorkspaceCause ||
|
||||
(workspaceFinalizeAttempt !== null
|
||||
? workspaceFinalizeAttempt >= 3
|
||||
: finalizationFailureCount! >= NATIVE_FINALIZATION_RETRY_LIMIT);
|
||||
@@ -781,7 +781,7 @@ async function recordRetryableFailure(input: {
|
||||
originalFailureCode: input.failureCode,
|
||||
},
|
||||
nextAction: exhausted
|
||||
? input.permanent
|
||||
? input.permanent || nonRetryableWorkspaceCause
|
||||
? input.nextAction
|
||||
: `Finalization retry budget exhausted. ${input.nextAction}`
|
||||
: input.nextAction,
|
||||
@@ -854,9 +854,11 @@ export async function recordNativeFinalizationFailure(input: {
|
||||
&& (message === "native_plugin_workspace_branch_mismatch" || message === "native_plugin_workspace_owner_mismatch")
|
||||
? "Repair the plugin workspace branch or owner, then resume finalization without another provider turn."
|
||||
: input.failureScope === "workspace"
|
||||
? input.permanent
|
||||
? "Restore the exact sandbox containing the unexported workspace changes, or resolve the task manually from durable evidence."
|
||||
: "Retry workspace export and merge from the retained sandbox; do not submit another provider turn."
|
||||
? input.permanent
|
||||
? "Restore the exact sandbox containing the unexported workspace changes, or resolve the task manually from durable evidence."
|
||||
: isWorkspaceGitOperationInProgress(readWorkspaceFailureCause(input.failureCause))
|
||||
? "Finish or abort the in-progress Git operation in the workspace, then retry saving the workspace; do not submit another provider turn."
|
||||
: "Retry workspace export and merge from the retained sandbox; do not submit another provider turn."
|
||||
: "Repair the persisted native result or contract discriminator, then resume finalization from the coordinator.",
|
||||
projectRunStatus: input.projectRunStatus,
|
||||
failureScope: input.failureScope,
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
classifyNativeWorkspaceFailure,
|
||||
isWorkspaceGitOperationInProgress,
|
||||
workspaceSaveRestCause,
|
||||
} from "./native-workspace-failure.js";
|
||||
import { remoteWorkspaceCaptureFailureMessage } from "../remote-workspace-snapshot-archive.js";
|
||||
import {
|
||||
REMOTE_WORKSPACE_SANDBOX_DISK_FULL,
|
||||
remoteWorkspaceFailureCause,
|
||||
} from "../remote-workspace-transport.js";
|
||||
import {
|
||||
createSystemRecovery,
|
||||
exhaustedSystemRecoveryAction,
|
||||
failSystemRecovery,
|
||||
reserveSystemRecoveryAttempt,
|
||||
savedFilesUnrecoverable,
|
||||
SystemRecoveryFailure,
|
||||
} from "../system-recovery-state.js";
|
||||
|
||||
describe("native workspace failure classification and save-rest policy", () => {
|
||||
it("recognizes the exact producer output for an in-progress Git operation through redaction", () => {
|
||||
const producerMessage = remoteWorkspaceCaptureFailureMessage({
|
||||
message: "remote_workspace_archive_git_operation_in_progress: finish or abort the Git operation before saving the workspace",
|
||||
});
|
||||
expect(producerMessage).not.toBeNull();
|
||||
const redactedCause = remoteWorkspaceFailureCause(new Error(producerMessage!));
|
||||
expect(redactedCause).toBe(producerMessage);
|
||||
expect(isWorkspaceGitOperationInProgress(new Error(producerMessage!))).toBe(true);
|
||||
expect(isWorkspaceGitOperationInProgress(redactedCause)).toBe(true);
|
||||
expect(workspaceSaveRestCause(new Error(producerMessage!))).toBe("git_operation_in_progress");
|
||||
expect(workspaceSaveRestCause(redactedCause)).toBe("git_operation_in_progress");
|
||||
expect(classifyNativeWorkspaceFailure(new Error(producerMessage!))).toEqual({
|
||||
code: "workspace_sync_out_failed",
|
||||
failureCode: "native_workspace_sync_out_failed",
|
||||
permanent: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("recognizes sandbox disk full and keeps transient or unrelated errors retryable", () => {
|
||||
const diskFullCause = remoteWorkspaceFailureCause(new Error(REMOTE_WORKSPACE_SANDBOX_DISK_FULL));
|
||||
expect(workspaceSaveRestCause(diskFullCause)).toBe("sandbox_disk_full");
|
||||
expect(workspaceSaveRestCause(new Error(REMOTE_WORKSPACE_SANDBOX_DISK_FULL))).toBe("sandbox_disk_full");
|
||||
|
||||
for (const transient of [
|
||||
"remote_workspace_archive_changed",
|
||||
"remote_workspace_capture_failed: stage=archive code=ECONNRESET",
|
||||
"Daytona syncOut directory download failed: timeout",
|
||||
]) {
|
||||
expect(isWorkspaceGitOperationInProgress(transient)).toBe(false);
|
||||
expect(workspaceSaveRestCause(transient)).toBeNull();
|
||||
expect(workspaceSaveRestCause(new Error(transient))).toBeNull();
|
||||
}
|
||||
|
||||
expect(classifyNativeWorkspaceFailure(new Error("daytona_sandbox_not_found"))).toEqual({
|
||||
code: "workspace_sync_out_unrecoverable",
|
||||
failureCode: "native_workspace_sync_out_unrecoverable",
|
||||
permanent: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("renders plain-language recovery copy for an in-progress Git operation rest", () => {
|
||||
const gitOp = failSystemRecovery(
|
||||
reserveSystemRecoveryAttempt(createSystemRecovery(randomUUID()), 0)!,
|
||||
new SystemRecoveryFailure("export_interrupted", "user_action_required"),
|
||||
{ now: 0, cause: { label: "git_operation_in_progress", code: null, status: null } },
|
||||
);
|
||||
expect(gitOp).toMatchObject({ state: "exhausted", attempts: 1, retriesUsed: 0, nextAttemptAt: null });
|
||||
expect(savedFilesUnrecoverable(gitOp)).toBe(false);
|
||||
const text = exhaustedSystemRecoveryAction(gitOp);
|
||||
expect(text).toMatch(/Git operation/i);
|
||||
expect(text).toContain("Retry");
|
||||
expect(text).not.toContain("git_operation_in_progress");
|
||||
expect(text).not.toMatch(/administrator|\bowner\b|board member|inspect the run|environment/i);
|
||||
});
|
||||
});
|
||||
@@ -1,17 +1,55 @@
|
||||
import { classifyWorkspaceRestoreFailure } from "@paperclipai/adapter-utils/workspace-restore-merge";
|
||||
import { REMOTE_WORKSPACE_SANDBOX_DISK_FULL_CODE } from "../remote-workspace-transport.js";
|
||||
|
||||
export type NativeWorkspaceFailureCode =
|
||||
| "workspace_sync_out_failed"
|
||||
| "workspace_sync_out_unrecoverable"
|
||||
| "workspace_sync_out_unsafe_archive";
|
||||
|
||||
export type WorkspaceSaveRestCause =
|
||||
| "sandbox_disk_full"
|
||||
| "git_operation_in_progress";
|
||||
|
||||
export const REMOTE_WORKSPACE_GIT_OPERATION_IN_PROGRESS_CODE =
|
||||
"remote_workspace_archive_git_operation_in_progress";
|
||||
|
||||
function readFailureText(value: unknown): string {
|
||||
return typeof value === "string"
|
||||
? value.trim()
|
||||
: value instanceof Error
|
||||
? value.message.trim()
|
||||
: "";
|
||||
}
|
||||
|
||||
/**
|
||||
* A workspace with an unfinished Git operation (such as a conflicted merge or
|
||||
* rebase) fails every copy-back attempt the same way: nothing finishes or
|
||||
* aborts the Git operation between automatic attempts.
|
||||
*/
|
||||
export function isWorkspaceGitOperationInProgress(value: unknown): boolean {
|
||||
const text = readFailureText(value);
|
||||
return text === REMOTE_WORKSPACE_GIT_OPERATION_IN_PROGRESS_CODE
|
||||
|| text.startsWith(`${REMOTE_WORKSPACE_GIT_OPERATION_IN_PROGRESS_CODE}:`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deterministic workspace-save refusals that repeat identically across
|
||||
* automatic attempts because the sandbox state does not change between tries.
|
||||
*/
|
||||
export function workspaceSaveRestCause(value: unknown): WorkspaceSaveRestCause | null {
|
||||
const text = readFailureText(value);
|
||||
if (text.startsWith(`${REMOTE_WORKSPACE_SANDBOX_DISK_FULL_CODE}:`)) return "sandbox_disk_full";
|
||||
if (isWorkspaceGitOperationInProgress(text)) return "git_operation_in_progress";
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Keep initial and recovered copy-back failures on the same retry policy. */
|
||||
export function classifyNativeWorkspaceFailure(error: unknown): {
|
||||
code: NativeWorkspaceFailureCode;
|
||||
failureCode: `native_${NativeWorkspaceFailureCode}`;
|
||||
permanent: boolean;
|
||||
} {
|
||||
const message = error instanceof Error ? error.message.trim() : "";
|
||||
const message = readFailureText(error);
|
||||
const code: NativeWorkspaceFailureCode =
|
||||
message === "workspace_sync_out_unrecoverable" || message.includes("daytona_sandbox_not_found")
|
||||
|| classifyWorkspaceRestoreFailure(error) === "restore_invalid_metadata"
|
||||
|
||||
Reference in new issue
Block a user