gitbutlerapp/gitbutler · error
Failed to disable merge request auto-merge
Error message
Failed to disable merge request auto-merge: {status} - {error_text} What it means
This is the disable branch of set_merge_request_auto_merge: it POSTs to the auto-merge cancel/delete endpoint and bails on any non-2xx response, including status and GitLab's error body. Most commonly this fires when no auto-merge is actually set on the MR (GitLab returns 404) or the MR is already merged.
Solutions
- Treat 404 as a benign case: the auto-merge is already gone (merged or cancelled) — ignore instead of failing.
- Check the MR state (`state == "merged"`) before attempting to disable and skip the call if already merged.
- For 401/403 verify token scopes and project permissions as with other MR endpoints.
- Retry 429/5xx responses with backoff; they are transient.
Example fix
// before
client.set_merge_request_auto_merge_disable(project_id, iid).await?;
// after
if let Err(e) = client.set_merge_request_auto_merge_disable(project_id, iid).await {
let msg = e.to_string();
if !msg.contains("404") {
return Err(e); // 404 = auto-merge already gone, safe to ignore
}
} Defensive patterns
Strategy: fallback
Validate before calling
let mr = client.get_merge_request(project_id, mr_iid).await?;
if mr.state != "opened" {
// nothing to disable on merged/closed MRs
return Ok(());
} Try / catch
if let Err(e) = client.disable_auto_merge(project_id, iid).await {
let msg = e.to_string();
if msg.contains("404") || msg.contains("405") {
// no active auto-merge: treat as success
} else {
return Err(e);
}
} Prevention
- Treat 404 from the cancel endpoint as 'already gone', not a failure
- Skip disabling when MR state is merged or closed
- Keep a local flag of whether you enabled auto-merge to avoid redundant cancels
- Retry 429/5xx with backoff
When it happens
Trigger: Calling the disable path when the MR has no pending auto-merge record (404 from GitLab), when the MR was already merged or closed, with an unauthorized token (401/403), or against a GitLab version lacking the endpoint.
Common situations: Race where auto-merge completed (MR merged) between enabling and disabling, so the cancel endpoint 404s; cleanup code running after a successful merge; switching auto-merge strategies by disable-then-enable where the disable hits a 404.
Understand the failure class
Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.
Related errors
- Failed to enable merge request auto-merge
- Failed to merge merge request
- Failed to set merge request draft state
- Failed to create merge request
- Failed to fetch project
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/6130f2f1b1cdfe36.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but-gitlab/src/client.rs:582
let status = response.status();
let error_text = response.text().await.unwrap_or_default();
bail!("Failed to enable merge request auto-merge: {status} - {error_text}");
}
return Ok(());
}
let url = format!(
"{}/projects/{}/merge_requests/{}/cancel_merge_when_pipeline_succeeds",
self.base_url, project_id, params.mr_iid
);
let response = self.client.post(&url).send().await?;
if !response.status().is_success() {
let status = response.status();
let error_text = response.text().await.unwrap_or_default();
bail!("Failed to disable merge request auto-merge: {status} - {error_text}");
}
Ok(())
}
pub async fn fetch_project(&self, project_id: GitLabProjectId) -> Result<GitLabProject> {
self.fetch_project_by_path(project_id.to_string()).await
}
pub async fn fetch_project_by_numeric_id(&self, project_id: i64) -> Result<GitLabProject> {
self.fetch_project_by_path(project_id.to_string()).await
}
async fn fetch_project_by_path(&self, project_id: String) -> Result<GitLabProject> {
#[derive(Deserialize)]
struct GitLabApiProject {
id: i64,
path_with_namespace: String,View on GitHub (pinned to 58e5313667)