Skip to content

Conversation

@ashenfad
Copy link
Owner

@ashenfad ashenfad commented Dec 29, 2025

This PR adds basic task cancellation.

@ashenfad ashenfad requested a review from Copilot December 29, 2025 07:05
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds task cancellation functionality to the agex framework. Long-running tasks can now be gracefully stopped by calling .cancel() on the task wrapper, which writes a cancellation sentinel to the state store that the task loop checks between iterations.

Key changes:

  • Added TaskCancelled exception and CancelledEvent for cancellation signaling
  • Implemented .cancel() method on task wrappers with cross-process support via raw KV store access
  • Added iteration-level cancellation checks in both sync and async task loops

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/agex/test_cancellation.py Comprehensive test suite covering cancellation scenarios (sync/async, sessions, concurrent execution)
tests/agex/test_agent_state.py Updated exception type for HTTP host state access from RuntimeError to NotImplementedError
tests/agex/test_agent.py Removed namespace prefixes from state key references (simplified state access)
docs/api/view.md Added reference to agent.state() method
docs/api/task.md Added comprehensive documentation for task cancellation feature
docs/api/state.md Added reference to agent.state() for accessing state directly
docs/api/agent.md Added documentation for .state() method with host compatibility table
agex/state/versioned.py Added set_raw(), get_raw(), remove_raw() methods for bypassing versioned commits
agex/host/modal.py Implemented state() method for Modal host to enable client-side state access
agex/host/local.py Implemented state() method for Local host (delegates to resolve_state)
agex/host/base.py Added abstract state() method to Host base class
agex/agent/task.py Added cancel() method to TaskWrapper for requesting task cancellation
agex/agent/loop/sync_loop.py Added cancellation checks at iteration start and removed namespace prefix
agex/agent/loop/common.py Added check_cancellation() helper and removed namespacing from state initialization
agex/agent/loop/async_loop.py Added cancellation checks at iteration start and removed namespace prefix
agex/agent/events.py Added CancelledEvent event type with rich formatting
agex/agent/datatypes.py Added TaskCancelled exception dataclass
agex/agent/base.py Updated state() method to use host's state access instead of Local-only restriction
agex/init.py Exported TaskCancelled and CancelledEvent

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ashenfad ashenfad merged commit 4b5feca into main Dec 29, 2025
7 checks passed
@ashenfad ashenfad deleted the nxt branch December 29, 2025 07:47
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.

2 participants