Skip to content

fix: "Refusing to move bookmark backwards or sideways" during sandbox creation - #197

Open
MingweiSamuel wants to merge 1 commit into
mainfrom
sandbox-5fb2d203-4ab4-4db2-8d30-6d1bc5e99e47
Open

MingweiSamuel wants to merge 1 commit into
mainfrom
sandbox-5fb2d203-4ab4-4db2-8d30-6d1bc5e99e47

Conversation

@MingweiSamuel

Copy link
Copy Markdown
Member

jj_git_clone (sandbox-core/src/jj.rs) first tries jj edit <bookmark> and,
on failure, falls back to jj new <base> + jj bookmark set <bookmark>. The
fallback assumed the bookmark didn't exist, but jj edit can also fail when
the bookmark does exist and simply isn't editable — e.g. it is conflicted or
points at an immutable commit. In that case jj bookmark set has to move the
existing bookmark sideways/backwards onto the fresh change, which jj refuses
without --allow-backwards, producing:

jj failed: Error: Refusing to move bookmark backwards or sideways: sandbox-...
Hint: Use --allow-backwards to allow it.

This was the only jj bookmark set call in the codebase still missing -B
(the push path in jj_push_working_copy already had it from an earlier fix).

Changes:

  • Add -B to the fallback jj bookmark set in jj_git_clone, with a comment
    explaining why, and clarify the log message.
  • Add a regression unit test jj::tests::clone_repoints_existing_uneditable_bookmark
    that creates a conflicted sandbox-x bookmark (two concurrent --at-op
    bookmark sets to sibling commits), calls jj_git_clone, and asserts the
    bookmark is re-pointed to the new working copy on top of the base revision.
    Verified the test reproduces the exact error without the -B and passes
    with it. The test isolates jj config via XDG_CONFIG_HOME (same approach as
    the sandbox-local integration tests) so it doesn't depend on host config.

… creation

`jj_git_clone` (sandbox-core/src/jj.rs) first tries `jj edit <bookmark>` and,
on failure, falls back to `jj new <base>` + `jj bookmark set <bookmark>`. The
fallback assumed the bookmark didn't exist, but `jj edit` can also fail when
the bookmark *does* exist and simply isn't editable — e.g. it is conflicted or
points at an immutable commit. In that case `jj bookmark set` has to move the
existing bookmark sideways/backwards onto the fresh change, which jj refuses
without `--allow-backwards`, producing:

    jj failed: Error: Refusing to move bookmark backwards or sideways: sandbox-...
    Hint: Use --allow-backwards to allow it.

This was the only `jj bookmark set` call in the codebase still missing `-B`
(the push path in `jj_push_working_copy` already had it from an earlier fix).

Changes:
- Add `-B` to the fallback `jj bookmark set` in `jj_git_clone`, with a comment
  explaining why, and clarify the log message.
- Add a regression unit test `jj::tests::clone_repoints_existing_uneditable_bookmark`
  that creates a conflicted `sandbox-x` bookmark (two concurrent `--at-op`
  bookmark sets to sibling commits), calls `jj_git_clone`, and asserts the
  bookmark is re-pointed to the new working copy on top of the base revision.
  Verified the test reproduces the exact error without the `-B` and passes
  with it. The test isolates jj config via `XDG_CONFIG_HOME` (same approach as
  the sandbox-local integration tests) so it doesn't depend on host config.


Co-authored-by: Infinity 🤖 <infinity@hydro.run>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Deploying infinity with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0f1c557
Status: ✅  Deploy successful!
Preview URL: https://2a4a22dc.infinity-dc7.pages.dev
Branch Preview URL: https://sandbox-5fb2d203-4ab4-4db2-8.infinity-dc7.pages.dev

View logs

@MingweiSamuel
MingweiSamuel marked this pull request as ready for review November 20, 2026 23:37
@MingweiSamuel
MingweiSamuel requested review from a team and a balanced review from Copilot November 20, 2026 23:37
@akainth015

Copy link
Copy Markdown
Member

Can you please add a picture to aid in my understanding

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The change still leaves a moderate test-isolation risk because isolate_jj_config() relies on a shared temp path and conditionally writes config.toml, so runs can pick up leftover state and become flaky under parallel execution.

1 open issue
What changed in this PR

Fixes sandbox creation failures in jj_git_clone when the target bookmark exists but cannot be edited (e.g., conflicted or immutable), by ensuring the fallback path can re-point the bookmark even when that requires a sideways/backwards move.

Changes:

  • Add -B (--allow-backwards) to the fallback jj bookmark set invocation and clarify the related log message/comment.
  • Add a regression unit test that creates a conflicted bookmark and verifies jj_git_clone re-points it to the new working copy on the requested base revision.
File Description
crates/​sandbox-core/​src/​jj.rs Updates jj_git_clone to allow backwards/sideways bookmark moves in the fallback path and adds a regression unit test covering conflicted/uneditable bookmark behavior.

Review effort: Balanced
Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.

Comment on lines +358 to +372
fn isolate_jj_config() {
let xdg = std::env::temp_dir().join("xdg-config-home");
let jj_dir = xdg.join("jj");
std::fs::create_dir_all(&jj_dir).expect("create jj config dir");
let cfg = jj_dir.join("config.toml");
if !cfg.exists() {
std::fs::write(&cfg, "[user]\nname = \"t\"\nemail = \"t@t\"\n")
.expect("write jj config");
}
// SAFETY: tests in this module are the only readers of this variable
// and set it to the same value.
unsafe {
std::env::set_var("XDG_CONFIG_HOME", &xdg);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants