Skip to content

Express fold nodes using accumulator nodes#540

Open
knoepfel wants to merge 7 commits into
Framework-R-D:mainfrom
knoepfel:fix-fold-caching
Open

Express fold nodes using accumulator nodes#540
knoepfel wants to merge 7 commits into
Framework-R-D:mainfrom
knoepfel:fix-fold-caching

Conversation

@knoepfel

@knoepfel knoepfel commented Apr 22, 2026

Copy link
Copy Markdown
Member

This PR replaces the caching mechanism for fold results with a similar mechanism as used in #118.


Resolves #359

Code Changes

Core Fold Mechanism Refactoring

  • Implemented new accumulator_node<Result> for per-partition result caching with concurrent cache management
  • Added fold_join_node composite node that wires accumulator nodes with repeater nodes via TBB join logic
  • Refactored declared_fold and fold_node to use partition-layer routing model instead of flush ports
  • Replaced flush-based result eviction with accumulator-driven cache management
  • Updated sendable_type concept with new trait-based implementation supporting both move-constructible and sendable-wrapped types

Index Router Refactoring

  • Simplified multilayer_slot to route index messages only (removed end-token handling)
  • Replaced two-step layer setup (establish_layers() + register_unfold_count_per_input_layer()) with unified finalize() call
  • Introduced establish_layer_hierarchy() to compute layer relationships and unfold metadata with fixed-point calculation
  • Changed multilayer_slots_for() return type to emit end-token entries per slot rather than separate slot references
  • Updated flush callback to materialize end-tokens via committed-count lookup instead of slot-based routing
  • Added helper methods: counting_layer_hashes_under() and deepest_layer_name() for hierarchy traversal

Infrastructure & Model Updates

  • Changed flush_gate to store committed_counts_ as value-based data_cell_counts instead of std::shared_ptr
  • Updated flush_gate method signatures: committed_counts() and roll_up_child() now use reference semantics
  • Extended named_index_port with counting_layer field to distinguish routing layer from counting layer
  • Removed flush_message struct entirely
  • Removed flusher_t type alias and associated TBB flow-graph dependency from phlex/core/fwd.hpp

API Removals & Cleanup

  • Removed store_counters.hpp and store_counters.cpp (cache management logic now in accumulator_node)
  • Removed obsolete public methods from index_router: establish_layers(), register_unfold_count_per_input_layer(), flusher() accessor
  • Removed fold_node inheritance from count_stores class
  • Updated declared_observer.hpp to remove store_counters.hpp include

Variable/Member Cleanup

  • Renamed generator::child_counts_ to child_count_ in declared_unfold for naming consistency
  • Removed obsolete fold node state: flush receiver, join-or-none logic, results caching map
  • Updated make_initializer() to only capture args when index pack is non-empty

Build System

  • Removed compilation of store_counters.cpp from phlex/core/CMakeLists.txt
  • Removed store_counters.hpp from public header installation
  • Added new accumulator CTest target using Catch2 (links against phlex::core_internal)

Tests

  • Added comprehensive accumulator_test.cpp suite covering:
    • Basic accumulation and delayed emission until flush
    • Multi-partition scenarios with interleaved messages
    • Queue/dispatch behavior for out-of-order arrivals
    • Destructor-time warning logging for unflushed accumulators
    • Edge case of zero-count flush on existing partitions
  • Updated flush_gate_test.cpp to use value-based data_cell_counts (removed heap allocation pattern)

Documentation

  • Updated .amazonq/rules/memory-bank/structure.md to reference product_selector.cpp/hpp instead of product_query.cpp/hpp under phlex/core directory organization

@codecov

codecov Bot commented Apr 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.34524% with 19 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
phlex/core/fold_join_node.hpp 80.39% 8 Missing and 2 partials ⚠️
phlex/core/declared_fold.hpp 94.11% 2 Missing ⚠️
phlex/core/detail/accumulator_node.hpp 97.93% 1 Missing and 1 partial ⚠️
phlex/core/framework_graph.cpp 93.93% 1 Missing and 1 partial ⚠️
phlex/core/index_router.cpp 98.13% 1 Missing and 1 partial ⚠️
phlex/model/flush_gate.cpp 83.33% 1 Missing ⚠️
@@            Coverage Diff             @@
##             main     #540      +/-   ##
==========================================
+ Coverage   83.27%   84.09%   +0.81%     
==========================================
  Files         162      167       +5     
  Lines        5912     6625     +713     
  Branches      670      789     +119     
