Repository navigation
fix(sandbox): return 409 instead of 500 for publish refusals on detached HEAD/protected branch - #5109
Merged
Merged
Conversation
…hed HEAD/protected branch publish() throwing on a detached HEAD or a protected branch is a conflict with the sandbox's current git state, not a server fault, but makeGitPublishHandler mapped it to a generic 500 like a real crash. Mirrors the InvalidDecofileBlockError -> 400 and InvalidRemoteBranchNameError -> 400 patterns already in this file, and the 409 repoNotReadyResponse() uses for the same "current git state blocks this request" class of condition.
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.
Source: a bug found while auditing
packages/sandbox/daemon/routes/git.tsfor missing/incorrect status codes, the same file (and same audit angle) as the just-merged #5105 ("return 400 for path-traversal in git discard").Why a maintainer wants it:
makeGitPublishHandlerreturns a generic 500 whenpublish()throws because the sandbox is on a detached HEAD or the checked-out branch is protected (e.g.main) — but that's a conflict with the current git state, not a server crash, exactly the same class of conditionrepoNotReadyResponse()already maps to 409 elsewhere in this file. A 500 here misleads alerting/monitoring into treating a normal "you're on main, publish to a feature branch instead" refusal as a daemon fault.Failure scenario + fix: POST
/git/publishwhile checked out onmain(or in a detached HEAD) throwsRefusing to push to protected branch "main".../Cannot publish from a detached HEAD, which the handler previously caught with the catch-all branch and returned as HTTP 500. Fixed by introducingPublishBlockedError, thrown from both refusal sites inpublish(), and mapped to 409 inmakeGitPublishHandler— mirroring the existingInvalidDecofileBlockError-> 400 andInvalidRemoteBranchNameError-> 400 patterns in the same file. Added a new handler-level test (publish route returns 409 (not 500) for a protected-branch refusal) asserting the status code; the existing function-level test for the protected-branch throw message is untouched (still passes, message unchanged).Reviewer command:
bun test packages/sandbox/daemon/routes/git.test.tsLocal checks run:
bun run fmt,cd packages/sandbox && bunx tsc --noEmit(clean), and the targeted test file above (30 pass, up from 29). Full CI validates the rest.Summary by cubic
Return 409 Conflict (not 500) when POST
/git/publishis refused due to detached HEAD or a protected branch, so monitoring doesn’t treat it as a server error. AddsPublishBlockedErrorand maps it inmakeGitPublishHandler; includes a new route test.publish()now throwsPublishBlockedErrorfor detached HEAD or protected branches, and the handler returns409instead of500(mirrors existing error-to-status mappings).git.test.tstest to assert the 409 response and error message.Written for commit 34b3546. Summary will update on new commits.