{"record":{"id":"f679da13d5c58171","repo":"gitbutlerapp/gitbutler","slug":"failed-to-find-commit-target-in-rebase-editor","errorCode":null,"errorMessage":"Failed to find commit {target} in rebase editor","messagePattern":"Failed to find commit (.+?) in rebase editor","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-rebase/src/graph_rebase/mutate.rs","lineNumber":241,"sourceCode":"impl ToSelector for &gix::refs::FullNameRef {\n    fn to_selector(&self, editor: &Editor<impl RefMetadata>) -> Result<Selector> {\n        editor.select_reference(self)\n    }\n}\n\nimpl ToSelector for gix::refs::FullName {\n    fn to_selector(&self, editor: &Editor<impl RefMetadata>) -> Result<Selector> {\n        editor.select_reference(self.as_ref())\n    }\n}\n\n/// Operations for mutating the commit graph\nimpl<M: RefMetadata> Editor<'_, '_, M> {\n    /// Get a selector to a particular commit in the graph\n    pub fn select_commit(&self, target: gix::ObjectId) -> Result<Selector> {\n        match self.try_select_commit(target) {\n            Some(selector) => Ok(selector),\n            None => Err(anyhow!(\"Failed to find commit {target} in rebase editor\")),\n        }\n    }\n\n    /// Get a selector to a particular reference in the graph\n    pub fn select_reference(&self, target: &gix::refs::FullNameRef) -> Result<Selector> {\n        match self.try_select_reference(target) {\n            Some(selector) => Ok(selector),\n            None => Err(anyhow!(\n                \"Failed to find reference {target} in rebase editor\"\n            )),\n        }\n    }\n\n    /// Get a selector to a particular commit in the graph\n    pub fn try_select_commit(&self, target: gix::ObjectId) -> Option<Selector> {\n        for node_idx in self.graph.node_indices() {\n            if let Step::Pick(Pick { id, .. }) = self.graph[node_idx]\n                && id == target","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/caf1f223d3cfb94488c9198ad34487c6006c648f/crates/but-rebase/src/graph_rebase/mutate.rs#L223-L259","documentation":"`Editor::select_commit` scans the loaded commit graph for a `Pick` step whose commit id equals `target` and returns this error when no step matches. The editor only knows commits that are part of the current rebase graph snapshot; anything else — dropped commits, rewritten/amended ids, commits in other worktrees — is 'not found'. Use `try_select_commit` for an Option-based probe.","triggerScenarios":"Calling `select_commit` with an OID captured before an amend/rebase rewrote it; a commit pruned from the workspace; a commit from a different repository or worktree; a bare OID never added as a Pick step in this editor's graph.","commonSituations":"Stale object ids held across a workspace refresh in GitButler flows; concurrent modification between reading the graph and selecting; tests using hardcoded OIDs against regenerated fixtures.","solutions":["Refresh/rebuild the editor (and its graph) right before selecting, and use ids read from that same snapshot","Switch to `try_select_commit(target)` and handle None explicitly when absence is expected","Verify the id exists and participates in the graph first (e.g. `repo.has_object` plus a graph lookup) if you need a better error message","If the id came from serialized state (oplog, UI), re-resolve it through a ref or workspace query instead of trusting the raw OID"],"exampleFix":"// before\nlet sel = editor.select_commit(oid)?; // Err: Failed to find commit ... in rebase editor\n\n// after\nuse anyhow::Context;\nlet sel = editor\n    .try_select_commit(oid)\n    .with_context(|| format!(\"commit {oid} not in editor graph; refresh workspace and retry with the current id\"))?;","handlingStrategy":"validation","validationCode":"// Probe without erroring — try_select_commit is the built-in guard:\nlet Some(sel) = editor.try_select_commit(oid) else {\n    anyhow::bail!(\"commit {oid} not present in editor graph; refresh and retry\");\n};","typeGuard":null,"tryCatchPattern":"match editor.select_commit(oid) {\n    Ok(sel) => sel,\n    Err(e) if e.to_string().contains(\"Failed to find commit\") => {\n        let editor = rebuild_editor()?; // refresh graph snapshot\n        editor.select_commit(oid)?\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Read oids and select them against the same editor snapshot; never carry oids across a mutation","Prefer try_select_commit wherever absence is a normal case","Re-derive long-lived oids from refs/workspace queries instead of caching them"],"tags":["rust","git","graph-rebase","commit-not-found","stale-state"],"backgroundTag":"commit-not-found","analyzedSha":"caf1f223d3cfb94488c9198ad34487c6006c648f","analyzedAt":"2026-08-20T07:55:40.983Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}