==========================================
+ Hits         4923     5571     +648     
- Misses        796      816      +20     
- Partials      193      238      +45     
Flag Coverage Δ
scripts 78.86% <ø> (+2.49%) ⬆️
unittests 86.53% <94.34%> (-0.32%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
phlex/core/declared_fold.cpp 100.00% <100.00%> (ø)
phlex/core/declared_observer.hpp 100.00% <ø> (ø)
phlex/core/declared_unfold.cpp 100.00% <100.00%> (ø)
phlex/core/declared_unfold.hpp 96.42% <100.00%> (ø)
phlex/core/detail/repeater_node.cpp 98.91% <100.00%> (ø)
phlex/core/fold/send.hpp 100.00% <ø> (ø)
phlex/core/framework_graph.hpp 100.00% <ø> (ø)
phlex/core/index_router.hpp 100.00% <ø> (ø)
phlex/core/message.hpp 100.00% <ø> (ø)
phlex/core/multilayer_join_node.hpp 92.00% <100.00%> (ø)
... and 9 more

... and 9 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0f6474d...0ddf5ee. Read the comment docs.

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

@knoepfel knoepfel force-pushed the fix-fold-caching branch 2 times, most recently from 7a865dc to 3d19c63 Compare April 23, 2026 15:12
@knoepfel knoepfel marked this pull request as draft April 23, 2026 15:12
@knoepfel knoepfel force-pushed the fix-fold-caching branch from 3d19c63 to 530eb15 Compare May 26, 2026 17:34
@greenc-FNAL

greenc-FNAL commented May 26, 2026

Copy link
Copy Markdown
Contributor

31 fixed, 0 new since branch point (0f6474d)
31 fixed, 0 new since previous report on PR (152c172)

✅ 31 CodeQL alerts resolved since the previous PR commit

  • Warning # 196 actions/untrusted-checkout-toctou/critical at .github/workflows/clang-tidy-fix.yaml:109:9 — Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
  • Warning # 197 actions/untrusted-checkout-toctou/critical at .github/workflows/clang-tidy-fix.yaml:137:9 — Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
  • Warning # 198 actions/untrusted-checkout-toctou/critical at .github/workflows/clang-tidy-fix.yaml:157:9 — Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
  • Warning # 199 actions/untrusted-checkout-toctou/critical at .github/workflows/clang-tidy-fix.yaml:201:9 — Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
  • Warning # 200 actions/untrusted-checkout-toctou/critical at .github/workflows/coverage.yaml:166:9 — Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
  • Warning # 201 actions/untrusted-checkout-toctou/critical at .github/workflows/coverage.yaml:188:9 — Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
  • Warning # 202 actions/untrusted-checkout-toctou/critical at .github/workflows/coverage.yaml:207:9 — Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
  • Warning # 203 actions/untrusted-checkout-toctou/critical at .github/workflows/coverage.yaml:226:9 — Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
  • Warning # 204 actions/untrusted-checkout-toctou/critical at .github/workflows/coverage.yaml:251:9 — Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
  • Warning # 205 actions/untrusted-checkout-toctou/critical at .github/workflows/header-guards-fix.yaml:107:9 — Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
    Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
  • Warning # 206 actions/untrusted-checkout-toctou/critical at .github/workflows/markdown-fix.yaml:107:9 — Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
    Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
  • Warning # 207 actions/untrusted-checkout-toctou/critical at .github/workflows/yaml-fix.yaml:108:9 — Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
    Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
  • Warning # 208 actions/untrusted-checkout-toctou/critical at .github/workflows/yaml-fix.yaml:111:9 — Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
    Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
  • Warning # 209 actions/untrusted-checkout-toctou/high at .github/workflows/clang-format-fix.yaml:94:9 — Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
    Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
  • Warning # 210 actions/untrusted-checkout-toctou/high at .github/workflows/cmake-format-fix.yaml:94:9 — Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
    Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
  • Warning # 211 actions/untrusted-checkout-toctou/high at .github/workflows/jsonnet-format-fix.yaml:95:9 — Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
    Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
  • Warning # 212 actions/untrusted-checkout-toctou/high at .github/workflows/python-fix.yaml:94:9 — Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
    Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
  • Warning # 213 actions/untrusted-checkout/high at .github/workflows/clang-format-fix.yaml:94:9 — Checkout of untrusted code in a privileged workflow with later potential execution (event trigger: issue_comment).
    Checkout of untrusted code in a privileged workflow with later potential execution (event trigger: issue_comment).
  • Warning # 214 actions/untrusted-checkout/high at .github/workflows/cmake-format-fix.yaml:94:9 — Checkout of untrusted code in a privileged workflow with later potential execution (event trigger: issue_comment).
    Checkout of untrusted code in a privileged workflow with later potential execution (event trigger: issue_comment).
  • Warning # 215 actions/untrusted-checkout/high at .github/workflows/jsonnet-format-fix.yaml:95:9 — Checkout of untrusted code in a privileged workflow with later potential execution (event trigger: issue_comment).
    Checkout of untrusted code in a privileged workflow with later potential execution (event trigger: issue_comment).
  • ✅ …and 11 more alerts (see Code Scanning for the full list).

✅ 31 CodeQL alerts resolved since the branch point

  • Warning # 196 actions/untrusted-checkout-toctou/critical at .github/workflows/clang-tidy-fix.yaml:109:9 — Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
  • Warning # 197 actions/untrusted-checkout-toctou/critical at .github/workflows/clang-tidy-fix.yaml:137:9 — Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
  • Warning # 198 actions/untrusted-checkout-toctou/critical at .github/workflows/clang-tidy-fix.yaml:157:9 — Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
  • Warning # 199 actions/untrusted-checkout-toctou/critical at .github/workflows/clang-tidy-fix.yaml:201:9 — Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
  • Warning # 200 actions/untrusted-checkout-toctou/critical at .github/workflows/coverage.yaml:166:9 — Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
  • Warning # 201 actions/untrusted-checkout-toctou/critical at .github/workflows/coverage.yaml:188:9 — Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
  • Warning # 202 actions/untrusted-checkout-toctou/critical at .github/workflows/coverage.yaml:207:9 — Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
  • Warning # 203 actions/untrusted-checkout-toctou/critical at .github/workflows/coverage.yaml:226:9 — Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
  • Warning # 204 actions/untrusted-checkout-toctou/critical at .github/workflows/coverage.yaml:251:9 — Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
  • Warning # 205 actions/untrusted-checkout-toctou/critical at .github/workflows/header-guards-fix.yaml:107:9 — Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
    Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
  • Warning # 206 actions/untrusted-checkout-toctou/critical at .github/workflows/markdown-fix.yaml:107:9 — Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
    Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
  • Warning # 207 actions/untrusted-checkout-toctou/critical at .github/workflows/yaml-fix.yaml:108:9 — Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
    Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
  • Warning # 208 actions/untrusted-checkout-toctou/critical at .github/workflows/yaml-fix.yaml:111:9 — Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
    Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
  • Warning # 209 actions/untrusted-checkout-toctou/high at .github/workflows/clang-format-fix.yaml:94:9 — Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
    Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
  • Warning # 210 actions/untrusted-checkout-toctou/high at .github/workflows/cmake-format-fix.yaml:94:9 — Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
    Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
  • Warning # 211 actions/untrusted-checkout-toctou/high at .github/workflows/jsonnet-format-fix.yaml:95:9 — Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
    Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
  • Warning # 212 actions/untrusted-checkout-toctou/high at .github/workflows/python-fix.yaml:94:9 — Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
    Insufficient protection against execution of untrusted code on a privileged workflow (issue_comment).
  • Warning # 213 actions/untrusted-checkout/high at .github/workflows/clang-format-fix.yaml:94:9 — Checkout of untrusted code in a privileged workflow with later potential execution (event trigger: issue_comment).
    Checkout of untrusted code in a privileged workflow with later potential execution (event trigger: issue_comment).
  • Warning # 214 actions/untrusted-checkout/high at .github/workflows/cmake-format-fix.yaml:94:9 — Checkout of untrusted code in a privileged workflow with later potential execution (event trigger: issue_comment).
    Checkout of untrusted code in a privileged workflow with later potential execution (event trigger: issue_comment).
  • Warning # 215 actions/untrusted-checkout/high at .github/workflows/jsonnet-format-fix.yaml:95:9 — Checkout of untrusted code in a privileged workflow with later potential execution (event trigger: issue_comment).
    Checkout of untrusted code in a privileged workflow with later potential execution (event trigger: issue_comment).
  • ✅ …and 11 more alerts (see Code Scanning for the full list).

Review the full CodeQL report for details.

@knoepfel knoepfel marked this pull request as ready for review May 26, 2026 17:39
@knoepfel knoepfel force-pushed the fix-fold-caching branch from 530eb15 to c3caf2f Compare May 26, 2026 20:48
@Framework-R-D Framework-R-D deleted a comment from github-actions Bot May 26, 2026
@knoepfel knoepfel force-pushed the fix-fold-caching branch from c3caf2f to 197de5e Compare May 26, 2026 21:43
@Framework-R-D Framework-R-D deleted a comment from github-actions Bot May 26, 2026
@knoepfel knoepfel force-pushed the fix-fold-caching branch from 197de5e to 10aac8e Compare May 27, 2026 14:41
@Framework-R-D Framework-R-D deleted a comment from github-actions Bot May 27, 2026
@knoepfel knoepfel force-pushed the fix-fold-caching branch 3 times, most recently from 322927f to decf3ae Compare June 2, 2026 20:58
@Framework-R-D Framework-R-D deleted a comment from github-actions Bot Jun 3, 2026
@Framework-R-D Framework-R-D deleted a comment from github-actions Bot Jun 3, 2026
@Framework-R-D Framework-R-D deleted a comment from github-actions Bot Jun 3, 2026
@Framework-R-D Framework-R-D deleted a comment from github-actions Bot Jun 3, 2026
@knoepfel knoepfel force-pushed the fix-fold-caching branch from decf3ae to e7eb445 Compare June 4, 2026 18:27
@Framework-R-D Framework-R-D deleted a comment from github-actions Bot Jun 4, 2026
@knoepfel knoepfel force-pushed the fix-fold-caching branch 2 times, most recently from e564fb3 to 5471faa Compare June 8, 2026 18:24
@Framework-R-D Framework-R-D deleted a comment from github-actions Bot Jun 8, 2026
@knoepfel knoepfel force-pushed the fix-fold-caching branch 2 times, most recently from 34e1b5e to e106e73 Compare June 15, 2026 17:09
@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

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: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: c37275d2-eaeb-4af9-9c79-b8d9f9f3b54d

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:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Replaces the store_counters/flush_message-based fold-result caching with a new accumulator_node + fold_join_node TBB pipeline. declared_fold gains a partition_port and drops count_stores; index_router::finalize() is refactored to carry unfold_data and fold-partition ports explicitly; flush_gate switches committed_counts_ to value semantics; store_counters is deleted.

Changes

Fold pipeline refactor (linked to #359)

Layer / File(s) Summary
sendable_type trait and sendable concept
phlex/core/fold/send.hpp, phlex/core/concepts.hpp
Adds sendable_type_impl/sendable_type<T> alias that selects T when move-constructible or deduces decltype(send(t)); updates the sendable concept to validate sendable_type<T>{t} construction instead of an lvalue send(t) call.
New accumulator_node composite TBB node
phlex/core/detail/accumulator_node.hpp
Introduces detail::accumulator_node<Result>: per-partition concurrent cache keyed by index hash, three-port dispatch (partition / index / flush), queued-id delivery when partition arrives late, cleanup-on-flush with optional sendable_type wrapping, and destructor-time spdlog warnings for un-flushed state.
New fold_join_node composite TBB node
phlex/core/fold_join_node.hpp
Defines fold_join_node<FoldResult, NInputs> wiring accumulator_node + N per-input repeaters into a tag_matching join_node; exposes index_ports() with counting_layer, notify_result_repeater_port(), and receiver_for/input_ports helpers.
declared_fold rewrite
phlex/core/declared_fold.hpp, phlex/core/declared_fold.cpp
Replaces flush_port() pure virtual + count_stores inheritance with partition_port() + partition_layer_; rewrites fold_node constructor around fold_join_node join_ + multifunction_node fold_; introduces apply_fold helper; fixes empty-pack lambda-capture warning.
flush_gate value semantics + store_counters deletion
phlex/model/flush_gate.hpp, phlex/model/flush_gate.cpp, phlex/core/store_counters.hpp, phlex/core/store_counters.cpp, phlex/core/declared_observer.hpp, phlex/core/CMakeLists.txt
Changes committed_counts_ from shared_ptr<data_cell_counts> to a direct value; updates roll_up_child/committed_counts()/commit() to use value semantics; completely removes store_counter/count_stores classes and their build registration.
Message type cleanup
phlex/core/message.hpp, phlex/core/fwd.hpp, phlex/core/multilayer_join_node.hpp
Removes flush_message struct and flusher_t alias; adds counting_layer field to named_index_port with routing-vs-counting documentation; updates multilayer_join_node::index_ports() to populate the new field.
index_router refactor
phlex/core/index_router.hpp, phlex/core/index_router.cpp
Introduces fold_input_port_t, unfold_layer_pair, unfold_data, join_node_slots, flush_spec, end_token_entry; rewrites finalize() signature; replaces establish_layers/register_unfold_count_per_input_layer with establish_layer_hierarchy() fixed-point; simplifies multilayer_slot to message-only routing; rewrites multilayer_slots_for() to return end_token_entries; adds counting_layer_hashes_under and deepest_layer_name helpers; removes flusher() accessor.
framework_graph wiring, tests, minor cleanups
phlex/core/framework_graph.cpp, phlex/core/framework_graph.hpp, test/accumulator_test.cpp, test/flush_gate_test.cpp, test/CMakeLists.txt, phlex/core/declared_unfold.hpp, phlex/core/declared_unfold.cpp, .amazonq/rules/memory-bank/structure.md
Adds framework_graph helpers for fold partition mapping and unfold-layer metadata; replaces finalize_router() call with direct index_router_.finalize(); adds 268-line Catch2 suite for accumulator_node covering basic, multi-partition, out-of-order, destructor-warning, and zero-count scenarios; updates flush_gate_test for value-semantics roll-up; renames child_counts_child_count_ in generator.

Sequence Diagram(s)

sequenceDiagram
  participant FG as framework_graph
  participant IR as index_router
  participant FJN as fold_join_node
  participant AN as accumulator_node
  participant FoldMFN as fold multifunction_node

  rect rgba(100, 149, 237, 0.5)
    note over FG,IR: Graph finalization
    FG->>IR: finalize(layer_paths, unfold_data, provider_ports, fold_partition_ports, join_ports)
    IR->>IR: establish_layer_hierarchy, precompute is_lowest_layer_hashes_
    IR->>IR: wire_provider_index_sets, wire_fold_partition_index_sets
    IR->>IR: build_multilayer_join_slots with flush_specs
  end

  rect rgba(60, 179, 113, 0.5)
    note over IR,FoldMFN: Runtime fold execution
    IR->>AN: index_message to partition_port
    AN->>AN: initialize cached_accumulator, emit pending ids
    IR->>FJN: index_message to data repeater port
    FJN->>FoldMFN: joined tuple of accumulator_message and input product
    FoldMFN->>AN: notify_result_repeater_port, increment call counter
    IR->>AN: indexed_end_token to flush_port
    AN->>AN: decrement counter, check flush received
    AN-->>FJN: release_as_message when counter is zero and flush received
  end
Loading

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.41% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the main architectural change: fold nodes are now implemented using accumulator nodes instead of previous caching mechanisms.
Linked Issues check ✅ Passed The PR directly addresses issue #359 by replacing fold-result caching with accumulator-based mechanism using multilayer_join_node pattern.
Out of Scope Changes check ✅ Passed All changes are directly related to the accumulator-based fold node refactoring. Incidental cleanup (store_counters removal, sendable_type introduction) directly supports the core objective.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@Framework-R-D Framework-R-D deleted a comment from github-actions Bot Jun 15, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@phlex/core/concepts.hpp`:
- Around line 20-21: The `sendable` concept's constraint `sendable_type<T>{t}`
is ill-formed for `std::atomic<T>` types because direct brace-initialization
from an atomic reference is not allowed (e.g., `int{atomic_const_ref}` fails).
Fix this by reverting to the previous constraint approach that used `{ send(t) }
-> std::move_constructible`, which properly handles type conversion through the
`send()` function, or alternatively verify that `sendable_type<T>` exists
without attempting direct initialization.

In `@phlex/core/declared_fold.hpp`:
- Line 149: Remove the unused member variable `initializer_` from the class
definition in declared_fold.hpp. This member variable is default-constructed and
never referenced in the class implementation, making it leftover code. The
`initializer` constructor parameter is already being passed directly to
`make_initializer` and `join_`, so the member variable is not needed. Simply
delete the `InitTuple initializer_;` declaration line.
- Line 157: The member variable `product_count_` in the class is declared with
an accessor but never incremented, unlike the similar implementations in
declared_unfold.hpp and declared_transform.hpp. Either remove the
`product_count_` member variable and its corresponding accessor method if this
metric is not applicable to the fold pipeline design, or implement the logic to
increment `product_count_` at the appropriate point in the fold operation
processing to ensure it actually tracks the product count as intended,
maintaining consistency with the other declared pipeline classes.

In `@phlex/core/detail/accumulator_node.hpp`:
- Around line 295-304: The cleanup_cache_entry method dereferences
entry->accumulator_msg without checking if it is null. When flush_received is
true and counter is zero, but the partition message has not yet arrived,
accumulator_msg remains null, causing a null pointer dereference. Add a null
pointer check for entry->accumulator_msg before calling release_as_message on
it, and only proceed with the try_put and cached_results_.erase operations if
accumulator_msg is not null.

In `@phlex/core/fold_join_node.hpp`:
- Line 67: Fix the typo in the comment on line 67 of the fold_join_node.hpp
file. Change "qacross" to "across" in the comment that describes message
matching behavior. The corrected comment should read "Messages with the same ID
across" instead of "Messages with the same ID qacross".

In `@phlex/core/fold/send.hpp`:
- Around line 27-38: The two specializations of sendable_type_impl can become
ambiguous if a type is both std::move_constructible and has a valid send()
overload. To make these specializations mutually exclusive, add a requires
clause to the first sendable_type_impl specialization (the one that matches
std::move_constructible T) that explicitly excludes types satisfying the send()
requirement. This requires clause should check that the type does not satisfy
the condition in the second specialization, ensuring only one specialization can
match for any given type.
🪄 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: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 26a2d1c9-a41c-4558-90d8-009f33711ab4

📥 Commits

Reviewing files that changed from the base of the PR and between 6ab0734 and e106e73.

📒 Files selected for processing (25)
  • .amazonq/rules/memory-bank/structure.md
  • phlex/core/CMakeLists.txt
  • phlex/core/concepts.hpp
  • phlex/core/declared_fold.cpp
  • phlex/core/declared_fold.hpp
  • phlex/core/declared_observer.hpp
  • phlex/core/declared_unfold.cpp
  • phlex/core/declared_unfold.hpp
  • phlex/core/detail/accumulator_node.hpp
  • phlex/core/fold/send.hpp
  • phlex/core/fold_join_node.hpp
  • phlex/core/framework_graph.cpp
  • phlex/core/framework_graph.hpp
  • phlex/core/fwd.hpp
  • phlex/core/index_router.cpp
  • phlex/core/index_router.hpp
  • phlex/core/message.hpp
  • phlex/core/multilayer_join_node.hpp
  • phlex/core/store_counters.cpp
  • phlex/core/store_counters.hpp
  • phlex/model/flush_gate.cpp
  • phlex/model/flush_gate.hpp
  • test/CMakeLists.txt
  • test/accumulator_test.cpp
  • test/flush_gate_test.cpp
💤 Files with no reviewable changes (6)
  • phlex/core/declared_observer.hpp
  • phlex/core/store_counters.hpp
  • phlex/core/CMakeLists.txt
  • phlex/core/store_counters.cpp
  • phlex/core/framework_graph.hpp
  • phlex/core/fwd.hpp
📜 Review details
⏰ 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). (4)
  • GitHub Check: build (gcc, none)
  • GitHub Check: Analyze cpp with CodeQL
  • GitHub Check: clang-tidy-check
  • GitHub Check: coverage
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{cpp,cc,cxx,h,hpp}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.{cpp,cc,cxx,h,hpp}: Use clang-format tool for all C++ code formatting (VS Code auto-formats on save); configuration defined in .clang-format with 100-character line limit and 2-space indentation
Follow clang-tidy recommendations defined in .clang-tidy

Files:

  • phlex/core/fold/send.hpp
  • phlex/core/declared_unfold.cpp
  • phlex/core/declared_fold.cpp
  • phlex/core/concepts.hpp
  • phlex/core/multilayer_join_node.hpp
  • phlex/model/flush_gate.hpp
  • phlex/core/declared_unfold.hpp
  • test/flush_gate_test.cpp
  • phlex/core/fold_join_node.hpp
  • phlex/core/detail/accumulator_node.hpp
  • test/accumulator_test.cpp
  • phlex/model/flush_gate.cpp
  • phlex/core/framework_graph.cpp
  • phlex/core/message.hpp
  • phlex/core/index_router.hpp
  • phlex/core/declared_fold.hpp
  • phlex/core/index_router.cpp
**/*.{hpp,cpp}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{hpp,cpp}: Use .hpp for C++ header files and .cpp for implementation files; test files should be named *_test.cpp
All C++ identifiers (namespaces, classes, structs, enums, functions, variables, parameters, members, constants, type aliases) must use lower_case naming
Template parameters in C++ must use CamelCase naming
C++ macros must use UPPER_CASE naming
Private, protected, and constant C++ members must have a trailing underscore (_)
Use east-const style in C++: int const x not const int x
Prefer enum class over plain enum in C++
Avoid boolean parameters in C++ function interfaces; prefer enumerations instead
Use std::shared_ptr for shared ownership, std::unique_ptr for exclusive ownership, and raw pointers only for non-owning references in C++
C++ clang-format enforces 100-character line limit and 2-space indentation with QualifierAlignment: Right and PointerAlignment: Left
Use namespaces phlex:: for core code and phlex::experimental:: for experimental features in C++
Use functors with agent noun naming (e.g., ModelEvaluator evaluate_model(...)) in C++

Files:

  • phlex/core/fold/send.hpp
  • phlex/core/declared_unfold.cpp
  • phlex/core/declared_fold.cpp
  • phlex/core/concepts.hpp
  • phlex/core/multilayer_join_node.hpp
  • phlex/model/flush_gate.hpp
  • phlex/core/declared_unfold.hpp
  • test/flush_gate_test.cpp
  • phlex/core/fold_join_node.hpp
  • phlex/core/detail/accumulator_node.hpp
  • test/accumulator_test.cpp
  • phlex/model/flush_gate.cpp
  • phlex/core/framework_graph.cpp
  • phlex/core/message.hpp
  • phlex/core/index_router.hpp
  • phlex/core/declared_fold.hpp
  • phlex/core/index_router.cpp
🪛 Cppcheck (2.20.0)
test/accumulator_test.cpp

[style] 24-24: The function 'convert' is never used.

(unusedFunction)

🔇 Additional comments (29)
phlex/core/detail/accumulator_node.hpp (1)

1-186: LGTM!

Also applies to: 206-237, 239-293

phlex/core/fold_join_node.hpp (1)

1-66: LGTM!

Also applies to: 68-171, 173-233

phlex/core/declared_fold.hpp (1)

38-54: LGTM!

Also applies to: 59-70, 74-148, 150-156, 158-158

phlex/core/declared_fold.cpp (1)

1-15: LGTM!

phlex/core/message.hpp (1)

52-77: LGTM!

phlex/core/multilayer_join_node.hpp (1)

114-117: LGTM!

phlex/core/index_router.hpp (1)

27-65: LGTM!

Also applies to: 85-98, 103-125, 148-184, 190-226

phlex/core/index_router.cpp (8)

45-106: LGTM!


108-126: LGTM!


128-143: LGTM!


199-258: LGTM!


362-450: LGTM!


452-513: LGTM!


577-611: LGTM!


175-175: This is not a concern—the project explicitly targets C++23 as its baseline standard (per AGENTS.md and CLANG_TIDY_CONFIGURATION.md), and std::ranges::contains is already used elsewhere in the codebase without issue (e.g., phlex/model/fixed_hierarchy.cpp:24). No action needed.

phlex/core/framework_graph.cpp (4)

17-41: LGTM!


43-75: LGTM!


218-223: LGTM!


122-128: LGTM!

phlex/core/declared_unfold.hpp (1)

45-55: LGTM!

test/accumulator_test.cpp (3)

20-80: LGTM!


81-117: LGTM!


120-268: LGTM!

phlex/core/declared_unfold.cpp (1)

23-23: LGTM!

test/CMakeLists.txt (1)

14-14: LGTM!

test/flush_gate_test.cpp (1)

29-29: LGTM!

Also applies to: 225-231

.amazonq/rules/memory-bank/structure.md (1)

19-19: LGTM!

phlex/model/flush_gate.hpp (1)

43-43: LGTM!

Also applies to: 61-61, 70-70, 88-88

phlex/model/flush_gate.cpp (1)

11-11: LGTM!

Also applies to: 22-22, 28-28, 38-42, 86-86

Comment thread phlex/core/concepts.hpp Outdated
Comment thread phlex/core/declared_fold.hpp Outdated
Comment thread phlex/core/declared_fold.hpp Outdated
Comment thread phlex/core/detail/accumulator_node.hpp
Comment thread phlex/core/fold_join_node.hpp Outdated
Comment thread phlex/core/fold/send.hpp Outdated
@knoepfel knoepfel force-pushed the fix-fold-caching branch 2 times, most recently from e47a8b2 to 979191e Compare June 17, 2026 13:32
@Framework-R-D Framework-R-D deleted a comment from github-actions Bot Jun 17, 2026
@Framework-R-D Framework-R-D deleted a comment from github-actions Bot Jun 17, 2026
@Framework-R-D Framework-R-D deleted a comment from github-actions Bot Jun 17, 2026
@Framework-R-D Framework-R-D deleted a comment from github-actions Bot Jun 17, 2026
@Framework-R-D Framework-R-D deleted a comment from github-actions Bot Jun 18, 2026
@Framework-R-D Framework-R-D deleted a comment from github-actions Bot Jun 18, 2026
@Framework-R-D Framework-R-D deleted a comment from github-actions Bot Jun 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Clang-Tidy Check Results

Found 6282 issue(s); none are newly introduced by this patch.

All issues by check:

  • readability-identifier-naming: 1858
  • readability-redundant-typename: 1405
  • readability-redundant-member-init: 1268
  • performance-unnecessary-value-param: 479
  • readability-avoid-const-params-in-decls: 257
  • modernize-pass-by-value: 199
  • readability-use-concise-preprocessor-directives: 189
  • modernize-use-designated-initializers: 101
  • readability-braces-around-statements: 90
  • readability-convert-member-functions-to-static: 79
  • readability-const-return-type: 47
  • modernize-use-auto: 36
  • readability-qualified-auto: 26
  • modernize-avoid-c-style-cast: 22
  • readability-inconsistent-ifelse-braces: 21
  • readability-redundant-control-flow: 20
  • readability-math-missing-parentheses: 17
  • modernize-avoid-c-arrays: 15
  • modernize-use-equals-default: 14
  • modernize-use-using: 13
  • readability-function-size: 13
  • readability-static-definition-in-anonymous-namespace: 12
  • modernize-return-braced-init-list: 11
  • modernize-concat-nested-namespaces: 10
  • readability-isolate-declaration: 8
  • readability-container-contains: 8
  • cppcoreguidelines-special-member-functions: 8
  • modernize-use-starts-ends-with: 7
  • readability-container-size-empty: 7
  • modernize-use-ranges: 6
  • readability-inconsistent-declaration-parameter-name: 5
  • readability-redundant-access-specifiers: 5
  • readability-redundant-casting: 4
  • bugprone-branch-clone: 3
  • modernize-use-emplace: 3
  • modernize-use-std-numbers: 3
  • performance-move-const-arg: 2
  • clang-analyzer-security.ArrayBound: 2
  • readability-redundant-string-init: 1
  • modernize-redundant-void-arg: 1
  • readability-use-std-min-max: 1
  • modernize-make-shared: 1
  • readability-simplify-boolean-expr: 1
  • modernize-use-integer-sign-comparison: 1
  • readability-use-anyofallof: 1
  • readability-else-after-return: 1
  • performance-avoid-endl: 1

See inline comments for details. Comment @phlexbot tidy-fix to auto-fix.

@Framework-R-D Framework-R-D deleted a comment from github-actions Bot Jun 18, 2026
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.

Change fold-result caching to use multilayer_join_node

2 participants