nikivdev/code · error

jj workspace corrupted

Error message

jj workspace corrupted

What it means

This error is raised when the tool detects that the jj (Juujutsu VCS) workspace is in a state that prevents it from creating a review bookmark. It is thrown after a jj command fails with messages indicating a failed checkout or inconsistent workspace (e.g. after `jj workspace`/checkout operations fail). The library bails out early and prints remediation hints instead of continuing with a broken workspace.

Source

Thrown at src/commit.rs:8421

        index += 1;
        if index > 50 {
            bail!("too many review bookmarks with base {}", base);
        }
    }

    if let Err(err) = jj_run_in(&jj_root, &["bookmark", "create", &name, "-r", commit_sha]) {
        let msg = err.to_string().to_lowercase();
        if msg.contains("commit not found")
            || msg.contains("current working-copy commit not found")
            || msg.contains("failed to load short-prefixes index")
            || msg.contains("unexpected error from store")
            || msg.contains("failed to check out a commit")
        {
            println!("⚠️  jj workspace appears corrupted; skipping review bookmark creation.");
            println!(
                "   Fix: `jj git import` (or if still broken: `rm -rf .jj && jj git init --colocate`)"
            );
            bail!("jj workspace corrupted");
        }
        return Err(err);
    }
    println!("Queued review bookmark {}", name);
    Ok(name)
}

fn delete_review_bookmark(repo_root: &Path, bookmark: &str) {
    if let Some(jj_root) = vcs::jj_root_if_exists(repo_root) {
        let _ = jj_run_in(&jj_root, &["bookmark", "delete", bookmark]);
    }
}

fn jj_bookmark_exists(repo_root: &Path, name: &str) -> bool {
    let output = jj_capture_in(repo_root, &["bookmark", "list"]).unwrap_or_default();
    for line in output.lines() {
        let trimmed = line.trim_start().trim_start_matches('*').trim();
        let Some((token, _rest)) = trimmed.split_once(' ') else {

View on GitHub (pinned to a747e741ae)

Solutions

  1. Run `jj git import` to re-sync jj with the underlying git refs
  2. If import does not fix it, reinitialize the colocated workspace: `rm -rf .jj && jj git init --colocate`
  3. Verify jj version compatibility with the repo format and re-run the command
  4. Restore the workspace from a clean clone if corruption persists

Example fix

// before (broken workspace)
$ tool create-review
⚠️  jj workspace appears corrupted; skipping review bookmark creation.
Error: jj workspace corrupted
// after
$ jj git import
$ tool create-review
Queued review bookmark review/pr-123
Defensive patterns

Strategy: try-catch

Validate before calling

// Run before invoking the review flow
let out = Command::new("jj").args(["st"]).output()?;
if !out.status.success() {
    eprintln!("jj workspace unhealthy; run `jj git import` first");
    return Ok(()); // skip review flow
}

Try / catch

match result {
    Err(e) if e.to_string().contains("jj workspace corrupted") => {
        // user ran `rm -rf .jj && jj git init --colocate`? recover and retry once
        run("jj git import")?;
        retry_operation()
    }
    Err(e) => return Err(e),
    Ok(v) => Ok(v),
}

Prevention

When it happens

Trigger: Running the review-bookmark creation flow when a preceding jj command's stderr/stdout contains 'failed to check out a commit' (or a similar corruption-indicating message), so the function prints the corruption warning and calls bail!("jj workspace corrupted").

Common situations: A `.jj` directory that was created by a different jj version or partially initialized; a workspace where `jj git init` was never run with --colocate in a git repo; interrupted jj operations leaving stale lockfiles/checkouts; importing a git repo whose refs jj cannot map.

Related errors


AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01). Data as JSON: /api/errors/b1e38fd25133adef. Report an issue: GitHub.