|
| 1 | +--- |
| 2 | +summary: "Plan for connecting Durable Core with Background Tasks, Task Flow, and Workboard" |
| 3 | +read_when: |
| 4 | + - You are wiring native durable workflow state into OpenClaw task surfaces |
| 5 | + - You need an upstream-friendly contract between Durable Core and Workboard |
| 6 | + - You are debugging silent long-running agent coordination, fan-in, or gateway restart recovery |
| 7 | +title: "Durable Coordination Bridge Plan" |
| 8 | +--- |
| 9 | + |
| 10 | +# Durable Coordination Bridge Plan |
| 11 | + |
| 12 | +This plan connects the native Durable Core with three existing OpenClaw surfaces: |
| 13 | + |
| 14 | +- Background Tasks: the operator ledger for detached work. |
| 15 | +- Task Flow: the multi-step orchestration view above tasks. |
| 16 | +- Workboard: the optional plugin control board for agent-owned work. |
| 17 | + |
| 18 | +The bridge must stay upstream-friendly. Durable Core must not import or require |
| 19 | +the Workboard plugin. Workboard should consume a generic durable projection when |
| 20 | +the plugin is enabled. |
| 21 | + |
| 22 | +## Architecture decision |
| 23 | + |
| 24 | +Durable Core is the source of truth for workflow identity, run state, step |
| 25 | +ordering, child links, retry, recovery, signals, timers, and event history. |
| 26 | + |
| 27 | +Background Tasks, Task Flow, and Workboard are projections and control surfaces: |
| 28 | + |
| 29 | +- Background Tasks show individual detached runtime work. |
| 30 | +- Task Flow shows human-readable multi-step progress. |
| 31 | +- Workboard shows operational cards, claims, dispatch, proof, diagnostics, and |
| 32 | + recovery actions. |
| 33 | + |
| 34 | +The bridge is intentionally metadata-first at the beginning. Existing task and |
| 35 | +flow schemas already have `runId`, `parentFlowId`, `stateJson`, `waitJson`, and |
| 36 | +Workboard metadata. The first upstream-friendly PRs should avoid schema churn |
| 37 | +unless typed durable IDs become widely used. |
| 38 | + |
| 39 | +## Shared durable projection contract |
| 40 | + |
| 41 | +Durable Core exposes a small coordination projection: |
| 42 | + |
| 43 | +```ts |
| 44 | +type DurableCoordinationProjection = { |
| 45 | + workflowRunId: string; |
| 46 | + workflowId: string; |
| 47 | + workflowVersion: string; |
| 48 | + status: string; |
| 49 | + recoveryState: string; |
| 50 | + sourceType?: string; |
| 51 | + sourceRef?: string; |
| 52 | + parentWorkflowRunId?: string; |
| 53 | + parentStepId?: string; |
| 54 | + currentStepId?: string; |
| 55 | + waitingReason?: "signal" | "timer" | "child" | "retry" | "worker" | "unknown"; |
| 56 | + heartbeatAt?: number; |
| 57 | + updatedAt: number; |
| 58 | + completedAt?: number; |
| 59 | + refs: { |
| 60 | + inputRef?: string; |
| 61 | + checkpointRef?: string; |
| 62 | + outputRefs: string[]; |
| 63 | + errorRefs: string[]; |
| 64 | + artifactRefs: string[]; |
| 65 | + }; |
| 66 | + external: { |
| 67 | + taskId?: string; |
| 68 | + taskFlowId?: string; |
| 69 | + workboardCardId?: string; |
| 70 | + sessionKey?: string; |
| 71 | + runId?: string; |
| 72 | + agentId?: string; |
| 73 | + requesterAgentId?: string; |
| 74 | + }; |
| 75 | + children: { |
| 76 | + total: number; |
| 77 | + pending: number; |
| 78 | + running: number; |
| 79 | + succeeded: number; |
| 80 | + failed: number; |
| 81 | + cancelled: number; |
| 82 | + lost: number; |
| 83 | + terminal: number; |
| 84 | + open: number; |
| 85 | + }; |
| 86 | + controls: { |
| 87 | + canCancel: boolean; |
| 88 | + canRetry: boolean; |
| 89 | + canResume: boolean; |
| 90 | + canSignal: boolean; |
| 91 | + canOpenTimeline: boolean; |
| 92 | + }; |
| 93 | +}; |
| 94 | +``` |
| 95 | + |
| 96 | +This contract is stable enough for CLI, Gateway RPC, TaskFlow projections, and |
| 97 | +Workboard without making those systems depend on durable table internals. |
| 98 | + |
| 99 | +## Background Task bridge |
| 100 | + |
| 101 | +### Goals |
| 102 | + |
| 103 | +- Every subagent or detached agent task should be discoverable from its durable |
| 104 | + workflow run. |
| 105 | +- A durable child workflow should preserve `taskId`, `parentFlowId`, `runId`, |
| 106 | + `childSessionKey`, `agentId`, and `requesterAgentId`. |
| 107 | +- Task audit should be able to ask Durable Core whether a stale runtime is |
| 108 | + truly lost, retryable, waiting for child, or unknown after side effect. |
| 109 | + |
| 110 | +### Initial implementation |
| 111 | + |
| 112 | +When a subagent run is registered: |
| 113 | + |
| 114 | +1. Create or update the Background Task record as today. |
| 115 | +2. Capture the returned `taskId` and one-task `parentFlowId`. |
| 116 | +3. Mirror those IDs into the durable child run metadata. |
| 117 | +4. Mirror the same IDs into the parent durable child link metadata. |
| 118 | +5. Preserve the IDs when the durable child reaches terminal state. |
| 119 | + |
| 120 | +### Later implementation |
| 121 | + |
| 122 | +- Add task audit reconciliation that checks durable state before marking a task |
| 123 | + lost. |
| 124 | +- Add task CLI fields: |
| 125 | + - `durable.workflowRunId` |
| 126 | + - `durable.status` |
| 127 | + - `durable.recoveryState` |
| 128 | + - `durable.waitingReason` |
| 129 | +- Add a task cancel path that records a durable cancel signal before cancelling |
| 130 | + backing runtime handles. |
| 131 | + |
| 132 | +## Task Flow bridge |
| 133 | + |
| 134 | +### Goals |
| 135 | + |
| 136 | +- Task Flow remains the human-readable orchestration surface. |
| 137 | +- Durable Core owns fan-in/fan-out, retries, timers, and recovery. |
| 138 | +- A TaskFlow can be managed by Durable Core without rewriting TaskFlow storage. |
| 139 | + |
| 140 | +### Metadata convention |
| 141 | + |
| 142 | +TaskFlow `stateJson` may include: |
| 143 | + |
| 144 | +```json |
| 145 | +{ |
| 146 | + "durable": { |
| 147 | + "workflowRunId": "wfr_...", |
| 148 | + "workflowId": "openclaw.agent.turn", |
| 149 | + "status": "waiting_child", |
| 150 | + "recoveryState": "waiting_child", |
| 151 | + "currentStepId": "subagents", |
| 152 | + "waitingReason": "child", |
| 153 | + "children": { |
| 154 | + "total": 3, |
| 155 | + "running": 1, |
| 156 | + "succeeded": 1, |
| 157 | + "failed": 1, |
| 158 | + "open": 1 |
| 159 | + }, |
| 160 | + "updatedAt": 1234567890 |
| 161 | + } |
| 162 | +} |
| 163 | +``` |
| 164 | + |
| 165 | +TaskFlow `waitJson` may include: |
| 166 | + |
| 167 | +```json |
| 168 | +{ |
| 169 | + "durable": { |
| 170 | + "waitingReason": "child", |
| 171 | + "workflowRunId": "wfr_...", |
| 172 | + "stepId": "subagents" |
| 173 | + } |
| 174 | +} |
| 175 | +``` |
| 176 | + |
| 177 | +### Initial implementation |
| 178 | + |
| 179 | +- Add a pure Durable Core projection builder that can produce TaskFlow-safe JSON. |
| 180 | +- Keep TaskFlow writes out of Durable Core in the first bridge PR. |
| 181 | +- Let TaskFlow runtime or gateway later opt into writing the projection. |
| 182 | + |
| 183 | +### Later implementation |
| 184 | + |
| 185 | +- Add a TaskFlow sync job: |
| 186 | + - finds flows with durable bindings; |
| 187 | + - reads durable projection; |
| 188 | + - updates `status/currentStep/stateJson/waitJson`; |
| 189 | + - never blocks live agent execution. |
| 190 | +- Add a managed TaskFlow mode where Durable Core advances steps and TaskFlow is |
| 191 | + the operator view. |
| 192 | + |
| 193 | +## Workboard bridge |
| 194 | + |
| 195 | +### Goals |
| 196 | + |
| 197 | +- Workboard remains optional and plugin-owned. |
| 198 | +- Workboard can show durable state, child counts, retry state, waiting reason, |
| 199 | + and timeline links. |
| 200 | +- Workboard dispatch can start durable workflows when Durable Core is enabled, |
| 201 | + with existing subagent dispatch as fallback. |
| 202 | + |
| 203 | +### Metadata convention |
| 204 | + |
| 205 | +Workboard card metadata may include: |
| 206 | + |
| 207 | +```json |
| 208 | +{ |
| 209 | + "durable": { |
| 210 | + "workflowRunId": "wfr_...", |
| 211 | + "workflowId": "openclaw.subagent.run", |
| 212 | + "status": "running", |
| 213 | + "recoveryState": "running", |
| 214 | + "waitingReason": null, |
| 215 | + "taskId": "task_...", |
| 216 | + "taskFlowId": "flow_...", |
| 217 | + "sessionKey": "agent:bo:subagent:workboard-default-card", |
| 218 | + "runId": "run_...", |
| 219 | + "children": { |
| 220 | + "total": 0, |
| 221 | + "open": 0, |
| 222 | + "failed": 0 |
| 223 | + }, |
| 224 | + "timelineCommand": "openclaw durable timeline wfr_..." |
| 225 | + } |
| 226 | +} |
| 227 | +``` |
| 228 | + |
| 229 | +### Initial implementation |
| 230 | + |
| 231 | +- Add a durable projection helper that emits Workboard-safe metadata. |
| 232 | +- Do not import Workboard types from Durable Core. |
| 233 | +- Let Workboard adapter merge `metadata.durable` into cards later. |
| 234 | + |
| 235 | +### Later implementation |
| 236 | + |
| 237 | +- Add Workboard plugin adapter: |
| 238 | + - maps durable projection to card execution status; |
| 239 | + - maps durable stale/lost/retry/wait states to diagnostics; |
| 240 | + - links card to durable timeline; |
| 241 | + - writes only summaries, never full durable events. |
| 242 | +- Update Workboard dispatch: |
| 243 | + - start Durable Core workflow when enabled; |
| 244 | + - fallback to direct `subagent.run` when not enabled; |
| 245 | + - reuse card `idempotencyKey`. |
| 246 | + |
| 247 | +## PR stack |
| 248 | + |
| 249 | +This bridge PR stack is the integration subset of the broader upstream stack in |
| 250 | +[`durable-workflow-core-upstream-pr-stack.md`](./durable-workflow-core-upstream-pr-stack.md). |
| 251 | +The upstream stack should remain split so reviewers can accept durable store, |
| 252 | +gateway inspection, subagent fan-in, TaskFlow binding, and Workboard projection |
| 253 | +independently. |
| 254 | + |
| 255 | +1. Durable coordination projection contract. |
| 256 | + - Add pure projection module. |
| 257 | + - Add CLI `openclaw durable coordination <workflowRunId>`. |
| 258 | + - Add tests for child counts, waiting reason, and metadata patch output. |
| 259 | + - Status: implemented. |
| 260 | + |
| 261 | +2. Background Task durable binding. |
| 262 | + - Pass `taskId` and `parentFlowId` from subagent task creation into durable |
| 263 | + subagent metadata. |
| 264 | + - Preserve bindings through terminal updates. |
| 265 | + - Add tests around metadata preservation. |
| 266 | + - Status: implemented for subagent runs. |
| 267 | + |
| 268 | +3. TaskFlow projection writer. |
| 269 | + - Add optional helper that writes projection into `stateJson/waitJson`. |
| 270 | + - Add maintenance sync for flows with durable bindings. |
| 271 | + - Status: implemented as a best-effort helper and tests. Runtime wiring is |
| 272 | + intentionally left for a separate adapter PR so Durable Core does not |
| 273 | + depend directly on TaskFlow. |
| 274 | + |
| 275 | +4. Workboard projection adapter. |
| 276 | + - Add plugin-side adapter that reads durable projection. |
| 277 | + - Store compact `metadata.durable`. |
| 278 | + - Show status, waiting reason, child counts, and timeline command. |
| 279 | + - Status: implemented as plugin-side projection-to-card-patch adapter plus |
| 280 | + typed `metadata.durable` persistence and |
| 281 | + `workboard.cards.applyDurableProjection` gateway method. UI rendering is |
| 282 | + still pending. |
| 283 | + |
| 284 | +5. Durable dispatch path. |
| 285 | + - Let Workboard dispatch start durable workflows when enabled. |
| 286 | + - Keep direct subagent dispatch fallback. |
| 287 | + - Status: pending. |
| 288 | + |
| 289 | +6. Recovery integration. |
| 290 | + - Task audit asks Durable Core before marking task lost. |
| 291 | + - Workboard diagnostics consume durable stale/lost/retry findings. |
| 292 | + - Status: partial. Core recovery now reconciles retry timers and pending |
| 293 | + signals back to runnable run/step state. Task audit, TaskFlow projection |
| 294 | + refresh, and Workboard diagnostics are pending adapter work. |
| 295 | + |
| 296 | +7. Gateway read API. |
| 297 | + - Expose durable coordination projection to UI/plugin/operator clients. |
| 298 | + - Status: implemented as `durable.coordination.get` with `operator.read` |
| 299 | + scope. |
| 300 | + |
| 301 | +## Anti-goals |
| 302 | + |
| 303 | +- Do not make Workboard a required dependency of Durable Core. |
| 304 | +- Do not duplicate the full durable event timeline into task, flow, or card |
| 305 | + records. |
| 306 | +- Do not hard-code AICOS terms into upstream OpenClaw core. |
| 307 | +- Do not convert TaskFlow into a second event journal. |
| 308 | +- Do not block agent execution if a projection write fails. |
| 309 | + |
| 310 | +## Acceptance criteria |
| 311 | + |
| 312 | +- A subagent background task has a durable child workflow run. |
| 313 | +- The durable child run metadata contains task and flow identity when available. |
| 314 | +- A durable parent link preserves the same child task identity. |
| 315 | +- A CLI/user can inspect a durable coordination projection without direct SQLite |
| 316 | + queries. |
| 317 | +- A Gateway client can read a durable coordination projection through |
| 318 | + `durable.coordination.get`. |
| 319 | +- Workboard can consume the projection later without core importing Workboard. |
0 commit comments