Retrying Cloud Browser Jobs Without Creating Duplicate Sessions
TL;DR
Persist a creation intent with a UUIDv4 requestId and its exact payload before sending the first create request.
On a retriable create failure, keep the original ID, body and workspace while applying bounded backoff.
If the session ID is known, inspect that session rather than creating a second one.
Creation idempotency protects the browser lifecycle. A website form or purchase needs its own documented result and reconciliation rule.
Keep unresolved attempts visible to an operator and honor reasonable retry hints when available.
Confirm the original session has ended before considering its cleanup complete.
Why do browser automation retries create duplicate sessions?
Browser automation retries create duplicate sessions when a caller mistakes a lost response for a request that never arrived. The service may have started a browser even if the worker timed out before saving the response. A retry with a new request ID can then create another browser for the same job. The job should recover the original intent first. Nstdata Cloud Browser.
Compare three timeouts. The create request can time out before returning a Session ID. The connection can drop after an existing session reaches ready. A website action can time out after submitting a form. These events involve different earlier effects. Each needs a durable reference and a rule for deciding whether it is safe to proceed. See the Cloud Browser session lifecycle guide.
Which operations can you safely retry?
Retry an operation when you have a stable way to identify the intended effect and sufficient evidence that repeating it is allowed. Nstdata's Cloud Browser guide instructs callers to keep the same requestId and identical create parameters for a retry of the same creation intent. Use a new ID for an intentional new session or changed configuration. HTTP method semantics alone do not grant your application permission to repeat a write. .
Reconcile the original job before starting new work
The restart path should recover state from durable storage. A random ID held in memory works only until the current process ends. Persist the job intent and the browser create intent before submitting the request. Tie both to the workspace scope. For an explanation of attaching to an already running browser, see Playwright CDP connection.
How do you implement an idempotent create retry?
Persist the request bytes, retry only well-defined transient outcomes, and save the returned Session ID before proceeding to page operations. The example keeps the happy path close to the recovery path. It uses current Nstdata endpoints and a small configurable application policy. Browser Automation API tutorial.
Step 1. Determine allowed session options
Read GET /api/v1/cloud-browser/sessions/options in the intended workspace. Choose allowed resource class and proxy values and a permitted duration. Build a create body following the current schema. A UUIDv4 requestId should be stable for this intent. A create response can contain configuration warnings, so inspect the effective settings before relying on the session for an environment-sensitive test.
Step 2. Save the intended request before sending it
Write the serialized create body to a protected job record or a file such as request.json for the example. Keep the original body across worker restarts. Bind the record to the correct workspace and use a database constraint or lease to avoid parallel owners racing a job. Store only approved experiment settings. A custom proxy URL can contain credentials, so use appropriate secret storage if your application elects that path.
Step 3. Run the bounded retry worker
Use Node.js 22.12 or later. Save retry.mjs and retry-demo.mjs, set NSTDATA_API_KEY and any applicable NSTDATA_TEAM_ID, and run node retry-demo.mjs request.json. This managed branch requires your authorized Cloud Browser workspace. The retry function was tested with a synthetic transport that loses the first response, returns a session on the second, and compares the two bodies byte for byte.
import{ setTimeout as wait }from'node:timers/promises';exportasyncfunctionresumeCreate(bodyBytes, send, delay = wait){const intended =JSON.parse(bodyBytes);if(!/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(intended.requestId)){thrownewError('Expected a saved UUIDv4 requestId');}for(let attempt =0; attempt <3; attempt++){let response;try{ response =awaitsend(bodyBytes);}catch{if(attempt ===2)break;awaitdelay(500*2** attempt);continue;}if(!response.ok){const retryable =[429,503].includes(response.status);if(!retryable)thrownewError('Inspect create HTTP '+ response.status);if(attempt ===2)break;const header = response.headers.get('retry-after');const hint = header &&/^\d+$/.test(header)?Number(header)*1000: header ?Math.max(0,Date.parse(header)-Date.now()):0;if(hint >10_000)break;// Leave the saved intent for a later worker.awaitdelay(Math.max(500*2** attempt, hint ||0));continue;}const result =await response.json().catch(()=>null);if(result?.err !==true&& result?.success !==false&&typeof result?.data?.sessionId ==='string'&& result.data.sessionId){return result.data.sessionId;}break;}thrownewError('Create outcome unresolved. Retain the original requestId and payload.');}
The sample repeats a transport failure, HTTP 429 or HTTP 503 within its own bounded policy. It waits at least the available Retry-After hint if that hint fits the worker budget. If the service asks for a longer wait, the worker leaves the original intent pending for another permitted attempt. For production, spread clients out with jitter and enforce queue capacity. MDN guidance for rate-limited clients.
Step 4. Reconcile errors that require a decision
Treat validation and authorization errors as configuration issues. On HTTP 400, inspect the invalid field against current options and create a new intent if the corrected settings differ. On 401, 403 or 470, check key type and team selection. On 409, inspect the original operation and session state where available. Save the outcome and leave the protected request intact if the result remains uncertain.
Step 5. Confirm browser readiness and business outcome
Save sessionId and inspect the original session. Request automation credentials only when the session is ready. Before executing an action, check page identity, intended origin and the application's current state. If the worker is resuming after a disconnect, verify whether a previous website action already took effect. The live browser debugging guide explains how to inspect the page and request context.
Step 6. Reconcile shutdown
Stop the original session and inspect it until ended, or follow your timeout and operator handoff policy. A disconnected client and a succeeded task are separate from a stopped managed browser. If the controller crashed with only the request ID recorded, investigate that original creation before assuming it never ran.
How should you test browser-job recovery?
Simulate an ambiguous create result and verify that a restarted worker reads the same bytes before sending again. After the successful synthetic response, assert that its ID is stored against the intended business job. Simulate a permanent error and confirm that the worker stops after the first response. Simulate a rate limit and check the chosen delay. These tests measure request and scheduler behavior without spending browser runtime.
Test the application action separately. In authorized staging, create a record with a synthetic reference, interrupt the client after the click, and confirm recovery can find the receipt without another successful write. Then simulate an operation that never reached the backend and verify the agreed policy for retry. A Playwright test retry can rerun the test body, which matters when a test creates state. Playwright retries guide.
How do multiple workers share a recovery policy?
Multiple workers can share a recovery policy by claiming one durable job before acting on its creation intent. One owner reads or writes the intent and records the returned session ID. A later owner checks for prior progress before creating anything. A database claim or durable queue lease can serialize this decision. The sample file represents one persisted intent and does not provide concurrent scheduling.
For a staged restart test, interrupt the worker after its create call begins, start a new worker against the same record, and compare what it sends. Keep the original job identity and confirm that cleanup uses the returned session. If a definitive resource outcome is unavailable, mark the job for reconciliation rather than allowing an unbounded cycle of replacement jobs.
How does Nstdata Cloud Browser fit this recovery design?
Nstdata Cloud Browser provides managed cloud browsers for browser automation and AI agents. Its lifecycle endpoints give a worker a path to inspect the browser it created and recover after interruption. Built-in proxy options belong to the saved session configuration, so a retry preserves the egress choice for the same intent. Live View helps authorized operators investigate when a worker cannot decide from structured state. The app remains responsible for durable ownership and for validating the business action.
Creation identity. Preserve the documented request ID and payload for the same intended create.
Explicit session state. Poll readiness, keep a known session ID, and require separate shutdown confirmation.
Operator visibility. Inspect original state when diagnosis requires observing the managed page or reviewing available logs.
Usage reconciliation. Join accepted and failed runs to observed runtime and traffic. Cloud Browser pricing.
Record the job ID, workspace, original request ID, known Session ID, last completed stage, safe status code, and next reconciliation action. Keep the raw protected create record in durable storage and redact access credentials from operational output. Track unresolved submissions and unconfirmed stops so the next owner knows where to begin. Test recovery with one deliberately interrupted case before adding unattended retries.
Reuse the original ID and identical create payload for the same creation intent. Generate a new ID when you intentionally start another session or change configuration.
Q: Does a failed HTTP request prove no browser was created?
A transport error can leave the result uncertain. Reconcile the stored creation intent before starting another job.
Q: Does browser lifecycle idempotency prevent duplicate website submissions?
The website action needs its own durable reference and result check. Confirm the business state before any repeat attempt.
Q: Can I reconnect when the browser already ended?
Check the original session. An ended browser requires a deliberate new session if the workflow must run again.
Q: What if a stop request times out?
Inspect the original Session ID. Keep cleanup pending until the terminal state has been confirmed.
Marcus Chen
Nov. 19th 2026
Launch cloud browsers on demand
Handle fingerprints and CAPTCHAs
Automate workflows and power AI agents
From web scraping and testing to AI-driven automation, run it all in the cloud.