Skip to content

[Bug] A paused search-stream consumer can trigger the upstream raw-byte inactivity timer #8159

Closed

Description

@tackle-me

Client or integration

Routed web-search stream; deterministic streaming-parser reproduction.

Area

Streaming

Summary

parseStreamWithProgress() resets its raw-byte inactivity timer after a read, but leaves it running while a non-terminal event is held in the capacity-one handoff. With highWaterMark: 0, the parser/consumer pause prevents the next upstream read, even when the source already has more bytes queued. The pause can therefore be classified as upstream inactivity.

Related PR #3979 addresses the same distinction for held terminal events. Its source change clears the timer after a terminal; a non-terminal handoff still leaves it armed. The PR is closed with landed-via-maintainer, rather than directly merged.

Reproduction

Save at the repository root as repro-consumer-pause.ts and run bun repro-consumer-pause.ts. No network is used.

import { parseStreamWithProgress } from './src/web-search/progress-stream.ts';
import { createTranslatorBudget } from './src/lib/translator-budget.ts';
const enc = new TextEncoder(), budget = createTranslatorBudget();
const response = new Response(new ReadableStream({ start(c) {
  c.enqueue(enc.encode('{"type":"text_delta","text":"first"}\n' +
    '{"type":"text_delta","text":"second"}\n'));
  c.enqueue(enc.encode('{"type":"done","usage":{"inputTokens":1,"outputTokens":1}}\n'));
  c.close();
} }));
async function* parse(res: Response) {
  const reader = res.body!.getReader(); let buffer = '';
  try { for (;;) {
    const { done, value } = await reader.read(); if (done) break;
    buffer += new TextDecoder().decode(value); let p: number;
    while ((p = buffer.indexOf('\n')) >= 0) {
      const line = buffer.slice(0, p); buffer = buffer.slice(p + 1);
      if (line) yield JSON.parse(line);
    }
  } } finally { reader.releaseLock(); }
}
const iterator = parseStreamWithProgress(response, parse as any,
  { translatorBudget: budget, inactivityTimeoutMs: 25 });
try {
  while ((await iterator.next()).value?.type !== 'text_delta') {}
  await Bun.sleep(65);
  for await (const event of iterator) console.log(event.type);
} catch (error) { console.log((error as Error).name); }
finally { await iterator.return(undefined); budget.dispose(); }

Actual: RoutedModelInactivityError, although all source bytes were queued before the consumer pause. This parser reads incrementally; it does not buffer the entire body with response.text().

Preconditions

The consumer must pause longer than the configured inactivityTimeoutMs. The reproduction deliberately scales this to a 65 ms pause against a 25 ms budget. web-search/index.ts defines a 200,000 ms default routed-model stall budget, but configuration and caller resolution can change the effective value. I have not observed a production consumer pause exceeding its effective budget; this report concerns attribution of the synthetic pause, not the frequency of a live failure.

Expected behavior and resource-lifetime boundary

Distinguish time spent awaiting upstream bytes from time spent waiting for the consumer. Genuine pending reads and repeated zero-byte chunks should still hit the configured inactivity limit, and terminal cleanup should stay bounded.

Pausing this timer during consumer waits also needs a separate downstream-lifetime policy or an existing outer bound, so a consumer that never resumes cannot retain the upstream reader indefinitely. I have not proved such an outer bound for every caller. This report does not propose removing all lifetime protection.

This synthetic failure does not establish that consumer backpressure caused the earlier live upstream-silence incident.

Version

OpenCodex 2.97.0; Bun 1.4.4.

src/web-search/progress-stream.ts matches inspected dev commit ad6a80e5cd5cf347097dbd0572e2410f92e7604b.

Operating system

Windows 10 Pro, x64, build 19045.

Checks

Activity

  1. github-actions commented on Nov 4, 2026

    @github-actions
    Contributor

    Automated translation bookkeeping — detected language: English.

  2. added
    bug
    streaming
    tools
    on Nov 4, 2026
  3. github-actions commented on Nov 4, 2026

    @github-actions
    Contributor

    Issue reopened

    The report now contains the information required by the automated check. Thanks for updating it.

  4. lidge-jun commented on Nov 6, 2026

    @lidge-jun
    Owner

    Fixed on dev by #8213 (650cbc6): a paused search-stream consumer no longer trips the upstream inactivity timer; it has its own deadline and reports 504. It ships in the next release from dev.

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

    bugstreamingtools

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions