Skip to content

fix(browserbase): retry session api failures#3211

Open
tofikwest wants to merge 1 commit into
mainfrom
tofik/browserbase-session-api-retry
Open

fix(browserbase): retry session api failures#3211
tofikwest wants to merge 1 commit into
mainfrom
tofik/browserbase-session-api-retry

Conversation

@tofikwest

@tofikwest tofikwest commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • retry transient Browserbase SDK failures for session create/debug/retrieve/update, not only context creation
  • fixes the stage error from GET /v1/sessions/:id returning ERR_STREAM_PREMATURE_CLOSE / Premature close
  • keep Browserbase response headers set to identity encoding, and map exhausted retryable upstream failures to a stable 503
  • best-effort close a created session if live-view URL lookup fails after retries

Tests

  • cd apps/api && bunx jest src/browserbase/browserbase-session.service.spec.ts src/browserbase/browserbase-upstream-error.spec.ts --passWithNoTests
  • bunx turbo run typecheck --filter=@trycompai/api (fails on existing unrelated API type errors in assistant-chat, auth, cloud-security, integration-platform specs, and other modules)

Summary by cubic

Add unified retry logic for Browserbase session APIs (create, debug, retrieve, update) to handle transient failures. Fixes premature close errors, returns 503 when retries are exhausted, and cleans up sessions if live-view lookup fails.

  • Bug Fixes
    • Retries applied to session create/debug/retrieve/update (3 attempts with small backoff).
    • Consolidated logic via a shared retry helper for consistent error handling.
    • Sends identity encoding to keep responses stable.
    • Best-effort session close if live-view URL lookup fails after retries.
    • Added tests for session retrieval and live view retry behavior.

Written for commit b3ac466. Summary will update on new commits.

Review in cubic

@vercel

vercel Bot commented Jun 19, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
comp-framework-editor Ready Ready Preview, Comment Jun 19, 2026 9:23pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
app Skipped Skipped Jun 19, 2026 9:23pm
portal Skipped Skipped Jun 19, 2026 9:23pm

Request Review

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1 issue found across 2 files

Confidence score: 3/5

  • In apps/api/src/browserbase/browserbase-session.service.ts, non-retryable Browserbase errors are being remapped to 503, which can misclassify client/upstream failures as transient server outages and change API behavior for callers relying on status codes; restrict the 503 remap to exhausted retryable paths and preserve original error types for non-retryable failures before merging.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/api/src/browserbase/browserbase-session.service.ts">

<violation number="1" location="apps/api/src/browserbase/browserbase-session.service.ts:133">
P2: Non-retryable Browserbase errors are incorrectly remapped to 503. This masks real client/upstream error types and changes behavior beyond exhausted retryable failures.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment on lines +133 to +139
if (!retryable || attempt === BROWSERBASE_API_MAX_ATTEMPTS) {
this.logger.error(`Browserbase ${operationName} failed`, {
attempt,
error: getBrowserbaseErrorText(error),
});
throw browserbaseUnavailableException();
}

@cubic-dev-ai cubic-dev-ai Bot Jun 19, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: Non-retryable Browserbase errors are incorrectly remapped to 503. This masks real client/upstream error types and changes behavior beyond exhausted retryable failures.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/api/src/browserbase/browserbase-session.service.ts, line 133:

<comment>Non-retryable Browserbase errors are incorrectly remapped to 503. This masks real client/upstream error types and changes behavior beyond exhausted retryable failures.</comment>

<file context>
@@ -35,82 +35,120 @@ export class BrowserbaseSessionService {
+        return await operation();
+      } catch (error) {
+        const retryable = isRetryableBrowserbaseUpstreamError(error);
+        if (!retryable || attempt === BROWSERBASE_API_MAX_ATTEMPTS) {
+          this.logger.error(`Browserbase ${operationName} failed`, {
+            attempt,
</file context>
Suggested change
if (!retryable || attempt === BROWSERBASE_API_MAX_ATTEMPTS) {
this.logger.error(`Browserbase ${operationName} failed`, {
attempt,
error: getBrowserbaseErrorText(error),
});
throw browserbaseUnavailableException();
}
if (!retryable) {
this.logger.error(`Browserbase ${operationName} failed`, {
attempt,
error: getBrowserbaseErrorText(error),
});
throw error;
}
if (attempt === BROWSERBASE_API_MAX_ATTEMPTS) {
this.logger.error(`Browserbase ${operationName} failed`, {
attempt,
error: getBrowserbaseErrorText(error),
});
throw browserbaseUnavailableException();
}
Fix with cubic

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