Skip to content

fix(sandbox): surface a SandboxGitError on a malformed git-api response body - #6359

Merged
pedrofrxncx merged 1 commit into
mainfrom
fix/sandbox-git-api-malformed-body-w4
Aug 20, 2026
Merged

fix(sandbox): surface a SandboxGitError on a malformed git-api response body#6359
pedrofrxncx merged 1 commit into
mainfrom
fix/sandbox-git-api-malformed-body-w4

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

Source: bug found while auditing apps/web/src/components/thread/github/sandbox-git-api.ts (the Fast Preview / sandbox git plumbing behind usePrDiff and the publish popover) for resilience against network hiccups.

Why a maintainer wants this: fetchGitStatus/fetchGitDiff/publishGitChanges/rebaseGitBranch/fetchSuggestCommitMessage/fetchReviewVerdict/discardGitFiles all funnel through one parseJson() that called res.json() unguarded. A response whose body isn't valid JSON — a proxy's HTML error page, a timeout returning a truncated body — throws a raw SyntaxError instead of the SandboxGitError every caller is written to expect.

Failure scenario: isSandboxUnreachable(error) (used by the status-poll backoff) only recognizes SandboxGitError with 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 in sandbox-git-api.test.ts reproduces this: a 502 with an HTML body now surfaces as SandboxGitError with status: 502 instead of an unrecognized SyntaxError.

Fix: wrap the res.json() read in try/catch inside parseJson; on parse failure, throw SandboxGitError('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.ts

Verified locally: bun run fmt, bunx tsc --noEmit (apps/web), the one targeted test file, bunx oxlint on 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, parseJson called res.json() unguarded, so HTML/truncated bodies threw a raw SyntaxError that callers (e.g., the status poller) could not classify.

  • Wraps res.json() in try/catch inside parseJson; on parse failure, throws SandboxGitError("Request failed (<status>)", status).
  • Adds a test that a 502 with HTML yields SandboxGitError (status 502) and is not treated as unreachable by isSandboxUnreachable.

Review notes

  • Run: cd apps/web && bun test src/components/thread/github/sandbox-git-api.test.ts
  • No migration required.

Written for commit 58ca40c. Summary will update on new commits.

Review in cubic

…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.
@pedrofrxncx
pedrofrxncx merged commit dff3ddf into main Aug 20, 2026
34 checks passed
@pedrofrxncx
pedrofrxncx deleted the fix/sandbox-git-api-malformed-body-w4 branch August 20, 2026 19:06
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
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