Skip to content

Add guard for request handling - #2475

Draft
shariarriday wants to merge 2 commits into
mainfrom
topic/shariarriday/sub-request-improvement
Draft

shariarriday wants to merge 2 commits into
mainfrom
topic/shariarriday/sub-request-improvement

Conversation

@shariarriday

Copy link
Copy Markdown
Member

Relates #2471

Copilot AI 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.

Pull request overview

Defines and enforces request(0) as a no-op across CAF flow subscriptions.

Changes:

  • Documents the zero-demand contract.
  • Guards affected operators from scheduling work or changing state.
  • Adds regression tests for key operators.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
CHANGELOG.md Records the behavior fix.
manual/core/DataFlows.rst Documents zero-demand semantics.
libcaf_core/caf/flow/subscription.hpp Filters zero-demand requests centrally.
libcaf_core/caf/detail/stream_bridge.cpp Ignores zero bridge demand.
libcaf_core/caf/flow/op/buffer.hpp Prevents zero-demand scheduling.
libcaf_core/caf/flow/op/cache.hpp Prevents zero-demand updates.
libcaf_core/caf/flow/op/cell.hpp Avoids registering zero-demand listeners.
libcaf_core/caf/flow/op/cell.test.cpp Tests cell behavior.
libcaf_core/caf/flow/op/from_generator.hpp Prevents zero-demand runs.
libcaf_core/caf/flow/op/from_resource.hpp Ignores zero resource demand.
libcaf_core/caf/flow/op/from_steps.hpp Ignores zero step demand.
libcaf_core/caf/flow/op/interval.cpp Prevents timer arming and underflow.
libcaf_core/caf/flow/op/interval.test.cpp Tests interval behavior.
libcaf_core/caf/flow/op/mcast.test.cpp Tests multicast behavior.
libcaf_core/caf/flow/op/merge.hpp Guards merge requests.
libcaf_core/caf/flow/op/prefix_and_tail.hpp Guards prefix demand.
libcaf_core/caf/flow/op/ucast.hpp Guards unicast demand.
libcaf_core/caf/flow/op/ucast.test.cpp Tests unicast behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread libcaf_core/caf/flow/op/merge.hpp Outdated
@codecov

codecov Bot commented Aug 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 36.36364% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.14%. Comparing base (8379b1b) to head (6cf4ed5).
⚠️ Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
libcaf_core/caf/flow/op/buffer.hpp 0.00% 1 Missing ⚠️
libcaf_core/caf/flow/op/cache.hpp 0.00% 1 Missing ⚠️
libcaf_core/caf/flow/op/cell.hpp 50.00% 1 Missing ⚠️
libcaf_core/caf/flow/op/from_generator.hpp 0.00% 1 Missing ⚠️
libcaf_core/caf/flow/op/merge.hpp 0.00% 1 Missing ⚠️
libcaf_core/caf/flow/op/ucast.hpp 0.00% 1 Missing ⚠️
libcaf_core/caf/flow/subscription.hpp 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2475      +/-   ##
==========================================
- Coverage   73.30%   73.14%   -0.17%     
==========================================
  Files         645      657      +12     
  Lines       30836    31433     +597     
  Branches     3385     3446      +61     
==========================================
+ Hits        22605    22992     +387     
- Misses       6319     6480     +161     
- Partials     1912     1961      +49     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@shariarriday
shariarriday force-pushed the topic/shariarriday/sub-request-improvement branch from d223eae to fe7615f Compare August 30, 2026 11:49
@shariarriday
shariarriday force-pushed the topic/shariarriday/sub-request-improvement branch from fe7615f to a3f75a8 Compare August 30, 2026 13:31
@shariarriday
shariarriday requested a review from Neverlord August 30, 2026 14:23
@shariarriday
shariarriday marked this pull request as ready for review September 1, 2026 18:43
void request(size_t n) {
pimpl_->request(n);
if (n > 0)
pimpl_->request(n);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think we need any other check besides this one, or can you find a counter-example (outside of tests) where we hold a pointer directly instead of going through a subscription? As it stands, I think the checks inside the operators are purely redundant. Maybe we can put a CAF_ASSERT into the operators.

Comment thread libcaf_core/caf/flow/subscription.hpp Outdated
Comment on lines +42 to +44
/// Signals demand for `n` more items. Calling this member function with
/// `n == 0` is a no-op: it neither adds demand nor triggers any observable
/// side effect such as arming a timer or scheduling work.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
/// Signals demand for `n` more items. Calling this member function with
/// `n == 0` is a no-op: it neither adds demand nor triggers any observable
/// side effect such as arming a timer or scheduling work.
/// Signals demand for `n` more items.
/// @pre `n > 0`

We enforce this in the request on the subscription object. Hence, we don't need to re-check in every single implementation (except maybe putting a CAF_ASSERT).

}
}

SCENARIO("requesting zero items from a cell is a no-op") {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please think about what you are testing here. There's an assert in the cell for n > 0. The only reason this doesn't crash is because subscription will discard any request with n == 0 and not forward it to the implementation. This test doesn't add any useful coverage. The other new tests probably as well. Please make a pass over the PR to see what's actually worth keeping. Then rebase and squash.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, there are still some pending issues and I did not re-request the PR review for that reason. I am converting the PR to draft for now to avoid confusion.

@shariarriday
shariarriday marked this pull request as draft September 24, 2026 15: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.

3 participants