eda: CEL expression environment (compile/validate at load, evaluate at dispatch) #437

Closed
opened 2026-10-27 13:36:19 +00:00 by sam · 0 comments
Owner

Sixth slice of docs/prds/eda-playbook-engine.md, implementing the 'Implementation placement' section of the resolved open question 1 (CEL). Builds internal/domain/eda/expr in isolation, no coordinator/dispatch yet -- mirrors how t2db.13 built ModuleRegistry as a standalone, fully-tested unit before anything consumed it.

This is pure infrastructure for the dispatch slice (t2db.15) that depends on it. No production wiring in this ticket.

Design

Package internal/domain/eda/expr (domain layer: no infrastructure imports).

Per the resolved doc section, build:

  1. Environment construction: a CEL env declaring the two context roots -- 'event' as map(string, dyn), 'actions' as map(string, dyn). Cost limit (J5): pick a constant (start at 100,000, name it clearly as a tunable, e.g. DefaultCostLimit) -- exact value is a judgment call already flagged as tunable, don't block on picking the 'right' number.
  2. Compile/validate at load: a function taking a CEL expression string and returning (compiled program, error) -- a syntax error, a reference to an unknown root (anything other than event/actions), or exceeding the cost limit is a returned error, never a panic. This is what both the playbook loader (t2db.15) and the lint tool (t2db.12, follow-up integration is a SEPARATE ticket, do not touch cmd/archie-playbooks in this one) will eventually call.
  3. Evaluate at dispatch: a function taking a compiled program and a context (event map[string]any, actions map[string]map[string]any) and returning (value, error) -- CEL evaluation errors (missing field, wrong type against a dyn value) are returned as errors, never panics. Use CEL's own panic-free evaluation; do not add a recover() wrapper unless a test proves CEL itself can panic (verify this, don't assume).
  4. actions..result field-level typing (J1/context-conformance in the doc): NOT required in this ticket -- that needs the generated Module Result structs wired in as CEL type declarations, which only matters once a playbook can reference a prior action's result (t2db.15 is single-action, so there IS no prior action). Keep actions declared as dyn for now; note in a comment that per-kind typed declarations are follow-up work once multi-action playbooks exist.
  5. Dependency: add cel.dev/cel-go v0.32.0 (pinned) to go.mod -- this is the only new dependency, already vetted (see the resolved doc section's vetting record). Do not re-vet it.

Follow docs/prds/eda-playbook-engine.md's reject-at-load philosophy throughout: anything not accepted by the schema is a reported error, never a silent default.

Acceptance criteria

internal/domain/eda/expr exists with: environment construction, Compile(expr string) (returned type, error), Eval(program, ctx) (value, error). Table-driven tests cover: a valid boolean expression against event fields evaluates correctly; a syntax error is a Compile-time error; a reference to an unknown root (e.g. 'foo.bar') is a Compile-time error; evaluating against a missing event field does not panic (returns an error or CEL's documented behavior, whichever is correct -- verify against real CEL semantics, don't guess); an expression that would exceed the cost limit is rejected, not silently truncated. go.mod gains cel.dev/cel-go v0.32.0 only. task check passes.

Close reason

Verified landed: internal/domain/eda/expr (Env, DefaultCostLimit) consumed by the playbook loader at load time.


Imported from beads archie-core-t2db.14 · GitHub #740 · type task · priority P2 · created 2026-09-02 · closed 2026-09-11

Sixth slice of docs/prds/eda-playbook-engine.md, implementing the 'Implementation placement' section of the resolved open question 1 (CEL). Builds internal/domain/eda/expr in isolation, no coordinator/dispatch yet -- mirrors how t2db.13 built ModuleRegistry as a standalone, fully-tested unit before anything consumed it. This is pure infrastructure for the dispatch slice (t2db.15) that depends on it. No production wiring in this ticket. ### Design Package internal/domain/eda/expr (domain layer: no infrastructure imports). Per the resolved doc section, build: 1. Environment construction: a CEL env declaring the two context roots -- 'event' as map(string, dyn), 'actions' as map(string, dyn). Cost limit (J5): pick a constant (start at 100,000, name it clearly as a tunable, e.g. DefaultCostLimit) -- exact value is a judgment call already flagged as tunable, don't block on picking the 'right' number. 2. Compile/validate at load: a function taking a CEL expression string and returning (compiled program, error) -- a syntax error, a reference to an unknown root (anything other than event/actions), or exceeding the cost limit is a returned error, never a panic. This is what both the playbook loader (t2db.15) and the lint tool (t2db.12, follow-up integration is a SEPARATE ticket, do not touch cmd/archie-playbooks in this one) will eventually call. 3. Evaluate at dispatch: a function taking a compiled program and a context (event map[string]any, actions map[string]map[string]any) and returning (value, error) -- CEL evaluation errors (missing field, wrong type against a dyn value) are returned as errors, never panics. Use CEL's own panic-free evaluation; do not add a recover() wrapper unless a test proves CEL itself can panic (verify this, don't assume). 4. actions.<id>.result field-level typing (J1/context-conformance in the doc): NOT required in this ticket -- that needs the generated Module Result structs wired in as CEL type declarations, which only matters once a playbook can reference a prior action's result (t2db.15 is single-action, so there IS no prior action). Keep actions declared as dyn for now; note in a comment that per-kind typed declarations are follow-up work once multi-action playbooks exist. 5. Dependency: add cel.dev/cel-go v0.32.0 (pinned) to go.mod -- this is the only new dependency, already vetted (see the resolved doc section's vetting record). Do not re-vet it. Follow docs/prds/eda-playbook-engine.md's reject-at-load philosophy throughout: anything not accepted by the schema is a reported error, never a silent default. ### Acceptance criteria internal/domain/eda/expr exists with: environment construction, Compile(expr string) (returned type, error), Eval(program, ctx) (value, error). Table-driven tests cover: a valid boolean expression against event fields evaluates correctly; a syntax error is a Compile-time error; a reference to an unknown root (e.g. 'foo.bar') is a Compile-time error; evaluating against a missing event field does not panic (returns an error or CEL's documented behavior, whichever is correct -- verify against real CEL semantics, don't guess); an expression that would exceed the cost limit is rejected, not silently truncated. go.mod gains cel.dev/cel-go v0.32.0 only. task check passes. ### Close reason Verified landed: internal/domain/eda/expr (Env, DefaultCostLimit) consumed by the playbook loader at load time. --- _Imported from beads `archie-core-t2db.14` · GitHub #740 · type task · priority P2 · created 2026-09-02 · closed 2026-09-11_
sam added the mediumtask labels 2026-10-27 13:36:19 +00:00
sam self-assigned this 2026-10-27 13:36:19 +00:00
sam closed this issue 2026-10-27 13:36:19 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Reference: sam/archie#437