{"record":{"id":"5a8c106be181c4a0","repo":"paperclipai/paperclip","slug":"refusing-terminal-workspace-cleanup-because-the-gi-5a8c10","errorCode":null,"errorMessage":"Refusing terminal workspace cleanup because the git worktree changed after delivery was verified","messagePattern":"Refusing terminal workspace cleanup because the git worktree changed after delivery was verified","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/src/services/execution-workspaces.ts","lineNumber":1464,"sourceCode":"      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\");\n    }\n  }\n\n  async function hydrateWorkspace(row: ExecutionWorkspaceRow, runtimeServices: WorkspaceRuntimeService[] = []) {\n    const workspace = toExecutionWorkspace(row, runtimeServices);\n    const { git } = await inspectGitCloseReadiness(workspace);\n    const assessment = await assessDelivery(row, git);\n    return toExecutionWorkspace(row, runtimeServices, assessment.deliveryState);\n  }\n\n  async function workspaceHasActiveRun(workspace: Pick<ExecutionWorkspaceRow, \"id\" | \"companyId\" | \"sourceIssueId\">) {\n    const linkedIssues = await db\n      .select({\n        checkoutRunId: issues.checkoutRunId,\n        executionRunId: issues.executionRunId,\n      })\n      .from(issues)\n      .where(and(","sourceCodeStart":1446,"sourceCodeEnd":1482,"githubUrl":"https://github.com/paperclipai/paperclip/blob/a7e689b3c35347b529cb9f54c9b9a8575a3dcab6/server/src/services/execution-workspaces.ts#L1446-L1482","documentation":"Integrity-violation check in assertTerminalCleanupGitStateUnchanged: the git inspection succeeded, but the worktree's current HEAD/branch differs from the expectedHeadSha captured when delivery was verified — the workspace changed after its final state was signed off. Terminal cleanup is refused to avoid destroying unaccounted-for work.","triggerScenarios":"Thrown at server/src/services/execution-workspaces.ts:1464 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the worktree changes made after delivery verification; restore the verified state or clean up 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-14T00:17:10.932Z"}