gitbutlerapp/gitbutler · error

push failed after attempts

Error message

push failed after {MAX_RETRIES} attempts

What it means

sync_metadata retries pushing GitMeta metadata after resolving non-fast-forward conflicts, up to MAX_RETRIES. If after MAX_RETRIES attempts the push still reports non-fast-forward failure, it gives up with 'push failed after {MAX_RETRIES} attempts', meaning the remote kept advancing (or conflicts could not be resolved) faster than local pushes landed.

Solutions

  1. Re-run the sync later — a transient contention burst usually resolves once other writers pause.
  2. Fetch the GitMeta ref and inspect what keeps advancing; identify competing writers or a broken resolve loop.
  3. Manually integrate the remote GitMeta state locally (fetch, rebase/merge the GitMeta branch) and push once.
  4. Check that all writers run a compatible agentlog version so conflict resolution converges instead of looping.
Defensive patterns

Strategy: retry

Validate before calling

// ensure the local GitMeta ref is up to date before syncing
git fetch <remote> <gitmeta_ref> && git log --oneline HEAD..<remote>/<gitmeta_ref> | head -n 5

Try / catch

match sync_metadata(...).context("syncing GitMeta") {
    Err(e) if e.to_string().contains("push failed after") => {
        // contention loop: pause, fetch and integrate remote state, then retry later
        std::thread::sleep(BACKOFF);
        gitmeta.fetch_and_rebase()?;
        sync_metadata(...)?;
    }
    other => other?,
}

Prevention

When it happens

Trigger: Calling sync_metadata (via run_from_dir) when repeated cycles of push_once + resolve_push_conflict all yield non_fast_forward failures for MAX_RETRIES consecutive attempts.

Common situations: A very active remote where other writers continuously push GitMeta updates; a persistent rebasing/resolution loop caused by conflicting writer versions; a stuck or failing resolve_push_conflict that never produces a pushable ref.

Understand the failure class

Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.

Related errors


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

Appendix: source

Thrown at crates/but-agentlog/src/gitmeta/write.rs:301

        Err(git_meta_lib::Error::GitCommand(message))
            if message.contains("couldn't find remote ref") => {}
        Err(err) => return Err(err).context("failed to pull GitMeta metadata"),
    }

    let mut attempts = 0;
    loop {
        attempts += 1;
        let output = gitmeta
            .push_once(None)
            .context("failed to push GitMeta metadata")?;
        if output.success {
            return Ok(());
        }
        if !output.non_fast_forward {
            bail!("push failed");
        }
        if attempts >= MAX_RETRIES {
            bail!("push failed after {MAX_RETRIES} attempts");
        }
        gitmeta
            .resolve_push_conflict(None)
            .context("failed to resolve GitMeta push conflict")?;
    }
}

fn stored_text(kind: RecordKind, text: Option<&str>) -> Option<String> {
    let text = text?;
    Some(match kind {
        RecordKind::ToolResult => redact_text(cap_tool_result_text(text).as_ref()),
        _ => redact_text(text),
    })
}

fn file_path_hashes_for_record(
    repo_root: &Path,
    tool_kind: Option<ToolKind>,

View on GitHub (pinned to 58e5313667)