gitbutlerapp/gitbutler · error

Failed to create a runtime for the settled-review sweep

Error message

Failed to create a runtime for the settled-review sweep: {e}

What it means

In list_recently_settled_reviews (crates/but-forge/src/review.rs), the GitHub branch spawns a thread and creates a fresh tokio Runtime inside it. If Runtime::new() fails, this error is returned. Runtime::new() typically fails only when the OS cannot allocate the resources the runtime needs (threads/io driver).

Solutions

  1. Free system resources / raise thread and memory limits on the host
  2. Use Handle::current() or a shared static runtime instead of building a new Runtime per call
  3. Retry the sync after transient resource pressure subsides
  4. Log the underlying std::io::Error to confirm which resource failed

Example fix

// before
tokio::runtime::Runtime::new().map_err(|e| anyhow::anyhow!("Failed to create a runtime for the settled-review sweep: {e}"))?
// after
// run on an existing runtime via tokio::runtime::Handle::current().block_on(...) so Runtime::new() is never called
Defensive patterns

Strategy: retry

Try / catch

match list_recently_settled_reviews(...) {
    Ok(reviews) => reviews,
    Err(e) if e.to_string().contains("Failed to create a runtime") => {
        std::thread::sleep(Duration::from_secs(2));
        retry_with_backoff(|| list_recently_settled_reviews(...), 3)
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: tokio::runtime::Runtime::new() returns Err inside the spawned thread while sweeping recently closed GitHub PRs — e.g. OS out of memory, thread-creation limits, or inability to initialize the IO driver.

Common situations: Container/resource-limited environments hitting thread or memory caps; heavily loaded CI machines; RLIMIT settings blocking thread creation.

Related errors


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

Appendix: source

Thrown at crates/but-forge/src/review.rs:671

    forge_repo_info: &crate::forge::ForgeRepoInfo,
    storage: &but_forge_storage::Controller,
) -> Result<Vec<ForgeReview>> {
    let crate::forge::ForgeRepoInfo {
        forge, owner, repo, ..
    } = forge_repo_info;
    let reviews = match forge {
        ForgeName::GitHub => {
            let preferred_account = preferred_forge_user
                .as_ref()
                .and_then(|user| user.github().cloned());
            let owner = owner.clone();
            let repo = repo.clone();
            let storage = storage.clone();

            let pulls = std::thread::spawn(move || {
                tokio::runtime::Runtime::new()
                    .map_err(|e| {
                        anyhow::anyhow!(
                            "Failed to create a runtime for the settled-review sweep: {e}"
                        )
                    })?
                    .block_on(but_github::pr::list_recently_closed(
                        preferred_account.as_ref(),
                        &owner,
                        &repo,
                        &storage,
                    ))
            })
            .join()
            .map_err(|e| anyhow::anyhow!("Failed to join thread: {e:?}"))??;

            pulls.into_iter().map(ForgeReview::from).collect()
        }
        ForgeName::GitLab => {
            let preferred_account = preferred_forge_user
                .as_ref()

View on GitHub (pinned to 58e5313667)