{"record":{"id":"c2186368230f6619","repo":"paperclipai/paperclip","slug":"refusing-terminal-workspace-cleanup-because-the-ex","errorCode":null,"errorMessage":"Refusing terminal workspace cleanup because the expected git HEAD is unknown","messagePattern":"Refusing terminal workspace cleanup because the expected git HEAD is unknown","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/src/services/execution-workspaces.ts","lineNumber":1446,"sourceCode":"        pullRequestStateUnknown,\n        isMergedIntoBase: git?.isMergedIntoBase ?? null,\n      }),\n      sourceIssueTerminal,\n      subtreeTerminal,\n      cooldownAnchor,\n      workspaceDirty: Boolean(git?.hasDirtyTrackedFiles || git?.hasUntrackedFiles),\n      workspaceHeadSha,\n    };\n  }\n\n  async function assertTerminalCleanupGitStateUnchanged(\n    workspace: ExecutionWorkspaceRow,\n    expectedHeadSha: string | null,\n  ) {\n    if (workspace.providerType !== \"git_worktree\") return;\n    const workspacePath = readNullableString(workspace.providerRef) ?? readNullableString(workspace.cwd);\n    if (!workspacePath || !expectedHeadSha) {\n      throw new Error(\"Refusing terminal workspace cleanup because the expected git HEAD is unknown\");\n    }\n\n    const [current, currentHeadSha, currentBranchName] = await Promise.all([\n      inspectGitCloseReadiness(toExecutionWorkspace(workspace)),\n      readGitStdout([\"rev-parse\", \"HEAD\"], workspacePath).catch(() => null),\n      readGitStdout([\"symbolic-ref\", \"--quiet\", \"--short\", \"HEAD\"], workspacePath).catch(() => null),\n    ]);\n    if (!current.statusInspectionSucceeded) {\n      throw new Error(\"Refusing terminal workspace cleanup because the git status could not be verified\");\n    }\n    if (\n      !current.git?.repoRoot\n      || current.git.hasDirtyTrackedFiles\n      || current.git.hasUntrackedFiles\n      || currentHeadSha !== expectedHeadSha\n      || (workspace.branchName && currentBranchName !== workspace.branchName)\n    ) {\n      throw new Error(\"Refusing terminal workspace cleanup because the git worktree changed after delivery was verified\");","sourceCodeStart":1428,"sourceCodeEnd":1464,"githubUrl":"https://github.com/paperclipai/paperclip/blob/a7e689b3c35347b529cb9f54c9b9a8575a3dcab6/server/src/services/execution-workspaces.ts#L1428-L1464","documentation":"Fail-closed safety check in assertTerminalCleanupGitStateUnchanged: a git_worktree workspace is about to be terminally cleaned up, but either its local path or the expected HEAD SHA (workspaceHeadSha captured when delivery was verified) is unknown. Without a pinned expected HEAD the 'unchanged since verification' invariant cannot be checked, so destructive cleanup is refused.","triggerScenarios":"Thrown at server/src/services/execution-workspaces.ts:1446 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Restore the expected git HEAD record for the workspace before cleanup, or clean up the workspace manually."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a7e689b3c35347b529cb9f54c9b9a8575a3dcab6","analyzedAt":"2026-08-18T22:49:45.177Z","contentChangedAt":"2026-08-18T22:49:45.177Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}