gitbutlerapp/gitbutler · error

Unknown stack_id in assignment request for

Error message

Unknown stack_id {stack_id} in assignment request for '{}'

What it means

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.

Solutions

  1. Refresh workspace/stack state and re-submit with a currently existing stack_id
  2. Target the branch (HunkAssignmentTarget::Branch) instead if the stack was merged away
  3. Verify the stack_id against the current workspace before calling assign

Example fix

// before
let target = HunkAssignmentTarget::Stack { stack_id: stale_id };
// after
let target = if workspace.find_stack_by_id(stale_id).is_some() {
    HunkAssignmentTarget::Stack { stack_id: stale_id }
} else {
    HunkAssignmentTarget::Branch { branch_ref_bytes: current_ref }
};
Defensive patterns

Strategy: validation

Validate before calling

if let HunkAssignmentTarget::Stack { stack_id } = &req.target {
    if workspace.find_stack_by_id(*stack_id).and_then(|s| s.ref_name()).is_none() {
        eprintln!("Stack {stack_id} no longer exists; refresh workspace state");
        continue;
    }
}

Type guard

fn stack_resolvable(ws: &Workspace, id: StackId) -> bool {
    ws.find_stack_by_id(id).and_then(|s| s.ref_name()).is_some()
}

Prevention

When it happens

Trigger: 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.

Common situations: UI/SDK holding workspace state from before a stack was applied or unapplied; concurrent modification of the workspace; ids from a different project/session.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/e9a222d643fb18f2. Report an issue: GitHub.

Appendix: source

Thrown at crates/but-hunk-assignment/src/lib.rs:631

            target,
        } = req;
        let branch_ref_bytes = match target {
            None => None,
            Some(HunkAssignmentTarget::Branch { branch_ref_bytes }) => Some(
                gix::refs::FullName::try_from(branch_ref_bytes).map_err(|err| {
                    anyhow::anyhow!(
                        "Invalid branch_ref_bytes in assignment request for '{}': {err}",
                        path_bytes.to_str_lossy()
                    )
                })?,
            ),
            Some(HunkAssignmentTarget::Stack { stack_id }) => Some(
                workspace
                    .find_stack_by_id(stack_id)
                    .and_then(|stack| stack.ref_name())
                    .map(|ref_name| ref_name.to_owned())
                    .ok_or_else(|| {
                        anyhow::anyhow!(
                            "Unknown stack_id {stack_id} in assignment request for '{}'",
                            path_bytes.to_str_lossy()
                        )
                    })?,
            ),
        };
        let assignment = HunkAssignment {
            id: None,
            hunk_header,
            path: path_bytes.to_str_lossy().into(),
            path_bytes,
            stack_id: None,
            branch_ref_bytes,
            line_nums_added: None,
            line_nums_removed: None,
            diff: None,
        };
        assignments.push(assignment);

View on GitHub (pinned to 58e5313667)