gitbutlerapp/gitbutler · error
Failed to assure that
Error message
Failed to assure that {rn} is in the workspace as dependent branch after removing it What it means
After removing a conflicting segment, apply re-inserts the branch as a dependent branch above an anchor and requires `insert_new_segment_above_anchor_if_not_present` to return `Some(true)`. Any other result means the branch could not be established as a dependent branch, so apply fails to leave the workspace in a defined state.
Solutions
- Rebuild workspace metadata from the repository state and retry the apply
- Retry the apply operation once metadata is consistent (no concurrent writers)
- If reproducible, file a bug — this indicates the insert helper failed unexpectedly after a successful remove
Defensive patterns
Strategy: try-catch
Try / catch
match apply(...) {
Err(e) if e.to_string().contains("as dependent branch after removing") => { rebuild_workspace(); retry(); }
Err(e) => return Err(e.into()),
Ok(r) => r,
} Prevention
- Avoid concurrent operations on the same workspace
- Refresh workspace state before applying into adhoc workspaces
- Report reproducible failures as upstream bugs
When it happens
Trigger: Apply flow on an adhoc workspace where, after `remove_segment`, the anchor for re-insertion is not found or the insert reports the branch still not added — a race between the removal and insertion or missing anchor in metadata.
Common situations: Same class as error 352: stale/incorrect workspace metadata during adhoc workspace apply, or a bug in the segment bookkeeping.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- Missing reference which should be known to workspace…
- Unexpectedly failed to find anchor for
- Ad-hoc (single-branch) branch moves are not supported…
- Branch ' ' cannot be created: the target commit ( ) already…
- BranchNotFound
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/9a9977f4d527e81f.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but-workspace/src/branch/apply.rs:694
match ws_mut.insert_new_segment_above_anchor_if_not_present(
rn.as_ref(),
segment_to_insert_above,
) {
None => {
// For now bail, until we know it's worth fixing this case automatically.
bail!(
"Missing reference {segment_to_insert_above} which should be known to workspace metadata to serve as insertion position for {rn}"
);
}
Some(false) => {
// The branch already existed, probably as stack, but it didn't come through. Remove it and use the anchor.
ws_mut.remove_segment(rn.as_ref());
if ws_mut.insert_new_segment_above_anchor_if_not_present(
rn.as_ref(),
segment_to_insert_above,
) != Some(true)
{
bail!(
"Failed to assure that {rn} is in the workspace as dependent branch after removing it"
);
}
}
Some(true) => {}
}
} else {
bail!("Unexpectedly failed to find anchor for {rn} to make it a dependent branch")
}
}
// Redo the merge, with the different stack configuration.
// Note that this is the exception, typically using stacks will be fine.
let existing_stacks_superseded_by_branch =
find_superseded_stacks(branch.as_ref(), &ws, &mut ws_md);
merge_result = WorkspaceCommit::from_new_merge_with_metadata(
filter_superseded_metadata_stacks(
ws_md.stacks.iter(),View on GitHub (pinned to 58e5313667)