Skip to content

fix(think): a recovery attempt runs outside the turn its run was started in (F29) - #3491

Closed
mattzcarey wants to merge 2 commits into
mainfrom
slim/turn-task-f29
Closed

mattzcarey wants to merge 2 commits into
mainfrom
slim/turn-task-f29

Conversation

@mattzcarey

@mattzcarey mattzcarey commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Think's chat recovery attempt now runs outside the context of the turn whose run carries it, so continueLastTurn in a recovery no longer fails with "cannot be called from inside an active turn".

A stalled turn could be given up with recovery_error now and then:

  • a turn's Task run is started from inside that turn, so everything the run does afterwards inherits the turn's async context
  • the recovery attempt runs in that same run after the turn; when the run was resumed in the isolate and not from the alarm, the attempt still had the turn's context and the turn-admission guard refused it
  • seen once in CI (chat-recovery-public, "gives a stalled turn up at stall maxAttempts + 1…"); not in a release, where an attempt was a run of its own started from the alarm

Tests ran: think-session.test.ts, chat-recovery-public.test.ts, channel-recovery.test.ts and empty-reply.test.ts on the class. The new test starts a recovery run from inside a turn and failed before the fix; it is class-only (the harness-backed Think has no attempt callback).

Cost: none. How to probe: stall a Think turn with chatRecovery on (a model stream that goes quiet past chatStreamStallTimeoutMs), many times; no turn ends with recovery_error and "cannot be called from inside an active turn" does not appear in the logs.


Devin Review

@changeset-bot

changeset-bot Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 046e2e9

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

devin-ai-integration[bot]

This comment was marked as resolved.

@pkg-pr-new

pkg-pr-new Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

agents

npm i https://pkg.pr.new/agents@3491

@cloudflare/ai-chat

npm i https://pkg.pr.new/@cloudflare/ai-chat@3491

@cloudflare/codemode

npm i https://pkg.pr.new/@cloudflare/codemode@3491

hono-agents

npm i https://pkg.pr.new/hono-agents@3491

@cloudflare/shell

npm i https://pkg.pr.new/@cloudflare/shell@3491

@cloudflare/think

npm i https://pkg.pr.new/@cloudflare/think@3491

@cloudflare/voice

npm i https://pkg.pr.new/@cloudflare/voice@3491

@cloudflare/worker-bundler

npm i https://pkg.pr.new/@cloudflare/worker-bundler@3491

commit: 046e2e9

@agent-think

agent-think Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

✅ agents import sizes: no significant changes (372822c4 → 046e2e90, workflow run)

@mattzcarey
mattzcarey marked this pull request as draft November 27, 2026 16:51
@mattzcarey
mattzcarey marked this pull request as ready for review November 27, 2026 16:51
devin-ai-integration[bot]

This comment was marked as resolved.

@mattzcarey
mattzcarey force-pushed the slim/turn-task-f29 branch 3 times, most recently from 046e2e9 to 200b308 Compare November 28, 2026 14:32
@mattzcarey

Copy link
Copy Markdown
Member Author

Replaced by #3503, which carries this change with the rest of its unit, integrated and tested together.

@mattzcarey mattzcarey closed this Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant