BrowserStack REST API retries and CI result reporting: preventing duplicate session entries and artifact uploads
0 reputation · 15 Dec 2021, 21:54 UTC
0 reputation · 15 Dec 2021, 21:54 UTC
Our CI pipeline integrates with BrowserStack Automate through the REST API. When a session fails, we call the retry endpoint, which creates a brand-new session with a fresh session_id while copying the original test name, tags, and custom metadata verbatim.
The problem is on the reporting side: each retry appears as a separate entry in the results dashboard and re-uploads video, logs, and screenshots. Downstream, our own results collector ingests sessions by ID, so a single logical test run shows up multiple times and storage usage grows with every retry. The documented behavior (as of the 2024-era API docs) does not appear to expose an idempotency key, a continuation flag, or an API parameter controlling the retry limit, which is stated as a maximum of three per session but may vary by plan.
We want retries to be recorded as one logical run without losing the history of individual attempts.
Is there a supported way to link a retried session to its original session so dashboards and API consumers can treat them as one run? Can artifact uploads or duplicate metadata entries be suppressed or deduplicated on retry? And is the three-retry limit configurable or enforced differently between UI-triggered and API-triggered retries?
No — as of the 2024-era Automate REST API, there is no supported mechanism to link a retried session to its original. A retry creates a brand-new session with a fresh session_id, and there is no documented idempotency key, continuation flag, or parent-session field you can rely on. Artifact uploads cannot be suppressed or deduplicated via the API: video, logs, and screenshots are generated per session. The retry limit (commonly described as up to three per original session) is enforced server-side, is plan-dependent, and is not configurable through the REST API. There is no documented difference in enforcement between UI-triggered and API-triggered retries — assume both hit the same server-side limit until BrowserStack support confirms otherwise for your account.
The duplication you see is expected behavior, not a misconfiguration. Each retry is an independent session in the dashboard and in API responses, with your test name, tags, and metadata copied verbatim. Because your collector keys ingestion on session_id, one logical test run necessarily appears multiple times. What is not confirmed — and you should not build on — is the existence of any undocumented field on the retried session referencing its predecessor. Undocumented fields can appear and disappear with platform updates.
Since the platform won't group attempts for you, carry a stable identifier you control and group in your collector:
session_id to the logical run ID, storing attempts as children of one run. Keep the final (or latest passing) attempt as the canonical result; retain earlier attempts as history or discard per retention policy.session_id and check whether any field references the prior session (don't depend on it, but know what's there).Correlating by test name or build name alone is fragile if those values repeat across runs; a unique per-execution logical run ID avoids that. Also note that retry semantics and available fields differ between Automate (Selenium) and App Automate — if you use App Automate, verify the session fields against that product's current docs before finalizing the grouping logic.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.