-
Notifications
You must be signed in to change notification settings - Fork 258
fix request timeout for openai-compatible providers #1423
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
Forsakenrox
wants to merge
5
commits into
Zoo-Code-Org:main
Choose a base branch
from
Forsakenrox:fix-request-timeout
base: main
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.
+63
−6
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cefb1c0
fix request timeout for openai-compatible providers
Forsakenrox 92f5bea
Merge branch 'Zoo-Code-Org:main' into fix-request-timeout
Forsakenrox 37a5954
fix types and test pass
Forsakenrox 12d88f2
fix kimi mock
Forsakenrox fca1fa1
Merge branch 'main' into fix-request-timeout
Forsakenrox 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
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
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.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: Zoo-Code-Org/Zoo-Code
Length of output: 12410
🏁 Script executed:
Repository: Zoo-Code-Org/Zoo-Code
Length of output: 33059
🏁 Script executed:
Repository: Zoo-Code-Org/Zoo-Code
Length of output: 25442
🌐 Web query:
Nock 14 disableNetConnect Node fetch undici support official documentation💡 Result:
Nock version 14 introduces support for native Node.js fetch and includes basic support for Undici, allowing you to use Nock's mocking capabilities with these modern HTTP clients [1][2][3]. Regarding the specific components of your query: 1. disableNetConnect Support: Nock's
disableNetConnect()function is the standard method for forbidding unmocked HTTP requests [4][5]. In Nock v14, this functionality is designed to work with the updated interception logic that supports native fetch [6]. WhendisableNetConnect()is active, any request made to a host that is not explicitly mocked will trigger aNetConnectNotAllowedError[4][5]. 2. Undici Support: While Nock traditionally intercepted requests at the Node.js built-inhttpmodule level—which Undici bypasses by using thenetmodule directly [7]—Nock v14 added basic support for Undici [3]. This is achieved by allowing Nock to act as a dispatcher within the Undici ecosystem [3]. 3. Official Documentation: Official guidance on these features is primarily found in the Nock repository's pull request descriptions, release notes, and source code [1][2][3]. Because Undici and native fetch operate differently than traditionalhttprequests, Nock's integration with them is documented through these repository updates rather than a static, separate documentation page [1][8][3]. For users requiring advanced Undici mocking, the recommended approach remains using Undici's nativeMockAgentwhen possible, as it is purpose-built for that library [8][9][7]. If you are using Nock to support legacy and modern fetch/undici requests simultaneously, ensure you are on a recent v14 release [2][10].Citations:
🌐 Web query:
Nock v14 Undici custom dispatcher Agent disableNetConnect native fetch interception💡 Result:
Nock v14 introduced support for native fetch [1] by migrating to
@mswjs/interceptorsfor its interception logic [2]. While Nock v14 has added basic, experimental support for intercepting Undici requests [3], it does not fully replace Undici's native mocking capabilities or handle all custom dispatcher scenarios [4][5]. Regarding your specific requirements: 1. Undici Custom Dispatcher/Agent Interception: Nock v14 provides a NockAgent that attempts to intercept Undici requests by setting the global dispatcher [3]. However, this mechanism can be bypassed if an explicit custom dispatcher or agent is provided to the fetch or Undici request call [4]. In such cases, Nock's global interceptor is ignored because the request bypasses the global dispatcher that Nock has wrapped [4]. 2. disableNetConnect: Nock's nock.disableNetConnect is primarily designed for the standard Node.js http/https modules [6]. Because Undici operates differently—often by design ignoring global monkey-patching in favor of its own dispatcher-based model—nock.disableNetConnect does not reliably block outgoing network requests made through Undici [6][7]. Recommended Approach: For Undici-based code, particularly when using custom dispatchers or agents, it is best practice to use Undici's built-in MockAgent [6][5]. This provides native, reliable mocking and network control without the limitations of Nock's interception layer: const { MockAgent, setGlobalDispatcher } = require('undici'); const mockAgent = new MockAgent; mockAgent.disableNetConnect; // Reliably disables network for Undici requests [8] setGlobalDispatcher(mockAgent); // To handle custom clients/pools, use the mock agent to get an interceptor const mockPool = mockAgent.get('http://example.com'); mockPool.intercept({ path: '/test', method: 'GET' }).reply(200, { data: 'ok' }); If you must use Nock, be aware that it currently supports interception primarily at the global level [3]. If your application architecture requires passing explicit custom dispatchers, you may need to use a manual stubbing workaround (such as using Reflect to force the use of the Nock-managed dispatcher) [4], though this is not officially supported and may be brittle.Citations:
Block real network access in KimiCode tests.
OpenAiHandler.customFetchpasses an explicitundici.Agent, which bypasses Nock's global dispatcher. Therefore,nock.disableNetConnect()does not protect the request-consuming tests that rely on the forwarding mock. Install a default rejectingglobalThis.fetchstub and override it only in tests that need responses, or use an UndiciMockAgent.🤖 Prompt for AI Agents