{"record":{"id":"1d8dc0737625d3bf","repo":"gitbutlerapp/gitbutler","slug":"unexpectedly-failed-to-find-anchor-for-rn-to-mak","errorCode":null,"errorMessage":"Unexpectedly failed to find anchor for {rn} to make it a dependent branch","messagePattern":"Unexpectedly failed to find anchor for (.+?) to make it a dependent branch","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-workspace/src/branch/apply.rs","lineNumber":702,"sourceCode":"                        );\n                    }\n                    Some(false) => {\n                        // The branch already existed, probably as stack, but it didn't come through. Remove it and use the anchor.\n                        ws_mut.remove_segment(rn.as_ref());\n                        if ws_mut.insert_new_segment_above_anchor_if_not_present(\n                            rn.as_ref(),\n                            segment_to_insert_above,\n                        ) != Some(true)\n                        {\n                            bail!(\n                                \"Failed to assure that {rn} is in the workspace as dependent branch after removing it\"\n                            );\n                        }\n                    }\n                    Some(true) => {}\n                }\n            } else {\n                bail!(\"Unexpectedly failed to find anchor for {rn} to make it a dependent branch\")\n            }\n        }\n\n        // Redo the merge, with the different stack configuration.\n        // Note that this is the exception, typically using stacks will be fine.\n        let existing_stacks_superseded_by_branch =\n            find_superseded_stacks(branch.as_ref(), &ws, &mut ws_md);\n        merge_result = WorkspaceCommit::from_new_merge_with_metadata(\n            filter_superseded_metadata_stacks(\n                ws_md.stacks.iter(),\n                &existing_stacks_superseded_by_branch,\n            ),\n            filter_superseded_anon_stacks(\n                anon_stacks(&ws.stacks),\n                &existing_stacks_superseded_by_branch,\n            ),\n            &ws.graph,\n            &in_memory_repo,","sourceCodeStart":684,"sourceCodeEnd":720,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-workspace/src/branch/apply.rs#L684-L720","documentation":"In the apply flow's `else` branch, the anchor reference needed to turn an incoming remote branch into a dependent branch could not be found in the workspace graph, which the code considers impossible ('Unexpectedly'). The apply aborts rather than misplacing the branch.","triggerScenarios":"Applying a branch into an adhoc workspace when the computed anchor reference for the dependent-branch insertion is absent from the workspace graph/metadata.","commonSituations":"Workspace graph computed from an older state than the metadata; anchor branch was deleted concurrently; bug in adhoc-workspace handling.","solutions":["Ensure the anchor branch referenced by the workspace still exists; restore it if deleted","Recompute/refresh the workspace and metadata, then retry apply","File a bug with reproduction if the state appears consistent"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// confirm the anchor branch for the incoming remote branch is applied\nif !workspace_has_ref(&ws, &anchor_ref) {\n    return Err(\"anchor branch not applied; apply it first\");\n}","typeGuard":null,"tryCatchPattern":"match apply(...) {\n    Err(e) if e.to_string().contains(\"failed to find anchor\") => { refresh_workspace_and_retry(); }\n    Err(e) => return Err(e.into()),\n    Ok(r) => r,\n}","preventionTips":["Ensure anchor branches referenced by adhoc workspaces still exist","Recompute workspace state after any manual branch deletion","File a bug with a reproduction if the state looks consistent"],"tags":["git","workspace","invariant"],"backgroundTag":"internal-invariant-violation","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}