Commit 52ff050
Implement OTP supervision tree and public API for wf_substrate
This commit implements the complete OTP supervision tree and public API
for wf_substrate as specified in item 012. The implementation provides a
production-grade process architecture for workflow case management with
proper fault containment and supervision.
Key changes:
**New Modules:**
- wf_case_runner: Per-case gen_statem managing execution lifecycle with
explicit states (initializing, running, waiting_effect, waiting_signal,
cancelled, done). Executes bytecode in quanta, handles signals, and
supports state timeout for case timeout.
- wf_case_sup: Dynamic supervisor using simple_one_for_one strategy to
manage per-case runner processes. Cases are temporary (not restarted on
normal termination) to avoid replaying execution state.
- Updated wf_substrate_sup: Added wf_case_sup as permanent child in the
supervision tree alongside existing singletons (wf_governance,
wf_budget, wf_approval).
- Updated wf_substrate: Implemented complete public API including:
* new_case/3: Create workflow case (accepts bytecode directly until item 004)
* signal/2: Send external signal to running case
* cancel/1, cancel_region/2: Cancel case or specific region
* await/2: Block until case completion with monitor/timeout
* status/1: Query current case status
* trace/3: Configure trace level and sink
* validate/2: Stub returning ok (item 013 will implement)
**Testing:**
- wf_case_runner_tests: State machine transition tests
- wf_supervision_tree_tests: Supervisor behavior, dynamic children,
restart strategies, name conflicts
- wf_substrate_api_tests: Complete API coverage including error cases
- wf_exec_tests.hrl: Shared mock bytecode generators
**Examples:**
- examples/basic_usage.erl: Demonstrates sequential and parallel workflows
with tracing and signal delivery
**Configuration:**
- Updated wf_substrate.app.src: registered includes wf_case_sup,
modules list includes all new modules
The supervision tree structure:
wf_substrate_sup (one_for_one)
├── wf_case_sup (simple_one_for_one)
│ └── wf_case_runner (temporary, per case)
├── wf_governance (permanent)
├── wf_budget (permanent)
└── wf_approval (permanent)
All modules compile without warnings and follow existing code patterns.
Process registration uses Erlang registry (no external dependencies).
TODO comments added for item 004 (wf_compile) and item 013 (wf_validate).
Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>1 parent 0f0951e commit 52ff050
11 files changed
Lines changed: 1051 additions & 27 deletions
File tree
- .wreckit/items/012-otp-supervision-tree
- examples
- src
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
| 5 | + | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | | - | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
0 commit comments