Skip to content

fix(sandbox): return 400 instead of 500 when the rebase base branch isn't on origin - #5144

Merged
pedrofrxncx merged 1 commit into
mainfrom
fix/rebase-base-branch-not-found-400-w2
Jul 23, 2026
Merged

pedrofrxncx merged 1 commit into
mainfrom
fix/rebase-base-branch-not-found-400-w2

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jul 23, 2026 •

Copy link
Copy Markdown
Collaborator

Follows #5142 and #5134's hardening of the sandbox git routes' error-status mapping.

rebaseOntoBase() threw a plain Error when the requested base branch didn't exist on origin (typo, deleted branch), which /git/rebase mapped to a generic 500 — the exact client/data condition that computeDiffAgainstBase already maps to 400 via BaseBranchNotFoundError (#5142), and the same class of "conflict with current state, not a server fault" that RebaseBlockedError already gets a 409 for on this same route (#5134). Added a matching RebaseBaseBranchNotFoundError, mapped to 400 in makeGitRebaseHandler.

While reproducing this I found the check was actually unreachable in the common case: git fetch -p origin <base> <branch> fails the whole fetch if base doesn't exist on origin, so the code threw a raw fetch error (128, "couldn't find remote ref") before ever reaching the BaseBranchNotFoundError check below it — and skipped fetching branch, which the force-push lease relies on. Fetching base and branch as separate requests fixes both: a missing base no longer blocks fetching the branch, and the existing post-fetch check now actually runs and throws the typed error.

Failure scenario: client calls POST /git/rebase with a base that was renamed/deleted upstream (or typo'd) — daemon returned 500 (crash-looking) instead of a clean, retryable 400 the UI can show as "branch not found."

Regression tests added:

  • packages/sandbox/daemon/git/rebase-onto-base.test.ts: rebaseOntoBase() throws RebaseBaseBranchNotFoundError for a base branch missing on origin (real bare-repo fixture, mirrors the existing conflict-resolution/protected-branch tests in this file).
  • packages/sandbox/daemon/routes/git.test.ts: /git/rebase route returns 400 (not 500) for the same condition, mirroring the existing diff-route test for the identical scenario.

Reviewer command: bun test packages/sandbox/daemon/git/rebase-onto-base.test.ts packages/sandbox/daemon/routes/git.test.ts

Locally ran: bun run fmt, cd packages/sandbox && bunx tsc --noEmit (clean), and the targeted test file above (37 pass / 0 fail). Full CI validates the rest.


Summary by cubic

Return 400 (not 500) from the sandbox rebase route when the base branch is missing on origin. Also fix fetch behavior so a missing base doesn’t prevent fetching the working branch.

  • Bug Fixes
    • Added RebaseBaseBranchNotFoundError and map it to 400 in makeGitRebaseHandler for /git/rebase.
    • Fetch base and branch separately to avoid whole-command failure and preserve the force-push lease.
    • Route now mirrors the diff path’s 400 semantics; 409 for RebaseBlockedError remains.
    • Added regression tests for the error and route behavior.

Written for commit 5581d63. Summary will update on new commits.

Review in cubic

…sn't on origin

rebaseOntoBase() threw a plain Error when the requested base branch didn't
exist on origin, which the /git/rebase route mapped to a generic 500 — the
same client/data condition that computeDiffAgainstBase already maps to 400
via BaseBranchNotFoundError. Add a matching RebaseBaseBranchNotFoundError so
the rebase route reports the same 400 semantics.

This also fixes a latent bug in the fetch itself: `git fetch origin <base>
<branch>` fails the whole command if `base` doesn't exist on origin, which
skipped fetching `branch` (needed for the force-push lease) and threw a raw
fetch error before the base-branch check ever ran. Fetching base and branch
as separate requests fixes both.
@pedrofrxncx
pedrofrxncx enabled auto-merge (squash) July 23, 2026 22:30
@pedrofrxncx
pedrofrxncx merged commit 9843533 into main Jul 23, 2026
15 checks passed
@pedrofrxncx
pedrofrxncx deleted the fix/rebase-base-branch-not-found-400-w2 branch July 23, 2026 22:31
decocms Bot pushed a commit that referenced this pull request Jul 23, 2026
PR: #5144 fix(sandbox): return 400 instead of 500 when the rebase base branch isn't on origin
Bump type: patch

- @decocms/sandbox (packages/sandbox/package.json): 1.22.2 -> 1.22.3
- deploy/helm/sandbox-env (chart 0.9.21) (deploy/helm/sandbox-env/values.yaml deploy/helm/sandbox-env/Chart.yaml): image.tag/appVersion -> 1.22.3

Deploy-Scope: both
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.

1 participant