{"record":{"id":"03304469b0212602","repo":"gitbutlerapp/gitbutler","slug":"could-not-find-associated-reference-name","errorCode":null,"errorMessage":"Could not find associated reference name","messagePattern":"Could not find associated reference name","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-action/src/simple.rs","lineNumber":113,"sourceCode":"    } else {\n        change_summary.to_string()\n    };\n\n    for (stack_id, diff_specs) in stack_assignments {\n        if diff_specs.is_empty() {\n            continue;\n        }\n        if let Some(exclusive_stack) = exclusive_stack\n            && exclusive_stack != stack_id\n        {\n            continue; // Skip stacks that are not the exclusive stack.\n        }\n\n        let stack_branch_name = stacks\n            .iter()\n            .find(|s| s.id == stack_id)\n            .map(|s| s.branch_name.clone())\n            .ok_or(anyhow!(\"Could not find associated reference name\"))?;\n        let full_ref_name: gix::refs::FullName =\n            format!(\"refs/heads/{stack_branch_name}\").try_into()?;\n\n        let editor = Editor::create(ws, meta, repo, db)?;\n        let outcome = but_workspace::commit::commit_create(\n            editor,\n            diff_specs,\n            RelativeToRef::Reference(full_ref_name.as_ref()),\n            InsertSide::Below,\n            &commit_message,\n            context_lines,\n            but_workspace::commit::ChangeSource::Head,\n        )?;\n\n        if !outcome.rejected_specs.is_empty() {\n            tracing::warn!(\n                ?outcome.rejected_specs,\n                \"Failed to commit at least one hunk\"","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/2497b8007aa4a1922dae9a805b32ffe5b5037785/crates/but-action/src/simple.rs#L95-L131","documentation":"handle_changes buckets hunk assignments by stack ID (stack_assignments.entry(stack_id).or_default()), then resolves each bucket back to a stack to get its branch name for refs/heads/<name>. This error fires when a bucket's stack_id has no entry in the stacks list collected at the start — a hunk assignment in the database references a stack that no longer exists in the workspace.","triggerScenarios":"handle_changes with stale hunk_assignment rows whose stack_id points at a deleted or unapplied stack: stacks come only from stacks_creating_if_none (current applied stacks), while assignments come from the DB, so any drift between them trips the lookup.","commonSituations":"Deleting a stack while hunks were still assigned to it; crashes between stack deletion and assignment cleanup; restored or migrated assignment data referencing old stack IDs.","solutions":["Reassign the pending changes to an existing stack in the GitButler UI, then retry.","Clear the stale hunk assignments for the missing stack in the assignment store, or discard the affected hunks.","If it recurs right after deleting a stack, report it — deletion should have cleaned up those assignment rows."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"use std::collections::HashSet;\n\nlet live_ids: HashSet<StackId> = stacks.iter().map(|s| s.id).collect();\nfor a in &assignments {\n    if let Some(id) = a.stack_id {\n        anyhow::ensure!(live_ids.contains(&id), \"assignment targets missing stack {id}\");\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["After deleting a stack, always unassign or reassign its hunks.","Prune assignment rows whose stack IDs no longer resolve.","Surface assignment-to-stack mismatches before running commit-creating actions."],"tags":["hunk-assignments","stacks","stale-state","agent-action"],"backgroundTag":"stale-hunk-assignment","analyzedSha":"2497b8007aa4a1922dae9a805b32ffe5b5037785","analyzedAt":"2026-08-17T00:30:25.648Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}