Skip to content
Source
Sign inSign up
TanStack/ai

ai-durable-stream: accept { runId, offset } like memoryStream does #2226

Openozolcar(GitHub profile, opens in a new tab) opened this issue 2 comments
ozolcar(GitHub profile, opens in a new tab)commented

TanStack AI version

@tanstack/ai 1.8.0, @tanstack/ai-durable-stream 1.0.0 (both latest on npm; durableStream on main has the same signature)

Framework/Library version

Node 26.12.0, server only (no UI framework involved)

Describe the bug and the steps to reproduce it

memoryStream takes plain values: memoryStream(source: Request | MemoryStreamInit) (@tanstack/ai src/stream-durability.ts:331). durableStream takes only a Request: durableStream(request: Request, options) (@tanstack/ai-durable-stream src/durable-stream.ts:472). Pass it the same { runId, offset } and it throws a raw TypeError at construction, before any request, because it reads request.headers.get('Last-Event-ID') and request.headers.get('X-Run-Id').

So a server that builds the durability adapter outside a request handler, for example a run reaper or a retry that replays from the start, has to make a Request only to carry ?runId and ?offset.

Steps:

  1. Install @tanstack/ai@1.8.0 and @tanstack/ai-durable-stream@1.0.0 in an ESM package.
  2. Save the script below as repro.mjs and run node repro.mjs.

repro.mjs:

import { memoryStream } from '@tanstack/ai'
import { durableStream } from '@tanstack/ai-durable-stream'

const init = { runId: 'run-1', offset: '-1' }
let fetchCalls = 0
const options = {
  server: 'http://127.0.0.1:9', // never reached
  fetch: async () => { fetchCalls++; throw new Error('no network') },
}

function attempt(label, make) {
  try {
    console.log(`${label}: ok, resumeFrom() = ${JSON.stringify(make().resumeFrom())}`)
  } catch (error) {
    console.log(`${label}: threw ${error.name}: ${error.message}`)
  }
}

attempt('memoryStream(init)', () => memoryStream(init))
// memoryStream(init): ok, resumeFrom() = "-1"

attempt('durableStream(init)', () => durableStream(init, options))
// durableStream(init): threw TypeError: Cannot read properties of undefined (reading 'get')

attempt('durableStream(Request)', () => durableStream(new Request('http://x/?runId=run-1&offset=-1'), options))
// durableStream(Request): ok, resumeFrom() = "-1"

console.log(`fetch calls: ${fetchCalls}`)
// fetch calls: 0

Expected: durableStream(init) works like memoryStream(init). durableStream accepts Request | { runId, offset } and reads the run id and offset from the plain values.

Inline above. Plain Node script. The fetch option is a stub that throws; it is called 0 times.

Screenshots or Videos (Optional)

None.

Do you intend to try to help solve this bug with your own PR?

Maybe, I'll investigate and start debugging

Terms & Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
  1. Thanks for the report, @ozolcar! To help us reproduce this, could you add a minimal reproduction?

    A runnable example makes fixes dramatically faster — you can fork one of the official examples, or use StackBlitz / CodeSandbox. For TypeScript-only issues, a TS Playground link works too.

    Automated triage — a maintainer will follow up.
  2. github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer

  3. I added a minimal, runnable reproduction to the description: a plain Node script with no network, no model and no API key, tested on the current npm releases.

Sign in to join this conversation.