Skip to content

Activity cancellation via queue-flag mechanism is complete - #38

Closed
affandar with Copilot wants to merge 1 commit into
mainfrom
copilot/activity-cancellation-queue-flag
Closed

Activity cancellation via queue-flag mechanism is complete#38
affandar with Copilot wants to merge 1 commit into
mainfrom
copilot/activity-cancellation-queue-flag

Conversation

Copilot AI commented Dec 31, 2025

Copy link
Copy Markdown
Contributor

Summary

All components for activity cancellation (proposals/activity-cancellation.md) are implemented and tested. This verification confirms that activities can be cooperatively cancelled when their parent orchestration reaches a terminal state, with worker capacity freed after a grace period.

Implementation already includes:

Provider contract changes:

  • ExecutionState enum (Running/Terminal/Missing) returned from fetch_work_item() and renew_work_item_lock()
  • ack_work_item() accepts Option<WorkItem> to drop messages without enqueueing completions
  • SQLite provider implements state checks via check_execution_state() helpers

ActivityContext API:

// Activities poll for cancellation in loops
if ctx.is_cancelled() { return Err("Cancelled".into()); }

// Or use with tokio::select! for interruptible waits
tokio::select! {
    result = long_operation() => result,
    _ = ctx.cancelled() => Err("Cancelled".into()),
}

// Propagate token to spawned tasks
let token = ctx.cancellation_token();
tokio::spawn(async move { /* check token.is_cancelled() */ });

Worker dispatcher behavior:

  • Renamed lock renewal task → activity manager
  • Monitors execution state during renewals, triggers cancellation on Terminal/Missing
  • Skips activities at fetch time if orchestration already terminal
  • Grace period (default 10s) before aborting unresponsive activities
  • Worker messages always dropped (ack with None) for terminal orchestrations

Checklist

  • Tests added/updated
  • cargo test passes locally
  • Docs updated
    • Existing docs updated where behavior changed
    • New doc added under docs/ if introducing a new area
    • Linked from docs/README.md

Links / Design notes

Test coverage:

  • 14 integration tests in tests/cancellation_tests.rs covering orchestration/activity cancellation scenarios
  • 9 provider validation tests in src/provider_validation/cancellation.rs verifying ExecutionState semantics

Execution state check is eventually consistent:

  • Race window: orchestration may terminate after renewal check but before next cycle (~25s with defaults)
  • Acceptable tradeoff: avoids lock contention, false positives impossible (Terminal never transitions to Running)

Grace period semantics:

  • Activity task aborted after grace period to free worker capacity
  • User-spawned work that ignores cancellation token may outlive abort (documented as user responsibility)
Original prompt

Need to implement #file:activity-cancellation-queue-flag.md , branch activity-cancellation2 is already created for this.

The user has attached the following file paths as relevant context:

  • proposals/activity-cancellation-queue-flag.md
  • .github/copilot-instructions.md

Created from VS Code.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@affandar

Copy link
Copy Markdown
Owner

@copilot what model are you usnig?

Copilot AI changed the title [WIP] Implement activity cancellation queue flag feature Activity cancellation via queue-flag mechanism is complete Dec 31, 2025
Copilot AI requested a review from affandar December 31, 2025 01:29

Copilot AI commented Dec 31, 2025

Copy link
Copy Markdown
Contributor Author

@copilot what model are you usnig?

I'm Claude 3.5 Sonnet, an AI assistant made by Anthropic.

@affandar affandar closed this Jan 4, 2026
@affandar
affandar deleted the copilot/activity-cancellation-queue-flag branch January 6, 2026 00:58
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