Repository navigation
fix: "Refusing to move bookmark backwards or sideways" during sandbox creation - #197
Open
MingweiSamuel wants to merge 1 commit into
Open
MingweiSamuel wants to merge 1 commit into
MingweiSamuel wants to merge 1 commit into
Conversation
… 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>
Deploying infinity with
|
| 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 |
MingweiSamuel
marked this pull request as ready for review
November 20, 2026 23:37
MingweiSamuel
requested review from
a team
and
a balanced review from Copilot
November 20, 2026 23:37
Member
|
Can you please add a picture to aid in my understanding |
akainth015
approved these changes
Nov 20, 2026
Contributor
There was a problem hiding this comment.
🟡 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 fallbackjj bookmark setinvocation and clarify the related log message/comment. - Add a regression unit test that creates a conflicted bookmark and verifies
jj_git_clonere-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); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

jj_git_clone(sandbox-core/src/jj.rs) first triesjj edit <bookmark>and,on failure, falls back to
jj new <base>+jj bookmark set <bookmark>. Thefallback assumed the bookmark didn't exist, but
jj editcan also fail whenthe bookmark does exist and simply isn't editable — e.g. it is conflicted or
points at an immutable commit. In that case
jj bookmark sethas to move theexisting bookmark sideways/backwards onto the fresh change, which jj refuses
without
--allow-backwards, producing:This was the only
jj bookmark setcall in the codebase still missing-B(the push path in
jj_push_working_copyalready had it from an earlier fix).Changes:
-Bto the fallbackjj bookmark setinjj_git_clone, with a commentexplaining why, and clarify the log message.
jj::tests::clone_repoints_existing_uneditable_bookmarkthat creates a conflicted
sandbox-xbookmark (two concurrent--at-opbookmark sets to sibling commits), calls
jj_git_clone, and asserts thebookmark is re-pointed to the new working copy on top of the base revision.
Verified the test reproduces the exact error without the
-Band passeswith it. The test isolates jj config via
XDG_CONFIG_HOME(same approach asthe sandbox-local integration tests) so it doesn't depend on host config.