Skip to content

Add collection-aggregation action to the playbook engine (sum/count over a for_each collection) #2639

Closed

Description

@malibio

Overview

The playbook engine's for_each (packages/core/src/playbook/actions.rs) applies the same action to every item in a resolved collection — one write per item (e.g. reassigning each incomplete task to a successor cycle). There is no primitive for the opposite shape: reducing a collection down to a single aggregate value (a sum, count, or similar) and writing that one result onto a different node. CEL itself, as wired into this engine (packages/core/src/playbook/cel.rs's build_condition_context), only registers three scalar helper functions (days_since, days_until, today) — no aggregate function exists anywhere in the current condition/action surface.

Problem Statement

A concrete, motivating case: a Cycle showing a running total of the estimate points across all Issues currently assigned to it (a very Linear-like affordance) needs something that sums a numeric field across every node related to the Cycle and writes that single number back onto the Cycle. Nothing in the current Play model can express this — for_each iterates and mutates per-item, it cannot collapse a collection into one derived value. Confirmed via inspection of actions.rs (for_each execution, ~line 633 onward) and cel.rs's registered function set (~lines 344-346) — no aggregation path exists today, and no ADR or architecture doc names this as a deferred/known gap.

Proposed Solution

Add an aggregation-capable action kind (exact shape to be decided during implementation, but should at minimum support sum and count over a resolved collection, keyed by a field path on each collection item), executed similarly to for_each but producing a single scalar result instead of iterating actions — then written onto a target field via the existing action-writing mechanism.

Two implementation shapes worth weighing during design:

  1. A new ActionKind variant (e.g. Aggregate) parallel to for_each, resolving a collection the same way for_each does, then reducing it (sum/count/etc.) rather than iterating an action per item.
  2. A CEL-level aggregate function (e.g. registering a sum(collection, field) custom function alongside days_since/days_until/today), usable inside a condition or action-value expression, letting existing action plumbing write the computed result without a new ActionKind.

Option 2 may be the lighter-weight fit, since it reuses existing action-value evaluation rather than adding new execution branching — but this needs a real design pass, not a default choice, given it changes how much computation CEL expressions are expected to carry versus the Rust action-execution layer.

Architecture Impact

No existing ADR documents playbook action/CEL capabilities as closed or enumerates a final set — this is additive new capability, not a reversal.

Acceptance Criteria

  • Design decision made and documented (new ActionKind vs. CEL aggregate function) with rationale
  • At minimum, sum over a numeric field across a resolved collection is supported
  • Result is written to a target node's field via existing action-writing mechanism
  • Aggregation correctly re-runs when any contributing item changes (not just once at collection-resolution time) — behavior under the existing trigger/event model needs explicit test coverage, since this is a derived value that must stay in sync with its inputs, the same correctness bar has_child auto-complete (a related but distinct issue) holds itself to
  • Tests pass (bun run test:all)
  • Code passes bun run quality:fix

Technical Specifications

Reference Files

  • packages/core/src/playbook/actions.rs — for_each execution (~line 633 onward) — the collection-resolution precedent to build from or alongside
  • packages/core/src/playbook/cel.rs — build_condition_context (~line 250), existing custom function registration (~lines 344-346) — where a CEL-level aggregate function would be added if that shape is chosen
  • packages/core/src/playbook/types.rs — ActionDefinition/ParsedAction (~lines 182, 341) — where a new ActionKind would be declared if that shape is chosen

Dependencies

None — this is a standalone engine capability, usable independent of any specific recipe.

Related Issues

Non-Goals

  • Any specific recipe content (Cycle estimate totals, etc.) — this issue is the general engine capability only
  • Aggregation functions beyond sum/count for this issue's initial scope (avg, min, max, etc. can follow as real needs surface)

Activity

  1. mstomar125 commented on Sep 17, 2026

    @mstomar125
    Contributor

    Frontend baseline: 251 test files / 5150 tests passed. Starting implementation.

  2. self-assigned this
    on Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions