gitbutlerapp/gitbutler · error
Failed to add to GitHub stack
Error message
Failed to add to GitHub stack: {} What it means
The REST request to add pull requests to an existing GitHub stack returned a non-success status; GitHub's response body is included via `response_error`. This is the append-members operation on an existing stack.
Solutions
- Read the embedded status/body for the specific cause.
- If 404, re-list stacks (existing_stacks) to get a fresh stack number — the old one is gone.
- If 401/403, repair token scopes and repo access.
- If 422, verify all pull_request numbers belong to the same repo and are open.
- On 5xx or 409, retry with exponential backoff.
Defensive patterns
Strategy: try-catch
Validate before calling
// refresh stack numbers before appending so the target still exists
let stacks = stacks_client.existing_stacks(owner, repo, pr).await?;
anyhow::ensure!(stacks.iter().any(|s| s.number == stack_number), "stack {stack_number} no longer exists"); Try / catch
match stacks.add_to_stack(owner, repo, stack_number, prs).await {
Ok(()) => (),
Err(e) if e.to_string().contains("404") => re_list_and_reconcile(), // stale stack number
Err(e) if e.to_string().contains("409") || e.to_string().contains("5") => retry_with_backoff(),
Err(e) => return Err(e),
} Prevention
- Re-list stacks before appending instead of caching stack numbers.
- Keep all PR numbers within the same repository.
- Handle concurrent unstack operations from other sessions.
- Back off on 5xx and conflicts.
When it happens
Trigger: Calling add_to_stack when POSTing members to `{base_url}/repos/{owner}/{repo}/stacks/{stack_number}` fails — nonexistent stack_number (404), insufficient permissions (403/401), invalid PR ids in the body (422), or 5xx.
Common situations: Using a stale stack number after the stack was unstacked/deleted elsewhere; PRs from a different repo; expired token; concurrent edits causing 409.
Related errors
- Failed to create GitHub stack
- Failed to unstack GitHub stack
- Failed to add labels
- Failed to get PR base repo
- Failed to get repo
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/0258bf598ea61551.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but-github/src/stacks.rs:335
async fn add_to_stack(
&self,
owner: &str,
repo: &str,
stack_number: i64,
pull_requests: &[i64],
) -> Result<()> {
let response = self
.client
.post(format!(
"{}/repos/{owner}/{repo}/stacks/{stack_number}/add",
self.base_url
))
.json(&StackMembersBody { pull_requests })
.send()
.await?;
if !response.status().is_success() {
bail!(
"Failed to add to GitHub stack: {}",
response_error(response).await
);
}
Ok(())
}
async fn unstack(&self, owner: &str, repo: &str, stack_number: i64) -> Result<()> {
let response = self
.client
.post(format!(
"{}/repos/{owner}/{repo}/stacks/{stack_number}/unstack",
self.base_url
))
.send()
.await?;
if !response.status().is_success() {
bail!(View on GitHub (pinned to 58e5313667)