fix(sandbox): surface a SandboxGitError on a malformed git-api response body - #6359
Merged
Merged
Conversation
…se body fetchGitStatus/fetchGitDiff/publishGitChanges and friends all read the response body with res.json() before checking res.ok. A network hiccup that returns a non-JSON body — a proxy's HTML error page, a truncated response — threw a raw SyntaxError instead of the SandboxGitError callers expect. That matters because isSandboxUnreachable(error) only recognizes SandboxGitError with status 503/410/404, so a malformed body from an unreachable sandbox fell through as an unrecognized error: no backoff, and status polling kept hammering a dead sandbox every 3s instead of backing off like the intended 503/410/404 path does. Wraps the res.json() call in try/catch and throws SandboxGitError(status) on parse failure, same shape callers already handle. Reviewer check: cd apps/web && bun test src/components/thread/github/sandbox-git-api.test.ts Verified locally: bun run fmt, bunx tsc --noEmit (apps/web), targeted test file, bunx oxlint on both changed files — all clean. CI runs the rest.
decocms Bot
pushed a commit
that referenced
this pull request
Aug 20, 2026
PR: #6359 fix(sandbox): surface a SandboxGitError on a malformed git-api response body Bump type: patch - decocms (apps/api/package.json): 4.248.2 -> 4.248.3 - @decocms/native (apps/native/package.json): 4.248.2 -> 4.248.3 Deploy-Scope: web
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: bug found while auditing
apps/web/src/components/thread/github/sandbox-git-api.ts(the Fast Preview / sandbox git plumbing behindusePrDiffand the publish popover) for resilience against network hiccups.Why a maintainer wants this:
fetchGitStatus/fetchGitDiff/publishGitChanges/rebaseGitBranch/fetchSuggestCommitMessage/fetchReviewVerdict/discardGitFilesall funnel through oneparseJson()that calledres.json()unguarded. A response whose body isn't valid JSON — a proxy's HTML error page, a timeout returning a truncated body — throws a rawSyntaxErrorinstead of theSandboxGitErrorevery caller is written to expect.Failure scenario:
isSandboxUnreachable(error)(used by the status-poll backoff) only recognizesSandboxGitErrorwith status 503/410/404. A malformed-body response from an unreachable sandbox now fails that check — the poller doesn't back off and keeps hitting a dead sandbox every 3s instead of the intended graceful backoff. The regression test insandbox-git-api.test.tsreproduces this: a 502 with an HTML body now surfaces asSandboxGitErrorwithstatus: 502instead of an unrecognizedSyntaxError.Fix: wrap the
res.json()read in try/catch insideparseJson; on parse failure, throwSandboxGitError('Request failed (<status>)', status)— the same shape callers already branch on.Reviewer check:
cd apps/web && bun test src/components/thread/github/sandbox-git-api.test.tsVerified locally:
bun run fmt,bunx tsc --noEmit(apps/web), the one targeted test file,bunx oxlinton both changed files — all clean. Full CI validates the rest.Summary by cubic
Surfaces
SandboxGitError(status)when the git-api returns a malformed JSON body, restoring consistent error handling and correct backoff. Previously,parseJsoncalledres.json()unguarded, so HTML/truncated bodies threw a rawSyntaxErrorthat callers (e.g., the status poller) could not classify.res.json()in try/catch insideparseJson; on parse failure, throwsSandboxGitError("Request failed (<status>)", status).SandboxGitError(status 502) and is not treated as unreachable byisSandboxUnreachable.Review notes
Written for commit 58ca40c. Summary will update on new commits.