{"record":{"id":"f0eef7bc01676607","repo":"can1357/oh-my-pi","slug":"git-apply-with-baseline-wip-failed-for-task-task","errorCode":null,"errorMessage":"git apply with baseline WIP failed for task ${taskId}: ${stderr}","messagePattern":"git apply with baseline WIP failed for task (.+?): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/task/worktree.ts","lineNumber":680,"sourceCode":"\t\t\ttry {\n\t\t\t\t// `git apply --3way` leaves conflict markers in `U` files when\n\t\t\t\t// it can't resolve; reset the worktree so the WIP-seeded retry\n\t\t\t\t// starts from a clean HEAD tree.\n\t\t\t\tawait repo.reset(\"hard\", \"HEAD\");\n\t\t\t\tawait applyDeltaOverBaselineWip(tmpDir, taskId, patchText, wipPatches, baselineWip);\n\t\t\t} catch (wipErr) {\n\t\t\t\tif (!vcs.isVcsError(wipErr)) throw wipErr;\n\t\t\t\tconst stderr = wipErr.stderr.slice(0, 2000);\n\t\t\t\tlogger.error(\"commitToBranch: git apply with baseline WIP failed\", {\n\t\t\t\t\ttaskId,\n\t\t\t\t\texitCode: wipErr.exitCode,\n\t\t\t\t\tstderr,\n\t\t\t\t\tthreeWayStderr: threeWayErr.stderr.slice(0, 2000),\n\t\t\t\t\tinitialStderr: plainErr.stderr.slice(0, 2000),\n\t\t\t\t\tpatchSize: patchText.length,\n\t\t\t\t\tpatchHead: patchText.slice(0, 500),\n\t\t\t\t});\n\t\t\t\tthrow new Error(`git apply with baseline WIP failed for task ${taskId}: ${stderr}`);\n\t\t\t}\n\t\t}\n\t}\n\n\tawait repo.stageFiles([]);\n\tawait repo.commitCreate(message, author ? { author } : {});\n}\n\n/**\n * Replay baseline WIP into the temp worktree so the delta patch's HEAD+WIP\n * context matches, apply the delta, then rewind files WIP touched but the\n * delta didn't — HEAD-tracked files are restored via `git restore`, untracked\n * or staged-new WIP files are removed from the worktree. The commit that\n * follows reflects agent's delta plus any overlap with WIP; parent's\n * stash-pop reconciles the WIP side on merge-back.\n */\nasync function applyDeltaOverBaselineWip(\n\ttmpDir: string,","sourceCodeStart":662,"sourceCodeEnd":698,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/task/worktree.ts#L662-L698","documentation":"Final fallback in the patch-application ladder: after plain `git apply` and `git apply --3way` both fail, the code resets the worktree, seeds the parent's WIP as a baseline commit, and retries `git apply` against that baseline. If this baseline-WIP attempt also fails, it throws with the git stderr attached.","triggerScenarios":"Calling the task-merge path when even applying against a WIP-seeded baseline fails: deeply diverged content, malformed patch, paths that no longer exist, or repository state issues (index locks, detached HEAD problems).","commonSituations":"Tasks touching files heavily refactored in the parent while the task ran; patches larger than git's size limits; corrupted or oversized patch payloads.","solutions":["Inspect the embedded stderr; apply the task's diff manually with `git apply --reject` and resolve rejects","Re-run the isolated task against the current parent HEAD so its patch is generated from fresh context","Check git repository health (index.lock, fsck) and patch size limits (`git config http.postBuffer` irrelevant locally but core limits matter)"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const probe = await $`git apply --check patch.diff`.cwd(repoDir).quiet().nothrow();\nif (probe.exitCode !== 0) {\n\t// apply manually with --reject before attempting the automated ladder\n}","typeGuard":null,"tryCatchPattern":"try {\n\tawait mergeTaskPatch(taskId, patchText);\n} catch (err) {\n\tif ((err as Error).message.startsWith(\"git apply with baseline WIP failed\")) {\n\t\t// fall back to `git apply --reject` and human conflict resolution\n\t}\n\tthrow err;\n}","preventionTips":["Re-run long-lived tasks against a fresh parent HEAD before merging","Inspect patchHead/stderr diagnostics logged before the throw","Check for index.lock or repo-health issues before automated merges"],"tags":["git","patch-apply","merge-conflict"],"backgroundTag":"git-apply-baseline-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}