feat(eda): run action playbooks at pin time through the at-most-once dispatch ledger
This commit is contained in:
1 parent
6046948ff0
commit
2bc4b8db32
11 files changed
+517
-95
No files matched your search
@@ -298,7 +298,7 @@
|
||||
"url": "/dev/prds/multi-action-playbooks/",
|
||||
"title": "Multi-action playbooks and typed action results",
|
||||
"section": "PRDs",
|
||||
"body": "# Multi-action playbooks and typed action results\n\n**Status:** Approved\n**Date:** 2026-09-22\n**Parent:** `docs/prds/eda-playbook-engine.md`, epic `archie-core-t2db`\n**Beads issue:** `archie-core-nx30` (unblocks `archie-core-t2db.27` and `archie-core-t2db.31`)\n\n## Why this exists\n\n`eda-playbook-engine.md`'s hard boundary rejects any playbook that is not\nexactly one `workflow` action, so the parent document's data-flow, Module and\nChannel/Forge decisions have no loadable shape to attach to. The boundary's own\nstated condition is now met: both execution-time gaps are resolved\n(`eda-playbook-engine.md`, \"Execution-time gaps\"; the `playbook_dispatches`\nledger). This document designs the relaxation.\n\n## A playbook is one of two shapes\n\n- A **workflow playbook** is exactly one `workflow` action. Unchanged: it names\n a workflow definition and is routed by the daemon's definition pin.\n- An **action playbook** is one or more `module` actions in order. Each action\n has an optional `id`, a `kind` naming a registered Module kind, `args`, and an\n optional `when`.\n\nOne playbook does not mix the two shapes.\n\n```yaml\ntrigger: { kind: bug }\nactions:\n - id: build\n position: module\n kind: log\n args: { message: '\"build started\"' }\n - id: done\n position: module\n kind: log\n args: { message: '\"done: \" + string(actions.build.result.written)' }\n when: actions.build.result.written == true\n```\n\nThe first Module kind is the side-effect-free `log` kind\n(`module-position.md`, \"Recommended first slice\"). A Module kind with an\nexternal side effect, and the Channel and Forge positions, are out of scope.\n\n## A result type is the kind's generated Result struct\n\nEach Module kind owns a hand-written `Args` and `Result` struct\n(`internal/domain/eda/module/log` is the worked example); `ModuleRegistry.Invoke`\nreturns the result as a flat `map[string]any`. `ModuleRegistry.DecodeResult`\n(`internal/domain/eda/module`) is the single site that converts that map into\nthe kind's `Result` struct before a later expression reads it, so the value the\nchecker validates and the value the run reads have one definition.\n\n`actions.\u003cid\u003e` is typed by the kind of the action that declares `\u003cid\u003e`:\n`{ result: \u003cKindResult\u003e }`. `event` stays `dyn` (J4,\n`playbook-expression-syntax.md`).\n\n## Reject-at-load, preserved\n\nRelaxing the boundary must not make a bad reference resolvable. The load fails,\nnaming the playbook and the offending action, for:\n\n- an `id` missing where a later action references it, duplicated, or outside\n its shape's grammar: a workflow action id keeps the shared\n stable-identifier grammar (J1, already enforced), while a module action id\n must be a lowercase CEL field name writable as `actions.\u003cid\u003e` (so a CEL\n keyword such as `in`, `true`, `false`, or `null` is rejected at load);\n- an `actions.\u003cid\u003e` read of an id no earlier action declares;\n- an `actions` read that is not statically resolvable to an id (any map index,\n literal or dynamic, `in`, a comprehension): the typed `actions` root is an\n object type, so only field selection `actions.\u003cid\u003e` resolves and the\n `actions[\"id\"]` spelling is not accepted;\n- a `result` field the referenced kind's `Result` does not define;\n- a reference to an earlier action that produces no result;\n- an unknown `position`, an unknown `kind`, or a `module` action with no `kind`;\n- a field belonging to the other shape (`kind` on a `workflow` action, or\n `workflow` on a `module` action);\n- an arg KEY the kind's `Args` schema does not define. Arg VALUE type-checking\n is tracked as `archie-core-t2db` debt, not shipped here.\n\nDeclaring the kind's `Result` schema to CEL at load makes a result-field typo a\nload failure rather than a dispatch failure. Matching arg keys against the\nkind's `Args` schema makes an arg-key typo a load failure; arg value\ntype-checking is tracked as `archie-core-t2db` debt.\n\n## The environment is per playbook\n\nResult typing depends on the ids a playbook declares and the kind each id runs,\nso the CEL environment is built from one playbook's action list rather than once\nper `Store`, and `expr.NewEnv` takes that list: each declared id becomes a field\nof the `actions` object typed by its kind's `Result`.\n\n## Running an action playbook is out of scope\n\nThis document makes an action playbook load and its references type-check. It\ndoes not invoke a Module kind. Invocation, the `playbook_dispatches` gate, and\nstop-on-first-failure across actions are `archie-core-t2db.31`.\n\n## Decisions\n\n**D1 — dispatch before `t2db.31`.** Settled: an action playbook loads and\nvalidates but is not routed; the definition-pin dispatch reports no match for it,\nand the daemon logs a visible warning naming it.\n\n**D2 — mixing positions.** Settled: one shape per playbook. A `workflow` action\nyields a task, not a rLine truncated
|
||||
"body": "# Multi-action playbooks and typed action results\n\n**Status:** Approved\n**Date:** 2026-09-22\n**Parent:** `docs/prds/eda-playbook-engine.md`, epic `archie-core-t2db`\n**Beads issue:** `archie-core-nx30` (unblocks `archie-core-t2db.27` and `archie-core-t2db.31`)\n\n## Why this exists\n\n`eda-playbook-engine.md`'s hard boundary rejects any playbook that is not\nexactly one `workflow` action, so the parent document's data-flow, Module and\nChannel/Forge decisions have no loadable shape to attach to. The boundary's own\nstated condition is now met: both execution-time gaps are resolved\n(`eda-playbook-engine.md`, \"Execution-time gaps\"; the `playbook_dispatches`\nledger). This document designs the relaxation.\n\n## A playbook is one of two shapes\n\n- A **workflow playbook** is exactly one `workflow` action. Unchanged: it names\n a workflow definition and is routed by the daemon's definition pin.\n- An **action playbook** is one or more `module` actions in order. Each action\n has an optional `id`, a `kind` naming a registered Module kind, `args`, and an\n optional `when`.\n\nOne playbook does not mix the two shapes.\n\n```yaml\ntrigger: { kind: bug }\nactions:\n - id: build\n position: module\n kind: log\n args: { message: '\"build started\"' }\n - id: done\n position: module\n kind: log\n args: { message: '\"done: \" + string(actions.build.result.written)' }\n when: actions.build.result.written == true\n```\n\nThe first Module kind is the side-effect-free `log` kind\n(`module-position.md`, \"Recommended first slice\"). A Module kind with an\nexternal side effect, and the Channel and Forge positions, are out of scope.\n\n## A result type is the kind's generated Result struct\n\nEach Module kind owns a hand-written `Args` and `Result` struct\n(`internal/domain/eda/module/log` is the worked example); `ModuleRegistry.Invoke`\nreturns the result as a flat `map[string]any`. `ModuleRegistry.DecodeResult`\n(`internal/domain/eda/module`) is the single site that converts that map into\nthe kind's `Result` struct before a later expression reads it, so the value the\nchecker validates and the value the run reads have one definition.\n\n`actions.\u003cid\u003e` is typed by the kind of the action that declares `\u003cid\u003e`:\n`{ result: \u003cKindResult\u003e }`. `event` stays `dyn` (J4,\n`playbook-expression-syntax.md`).\n\n## Reject-at-load, preserved\n\nRelaxing the boundary must not make a bad reference resolvable. The load fails,\nnaming the playbook and the offending action, for:\n\n- an `id` missing where a later action references it, duplicated, or outside\n its shape's grammar: a workflow action id keeps the shared\n stable-identifier grammar (J1, already enforced), while a module action id\n must be a lowercase CEL field name writable as `actions.\u003cid\u003e` (so a CEL\n keyword such as `in`, `true`, `false`, or `null` is rejected at load);\n- an `actions.\u003cid\u003e` read of an id no earlier action declares;\n- an `actions` read that is not statically resolvable to an id (any map index,\n literal or dynamic, `in`, a comprehension): the typed `actions` root is an\n object type, so only field selection `actions.\u003cid\u003e` resolves and the\n `actions[\"id\"]` spelling is not accepted;\n- a `result` field the referenced kind's `Result` does not define;\n- a reference to an earlier action that produces no result;\n- an unknown `position`, an unknown `kind`, or a `module` action with no `kind`;\n- a field belonging to the other shape (`kind` on a `workflow` action, or\n `workflow` on a `module` action);\n- an arg KEY the kind's `Args` schema does not define. Arg VALUE type-checking\n is tracked as `archie-core-t2db` debt, not shipped here.\n\nDeclaring the kind's `Result` schema to CEL at load makes a result-field typo a\nload failure rather than a dispatch failure. Matching arg keys against the\nkind's `Args` schema makes an arg-key typo a load failure; arg value\ntype-checking is tracked as `archie-core-t2db` debt.\n\n## The environment is per playbook\n\nResult typing depends on the ids a playbook declares and the kind each id runs,\nso the CEL environment is built from one playbook's action list rather than once\nper `Store`, and `expr.NewEnv` takes that list: each declared id becomes a field\nof the `actions` object typed by its kind's `Result`.\n\n## Running an action playbook is out of scope\n\nThis document makes an action playbook load and its references type-check.\nRunning one is designed in `docs/prds/action-playbook-run.md`.\n\n## Decisions\n\n**D1 — dispatch before `t2db.31`.** Superseded by\n`docs/prds/action-playbook-run.md`. Was: an action playbook loads and\nvalidates but is not routed; the definition-pin dispatch reports no match for it,\nand the daemon logs a visible warning naming it.\n\n**D2 — mixing positions.** Settled: one shape per playbook. A `workflow` action\nyields a task, not a result, so it cannot feed `actions.\u0Line truncated
|
||||
},
|
||||
{
|
||||
"url": "/dev/prds/news-and-releases/",
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
# Running action playbooks
|
||||
|
||||
**Status:** Approved
|
||||
**Date:** 2026-09-23
|
||||
**Parent:** `docs/prds/multi-action-playbooks.md`, epic `archie-core-t2db`
|
||||
**Beads issue:** `archie-core-t2db.31`
|
||||
|
||||
## Why this exists
|
||||
|
||||
An action playbook loads and type-checks but never runs: `Store.Dispatch`
|
||||
skips it and the daemon logs a warning at boot (`multi-action-playbooks.md`,
|
||||
D1). This document defines when it runs, what each action does, and how the
|
||||
`playbook_dispatches` ledger gates it.
|
||||
|
||||
## When a playbook runs
|
||||
|
||||
The daemon runs action playbooks at the point it pins a task's workflow
|
||||
definition (`Daemon.resolveWorkflowID`), using the same `DispatchInput` the
|
||||
workflow playbooks use. The definition is pinned once per task, so the run
|
||||
happens once per task.
|
||||
|
||||
- Every action playbook whose trigger matches runs, in load order. A workflow
|
||||
playbook stops at the first match because it chooses one workflow; action
|
||||
playbooks choose nothing, so no match suppresses another.
|
||||
- A run never changes routing. The task is pinned by the workflow playbooks
|
||||
and bindings exactly as when no action playbook exists.
|
||||
- An action or playbook failure never parks or fails the task. It is logged
|
||||
at warning level with the playbook, the action and the task.
|
||||
- A task that already names a workflow (the approval requeue) is skipped, as
|
||||
it is for workflow playbooks.
|
||||
- Actions run synchronously in the pin path, bounded by the daemon's context.
|
||||
The only Module kind, `log`, returns immediately. A slow kind must bring its
|
||||
own timeout.
|
||||
|
||||
## What one action does
|
||||
|
||||
Actions run in order against one evaluation context whose `actions` map
|
||||
starts empty.
|
||||
|
||||
1. Evaluate `when`. False or an evaluation error skips the action (J3). A
|
||||
skipped action records nothing and produces no result.
|
||||
2. Evaluate every `args` value. An evaluation error stops the playbook.
|
||||
3. Call `playbook.InvokeOnce` with the Module invoke as its function. The
|
||||
ledger row is written first. A duplicate row skips the invoke.
|
||||
4. An invoke error stops the playbook. The row stays, so the action is not
|
||||
retried: the ledger promises at most once, not at least once.
|
||||
5. On success, `ModuleRegistry.DecodeResult` converts the result, and it is
|
||||
stored as `actions.<id>.result` when the action declares an id.
|
||||
|
||||
The event id in the ledger key is `DispatchInput.TaskID`, the issue's
|
||||
idempotency key (`owner/repo/number`). An action therefore runs at most once
|
||||
per issue for each playbook version. Editing a playbook changes its version
|
||||
and lets it run again for issues it already handled.
|
||||
|
||||
A skipped duplicate has no result. A later action that reads it sees a
|
||||
missing field: its `when` evaluates false, or its args fail and the playbook
|
||||
stops. This only happens when the same issue is pinned twice under one
|
||||
playbook version.
|
||||
|
||||
## Wiring
|
||||
|
||||
- `storecontract.PlaybookDispatcher` is lifted onto the daemon from the State
|
||||
Store client in `internal/app/archied/bootstrap.go`, the same way
|
||||
`BindingDispatcher` is.
|
||||
- The daemon's `Playbooks` dependency gains the run method. The Module
|
||||
registry is passed to the playbook store at load, so the daemon needs no
|
||||
new dependency for it.
|
||||
- With no `PlaybookDispatcher` wired, action playbooks do not run, and the
|
||||
boot warning names each one. They never run without the ledger.
|
||||
- The boot warning that action playbooks do not execute is removed when the
|
||||
ledger is wired.
|
||||
|
||||
## Verification
|
||||
|
||||
- A matching two-action `log` playbook runs both actions in order, and the
|
||||
second reads the first's result.
|
||||
- Pinning the same task twice under one playbook version invokes each action
|
||||
once.
|
||||
- A `when` that evaluates false skips that action and the run continues.
|
||||
- An invoke error stops the playbook. The task is still pinned to the same
|
||||
workflow it would get with no action playbook.
|
||||
- A non-matching trigger runs nothing.
|
||||
- With no ledger wired, nothing runs and the warning names the playbook.
|
||||
@@ -92,13 +92,13 @@ of the `actions` object typed by its kind's `Result`.
|
||||
|
||||
## Running an action playbook is out of scope
|
||||
|
||||
This document makes an action playbook load and its references type-check. It
|
||||
does not invoke a Module kind. Invocation, the `playbook_dispatches` gate, and
|
||||
stop-on-first-failure across actions are `archie-core-t2db.31`.
|
||||
This document makes an action playbook load and its references type-check.
|
||||
Running one is designed in `docs/prds/action-playbook-run.md`.
|
||||
|
||||
## Decisions
|
||||
|
||||
**D1 — dispatch before `t2db.31`.** Settled: an action playbook loads and
|
||||
**D1 — dispatch before `t2db.31`.** Superseded by
|
||||
`docs/prds/action-playbook-run.md`. Was: an action playbook loads and
|
||||
validates but is not routed; the definition-pin dispatch reports no match for it,
|
||||
and the daemon logs a visible warning naming it.
|
||||
|
||||
|
||||
Reference in new issue
Block a user