Skip to content

Make sure we wake up the task when canceling it - #80

Merged
lalinsky merged 3 commits into
mainfrom
immediate-cancelation
Oct 26, 2025
Merged

lalinsky merged 3 commits into
mainfrom
immediate-cancelation

Conversation

@lalinsky

Copy link
Copy Markdown
Owner

No description provided.

@coderabbitai

coderabbitai Bot commented Oct 26, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

The PR renames Awaitable.requestCancellation() to Awaitable.cancel(), makes cancellation wake any suspended waiter, removes per-instance cancel() on AnyTask and AnyBlockingTask, updates runtime call sites to use awaitable.cancel(), and tightens a cancellation timing test.

Changes

Cohort / File(s) Summary
Core Awaitable API refactor
src/core/Awaitable.zig
Renamed requestCancellation() → cancel(). cancel() now sets the canceled flag and calls wait_node.wake() to wake suspended tasks. Documentation/comments updated to state cancellation is observed at the next yield point.
Runtime integration & public API cleanup
src/runtime.zig
Removed public cancel() methods from AnyTask and AnyBlockingTask. Updated FutureImpl.cancel and JoinHandle.cancel to call awaitable.cancel() (was requestCancellation()). Updated "runtime: sleep is cancelable" test to start a timer before spawning and assert elapsed time after cancellation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Check that the new wait_node.wake() call cannot cause double-wake or race issues with existing wake paths.
  • Verify external code relying on AnyTask.cancel() or AnyBlockingTask.cancel() is updated or still reachable via JoinHandle/FutureImpl.
  • Validate the test timing bounds to avoid flakiness on slow CI.

Possibly related PRs

Poem

Cancel the wait, wake sleepers bold,
A flag is set, the story told.
Tasks stir at the next yield line,
A cleaner call, a sharper sign.
Cheers to code that wakes on time. 🚀

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning No description was provided by the author. An empty description fails to communicate any information about the changeset and does not meet the basic criterion of being "related in some way to the changeset." While the instructions note this check is lenient, a complete absence of description means nothing about the changes is explained, not even at a minimal level. Add at least a brief description explaining the change. Even a sentence or two describing why tasks need to be awakened on cancellation and what problem this solves would satisfy the requirement and help reviewers understand the context faster.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The title "Make sure we wake up the task when canceling it" directly describes the core behavioral change in the PR. The primary modification adds a wait_node.wake() call to the new cancel() method in Awaitable, ensuring suspended tasks are awakened during cancellation rather than remaining blocked. This is specific enough that someone reviewing the commit history would immediately understand the intent and the problem being solved.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch immediate-cancelation

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e485113 and 91f3a35.

📒 Files selected for processing (1)
  • src/core/Awaitable.zig (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test (windows-latest)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 87361dd and e485113.

📒 Files selected for processing (2)
  • src/core/Awaitable.zig (1 hunks)
  • src/runtime.zig (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test (windows-latest)
🔇 Additional comments (4)
src/runtime.zig (4)

406-408: LGTM - API update follows Awaitable changes.

The method correctly delegates to the renamed awaitable.cancel() API.


634-636: LGTM - API update follows Awaitable changes.

The method correctly delegates to the renamed awaitable.cancel() API.


2089-2090: Good test improvement - enables timing verification.

Starting the timer before spawning the task allows measuring the total elapsed time, which is used to verify that cancellation wakes the task immediately rather than letting it sleep for the full duration.


2104-2107: Solid timing validation for immediate cancellation.

The assertion verifies that the 1000ms sleep was interrupted by cancellation within 500ms, confirming that cancel() properly wakes the suspended task. The 500ms threshold provides reasonable margin while still catching failures where cancellation doesn't wake the task.

Comment thread src/core/Awaitable.zig Resolved
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