{"record":{"id":"e9a222d643fb18f2","repo":"gitbutlerapp/gitbutler","slug":"unknown-stack-id-stack-id-in-assignment-request-for","errorCode":null,"errorMessage":"Unknown stack_id {stack_id} in assignment request for '{}'","messagePattern":"Unknown stack_id (.+?) in assignment request for '(.+?)'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-hunk-assignment/src/lib.rs","lineNumber":631,"sourceCode":"            target,\n        } = req;\n        let branch_ref_bytes = match target {\n            None => None,\n            Some(HunkAssignmentTarget::Branch { branch_ref_bytes }) => Some(\n                gix::refs::FullName::try_from(branch_ref_bytes).map_err(|err| {\n                    anyhow::anyhow!(\n                        \"Invalid branch_ref_bytes in assignment request for '{}': {err}\",\n                        path_bytes.to_str_lossy()\n                    )\n                })?,\n            ),\n            Some(HunkAssignmentTarget::Stack { stack_id }) => Some(\n                workspace\n                    .find_stack_by_id(stack_id)\n                    .and_then(|stack| stack.ref_name())\n                    .map(|ref_name| ref_name.to_owned())\n                    .ok_or_else(|| {\n                        anyhow::anyhow!(\n                            \"Unknown stack_id {stack_id} in assignment request for '{}'\",\n                            path_bytes.to_str_lossy()\n                        )\n                    })?,\n            ),\n        };\n        let assignment = HunkAssignment {\n            id: None,\n            hunk_header,\n            path: path_bytes.to_str_lossy().into(),\n            path_bytes,\n            stack_id: None,\n            branch_ref_bytes,\n            line_nums_added: None,\n            line_nums_removed: None,\n            diff: None,\n        };\n        assignments.push(assignment);","sourceCodeStart":613,"sourceCodeEnd":649,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-hunk-assignment/src/lib.rs#L613-L649","documentation":"When a request targets a Stack, requests_to_assignments resolves it via workspace.find_stack_id(stack_id) and derives its ref_name; if the stack does not exist in the workspace (or has no ref), the request is rejected with this error naming the file and stack id.","triggerScenarios":"Calling assign with HunkAssignmentTarget::Stack { stack_id } where find_stack_by_id returns None or the stack has no ref_name — the stack was deleted/merged, or the id came from stale workspace state.","commonSituations":"UI/SDK holding workspace state from before a stack was applied or unapplied; concurrent modification of the workspace; ids from a different project/session.","solutions":["Refresh workspace/stack state and re-submit with a currently existing stack_id","Target the branch (HunkAssignmentTarget::Branch) instead if the stack was merged away","Verify the stack_id against the current workspace before calling assign"],"exampleFix":"// before\nlet target = HunkAssignmentTarget::Stack { stack_id: stale_id };\n// after\nlet target = if workspace.find_stack_by_id(stale_id).is_some() {\n    HunkAssignmentTarget::Stack { stack_id: stale_id }\n} else {\n    HunkAssignmentTarget::Branch { branch_ref_bytes: current_ref }\n};","handlingStrategy":"validation","validationCode":"if let HunkAssignmentTarget::Stack { stack_id } = &req.target {\n    if workspace.find_stack_by_id(*stack_id).and_then(|s| s.ref_name()).is_none() {\n        eprintln!(\"Stack {stack_id} no longer exists; refresh workspace state\");\n        continue;\n    }\n}","typeGuard":"fn stack_resolvable(ws: &Workspace, id: StackId) -> bool {\n    ws.find_stack_by_id(id).and_then(|s| s.ref_name()).is_some()\n}","tryCatchPattern":null,"preventionTips":["Refresh workspace state before submitting assignment requests","Drop stack targets for stacks that were merged or unapplied","Prefer branch targets when stack lifetime is uncertain"],"tags":["workspace","stack","validation"],"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"}