Skip to content

Condition Agent nodes hang 15+ seconds on tiktoken.pages.dev DNS failure - need graceful fallback #5546

@Mordris

Description

@Mordris

Describe the bug

When using OpenAI models (gpt-4o-mini, gpt-3.5-turbo, gpt-4, etc.) in Condition Agent nodes, Flowise attempts to fetch tiktoken tokenizer data from tiktoken.pages.dev for pre-calculation of token counts. When this domain is unreachable due to network restrictions (DNS issues, firewalls, corporate proxies), the node hangs for 15+ seconds with multiple retry attempts before falling back to approximate counting.

This issue is specific to Condition Agent nodes only - regular Agent nodes, QnA nodes, and other specialist agents do not exhibit this behavior because they don't require pre-execution token counting.

Error logs:

flowise | Failed to calculate number of tokens, falling back to approximate count TypeError: fetch failed
flowise | at node:internal/deps/undici/undici:13510:13
flowise | at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
flowise | at async RetryOperation._fn (/usr/local/lib/node_modules/flowise/node_modules/p-retry/index.js:50:12) {
flowise | [cause]: Error: getaddrinfo EAI_AGAIN tiktoken.pages.dev
flowise | at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:122:26) {
flowise | errno: -3001,
flowise | code: 'EAI_AGAIN',
flowise | syscall: 'getaddrinfo',
flowise | hostname: 'tiktoken.pages.dev'
flowise | }
flowise | }

Impact:

  • Response times increase from 2-3 seconds to 15+ seconds
  • Production deployments unusable in corporate/restricted networks
  • Forced to use non-OpenAI models despite licensing/requirements

To Reproduce

  1. Deploy Flowise in an environment where tiktoken.pages.dev is unreachable (corporate network, firewall blocking Cloudflare Pages, DNS restrictions)
  2. Create an agentflow with a Condition Agent node
  3. Configure the Condition Agent to use any OpenAI model (gpt-4o-mini, gpt-3.5-turbo, gpt-4)
  4. Send a message through the agentflow
  5. Observe logs showing repeated DNS failures to tiktoken.pages.dev
  6. Notice 15+ second delay before response is generated

Network diagnostics showing the issue:

# DNS resolution fails
$ docker compose exec flowise nslookup tiktoken.pages.dev
;; connection timed out; no servers could be reached

# But other domains work fine
$ docker compose exec flowise nslookup google.com
Name:   google.com
Address: 142.251.140.46

Important: The issue does NOT occur with:

  • Google Gemini models (gemini-pro, gemini-2.5-flash) in Condition Agent
  • OpenAI models in regular Agent nodes (non-condition)
  • Other specialist agents (QnA, Database Query, etc.)

Expected behavior

Condition Agent nodes should handle tiktoken fetch failures gracefully:

  1. Fast timeout: Fail fast (1-2 seconds max) instead of hanging for 15+ seconds
  2. Immediate fallback: Switch to approximate token counting without blocking
  3. Configuration option: Provide environment variable to disable tiktoken fetching entirely:
    • DISABLE_TIKTOKEN=true
    • USE_APPROXIMATE_TOKENS=true
    • TIKTOKEN_TIMEOUT=1000 (milliseconds)
  4. Graceful degradation: Log warning but continue execution immediately

The node should function normally with approximate token counting when tiktoken is unavailable, similar to how it eventually behaves after the timeout.

Screenshots

flowise     | Failed to calculate number of tokens, falling back to approximate count TypeError: fetch failed
flowise     |     at node:internal/deps/undici/undici:13510:13
flowise     |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
flowise     |     at async RetryOperation._fn (/usr/local/lib/node_modules/flowise/node_modules/p-retry/index.js:50:12) {
flowise     |   [cause]: Error: getaddrinfo EAI_AGAIN tiktoken.pages.dev
flowise     |       at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:122:26) {
flowise     |     errno: -3001,
flowise     |     code: 'EAI_AGAIN',
flowise     |     syscall: 'getaddrinfo',
flowise     |     hostname: 'tiktoken.pages.dev'
flowise     |   }
flowise     | }
flowise     | Failed to calculate number of tokens, falling back to approximate count TypeError: fetch failed
flowise     |     at node:internal/deps/undici/undici:13510:13
flowise     |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
flowise     |     at async RetryOperation._fn (/usr/local/lib/node_modules/flowise/node_modules/p-retry/index.js:50:12) {
flowise     |   [cause]: Error: getaddrinfo EAI_AGAIN tiktoken.pages.dev
flowise     |       at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:122:26) {
flowise     |     errno: -3001,
flowise     |     code: 'EAI_AGAIN',
flowise     |     syscall: 'getaddrinfo',
flowise     |     hostname: 'tiktoken.pages.dev'
flowise     |   }
flowise     | }
Image Image

Flow

Issue test Agents.json

Use Method

Docker

Flowise Version

3.0.11

Operating System

None

Browser

None

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions