Skip to content

Raise CancelledError when a Claude Agent SDK Activity is cancelled - #317

Merged
patbeqo merged 1 commit into
mainfrom
patbeqo/quiet-read-cancel
Oct 30, 2026
Merged

patbeqo merged 1 commit into
mainfrom
patbeqo/quiet-read-cancel

Conversation

@patbeqo

@patbeqo patbeqo commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Fixes #316.

When a client closes while its read Activity is running, the Worker logs Fatal error in message reader: Activity cancelled. Nothing fails, but it reads like a crash.

The Claude Agent SDK cancels its read task on close and expects asyncio.CancelledError. TemporalTransport raised the cancelled ActivityError instead. It now raises CancelledError, with the ActivityError as its cause. Temporal treats both as a cancellation, so a cancelled Workflow still ends as Canceled.

Testing

  • New test: closing the client while a read runs logs no error. It fails without the fix.
  • make lint and make test pass (103 tests).
  • The agent_chat sample from Add Claude Agent SDK samples samples-python#403 no longer logs the error on Continue-As-New or at the end of the chat.

The Claude Agent SDK cancels its read task on close and expects
asyncio.CancelledError. A cancelled read Activity raised ActivityError
instead, which the SDK logged as "Fatal error in message reader".

Fixes #316
@patbeqo
patbeqo requested a review from a team as a code owner October 30, 2026 21:39
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T21:41:13.177725Z b989162 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@patbeqo
patbeqo enabled auto-merge (squash) October 30, 2026 21:44
@patbeqo
patbeqo merged commit 637f226 into main Oct 30, 2026
15 checks passed
@patbeqo
patbeqo deleted the patbeqo/quiet-read-cancel branch October 30, 2026 21:45
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.

Claude Agent SDK: closing a client logs "Fatal error in message reader: Activity cancelled"

2 participants