Repository navigation
Add computed-date arithmetic to the playbook engine (add_days + function-call action bindings) - #2715
Conversation
…oses #2640) Registers add_days(date_string, n) -> date_string in cel.rs alongside days_since/days_until/today, using checked date arithmetic so a huge or out-of-range offset from user-authored play content is a clean function error, never a panic. It reads no wall-clock time, so it is deliberately excluded from NON_DETERMINISTIC_FUNCTIONS and stays usable in invariant rule conditions. Extends actions.rs's {path} binding-interpolation syntax to also accept a function-call form, e.g. {add_days(item.start_date, 14)}, resolved through the same BindingContext rather than a separate CEL program (option A from the issue: scoped, additive, keeps the blast radius to the new syntax rather than changing the resolution path for every action-value across the engine). The function set is fixed and hardcoded to add_days; an unsupported name and a nested function-call argument are both rejected with a clear error rather than dispatched or evaluated. parse_function_call only recognizes the exact `identifier(...)` shape, which cannot occur in any existing bare dot-path, so ordinary {path} bindings are unaffected. Covers the motivating end-to-end case with an integration test: a scheduled play computing a new node's end_date as start_date + N days via the new binding syntax. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Code Review SummaryReview Type: Initial Review (no prior reviews/comments found via This PR closes #2640 cleanly on the "does it do what it claims" axis: There is one real, non-obvious gap this surfaced: the ADR-060 invariant-rule determinism validator was never updated to account for the new action-value function-call surface, and its doc comment now asserts something the PR makes false. Details below. Not exploitable today (the one function is deterministic), but it's exactly the class of "silently invalidated invariant" this subsystem has been adversarially reviewed for before, and it's cheap to close now. Requirements Check (issue #2640)
FindingsCritical Issues
Suggested Improvements
Nitpicks
VerdictREQUEST CHANGES — solely for the 🤖 Automated pragmatic-code-review |
mstomar125
left a comment
There was a problem hiding this comment.
Automated pragmatic-code-review: REQUEST CHANGES (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above. Summary: the new add_days function-call binding surface and date arithmetic are solid (verified via the PR's own tests plus my own adversarial probes — nested calls, malformed parens, i64::MAX/MIN, empty arg lists — all clean errors, no panics; clippy/fmt clean). One real gap requested to be fixed before merge: packages/core/src/playbook/validation.rs's ADR-060 determinism check (validate_invariant_eligibility) was not updated to cover the new action-value function-call surface, and its doc comment asserting action params have 'no function-call surface' is now false.
Address review feedback on PR #2715: the invariant-rule determinism check (ADR-060 §2) only scanned rule.conditions for non-deterministic CEL functions; action-value bindings could not express a function call before this PR, but now can via {add_days(...)}, and the check's own doc comment still claimed action params had "no function-call surface" -- a stale claim invalidated by this PR's own change, and an unenforced gap for any future non-deterministic function added to resolve_function_call's match arm. Adds a second determinism pass over each invariant rule's actions, scanning action params for the {name(...)} function-call shape (via new pub(crate) actions.rs helpers extract_binding_templates and collect_binding_templates_in_value, reusing parse_function_call) and checking matched names against the same NON_DETERMINISTIC_FUNCTIONS list conditions already use. add_days is genuinely deterministic and stays absent from that list, so this check is a no-op today -- it exists to catch a future violation by name, not to flag add_days itself. Co-Authored-By: Claude Sonnet 5 <[email protected]>
for_each is a raw, unbraced binding path resolved through the same
BindingContext::resolve_binding as any {path} action-value, so a
function-call form is reachable there too without {...} wrapping -- the
previous commit's scan only looked inside {...}-wrapped param text and
would have missed it. Check action.for_each directly with
parse_function_call alongside the params scan.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
|
Addressed the Critical finding from the automated review. Fix (commits a533ef2, 5b3d2c0): extended the ADR-060 §2 determinism check in
Full pre-push gate ( The Nits/Improvements from the review (DRY overlap between |
Summary
Closes #2640. Two coupled gaps, addressed together:
add_days(date_string, n) -> date_stringregistered inpackages/core/src/playbook/cel.rsalongside the existingdays_since/days_until/today. It followsparse_date_and_compute_days's parsing precedent (full RFC 3339 datetime or bareYYYY-MM-DD), returns the same format style as the input, and never reads wall-clock time — so it's deliberately excluded fromNON_DETERMINISTIC_FUNCTIONSand stays usable in ADR-060 §2 invariant-rule conditions. All arithmetic is checked (try_days/checked_add_signed), not wrapping or panicking, sincenultimately comes from user-authored play content — an out-of-range offset is a clean function error.A function-call form for action-value bindings in
packages/core/src/playbook/actions.rs:{add_days(item.start_date, 14)}alongside the existing bare{path}interpolation, both resolved through the sameBindingContext.Design decision (per the issue's explicit ask)
Built option A — extend
{path}interpolation to accept a function-call form, resolved through the same binding-resolution machinery, rather than option B (a full CEL program for any action param value). Option B would change the performance/complexity profile of every action-value resolution across the whole playbook engine — a broad change to already security-sensitive infrastructure that had a major ADR-060 build-out with multiple adversarial review rounds just before this issue. Option A is scoped and additive: the only new surface is the exactidentifier(...)shape inside a{...}binding, dispatched through a fixed, hardcodedmatch— not a general function-registration framework. I did not hit a case where the minimal path-plus-one-function version was insufficient, so no such framework was added.Implementation notes
parse_function_callinactions.rsrecognizes ONLY the whole-path shape<identifier>(...).(is not a legal character in anytrigger/actions/itempath segment a play author can write today (actions[N]uses square brackets), so this can never misfire on, or change the resolution of, an existing bare{path}binding — every string it newly recognizes previously hit"unknown binding root"anyway.BindingContext::resolve_function_callmatches on a fixed function name (add_daystoday); an unsupported name is a hard, immediate error — there is no lookup table an action param's string could index into.add_days's two arguments are each resolved as a dot-path (through this sameBindingContext, recursively viaBox::pinsince the recursion is indirect) or, for the day-offset, a bare integer literal. A nested function-call argument is explicitly detected and rejected with a clear error rather than evaluated — this stays a fixed one-level substitution, not a general expression evaluator reachable through argument position.Errs, never panics, including malformed/malicious input: unresolvable paths, non-numeric offsets, non-string dates, wrong argument counts, and offsets large enough to overflowchrono's internal representation.Testing
packages/core/src/playbook/cel.rs: unit tests foradd_days/compute_add_days(bare date, full datetime, negative offset, month/year boundary crossing, invalid date, extreme-offset overflow safety, CEL-condition usage, and confirmation it's excluded fromNON_DETERMINISTIC_FUNCTIONS).packages/core/src/playbook/actions.rs: unit tests forparse_function_call/split_top_level_args(including nested-parens handling), theadd_days(...)binding end-to-end (path arg, path-resolved day-offset arg, integer literal, negative offset,{...}fast path, mixed literal text), every malformed/malicious-input error case named in the issue ({add_days(bad.path, "not a number")}, non-string date, invalid date string, nested function call, unsupported function name), and two explicit regression tests asserting existing bare-path/{path}resolution is unchanged.packages/core/tests/playbook_engine_integration_test.rs:scheduled_play_computes_end_date_via_add_days_and_writes_it_to_a_new_node— a real runningPlaybookEngine, a scheduled play scanningpb_cycle_sourcenodes, computingend_date = start_date + 14 daysvia{add_days(...)}in acreate_nodeaction'sproperties, and writing it to a newpb_cycle_resultnode — the motivating end-to-end case from the issue.bun run test:alland the full pre-push gate (includingcargo build --bin nodespaced,test:e2e, and the Tauri-seam integration suite) pass locally.bun run quality:fixclean (0 errors, 0 warnings, clippy clean with-D warnings -D clippy::unused-async).Non-goals (unchanged from the issue)
No Cycle schema or Cycle-creation Play (engine capability only), and no date arithmetic beyond day-offset (month/year-aware or business-day-aware arithmetic).
Reviewer note
Per the issue's own request, I dispatched an independent adversarial review focused on: injection/malformed-input risk in the new function-call parsing, whether it correctly rejects anything attempting to call something other than the explicitly-supported function set, and whether existing
{path}-only behavior is byte-identical. See PR comments/review for that pass.🤖 Generated with Claude Code