-
Notifications
You must be signed in to change notification settings - Fork 3.8k
fix(providers): bound a non-streaming request with an explicit 10-minute deadline #6304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
waleedlatif1
wants to merge
1
commit into
staging
Choose a base branch
from
fix/provider-request-deadline
base: staging
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+138
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| /** | ||
| * @vitest-environment node | ||
| * | ||
| * A non-streaming generation is silent on the wire until it finishes, so nothing but an | ||
| * explicit deadline can bound it. A streaming one emits continuously and must NOT carry | ||
| * a total deadline, or a long answer still arriving normally gets cut off. | ||
| */ | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
| import { executeResponsesProviderRequest } from '@/providers/openai/core' | ||
| import { PROVIDER_REQUEST_TIMEOUT_MS } from '@/providers/timeouts' | ||
| import type { ProviderRequest } from '@/providers/types' | ||
|
|
||
| vi.mock('@/providers', () => ({ MAX_TOOL_ITERATIONS: 5 })) | ||
|
|
||
| vi.mock('@/providers/utils', () => ({ | ||
| isFunctionToolCall: () => false, | ||
| calculateCost: () => ({ input: 0, output: 0, total: 0 }), | ||
| sumToolCosts: () => 0, | ||
| enforceStrictSchema: (schema: unknown) => schema, | ||
| prepareToolExecution: () => ({ toolParams: {}, executionParams: {} }), | ||
| prepareToolsWithUsageControl: (tools: unknown[]) => ({ | ||
| tools, | ||
| toolChoice: undefined, | ||
| forcedTools: [], | ||
| hasFilteredTools: false, | ||
| }), | ||
| trackForcedToolUsage: () => ({ hasUsedForcedTool: false, usedForcedTools: [] }), | ||
| supportsReasoningEffort: () => false, | ||
| })) | ||
|
|
||
| const COMPLETED = { | ||
| id: 'resp_1', | ||
| status: 'completed', | ||
| output: [{ type: 'message', role: 'assistant', content: [{ type: 'output_text', text: 'ok' }] }], | ||
| usage: { input_tokens: 1, output_tokens: 1, total_tokens: 2 }, | ||
| } | ||
|
|
||
| describe('provider request deadline', () => { | ||
| const logger = { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() } as never | ||
|
|
||
| beforeEach(() => vi.clearAllMocks()) | ||
|
|
||
| function run(fetchMock: unknown, request: Partial<ProviderRequest> = {}) { | ||
| return executeResponsesProviderRequest( | ||
| { apiKey: 'k', model: 'gpt-5.5', messages: [{ role: 'user', content: 'hi' }], ...request }, | ||
| { | ||
| providerId: 'openai', | ||
| providerLabel: 'OpenAI', | ||
| modelName: 'gpt-5.5', | ||
| endpoint: 'https://api.openai.com/v1/responses', | ||
| headers: { Authorization: 'Bearer k' }, | ||
| logger, | ||
| fetch: fetchMock as typeof fetch, | ||
| } | ||
| ) | ||
| } | ||
|
|
||
| function okResponse() { | ||
| return { ok: true, status: 200, headers: new Headers(), json: () => Promise.resolve(COMPLETED) } | ||
| } | ||
|
|
||
| /** Ten minutes, matching the OpenAI client's own documented default. */ | ||
| it('matches the vendor default rather than inventing a number', () => { | ||
| expect(PROVIDER_REQUEST_TIMEOUT_MS).toBe(600_000) | ||
| }) | ||
|
|
||
| it('arms a deadline on a non-streaming request', async () => { | ||
| const fetchMock = vi.fn().mockResolvedValue(okResponse()) | ||
| await run(fetchMock) | ||
|
|
||
| const signal = fetchMock.mock.calls[0][1].signal as AbortSignal | ||
| expect(signal).toBeInstanceOf(AbortSignal) | ||
| expect(signal.aborted).toBe(false) | ||
| }) | ||
|
|
||
| /** | ||
| * The runtime's idle timer already bounds a stalled stream correctly. A total deadline | ||
| * here would kill a long answer that is still arriving. | ||
| */ | ||
| it('does not arm a deadline on a streaming request', async () => { | ||
| const fetchMock = vi.fn().mockResolvedValue(okResponse()) | ||
| await run(fetchMock, { stream: true }).catch(() => {}) | ||
|
|
||
| const streamCall = fetchMock.mock.calls.find( | ||
| (c) => JSON.parse(c[1].body as string).stream === true | ||
| ) | ||
| expect(streamCall).toBeDefined() | ||
| expect(streamCall?.[1].signal).toBeUndefined() | ||
| }) | ||
|
|
||
| /** A user pressing Stop must still win over the deadline. */ | ||
| it('preserves the caller signal alongside the deadline', async () => { | ||
| const controller = new AbortController() | ||
| const fetchMock = vi.fn().mockResolvedValue(okResponse()) | ||
| await run(fetchMock, { abortSignal: controller.signal }) | ||
|
|
||
| const signal = fetchMock.mock.calls[0][1].signal as AbortSignal | ||
| expect(signal.aborted).toBe(false) | ||
| controller.abort() | ||
| expect(signal.aborted).toBe(true) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| /** | ||
| * Deadline for a single non-streaming provider request, matching the OpenAI client's own | ||
| * documented default (`node_modules/openai/client.d.ts`: `[opts.timeout=10 minutes]`). | ||
| * | ||
| * Without an explicit value the request inherits whatever the runtime imposes — under Bun | ||
| * that is an undocumented ~300s idle timer, half the vendor's default and chosen by nobody. | ||
| * Measured production failures at 295.8s and 278.9s were generations still in progress, not | ||
| * stalled connections. | ||
| * | ||
| * Deliberately its own module rather than the `@/providers` barrel: that barrel is replaced | ||
| * wholesale by `vi.mock` in 21 test files, so an export added there resolves to `undefined` | ||
| * in all of them. | ||
| */ | ||
| export const PROVIDER_REQUEST_TIMEOUT_MS = 600_000 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deadline ignored by Bun idle timer
High Severity
On Bun 1.3.14,
AbortSignal.timeoutdoes not outrank the runtime's ~300s idlefetchlimit, so silent non-streaming generations can still die around five minutes—the failure mode this change aims to fix. The new 600s deadline never becomes the effective bound unless that idle timer is disarmed on the request.Additional Locations (1)
apps/sim/providers/openai/core.ts#L424-L432Reviewed by Cursor Bugbot for commit db40573. Configure here.