Skip to content

Provider timeout is silently ignored on non-streaming Workers AI calls #131

Closed

Description

@stackbilt-admin

Problem

The timeout option has no effect on non-streaming generateResponse calls through the Workers AI binding. The adapter applies it only when opening a stream.

Reproduction

@stackbilt/[email protected], in a deployed Worker with a real AI binding, on 2026-10-31:

const llm = new LLMProviders({
  cloudflare: { ai: env.AI, maxRetries: 0, timeout: 1 },
  fallbackRules: [],
  stateScope: 'client',
});
await llm.generateResponse({ model, maxTokens: 400, temperature: 0, messages });
Model Result with timeout: 1
@cf/zai-org/glm-5.3-flash Succeeded after 7,803 ms
@cf/openai/gpt-oss-20b Succeeded after 1,244 ms

In source, timeout appears in src/providers/cloudflare.ts only at line 1428, in the streaming path. HTTP providers enforce it through BaseProvider's request method, but the binding call at line 772 has no deadline.

Why it matters

A caller who sets timeout reasonably expects a bound on the call. Here, a stuck binding call has no package-level limit, and nothing signals that the setting was ignored. The README documents that binding calls can't be aborted, and that stream timeouts cover opening only. It doesn't say the non-streaming case has no deadline.

Expected

Race the binding call against timeout and throw TimeoutError, noting that the underlying work can't be cancelled and may still be billed. If that's not wanted, document clearly that timeout doesn't apply to this path.

Relationship to existing issues

Related to the deadline items in #110 and #116, which cover absolute deadlines and non-streaming body deadlines. Filed separately because this is a specific setting with no effect, and has a small fix.

Scope

Two deployed calls, plus reading the source on main. Our application handles this with its own deadline.

Activity

  1. added
    bug
    P2-medium
    on Oct 31, 2026
  2. mikemikimike commented on Oct 31, 2026

    @mikemikimike
    Contributor

    Implemented in PR #132: #132

    Non-streaming Cloudflare Workers AI binding calls now enforce the configured provider timeout and raise TimeoutError when the binding exceeds it. Successful calls clear the timer, and the existing streaming timeout behavior remains unchanged.

    Validated with npm test (791 tests), npm run typecheck, npm run build, and npm run test:worker-import.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2-mediumbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions