Skip to content
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
790c355
First response status changes for browser batch mode
MichaelGHSeg Jan 16, 2026
7ad65bb
Improving tests for batch dispatcher
MichaelGHSeg Jan 23, 2026
e92f798
More fetch dispatcher tests
MichaelGHSeg Jan 23, 2026
c860e62
Prospective change for updating 429 for Oauth endpoint - can be scale…
MichaelGHSeg Jan 23, 2026
0944201
Fixing browser oversize on retry issue, node response changes plus tests
MichaelGHSeg Jan 26, 2026
b32bf2a
Fixing timeouts and batching behavior
MichaelGHSeg Jan 29, 2026
ebd7f53
Updates for OAuth Token, fixing LIBRARIES-2977 and using updated Retr…
MichaelGHSeg Jan 29, 2026
31e275d
Always send X-Retry-Count and Authorization headers
MichaelGHSeg Feb 11, 2026
53bc05d
Add Retry-After cap and fix 413 handling
MichaelGHSeg Feb 11, 2026
7952be8
Fix node publisher to always send X-Retry-Count header
MichaelGHSeg Feb 12, 2026
ab34a07
Standardize backoff timing: 100ms min, 60s max
MichaelGHSeg Feb 12, 2026
de855e9
Increase default maxRetries to 1000
MichaelGHSeg Feb 12, 2026
937b970
Fix test failures from maxRetries increase to 1000
MichaelGHSeg Feb 12, 2026
2272886
Fix batched-dispatcher to flush remaining events after batch splits
MichaelGHSeg Feb 13, 2026
39495a0
Fix batched-dispatcher concurrency and flush issues
MichaelGHSeg Feb 13, 2026
369f01b
Cap Retry-After retries, fix maxRetries default, fix tests
MichaelGHSeg Feb 13, 2026
f0f8dc6
Fix CI test failures from backoff and header changes
MichaelGHSeg Feb 18, 2026
8533626
Guard against negative Retry-After and clockSkew values, add safety c…
MichaelGHSeg Feb 18, 2026
a08e4cb
Remove unused Jest manual mock for analytics-page-tools
MichaelGHSeg Feb 20, 2026
a12de67
Add config-driven status code helpers and wire httpConfig through dis…
MichaelGHSeg Feb 23, 2026
76b26d7
Wire exponential backoff and duration caps into batched dispatcher
MichaelGHSeg Feb 23, 2026
d99dfd8
Implement unified HTTP response handling per SDD (node + browser)
MichaelGHSeg Feb 25, 2026
51a12e5
Refine HTTP response handling: sleep-and-retry for 429, doc fixes
MichaelGHSeg Feb 25, 2026
f8f44c0
Address PR review: SDD comment and test name fixes
MichaelGHSeg Feb 25, 2026
087a8a4
Readjusting token min refresh time
MichaelGHSeg Feb 25, 2026
7ff2791
Addressing PR comments
MichaelGHSeg Feb 25, 2026
0406258
Fix test failures: X-Retry-Count default and 511 without auth
MichaelGHSeg Feb 26, 2026
5a99827
Merge branch 'master' of ssh://github.com/segmentio/analytics-next in…
MichaelGHSeg Feb 26, 2026
ed23808
Wire error event listener in e2e-cli for failure reporting
MichaelGHSeg Feb 26, 2026
c514bc2
Wire error event listener in browser e2e-cli for failure reporting
MichaelGHSeg Feb 26, 2026
9f094b3
Fix browser e2e-cli: replace fixed delay with fetch-based activity mo…
MichaelGHSeg Feb 27, 2026
913eb2c
Fix browser SDK retry behavior for e2e testing
MichaelGHSeg Feb 27, 2026
890ae95
Remove redundant HTTP patch step from browser e2e workflow
MichaelGHSeg Feb 27, 2026
a4ff990
Addressing PR comments
MichaelGHSeg Feb 27, 2026
5e675e2
Consolidate backoff parameters: 500ms base, 60s max, 10 retries
MichaelGHSeg Mar 4, 2026
3068e19
Fixing status code override handling
MichaelGHSeg Mar 17, 2026
e6b7c21
Support httpConfig from CDN settings with deep-merge
MichaelGHSeg Mar 18, 2026
8ead560
Enable retry and retry-settings test suites for browser
MichaelGHSeg Mar 18, 2026
822e663
Move httpConfig deep-merge into resolveHttpConfig, respect retryQueue
MichaelGHSeg Mar 18, 2026
330f2ab
Increase OAuth test timeout for new backoff parameters
MichaelGHSeg Mar 18, 2026
439ee12
Merge branch 'master' into response-status-updates
MichaelGHSeg Mar 18, 2026
91491b1
Omit X-Retry-Count header on first attempt, send only on retries
MichaelGHSeg Mar 20, 2026
ea499e8
fix: Enable retry suite for Node e2e-cli
MichaelGHSeg Mar 24, 2026
154373e
fix: Use local SDK in Node e2e-cli instead of published npm package
MichaelGHSeg Mar 27, 2026
0acf0f4
fix: Trim browser bundle size and increase flaky test timeout
MichaelGHSeg Mar 27, 2026
5661fff
Addressing PR comments
MichaelGHSeg Apr 8, 2026
7652157
Fixing spelling
MichaelGHSeg Apr 8, 2026
25271b3
fix: address Copilot review — correct totalAttempts counting and drop…
MichaelGHSeg Apr 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/browser/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ module.exports = createJestTSConfig(__dirname, {
modulePathIgnorePatterns: ['<rootDir>/e2e-tests', '<rootDir>/qa'],
setupFilesAfterEnv: ['./jest.setup.js'],
testEnvironment: 'jsdom',
moduleNameMapper: {
'^@segment/analytics-page-tools$': '<rootDir>/../page-tools/src',
},
coverageThreshold: {
global: {
branches: 0,
Expand Down
10 changes: 6 additions & 4 deletions packages/browser/src/browser/__tests__/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1603,9 +1603,11 @@ describe('setting headers', () => {
const [call] = fetchCalls.filter((el) =>
el.url.toString().includes('api.segment.io')
)
expect(call.headers).toEqual({
'Content-Type': 'text/plain',
'X-Test': 'foo',
})
expect(call.headers).toEqual(
expect.objectContaining({
'Content-Type': 'text/plain',
'X-Test': 'foo',
})
)
})
})
28 changes: 28 additions & 0 deletions packages/browser/src/core/__mocks__/analytics-page-tools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export type PageContext = Record<string, unknown>
export type BufferedPageContext = PageContext

export const BufferedPageContextDiscriminant = 'buffered' as const

export function getDefaultPageContext(): PageContext {
return {}
}

export function getDefaultBufferedPageContext(): BufferedPageContext {
return {}
}

export function createPageContext(ctx: Partial<PageContext> = {}): PageContext {
return { ...ctx }
}

export function createBufferedPageContext(
ctx: Partial<BufferedPageContext> = {}
): BufferedPageContext {
return { ...ctx }
}

export function isBufferedPageContext(
_ctx: unknown
): _ctx is BufferedPageContext {
return false
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { backoff } from '../backoff'

describe('backoff', () => {
it('increases with the number of attempts', () => {
expect(backoff({ attempt: 1 })).toBeGreaterThan(1000)
expect(backoff({ attempt: 2 })).toBeGreaterThan(2000)
expect(backoff({ attempt: 3 })).toBeGreaterThan(3000)
expect(backoff({ attempt: 4 })).toBeGreaterThan(4000)
expect(backoff({ attempt: 1 })).toBeGreaterThan(200)
expect(backoff({ attempt: 2 })).toBeGreaterThan(400)
expect(backoff({ attempt: 3 })).toBeGreaterThan(800)
expect(backoff({ attempt: 4 })).toBeGreaterThan(1600)
})

it('accepts a max timeout', () => {
expect(backoff({ attempt: 1, maxTimeout: 3000 })).toBeGreaterThan(1000)
expect(backoff({ attempt: 1, maxTimeout: 3000 })).toBeGreaterThan(200)
expect(backoff({ attempt: 3, maxTimeout: 3000 })).toBeLessThanOrEqual(3000)
expect(backoff({ attempt: 4, maxTimeout: 3000 })).toBeLessThanOrEqual(3000)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('backoffs', () => {
expect(spy).toHaveBeenCalled()

const delay = spy.mock.calls[0][1]
expect(delay).toBeGreaterThan(1000)
expect(delay).toBeGreaterThan(200)
})

it('increases the delay as work gets requeued', () => {
Expand All @@ -147,12 +147,12 @@ describe('backoffs', () => {
queue.pop()

const firstDelay = spy.mock.calls[0][1]
expect(firstDelay).toBeGreaterThan(1000)
expect(firstDelay).toBeGreaterThan(200)

const secondDelay = spy.mock.calls[1][1]
expect(secondDelay).toBeGreaterThan(2000)
expect(secondDelay).toBeGreaterThan(400)

const thirdDelay = spy.mock.calls[2][1]
expect(thirdDelay).toBeGreaterThan(3000)
expect(thirdDelay).toBeGreaterThan(800)
})
})
11 changes: 3 additions & 8 deletions packages/browser/src/lib/priority-queue/backoff.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
type BackoffParams = {
/** The number of milliseconds before starting the first retry. Default is 500 */
/** The number of milliseconds before starting the first retry. Default is 100 */
minTimeout?: number

/** The maximum number of milliseconds between two retries. Default is Infinity */
/** The maximum number of milliseconds between two retries. Default is 60000 (1 minute) */
maxTimeout?: number

/** The exponential factor to use. Default is 2. */
Expand All @@ -14,11 +14,6 @@ type BackoffParams = {

export function backoff(params: BackoffParams): number {
const random = Math.random() + 1
const {
minTimeout = 500,
factor = 2,
attempt,
maxTimeout = Infinity,
} = params
const { minTimeout = 100, factor = 2, attempt, maxTimeout = 60000 } = params
return Math.min(random * minTimeout * Math.pow(factor, attempt), maxTimeout)
}
Loading