|
| 1 | +# Issue 240 Design and Implementation Plan |
| 2 | + |
| 3 | +## Summary |
| 4 | + |
| 5 | +Issue 240 requests a clear way to distinguish nodes that were never executed because the workflow already failed. Today those nodes remain in `pending`, which is ambiguous. |
| 6 | + |
| 7 | +Proposed enhancement: |
| 8 | +- Add a terminal node status: `skipped`. |
| 9 | +- On workflow failure, convert remaining `pending` nodes to `skipped` when the failure came from node execution (that is, at least one node is `failed`). |
| 10 | + |
| 11 | +This keeps the existing instance-level status model unchanged (`df.instances.status` still ends as `failed`) while making node-level outcomes explicit. |
| 12 | + |
| 13 | +## Current Behavior (Observed) |
| 14 | + |
| 15 | +Live repro on local pg instance: |
| 16 | +- Step 1 SQL node: `completed` |
| 17 | +- Step 2 SQL node (intentional error): `failed` |
| 18 | +- Step 3 SQL node (never executed): `pending` |
| 19 | +- Instance: `failed` |
| 20 | + |
| 21 | +This is the ambiguity reported in issue 240. |
| 22 | + |
| 23 | +## Goals |
| 24 | + |
| 25 | +- Make unexecuted downstream nodes observable as `skipped` after terminal workflow failure. |
| 26 | +- Preserve backward compatibility of the new binary against old schemas. |
| 27 | +- Keep implementation minimal and low-risk (no new tables or public function signatures). |
| 28 | + |
| 29 | +## Non-Goals |
| 30 | + |
| 31 | +- No change to `df.instances.status` vocabulary. |
| 32 | +- No new monitoring projection table in this iteration. |
| 33 | +- No attempt to classify every failure mode as producing `skipped` (for example, pre-execution policy rejection may remain as-is). |
| 34 | + |
| 35 | +## Proposed Design |
| 36 | + |
| 37 | +### 1. Schema: add `skipped` to allowed node statuses |
| 38 | + |
| 39 | +Update node status check constraints so `skipped` is valid: |
| 40 | +- Install DDL in `src/lib.rs`: |
| 41 | + - `nodes_status_chk`: include `skipped`. |
| 42 | +- Upgrade DDL in next upgrade script: |
| 43 | + - drop and recreate `nodes_status_chk` (or equivalent alteration) to include `skipped`. |
| 44 | + |
| 45 | +`nodes_result_status_chk` can remain unchanged because `skipped` nodes should not carry `result`. |
| 46 | + |
| 47 | +### 2. Runtime: mark pending nodes as skipped at terminal failure |
| 48 | + |
| 49 | +Add an activity that performs one set-based update for a single instance: |
| 50 | + |
| 51 | +- New activity (suggested): `mark_pending_nodes_skipped`. |
| 52 | +- SQL behavior: |
| 53 | + - `UPDATE df.nodes` |
| 54 | + - `SET status = 'skipped', updated_at = now()` |
| 55 | + - `WHERE instance_id = $1 AND status = 'pending'` |
| 56 | + - guarded by `EXISTS (SELECT 1 FROM df.nodes WHERE instance_id = $1 AND status = 'failed')` |
| 57 | + |
| 58 | +Guard rationale: |
| 59 | +- Avoid changing semantics for failures that occur before any node execution (for example, instance-level rejection paths that currently do not mark node failures). |
| 60 | +- Keep behavior aligned with issue wording: downstream steps skipped due to an earlier step failure. |
| 61 | + |
| 62 | +### 3. Orchestration integration point |
| 63 | + |
| 64 | +In `execute_function_graph` top-level failure path (when instance is being moved to `failed`): |
| 65 | +- After node failure is recorded and before/after instance status update, schedule the new activity once for that instance. |
| 66 | +- Make the update idempotent and best-effort (safe if retried). |
| 67 | + |
| 68 | +Why this placement: |
| 69 | +- Central place where terminal failure is decided. |
| 70 | +- Avoids needing per-node graph traversal logic. |
| 71 | +- Handles linear and composite graphs (`THEN`, `IF`, `JOIN`, `RACE`, `LOOP`) uniformly. |
| 72 | + |
| 73 | +### 4. Optional hardening in `update_node_status` |
| 74 | + |
| 75 | +No required behavior change, but add a small guard in plan review: |
| 76 | +- Keep allowing transitions to `completed` / `failed` as today. |
| 77 | +- Ensure no code path writes result for `skipped`. |
| 78 | + |
| 79 | +## Backward Compatibility and Upgrade Strategy |
| 80 | + |
| 81 | +### Binary backward compatibility (B1) |
| 82 | + |
| 83 | +New `.so` may run against an older schema where `nodes_status_chk` does not include `skipped`. |
| 84 | +If runtime writes `skipped` in that state, updates would fail. |
| 85 | + |
| 86 | +Plan: |
| 87 | +- Runtime schema detection for `skipped` support before attempting the bulk update. |
| 88 | +- If unsupported, no-op and keep legacy behavior (`pending`). |
| 89 | + |
| 90 | +Implementation options: |
| 91 | +- Option A (preferred): activity checks `pg_constraint` definition for `nodes_status_chk` containing `skipped`. |
| 92 | +- Option B: attempt update inside savepoint-like handling and ignore check-constraint violation. |
| 93 | + |
| 94 | +Option A is clearer and avoids noisy errors. |
| 95 | + |
| 96 | +### Schema upgrade (A/B2) |
| 97 | + |
| 98 | +- Create next upgrade script `sql/pg_durable--0.2.2--0.2.3.sql` (version number illustrative; use actual next version). |
| 99 | +- Add DDL to update `nodes_status_chk` to include `skipped`. |
| 100 | +- Ensure fresh-install schema (from current `src/lib.rs` extension SQL) matches upgraded schema. |
| 101 | + |
| 102 | +## Test Plan |
| 103 | + |
| 104 | +### Unit / Rust-level |
| 105 | + |
| 106 | +- Activity test: when instance has a failed node plus pending nodes, only pending nodes become `skipped`. |
| 107 | +- Activity test: when no failed node exists, no rows are changed. |
| 108 | +- Compatibility test hook: when schema does not support `skipped`, activity no-ops without error. |
| 109 | + |
| 110 | +### E2E SQL |
| 111 | + |
| 112 | +Add a new E2E SQL test (for example `tests/e2e/sql/49_failed_downstream_nodes_skipped.sql`): |
| 113 | +- Build a 3-step sequence where step 2 fails. |
| 114 | +- Wait for terminal instance status `failed`. |
| 115 | +- Assert: |
| 116 | + - step 1 node is `completed` |
| 117 | + - step 2 node is `failed` |
| 118 | + - step 3 node is `skipped` (not `pending`) |
| 119 | +- Include clear failure messages. |
| 120 | + |
| 121 | +Also verify an instance-level failure path with no node failure (if represented in existing tests) does not force all nodes to `skipped`. |
| 122 | + |
| 123 | +### Upgrade tests |
| 124 | + |
| 125 | +Run: |
| 126 | +- `./scripts/test-upgrade.sh` |
| 127 | + |
| 128 | +Focus expectations: |
| 129 | +- Scenario A: fresh install vs upgraded schema parity for `nodes_status_chk`. |
| 130 | +- Scenario B1: new `.so` still works against old schema; `skipped` behavior degrades safely to legacy (`pending`) until upgrade. |
| 131 | +- Scenario B2: data remains accessible post-upgrade. |
| 132 | + |
| 133 | +## Docs Plan |
| 134 | + |
| 135 | +Update user-facing status vocabulary references: |
| 136 | +- `USER_GUIDE.md` (node status semantics) |
| 137 | +- `docs/api-reference.md` if status values are documented there |
| 138 | +- Optional release note entry in `CHANGELOG.md` |
| 139 | + |
| 140 | +## Rollout and Risk |
| 141 | + |
| 142 | +Risks: |
| 143 | +- Writing `skipped` against non-upgraded schema (mitigated by runtime check). |
| 144 | +- Unexpected interactions with in-flight parallel constructs (mitigated by set-based terminal update and idempotence). |
| 145 | + |
| 146 | +Rollout: |
| 147 | +1. Land schema + runtime + tests in one PR. |
| 148 | +2. Validate full local matrix: fmt, clippy, unit, e2e, upgrade. |
| 149 | +3. Document behavior change as node-level observability enhancement. |
| 150 | + |
| 151 | +## Acceptance Criteria |
| 152 | + |
| 153 | +- Failed workflow with downstream unexecuted nodes shows `skipped` for those nodes (post-upgrade schema). |
| 154 | +- No regression to existing instance terminal statuses. |
| 155 | +- New binary remains functional against pre-upgrade schema. |
| 156 | +- E2E and upgrade tests pass. |
| 157 | + |
| 158 | +## Implementation Checklist |
| 159 | + |
| 160 | +- [ ] Add `skipped` to node status check constraint in install DDL (`src/lib.rs`). |
| 161 | +- [ ] Add upgrade script change for `nodes_status_chk`. |
| 162 | +- [ ] Add new activity to mark pending nodes as skipped for failed instances. |
| 163 | +- [ ] Register activity in `src/registry.rs`. |
| 164 | +- [ ] Call activity from orchestration failure path. |
| 165 | +- [ ] Add schema-compatibility guard for pre-upgrade schemas. |
| 166 | +- [ ] Add E2E SQL coverage. |
| 167 | +- [ ] Update docs and changelog notes. |
| 168 | +- [ ] Run fmt, clippy, unit, e2e, upgrade tests. |
0 commit comments