:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(replay-vision): stop dead-end retries on infra timeouts (#87679)
posthog[bot]ed109921b72f
diff --git a/nodejs/src/session-replay/recording-rasterizer/__tests__/block-proxy.test.ts b/nodejs/src/session-replay/recording-rasterizer/__tests__/block-proxy.test.tsindex c99269ae9cd5..2fe7cf43dbbd 100644--- a/nodejs/src/session-replay/recording-rasterizer/__tests__/block-proxy.test.ts+++ b/nodejs/src/session-replay/recording-rasterizer/__tests__/block-proxy.test.ts@@ -20,6 +20,8 @@ function baseInput(overrides: Partial<RasterizeRecordingInput> = {}): RasterizeRconst testCfg = {recordingApiBaseUrl: 'http://localhost:6738',recordingApiSecret: 'test-secret',+ blockListingTimeoutMs: 30_000,+ blockFetchTimeoutMs: 60_000,}const mockLog = {@@ -58,7 +60,7 @@ describe('BlockProxy', () => {expect(proxy.totalCompressedBytes).toBe(3002)expect(mockInternalFetch).toHaveBeenCalledWith('http://localhost:6738/api/projects/1/recordings/test-session-123/blocks',- { headers: { 'X-Internal-Api-Secret': 'test-secret' } }+ { headers: { 'X-Internal-Api-Secret': 'test-secret' }, timeoutMs: 30_000 })})@@ -73,7 +75,10 @@ describe('BlockProxy', () => {expect(mockInternalFetch).toHaveBeenCalledWith('http://localhost:6738/api/projects/1/recordings/test-session-123/blocks',- { headers: { 'X-Internal-Api-Secret': 'test-secret', Authorization: 'Bearer minted-token' } }+ {+ headers: { 'X-Internal-Api-Secret': 'test-secret', Authorization: 'Bearer minted-token' },+ timeoutMs: 30_000,+ })})@@ -117,6 +122,21 @@ describe('BlockProxy', () => {const proxy = new BlockProxy(testCfg, mockLog)await expect(proxy.fetchBlocks(baseInput())).rejects.toThrow('Invalid block listing response')+ // The rethrow that lets timeouts through as retryable must not flip this.+ await expect(proxy.fetchBlocks(baseInput())).rejects.toMatchObject({ retryable: false })+ })++ it('marks a body read that aborts as retryable', async () => {+ mockInternalFetch.mockResolvedValue({+ status: 200,+ json: jest.fn().mockRejectedValue(new Error('The operation was aborted due to timeout')),+ })++ const proxy = new BlockProxy(testCfg, mockLog)+ await expect(proxy.fetchBlocks(baseInput())).rejects.toMatchObject({+ retryable: true,+ code: 'BLOCK_LISTING_FAILED',+ })})})@@ -159,7 +179,7 @@ describe('BlockProxy', () => {expect(mockInternalFetch).toHaveBeenCalledWith(expect.stringContaining('/api/projects/1/recordings/test-session-123/block?'),- { headers: { 'X-Internal-Api-Secret': 'test-secret' } }+ { headers: { 'X-Internal-Api-Secret': 'test-secret' }, timeoutMs: 60_000 })const fetchUrl = mockInternalFetch.mock.calls[0][0] as stringexpect(fetchUrl).toContain('key=recordings%2Fblock-0')@@ -184,6 +204,7 @@ describe('BlockProxy', () => {expect(mockInternalFetch).toHaveBeenCalledWith(expect.stringContaining('/block?'), {headers: { 'X-Internal-Api-Secret': 'test-secret', Authorization: 'Bearer minted-token' },+ timeoutMs: 60_000,})})diff --git a/nodejs/src/session-replay/recording-rasterizer/capture/block-proxy.ts b/nodejs/src/session-replay/recording-rasterizer/capture/block-proxy.tsindex 8b2dcdddf1cf..e984c51a692b 100644--- a/nodejs/src/session-replay/recording-rasterizer/capture/block-proxy.ts+++ b/nodejs/src/session-replay/recording-rasterizer/capture/block-proxy.ts@@ -19,7 +19,12 @@ export class BlockProxy {private recordingApiToken = ''constructor(- private cfg: { recordingApiBaseUrl: string; recordingApiSecret: string },+ private cfg: {+ recordingApiBaseUrl: string+ recordingApiSecret: string+ blockListingTimeoutMs: number+ blockFetchTimeoutMs: number+ },private log: Logger = createLogger()) {}@@ -56,14 +61,39 @@ export class BlockProxy {const url = `${this.cfg.recordingApiBaseUrl}/api/projects/${input.team_id}/recordings/${encodeURIComponent(input.session_id)}/blocks`- let resptry {- resp = await internalFetch(url, {+ const resp = await internalFetch(url, {headers: this.authHeaders(),+ timeoutMs: this.cfg.blockListingTimeoutMs,})+ if (resp.status < 200 || resp.status >= 300) {+ const body = await resp.text()+ // 404 stays retryable because a recording still being ingested has no blocks yet, the+ // same race the player's NO_SNAPSHOTS handling deliberately keeps retryable. 408/429+ // are transient by definition. Remaining 4xx (auth, bad request) cannot heal on retry.+ const retryable = resp.status >= 500 || [404, 408, 429].includes(resp.status)+ throw new RasterizationError(+ `Failed to fetch block listing: ${resp.status} - ${body}`,+ retryable,+ 'BLOCK_LISTING_FAILED'+ )+ }+ const data = await resp.json()+ if (!Array.isArray(data.blocks)) {+ throw new RasterizationError(+ `Invalid block listing response: expected blocks array, got ${typeof data.blocks}`,+ false,+ 'BLOCK_LISTING_FAILED'+ )+ }+ this.blocks = data.blocks as RecordingBlock[]+ return this.blocks.length} catch (err) {- // Connection-level failures (recording-api rollout, DNS blip) would otherwise surface as- // UNKNOWN; they are the most retryable failure this call has.+ if (err instanceof RasterizationError) {+ throw err+ }+ // The timeout covers the body read as well as the connection, so a rollout, a DNS blip and+ // a response that stalls mid-body all land here. All are transient, not UNKNOWN.throw new RasterizationError(`Failed to fetch block listing: ${(err as Error)?.message ?? String(err)}`,true,@@ -71,28 +101,6 @@ export class BlockProxy {err)}- if (resp.status < 200 || resp.status >= 300) {- const body = await resp.text()- // 404 stays retryable because a recording still being ingested has no blocks yet, the- // same race the player's NO_SNAPSHOTS handling deliberately keeps retryable. 408/429- // are transient by definition. Remaining 4xx (auth, bad request) cannot heal on retry.- const retryable = resp.status >= 500 || [404, 408, 429].includes(resp.status)- throw new RasterizationError(- `Failed to fetch block listing: ${resp.status} - ${body}`,- retryable,- 'BLOCK_LISTING_FAILED'- )- }- const data = await resp.json()- if (!Array.isArray(data.blocks)) {- throw new RasterizationError(- `Invalid block listing response: expected blocks array, got ${typeof data.blocks}`,- false,- 'BLOCK_LISTING_FAILED'- )- }- this.blocks = data.blocks as RecordingBlock[]- return this.blocks.length}async handleRequest(request: HTTPRequest, path: string): Promise<void> {@@ -114,6 +122,7 @@ export class BlockProxy {const url = `${apiBase}/${this.teamId}/recordings/${encodeURIComponent(this.sessionId)}/block?${params}`const resp = await internalFetch(url, {headers: this.authHeaders(),+ timeoutMs: this.cfg.blockFetchTimeoutMs,})if (resp.status < 200 || resp.status >= 300) {const text = await resp.text()diff --git a/nodejs/src/session-replay/recording-rasterizer/config.ts b/nodejs/src/session-replay/recording-rasterizer/config.tsindex e541043907ae..7ca13f446758 100644--- a/nodejs/src/session-replay/recording-rasterizer/config.ts+++ b/nodejs/src/session-replay/recording-rasterizer/config.ts@@ -49,6 +49,11 @@ export const config = {// Recording API. The dev recording-api listens on 6741 (bin/temporal-recording-rasterizer-worker).recordingApiBaseUrl: process.env.RECORDING_API_BASE_URL || 'http://localhost:6741',recordingApiSecret: process.env.INTERNAL_API_SECRET || '',+ // The listing hits ClickHouse through recording-api, so internalFetch's 3s default aborts it under load.+ blockListingTimeoutMs: parsePositiveInt(process.env.BLOCK_LISTING_TIMEOUT_MS, 30_000),+ // Bounds a stalled read rather than capping latency, so it stays generous enough for a slow but+ // progressing transfer. Unbounded, one stall holds its render slot until beginFrameTimeoutMs fires.+ blockFetchTimeoutMs: parsePositiveInt(process.env.BLOCK_FETCH_TIMEOUT_MS, 60_000),// Renders above this many compressed bytes fail permanently instead of loading the pod into its// memory limit. Deliberately generous: the every-render byte log is what tightens it over time.maxRecordingCompressedBytes: parsePositiveInt(process.env.MAX_RECORDING_COMPRESSED_BYTES, 512 * 1024 * 1024),