: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(cdp): only tell customers a fetch is being retried when it is (#80924)
Daniel Marchukca517ff60472
diff --git a/nodejs/src/cdp/cdp-e2e.test.ts b/nodejs/src/cdp/cdp-e2e.test.tsindex e5722de631e7..0188dc20ce40 100644--- a/nodejs/src/cdp/cdp-e2e.test.ts+++ b/nodejs/src/cdp/cdp-e2e.test.ts@@ -567,8 +567,10 @@ describe('CDP Consumer loop', () => {).toEqual(['Fetch response:, {"status":500,"body":{"error":"Server error"}}',expect.stringContaining('Function completed in '),- expect.stringContaining('HTTP fetch failed on attempt 1 with status code 500. Retrying in '),- expect.stringContaining('HTTP fetch failed on attempt 2 with status code 500. Retrying in '),+ expect.stringContaining('HTTP fetch failed on attempt 1 with status code 500. Retrying.'),+ // CDP_FETCH_RETRIES is 2 here, so attempt 2 is the last one and no retry follows it.+ // Matched exactly: a substring match would also accept the ' Retrying.' this guards against.+ 'HTTP fetch failed on attempt 2 with status code 500.',])})})diff --git a/nodejs/src/cdp/consumers/cdp-cyclotron-worker.test.ts b/nodejs/src/cdp/consumers/cdp-cyclotron-worker.test.tsindex 0678f1c2349e..5d87cf60a379 100644--- a/nodejs/src/cdp/consumers/cdp-cyclotron-worker.test.ts+++ b/nodejs/src/cdp/consumers/cdp-cyclotron-worker.test.ts@@ -221,7 +221,7 @@ describe('CdpCyclotronWorker', () => {expect(result.invocation.queueMetadata).toBeUndefined()// No logs from initial invokeexpect(result.logs.map((x) => x.message)).toEqual([- expect.stringContaining('HTTP fetch failed on attempt 1 with status code 500. Retrying in'),+ expect.stringContaining('HTTP fetch failed on attempt 1 with status code 500. Retrying.'),])// Now invoke the result againdiff --git a/nodejs/src/cdp/services/hog-executor-async.service.ts b/nodejs/src/cdp/services/hog-executor-async.service.tsindex 450f2247128b..21acd16f69fd 100644--- a/nodejs/src/cdp/services/hog-executor-async.service.ts+++ b/nodejs/src/cdp/services/hog-executor-async.service.ts@@ -439,6 +439,11 @@ export class HogExecutorAsyncService {)const canRetry = isFetchResponseRetriable(fetchResponse, fetchError)+ const maxRetries = options?.maxFetchRetries ?? this.config.fetchRetries+ // `canRetry` only says the failure class is retriable. On the last attempt it is still+ // true while no retry follows, so the customer-facing log has to gate on the same+ // condition the scheduling below does.+ const willRetry = canRetry && result.invocation.state.attempts < maxRetrieslet message = `HTTP fetch failed on attempt ${result.invocation.state.attempts} with status code ${fetchResponse?.status ?? '(none)'@@ -448,14 +453,13 @@ export class HogExecutorAsyncService {message += ` Error: ${fetchError.message}.`}- if (canRetry) {- message += ` Retrying in ${backoffMs}ms.`+ if (willRetry) {+ message += ` Retrying.`}addLog(isNonFailure ? 'info' : 'error', message)- const maxRetries = options?.maxFetchRetries ?? this.config.fetchRetries- if (canRetry && result.invocation.state.attempts < maxRetries) {+ if (willRetry) {await fetchResponse?.dump()result.invocation.queueParameters = paramsresult.invocation.queuePriority = invocation.queuePriority + 1diff --git a/nodejs/src/cdp/services/hog-executor.service.test.ts b/nodejs/src/cdp/services/hog-executor.service.test.tsindex 55eb20693c61..223235821507 100644--- a/nodejs/src/cdp/services/hog-executor.service.test.ts+++ b/nodejs/src/cdp/services/hog-executor.service.test.ts@@ -1086,7 +1086,7 @@ describe('Hog Executor', () => {// Should be scheduled for retryexpect(result.invocation.state.attempts).toBe(1)expect(result.logs.map((log) => log.message)).toEqual([- 'HTTP fetch failed on attempt 1 with status code 500. Retrying in 1500ms.',+ 'HTTP fetch failed on attempt 1 with status code 500. Retrying.',])expect(result.invocation.queuePriority).toBe(1) // Priority decreasedexpect(result.invocation.queueScheduledAt?.toISO()).toMatchInlineSnapshot(`"2025-01-01T00:00:01.500Z"`)@@ -1096,7 +1096,7 @@ describe('Hog Executor', () => {result = await executor.executeFetch(result.invocation)expect(result.invocation.state.attempts).toBe(2)expect(result.logs.map((log) => log.message)).toEqual([- 'HTTP fetch failed on attempt 2 with status code 500. Retrying in 2500ms.',+ 'HTTP fetch failed on attempt 2 with status code 500. Retrying.',])expect(result.invocation.queuePriority).toBe(2) // Priority decreasedexpect(result.invocation.queueScheduledAt?.toISO()).toMatchInlineSnapshot(`"2025-01-01T00:00:02.500Z"`)@@ -1104,7 +1104,7 @@ describe('Hog Executor', () => {// Execute the final retryresult = await executor.executeFetch(result.invocation)expect(result.logs.map((log) => log.message)).toEqual([- 'HTTP fetch failed on attempt 3 with status code 500. Retrying in 3500ms.',+ 'HTTP fetch failed on attempt 3 with status code 500.',])// All values reset due to no longer retryingexpect(result.invocation.state.attempts).toBe(0)@@ -1368,7 +1368,7 @@ describe('Hog Executor', () => {expect(result.invocation.queueScheduledAt).toMatchInlineSnapshot(`"2025-01-01T00:00:01.500Z"`)expect(result.logs.map((log) => log.message)).toMatchInlineSnapshot(`[- "HTTP fetch failed on attempt 1 with status code (none). Error: Invalid hostname. Retrying in 1500ms.",+ "HTTP fetch failed on attempt 1 with status code (none). Error: Invalid hostname. Retrying.",]`)})@@ -1413,7 +1413,7 @@ describe('Hog Executor', () => {expect(result.invocation.queueScheduledAt).toMatchInlineSnapshot(`"2025-01-01T00:00:01.500Z"`)expect(result.logs.map((log) => log.message)).toMatchInlineSnapshot(`[- "HTTP fetch failed on attempt 1 with status code (none). Error: The operation was aborted due to timeout. Retrying in 1500ms.",+ "HTTP fetch failed on attempt 1 with status code (none). Error: The operation was aborted due to timeout. Retrying.",]`)})