{"record":{"id":"15a6c77d8e7654a6","repo":"gitbutlerapp/gitbutler","slug":"failed-to-find-corresponding-segment-for-ref-name","errorCode":null,"errorMessage":"Failed to find corresponding segment for {ref_name}","messagePattern":"Failed to find corresponding segment for (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-rebase/src/graph_rebase/creation.rs","lineNumber":80,"sourceCode":"\n        // TODO(CTO): Look into traversing \"in workspace\" segments that are not\n        // reachable from the entrypoint TODO(CTO): Look into stopping at the\n        // common base\n        let worktree_tips = workspace.graph.worktree_tips.clone();\n        let entrypoint = workspace.graph.entrypoint()?;\n\n        let mut mutable_entrypoints = vec![entrypoint.segment.id];\n\n        for ref_name in options\n            .extra_mutable_refs\n            .iter()\n            .chain(worktree_tips.iter().filter_map(|tip| tip.ref_name.as_ref()))\n        {\n            let Some((segment, _)) = workspace\n                .graph\n                .segment_and_commit_by_ref_name(ref_name.as_ref())\n            else {\n                bail!(\"Failed to find corresponding segment for {ref_name}\");\n            };\n            mutable_entrypoints.push(segment.id);\n        }\n\n        // Segments reachable from a mutable entrypoint (following parent edges)\n        // may be rewritten. Every other segment is still included in the\n        // editor, but as immutable.\n        let mut mutable_segments = HashSet::new();\n        for entrypoint in mutable_entrypoints {\n            workspace.graph.visit_all_segments_including_start_until(\n                entrypoint,\n                Direction::Outgoing,\n                |segment| !mutable_segments.insert(segment.id),\n            );\n        }\n\n        // The editor contains every commit the graph contains, so we iterate\n        // over all segments rather than only those reachable from an entrypoint.","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-rebase/src/graph_rebase/creation.rs#L62-L98","documentation":"When building a graph rebase editor, every ref used as a mutable entrypoint (workspace/stack refs and worktree tips) must map to a segment in the workspace commit graph. If `segment_and_commit_by_ref_name` returns None for a ref, the graph is inconsistent with the refs and creation aborts.","triggerScenarios":"Calling `create_with_opts` when one of the supplied worktree tip ref_names (or workspace refs) is not present in `workspace.graph` — e.g. the ref was deleted, points outside the computed graph, or the workspace snapshot is stale.","commonSituations":"Workspace computed before a branch was deleted or force-pushed; passing ref names from a different repo; graph built with a filter that excludes the ref's commits; racing concurrent git operations.","solutions":["Refresh the workspace/commit graph snapshot and retry create_with_opts","Filter out tips whose ref_name is absent from the graph before calling","Verify each ref still resolves (`git rev-parse <ref>`) and belongs to the workspace graph"],"exampleFix":"// before\nlet tips: Vec<_> = worktree_tips.iter().filter_map(|t| t.ref_name.clone()).collect();\ncreate_with_opts(workspace, &tips, ...)?;\n// after\nlet tips: Vec<_> = worktree_tips.iter()\n    .filter_map(|t| t.ref_name.clone())\n    .filter(|r| workspace.graph.segment_and_commit_by_ref_name(r.as_bstr()).is_some())\n    .collect();","handlingStrategy":"validation","validationCode":"for r in &ref_names {\n    anyhow::ensure!(\n        workspace.graph.segment_and_commit_by_ref_name(r.as_bstr()).is_some(),\n        \"ref {} missing from workspace graph\", r\n    );\n}","typeGuard":null,"tryCatchPattern":"match create_with_opts(&workspace, &tips, opts) {\n    Ok(ed) => ed,\n    Err(e) if e.to_string().contains(\"corresponding segment\") => {\n        let ws = but_workspace::refresh(&repo)?;\n        create_with_opts(&ws, &tips, opts)?\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Recompute the workspace snapshot right before creating the editor","Skip tips whose refs no longer resolve","Avoid holding stale workspace graphs across git mutations"],"tags":["git","graph","workspace"],"backgroundTag":"record-not-found","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"}