Skip to content

fix(sdk-js): throw SandboxApiException from isolated session requests - #2466

Open
acodercat wants to merge 2 commits into
opensandbox-group:mainfrom
acodercat:fix/sdk-js-isolated-session-api-errors
Open

acodercat wants to merge 2 commits into
opensandbox-group:mainfrom
acodercat:fix/sdk-js-isolated-session-api-errors

Conversation

@acodercat

@acodercat acodercat commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

IsolatedSessionsAdapter calls fetch directly for every isolated session endpoint except the streaming run: create, attach, get, delete, list, capabilities, background run, run status and run logs. When one of these returned an error, the adapter threw a plain Error with the status and body folded into the message, for example GET /v1/isolated/session/x failed: 404 {"code":"SESSION_NOT_FOUND",...}.

Callers had no way to read the status code, the request id or the execd error code without parsing that string. Everything else in the SDK throws SandboxApiException with these fields, including the isolated filesystem adapter of the same session and the streaming run (through parseJsonEventStream), and so do the other language SDKs for the same endpoints.

Summary

  • Add throwOnFailedResponse to openapiError.ts, next to throwOnOpenApiFetchError, the function the generated-client adapters use. It reads the body of a failed fetch response and hands it to that function. The error now carries statusCode, requestId, rawBody, and the code and message from execd's JSON error body. Any other adapter that calls fetch directly can use it too.
  • Use it in jsonRequest, _runBackground and _getRunLogs, the three places that threw a plain Error.
  • An error without a body gets the message <METHOD> <path> failed (status=N) and the code UNEXPECTED_RESPONSE. _runBackground still rejects any status other than 202.

Testing

  • Not run (explain why)

  • Unit tests

  • Integration tests

  • e2e / manual verification

  • The four existing error tests (attach, background run, run status, run logs) now check for SandboxApiException with the status code, request id, error code and message. Two new tests cover an error response without a body and a 2xx response other than 202 from the background run. All six fail on the current code, which throws a plain Error.

  • Mutation checks: reverting _getRunLogs to a plain Error, or making the helper's final throw a plain Error, each fails the matching test.

  • pnpm test (400 passed), pnpm run lint and pnpm run typecheck are clean.

Breaking Changes

  • None
  • Yes (describe impact and migration path)

The thrown error is still an Error (SandboxApiException extends it). Its message is now execd's error message when the body has one, instead of the method, path, status and raw body. Code that pattern-matched the old message text would need to read statusCode or error.code instead.

Checklist

  • Linked Issue or clearly described motivation
  • Added/updated docs (if needed)
  • Added/updated tests (if needed)
  • Security impact considered
  • Backward compatibility considered

The isolated sessions adapter calls fetch directly for every endpoint
except the streaming run, and on an error response it threw a plain
Error with the status and body folded into the message. Callers could
not read the status code, request id or execd error code, unlike every
other adapter in the SDK, including the isolated filesystem adapter of
the same session and the streaming run.

Report these failures through throwOnOpenApiFetchError, as the
generated-client adapters do, so they carry statusCode, requestId,
rawBody and the error code and message from the body. An error without
a body falls back to "<METHOD> <path> failed (status=N)".
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T02:11:11.776828Z 41b53d9 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions github-actions Bot added sdk/js size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 29, 2026
…ApiFetchError

Turning a failed response into a SandboxApiException is not specific to
the isolated sessions adapter. Keep it in openapiError.ts, beside the
function it builds on, as throwOnFailedResponse, so any adapter that
calls fetch directly can use it; the adapter only decides when a
response failed and what the fallback message says.

@ninan-nn ninan-nn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. This reuses the existing SDK error conversion and aligns isolated-session HTTP failures with the structured SandboxApiException behavior used elsewhere. The regression cases cover structured errors, plain-text and empty bodies, and unexpected non-202 success responses for background runs. Static review only; tests were not run locally.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sdk/js size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants