Repository navigation
fix(think): return each wait turn's own answer - #2290
Conversation
🦋 Changeset detectedLatest commit: 02d9c45 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
⚪ agents import sizesMeasured 344 runtime imports as minified bundles. The primary size is gzip; raw minified size is included for diagnosis. An existing import growing by more than 10% is marked red. This report is informational.
Compared No import sizes changed. All 344 current runtime imports
Reported by agent-think[bot]. |
agents
@cloudflare/ai-chat
@cloudflare/codemode
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
|
I checked this against current The approach looks right. It uses the same
|
cfa5137 to
02d9c45
Compare
Problem
Two queued
runTurn({ mode: "wait" })calls can both finish successfully while one caller gets the other turn's answer, or no answer at all. The result looked up the session's newest message after the turn queue had released, and by then another turn or a response hook could have changed it.#2341 fixed the submission side of this (
ThinkSubmissionInspection.messageId). This PR fixes the wait side.Fix
Each wait turn records the assistant message it saved, and the result reads back that exact message.
AsyncLocalStorage, the same pattern ascontinuationOutputContext, so the protected override contracts don't change. It wraps both continuation branches (base and overriddencontinueLastTurn)._streamResultwrites the capture. The RPC-callback persist path doesn't.Behaviour change: a completed turn that saves no assistant message (for example, a continuation with only structured output) now returns no
message, instead of the previous assistant message in the session. The changeset calls this out.Validation: there are regression tests for queued wait turns, a queued continuation, a legacy override, a response hook that changes history, a later turn in the inherited context (fails with a single capture slot), aborts, and turns that save nothing. The full Think Workers suite passes apart from two truncation tests in
hooks.test.ts, which fail identically on currentmainlocally.pnpm run checkpasses.Fixes #2243
Fixes #2264