| 1 | <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 420" role="img" aria-labelledby="wfFlowTitle wfFlowDesc"> |
| 2 | <title id="wfFlowTitle">A replay re-enters run() from the top, and the ledger answers for every finished step</title> |
| 3 | <desc id="wfFlowDesc">A workflow instance starts when create() makes the first run, and it starts again every time the cell alarm fires on the node that owns the cell at that moment. Each run re-executes run(event, step) from the first line. The instance cell holds a ledger under the __wf prefix, with one record per step occurrence. The first two steps, step.do("fetch") and step.do("charge"), read their stored results out of the ledger records step.1.fetch and step.1.charge, so their callbacks do not run again. A key counts the occurrences of one step name, so each of these names is at its first occurrence. The third step, step.sleep("wait"), reads the record step.1.wait, finds the stored wake time, and blocks because the deadline is not due. The run then arms the cell alarm at the earliest blocked deadline and returns, so the cell hibernates and a fleet wake entry holds the time instead of an isolate. No isolate waits for the deadline, and the node that owns the cell when the alarm fires runs the next replay. The loop closes from the hibernated cell back to the alarm on every resume.</desc> |
| 4 | <style> |
| 5 | svg { font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif; } |
| 6 | text { font-size: 12.5px; fill: currentColor; } |
| 7 | tspan { fill: currentColor; } |
| 8 | .sm { font-size: 11.5px; } |
| 9 | .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 11.5px; } |
| 10 | .d-ink { color: #121212; } |
| 11 | .d-soft { color: #3d3b37; } |
| 12 | .d-faint { color: #6e6a62; } |
| 13 | .d-acc { color: #10803f; } |
| 14 | .d-panel { color: #ffffff; } |
| 15 | .d-sunk { color: #f0eee8; } |
| 16 | .d-tint { color: #d6efdf; } |
| 17 | @media (prefers-color-scheme: dark) { |
| 18 | .d-ink { color: #efede7; } |
| 19 | .d-soft { color: #c9c6be; } |
| 20 | .d-faint { color: #928e85; } |
| 21 | .d-acc { color: #3fc472; } |
| 22 | .d-panel { color: #1a1a19; } |
| 23 | .d-sunk { color: #232321; } |
| 24 | .d-tint { color: #10301d; } |
| 25 | } |
| 26 | </style> |
| 27 | <defs> |
| 28 | <marker id="wf-arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" |
| 29 | markerHeight="6" orient="auto-start-reverse"> |
| 30 | <path class="d-soft" fill="currentColor" d="M0 0 L10 5 L0 10 z" /> |
| 31 | </marker> |
| 32 | </defs> |
| 33 | |
| 34 | <!-- The two entries into a run: the first create, and every later alarm. --> |
| 35 | <rect class="d-tint" fill="currentColor" x="36" y="6" width="216" height="44" rx="6" /> |
| 36 | <rect class="d-acc" fill="none" stroke="currentColor" stroke-width="2" x="36" y="6" width="216" height="44" rx="6" /> |
| 37 | <text class="d-ink" fill="currentColor" x="144" y="26" text-anchor="middle">the alarm fires</text> |
| 38 | <text class="d-soft sm" fill="currentColor" x="144" y="42" text-anchor="middle">on the node that owns the cell</text> |
| 39 | |
| 40 | <rect class="d-panel" fill="currentColor" x="288" y="6" width="152" height="44" rx="6" /> |
| 41 | <rect class="d-soft" fill="none" stroke="currentColor" x="288" y="6" width="152" height="44" rx="6" /> |
| 42 | <text class="d-ink mono" fill="currentColor" x="364" y="26" text-anchor="middle">create()</text> |
| 43 | <text class="d-soft sm" fill="currentColor" x="364" y="42" text-anchor="middle">starts the first run</text> |
| 44 | |
| 45 | <g class="d-soft" fill="none" stroke="currentColor" stroke-width="1.5"> |
| 46 | <path d="M364 50 V56 H144" /> |
| 47 | <path d="M144 50 V62" marker-end="url(#wf-arrow)" /> |
| 48 | </g> |
| 49 | |
| 50 | <!-- The replay: one invocation that always begins at the first line. --> |
| 51 | <rect class="d-sunk" fill="currentColor" x="36" y="62" width="216" height="206" rx="8" /> |
| 52 | <rect class="d-soft" fill="none" stroke="currentColor" x="36" y="62" width="216" height="206" rx="8" /> |
| 53 | <text class="d-ink mono" fill="currentColor" x="144" y="84" text-anchor="middle">run(event, step)</text> |
| 54 | <text class="d-faint sm" fill="currentColor" x="144" y="101" text-anchor="middle">re-executed from the top</text> |
| 55 | |
| 56 | <rect class="d-panel" fill="currentColor" x="46" y="112" width="196" height="44" rx="6" /> |
| 57 | <rect class="d-soft" fill="none" stroke="currentColor" x="46" y="112" width="196" height="44" rx="6" /> |
| 58 | <text class="d-ink mono" fill="currentColor" x="58" y="131">step.do("fetch")</text> |
| 59 | <text class="d-acc sm" fill="currentColor" x="58" y="148">ledger hit, callback skipped</text> |
| 60 | |
| 61 | <rect class="d-panel" fill="currentColor" x="46" y="164" width="196" height="44" rx="6" /> |
| 62 | <rect class="d-soft" fill="none" stroke="currentColor" x="46" y="164" width="196" height="44" rx="6" /> |
| 63 | <text class="d-ink mono" fill="currentColor" x="58" y="183">step.do("charge")</text> |
| 64 | <text class="d-acc sm" fill="currentColor" x="58" y="200">ledger hit, callback skipped</text> |
| 65 | |
| 66 | <rect class="d-tint" fill="currentColor" x="46" y="216" width="196" height="44" rx="6" /> |
| 67 | <rect class="d-acc" fill="none" stroke="currentColor" stroke-width="2" x="46" y="216" width="196" height="44" rx="6" /> |
| 68 | <text class="d-ink mono" fill="currentColor" x="58" y="235">step.sleep("wait")</text> |
| 69 | <text class="d-soft sm" fill="currentColor" x="58" y="252">not due, so it blocks</text> |
| 70 | |
| 71 | <!-- The ledger in the instance cell: one record per step occurrence. --> |
| 72 | <rect class="d-sunk" fill="currentColor" x="288" y="62" width="152" height="206" rx="8" /> |
| 73 | <rect class="d-soft" fill="none" stroke="currentColor" x="288" y="62" width="152" height="206" rx="8" /> |
| 74 | <text class="d-ink" fill="currentColor" x="364" y="84" text-anchor="middle">instance cell</text> |
| 75 | <text class="d-faint mono" fill="currentColor" x="364" y="101" text-anchor="middle">__wf ledger</text> |
| 76 | |
| 77 | <rect class="d-panel" fill="currentColor" x="296" y="112" width="136" height="44" rx="6" /> |
| 78 | <rect class="d-soft" fill="none" stroke="currentColor" x="296" y="112" width="136" height="44" rx="6" /> |
| 79 | <text class="d-soft mono" fill="currentColor" x="306" y="131">step.1.fetch</text> |
| 80 | <text class="d-ink mono" fill="currentColor" x="306" y="148">{bytes: 812}</text> |
| 81 | |
| 82 | <rect class="d-panel" fill="currentColor" x="296" y="164" width="136" height="44" rx="6" /> |
| 83 | <rect class="d-soft" fill="none" stroke="currentColor" x="296" y="164" width="136" height="44" rx="6" /> |
| 84 | <text class="d-soft mono" fill="currentColor" x="306" y="183">step.1.charge</text> |
| 85 | <text class="d-ink mono" fill="currentColor" x="306" y="200">{ok: true}</text> |
| 86 | |
| 87 | <rect class="d-tint" fill="currentColor" x="296" y="216" width="136" height="44" rx="6" /> |
| 88 | <rect class="d-acc" fill="none" stroke="currentColor" stroke-width="2" x="296" y="216" width="136" height="44" rx="6" /> |
| 89 | <text class="d-soft mono" fill="currentColor" x="306" y="235">step.1.wait</text> |
| 90 | <text class="d-ink mono" fill="currentColor" x="306" y="252">wake at 09:00</text> |
| 91 | |
| 92 | <!-- The ledger answers; the callback never starts. --> |
| 93 | <g class="d-soft" fill="none" stroke="currentColor" stroke-width="1.5"> |
| 94 | <path d="M288 134 H254" marker-end="url(#wf-arrow)" /> |
| 95 | <path d="M288 186 H254" marker-end="url(#wf-arrow)" /> |
| 96 | <path d="M288 238 H254" marker-end="url(#wf-arrow)" /> |
| 97 | <path d="M144 268 V292" marker-end="url(#wf-arrow)" /> |
| 98 | <path d="M144 344 V356" marker-end="url(#wf-arrow)" /> |
| 99 | </g> |
| 100 | |
| 101 | <!-- The blocked step ends the invocation instead of waiting inside it. --> |
| 102 | <rect class="d-panel" fill="currentColor" x="36" y="292" width="216" height="52" rx="6" /> |
| 103 | <rect class="d-soft" fill="none" stroke="currentColor" x="36" y="292" width="216" height="52" rx="6" /> |
| 104 | <text class="d-ink" fill="currentColor" x="144" y="313" text-anchor="middle">arm the cell alarm at the</text> |
| 105 | <text class="d-ink" fill="currentColor" x="144" y="331" text-anchor="middle">earliest blocked deadline</text> |
| 106 | |
| 107 | <rect class="d-sunk" fill="currentColor" x="36" y="356" width="216" height="52" rx="6" /> |
| 108 | <rect class="d-soft" fill="none" stroke="currentColor" x="36" y="356" width="216" height="52" rx="6" /> |
| 109 | <text class="d-ink" fill="currentColor" x="144" y="377" text-anchor="middle">the cell hibernates</text> |
| 110 | <text class="d-soft sm" fill="currentColor" x="144" y="395" text-anchor="middle">a fleet wake entry holds the time</text> |
| 111 | |
| 112 | <rect class="d-faint" fill="none" stroke="currentColor" stroke-dasharray="5 4" |
| 113 | x="288" y="292" width="152" height="116" rx="8" /> |
| 114 | <text class="d-faint sm" fill="currentColor" x="364" y="318" text-anchor="middle">no isolate waits</text> |
| 115 | <text class="d-faint sm" fill="currentColor" x="364" y="336" text-anchor="middle">for the deadline.</text> |
| 116 | <text class="d-faint sm" fill="currentColor" x="364" y="360" text-anchor="middle">the owner at that</text> |
| 117 | <text class="d-faint sm" fill="currentColor" x="364" y="378" text-anchor="middle">moment runs the</text> |
| 118 | <text class="d-faint sm" fill="currentColor" x="364" y="396" text-anchor="middle">next replay.</text> |
| 119 | |
| 120 | <!-- The back edge: the loop that makes this a replay and not a sequence. --> |
| 121 | <path class="d-soft" fill="none" stroke="currentColor" stroke-width="1.5" |
| 122 | stroke-dasharray="6 4" d="M36 382 H10 V28 H36" marker-end="url(#wf-arrow)" /> |
| 123 | <text class="d-faint sm" fill="currentColor" x="26" y="200" text-anchor="middle" |
| 124 | transform="rotate(-90 26 200)">every resume</text> |
| 125 | </svg> |