cloudflare / cloudflare/agents-starter

Streamed chat responses are duplicated verbatim (e.g. "HelloHello!!") on fresh scaffold, local dev and production

Open
#157 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
1.3k
Forks
283
PR merge metrics
No merged PRs in 30d

Description

## Title
Streamed chat responses are duplicated verbatim (e.g. "HelloHello!!") on fresh scaffold, local dev and production

## Body

**Summary**

A fresh `npm create cloudflare@latest -- --template=cloudflare/agents-starter` scaffold produces duplicated response text on every chat turn, reproducible in both `npm run dev` (local) and after `npm run deploy` (production). The duplication is a verbatim repeat of the model's output concatenated with no separator, e.g. asking "Say hello in one sentence." returns:

```
HelloHello!!
```

instead of a single `Hello!`.

**Steps to reproduce**

1. `npm create cloudflare@latest my-agent -- --template=cloudflare/agents-starter`
2. `cd my-agent && npm install`
3. Default `src/server.ts` uses `@cf/moonshotai/kimi-k2.7-code`, which 404s with "Model ... is not available on the Workers Free plan" on a free-tier account. Swapped `model:` to `@cf/meta/llama-4-scout-17b-16e-instruct` (per the model used in the Chat Agents docs example) to unblock testing.
4. `npm run dev`, open `http://localhost:5173`, send any message (e.g. "Say hello in one sentence.")
5. Observe duplicated text in the response bubble.
6. `npm run deploy`, repeat step 4 against the live `*.workers.dev` URL — same duplication observed.

**Isolation already done**

- Reproduces with two different models (`@cf/meta/llama-3.3-70b-instruct-fp8-fast` and `@cf/meta/llama-4-scout-17b-16e-instruct`) — not model-specific.
- Reproduces with `resume: false` passed to `useAgentChat` in `app.tsx` — not a resumable-streaming/reconnect artifact.
- Reproduces on a fresh conversation (post-`Clear`) on the very first message — not a multi-turn context-accumulation artifact (though duplication does compound across turns if left unaddressed).
- Reproduces identically on local `wrangler dev`/Vite and on the deployed Worker — not a local-dev-only proxy issue.
- Only one `vite dev` process was running — not a duplicate-process artifact.
- `workers-ai-provider@3.3.1`'s declared peer dependency (`ai: ^6.0.0`) is satisfied by the installed `ai@6.0.197` — not an obvious peer-dependency mismatch.

**Environment**

- `create-cloudflare` 2.71.0
- `wrangler` 4.113.0 (also seen against 4.121.0 during initial scaffold)
- `agents` ^0.17.4
- `ai` ^6.0.197
- `workers-ai-provider` ^3.2.1 (resolved 3.3.1)
- `@cloudflare/ai-chat` ^0.9.3
- Node v26.3.1
- macOS (Darwin 25.5.0)

**Expected behavior**

Streamed response text should appear once, matching the model's actual generation.

**Additional notes**

Given the exact same short greeting duplicates identically in back-to-back tests, this looks more like the response being emitted/appended twice at the `streamText`/`workers-ai-provider` layer than the model genuinely generating the same text twice via independent sampling — but I haven't instrumented the raw SSE/stream chunks to confirm which layer duplicates it.

Contributor guide

Open the contributing guide

Research direction

Read src/server.ts and app.tsx first, then run the fresh scaffold locally and trace one request from useAgentChat through the streamed response. Inspect the raw SSE or stream chunks to identify where the text is appended twice; done means each model response appears once in both local and deployed environments.

Written by the indexing model from the issue text.

Assessment

Tech stack
ai-infra-agents, typescript, vite
Domain
ai, full-stack
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
56/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.