Skip to content

[V4] Schedule 2#95

Merged
ConorWilliams merged 33 commits intomodulesfrom
v4-schedule-2
Apr 20, 2026
Merged

[V4] Schedule 2#95
ConorWilliams merged 33 commits intomodulesfrom
v4-schedule-2

Conversation

@ConorWilliams
Copy link
Copy Markdown
Owner

@ConorWilliams ConorWilliams commented Apr 19, 2026

Summary by CodeRabbit

  • New Features

    • Added operation_cancelled_error exception for cancelled operations.
    • Added root_alloc_error exception when coroutine frame exceeds buffer capacity.
    • Added [[nodiscard]] attribute to stop_source::token() method.
  • Bug Fixes

    • Improved control flow in suspension finalization for more reliable state release.
    • Enhanced cancellation handling to prevent rethrow issues during finalization.
  • Tests

    • Expanded cancellation stress testing with concurrent scenarios.
    • Added test coverage for large argument scheduling and buffer allocation errors.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 19, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e1f3e022-4bb4-420a-9a69-8ad69f18c0bc

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch v4-schedule-2

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.

@ConorWilliams ConorWilliams changed the base branch from main to modules April 19, 2026 20:34
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/core/receiver.cxx`:
- Around line 167-173: The current stop_source() function returns a reference
into shared receiver state which can dangle if another thread consumes the
receiver via get(); change the API to avoid returning a borrowed cancellation
source: either (preferred) return an owning stop_source by value from
stop_source() (copy or move m_state->stop into the returned object) so the
returned handle keeps the necessary state alive, or expose a new request_stop()
method on the receiver that forwards to m_state->stop.request_stop() without
exposing internal references; update callers to take the owning stop_source or
call request_stop() and remove any code that stores a reference to
m_state->stop.
- Around line 197-200: The code currently checks state->stop.stop_requested()
after wait() and may throw operation_cancelled_error even when a result
completed; to fix, capture the completed snapshot in the producer (root_pkg)
before calling recv->ready.test_and_set(): record the final
state/result/exception and a cancellation flag or set an exception field on
root_pkg, then call ready.test_and_set(); update get() to consume that recorded
snapshot from root_pkg (instead of re-querying state->stop) so a stop requested
after completion does not discard a valid result; ensure this touches the
producer-side path that signals readiness (root_pkg /
recv->ready.test_and_set()) and the consumer get() path that currently throws on
state->stop.stop_requested().

In `@src/core/root.cxx`:
- Around line 51-55: The coroutine allocator rejects frames larger than the
embedded buffer but is missing aligned allocation overloads, so add operator
new(std::size_t, std::align_val_t) and matching operator delete(std::size_t,
std::align_val_t) that check the incoming alignment against k_new_align and
throw or otherwise signal root_alloc_error when alignment > k_new_align (use the
same error type and semantics as the existing scalar operator new used around
recv->buffer and root_alloc_error). Ensure the aligned delete overloads mirror
behavior of the non-aligned delete, and add a unit test that schedules an
over-aligned callable or argument (causing an alignment > k_new_align) to
confirm the allocator rejects it with root_alloc_error.

In `@test/src/cancel.cpp`:
- Around line 413-415: The test uses sc.join() and task<void> but leaves
sentinel updates (count.fetch_add(10000,...)) unchecked; change the stress
helper(s) that perform cancel_source-driven joins to return a bool or an integer
count instead of task<void>, have the helper set/return a value indicating the
sentinel was hit (e.g., true/1 only when count.fetch_add would have been
called), and update callers to await the task result and assert the sentinel was
not hit (assert returned bool is false or returned count is 0). Locate uses
around sc.join(), cancel_source, and count.fetch_add and adjust both the helper
signature and all call sites (including the other instances noted) so the test
fails if the “should not be reached” path executes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1b2b56e5-7023-4a8f-ae57-1c8d36568913

📥 Commits

Reviewing files that changed from the base of the PR and between 74b7eaf and 01496a6.

📒 Files selected for processing (8)
  • src/core/concepts/scheduler.cxx
  • src/core/promise.cxx
  • src/core/receiver.cxx
  • src/core/root.cxx
  • src/core/schedule.cxx
  • src/core/stop.cxx
  • test/src/cancel.cpp
  • test/src/schedule.cpp

Comment thread src/core/receiver.cxx
Comment thread src/core/receiver.cxx
Comment thread src/core/root.cxx
Comment thread test/src/cancel.cpp
@ConorWilliams ConorWilliams marked this pull request as ready for review April 20, 2026 18:24
@ConorWilliams ConorWilliams merged commit 56eec7d into modules Apr 20, 2026
7 of 10 checks passed
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