Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 2 additions & 3 deletions packages/sdk/js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ export { type Config as OpencodeClientConfig, OpencodeClient }

export function createOpencodeClient(config?: Config & { directory?: string }) {
if (!config?.fetch) {
const customFetch: any = (req: any) => {
// @ts-ignore
req.timeout = false
const customFetch = (req: Request) => {
;(req as Request & { timeout: boolean }).timeout = false
return fetch(req)
Comment on lines +10 to 12
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🌐 Web query:

Node.js undici fetch request timeout property type

💡 Result:

In Undici's fetch implementation (used in Node.js), there is no direct "timeout" property on the fetch request options (RequestInit). Timeouts are configured via the optional "dispatcher" property, which accepts a Dispatcher instance (e.g., new Agent({ ... })) or similar. The relevant timeout properties on the dispatcher (e.g., Agent or Client constructor options, or DispatchOptions) are of type "number | null": - headersTimeout: number | null (time to receive headers, default 300000 ms) - bodyTimeout: number | null (time between body data, default 300000 ms) - connect.timeout: number (for connection timeout, nested under "connect" option) These are specified in Undici's Dispatcher.DispatchOptions and ClientOptions. Use 0 to disable. For fetch example: fetch(url, { dispatcher: new Agent({ headersTimeout: 10000, bodyTimeout: 10000 }) }) AbortSignal in RequestInit can also be used for overall request abortion, but it's not a numeric timeout property on the request itself.

Citations:


🏁 Script executed:

cat -n packages/sdk/js/src/client.ts | head -30

Repository: AltimateAI/altimate-code

Length of output: 1079


🏁 Script executed:

rg "timeout" packages/sdk/js/src/ -A 3 -B 3

Repository: AltimateAI/altimate-code

Length of output: 6926


🏁 Script executed:

rg "customFetch" packages/sdk/js/src/ -A 3 -B 3

Repository: AltimateAI/altimate-code

Length of output: 1548


🏁 Script executed:

# Check if there are any comments or documentation about this
rg "timeout.*false|false.*timeout" packages/sdk/js/ -A 2 -B 2

Repository: AltimateAI/altimate-code

Length of output: 1877


🏁 Script executed:

git log --oneline -p packages/sdk/js/src/client.ts | grep -A 10 -B 10 "timeout" | head -50

Repository: AltimateAI/altimate-code

Length of output: 713


🏁 Script executed:

# Check if there are any TODOs or comments in the file explaining this
grep -n "TODO\|FIXME\|NOTE\|HACK" packages/sdk/js/src/client.ts

Repository: AltimateAI/altimate-code

Length of output: 50


Remove dead code: timeout property has no effect on Node.js fetch behavior.

Setting timeout = false on the Request object has no effect in Node.js's undici implementation. Timeouts are configured via:

  • AbortSignal in RequestInit (e.g., fetch(req, { signal: controller.signal }))
  • dispatcher option with headersTimeout / bodyTimeout properties
  • Not via a timeout property on the Request object itself

The type assertion Request & { timeout: boolean } masks this non-functional property. This code should either be removed or replaced with proper timeout handling using AbortSignal or dispatcher configuration if timeout control is needed.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/sdk/js/src/client.ts` around lines 10 - 12, The customFetch function
contains dead code: the type assertion and assignment (Request & { timeout:
boolean }).timeout = false have no effect on Node.js/undici fetch; remove that
assertion and assignment from customFetch and either leave customFetch as `const
customFetch = (req: Request) => fetch(req)` or, if you need timeout control,
implement it by accepting RequestInit/AbortSignal (use AbortController.signal)
or configuring an undici dispatcher with headersTimeout/bodyTimeout; update any
callers of customFetch accordingly (refer to the customFetch function and its
Request type assertion).

}
config = {
Expand Down
5 changes: 2 additions & 3 deletions packages/sdk/js/src/v2/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ export { type Config as OpencodeClientConfig, OpencodeClient }

export function createOpencodeClient(config?: Config & { directory?: string; experimental_workspaceID?: string }) {
if (!config?.fetch) {
const customFetch: any = (req: any) => {
// @ts-ignore
req.timeout = false
const customFetch = (req: Request) => {
;(req as Request & { timeout: boolean }).timeout = false
return fetch(req)
}
config = {
Expand Down
Loading