@osolmaz/pi-workflows 0.16.0 → 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -2
- package/dist/channels/adapter-entry.d.ts +3 -0
- package/dist/channels/adapter-entry.js +203 -0
- package/dist/channels/adapter-entry.js.map +1 -0
- package/dist/channels/config.d.ts +43 -0
- package/dist/channels/config.js +234 -0
- package/dist/channels/config.js.map +1 -0
- package/dist/channels/protocol.d.ts +94 -0
- package/dist/channels/protocol.js +219 -0
- package/dist/channels/protocol.js.map +1 -0
- package/dist/channels/telegram.d.ts +46 -0
- package/dist/channels/telegram.js +285 -0
- package/dist/channels/telegram.js.map +1 -0
- package/dist/client/client.d.ts +1 -0
- package/dist/client/client.js +5 -1
- package/dist/client/client.js.map +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/protocol.d.ts +1 -1
- package/dist/client/protocol.js +11 -5
- package/dist/client/protocol.js.map +1 -1
- package/dist/client/view.d.ts +42 -16
- package/dist/client/view.js.map +1 -1
- package/dist/controllers/index.d.ts +1 -1
- package/dist/controllers/index.js.map +1 -1
- package/dist/controllers/sqlite.d.ts +12 -165
- package/dist/controllers/sqlite.js +124 -435
- package/dist/controllers/sqlite.js.map +1 -1
- package/dist/extension/index.d.ts +23 -2
- package/dist/extension/index.js +619 -535
- package/dist/extension/index.js.map +1 -1
- package/dist/extension/recorder.d.ts +95 -0
- package/dist/extension/recorder.js +530 -0
- package/dist/extension/recorder.js.map +1 -0
- package/dist/extension/remote-recorder-store.d.ts +25 -0
- package/dist/extension/remote-recorder-store.js +81 -0
- package/dist/extension/remote-recorder-store.js.map +1 -0
- package/dist/extension/session-events.d.ts +134 -0
- package/dist/extension/session-events.js +60 -0
- package/dist/extension/session-events.js.map +1 -0
- package/dist/extension/session-view.d.ts +2 -0
- package/dist/extension/session-view.js +60 -2
- package/dist/extension/session-view.js.map +1 -1
- package/dist/extension/step-message.d.ts +6 -4
- package/dist/extension/step-message.js +12 -6
- package/dist/extension/step-message.js.map +1 -1
- package/dist/extension/widget.d.ts +2 -2
- package/dist/extension/widget.js +28 -18
- package/dist/extension/widget.js.map +1 -1
- package/dist/extension/workflow-message-coordinator.d.ts +27 -0
- package/dist/extension/workflow-message-coordinator.js +294 -0
- package/dist/extension/workflow-message-coordinator.js.map +1 -0
- package/dist/host/channel-effects.d.ts +72 -0
- package/dist/host/channel-effects.js +271 -0
- package/dist/host/channel-effects.js.map +1 -0
- package/dist/host/channel-supervisor.d.ts +21 -0
- package/dist/host/channel-supervisor.js +54 -0
- package/dist/host/channel-supervisor.js.map +1 -0
- package/dist/host/runner.d.ts +43 -8
- package/dist/host/runner.js +1567 -331
- package/dist/host/runner.js.map +1 -1
- package/dist/host/state.d.ts +19 -16
- package/dist/host/state.js +251 -63
- package/dist/host/state.js.map +1 -1
- package/dist/host/view.d.ts +19 -9
- package/dist/host/view.js +222 -118
- package/dist/host/view.js.map +1 -1
- package/dist/state/prune.js +3 -25
- package/dist/state/prune.js.map +1 -1
- package/dist/state/schema.js +76 -97
- package/dist/state/schema.js.map +1 -1
- package/dist/state/workflow-messages.d.ts +96 -0
- package/dist/state/workflow-messages.js +335 -0
- package/dist/state/workflow-messages.js.map +1 -0
- package/dist/viewer/render.js +1 -1
- package/dist/viewer/render.js.map +1 -1
- package/dist/viewer/tui.d.ts +1 -1
- package/dist/viewer/tui.js +65 -8
- package/dist/viewer/tui.js.map +1 -1
- package/dist/workflows/human-decision.d.ts +2 -0
- package/dist/workflows/human-decision.js +8 -2
- package/dist/workflows/human-decision.js.map +1 -1
- package/dist/workflows/index.d.ts +1 -1
- package/dist/workflows/index.js.map +1 -1
- package/dist/workflows/settings.d.ts +1 -8
- package/dist/workflows/settings.js.map +1 -1
- package/dist/workflows/store.d.ts +5 -19
- package/dist/workflows/store.js +121 -354
- package/dist/workflows/store.js.map +1 -1
- package/dist/workflows/tool-input.d.ts +21 -0
- package/dist/workflows/tool-input.js +23 -1
- package/dist/workflows/tool-input.js.map +1 -1
- package/dist/workflows/types.d.ts +5 -5
- package/dist/workflows/workflow-message-content.d.ts +38 -0
- package/dist/workflows/workflow-message-content.js +157 -0
- package/dist/workflows/workflow-message-content.js.map +1 -0
- package/docs/2026-08-18-herdr-piw-plan.md +2 -1
- package/docs/2026-08-20-durable-workflow-launch-plan.md +1 -1
- package/docs/2026-08-25-workflow-follow-ups.md +26 -50
- package/docs/2026-08-30-out-of-process-workflow-host-plan.md +3 -3
- package/docs/2026-09-01-restore-session-delivery-controls-plan.md +4 -0
- package/docs/2026-09-01-unified-workflow-client-plan.md +5 -1
- package/docs/2026-09-02-installed-live-e2e-plan.md +15 -1
- package/docs/2026-09-02-unify-workflow-messages-plan.md +562 -0
- package/docs/DEFERRED_TURNS.md +66 -294
- package/docs/HUMAN_DECISIONS.md +29 -30
- package/docs/HUMAN_DECISION_PRESENTATIONS.md +4 -11
- package/docs/SQLITE_STATE.md +19 -15
- package/docs/WORKFLOW_HOST.md +93 -28
- package/docs/WORKFLOW_STEP_MESSAGES.md +166 -75
- package/docs/live-replay-protocol.md +8 -4
- package/docs/tui-viewer.md +3 -1
- package/docs/workflows.md +34 -27
- package/herdr-plugin.toml +1 -1
- package/package.json +1 -1
- package/plugins/herdr/viewer.mjs +14 -5
- package/src/channels/adapter-entry.ts +220 -0
- package/src/channels/config.ts +296 -0
- package/src/channels/protocol.ts +333 -0
- package/src/channels/telegram.ts +335 -0
- package/src/client/client.ts +6 -2
- package/src/client/index.ts +2 -1
- package/src/client/protocol.ts +11 -5
- package/src/client/view.ts +43 -18
- package/src/controllers/index.ts +0 -1
- package/src/controllers/sqlite.ts +164 -844
- package/src/extension/index.ts +693 -646
- package/src/extension/recorder.ts +687 -0
- package/src/extension/remote-recorder-store.ts +126 -0
- package/src/extension/session-events.ts +119 -0
- package/src/extension/session-view.ts +86 -3
- package/src/extension/step-message.ts +19 -9
- package/src/extension/widget.ts +37 -17
- package/src/extension/workflow-message-coordinator.ts +334 -0
- package/src/host/channel-effects.ts +465 -0
- package/src/host/channel-supervisor.ts +73 -0
- package/src/host/runner.ts +2120 -531
- package/src/host/state.ts +333 -94
- package/src/host/view.ts +249 -121
- package/src/state/prune.ts +3 -31
- package/src/state/schema.ts +76 -97
- package/src/state/workflow-messages.ts +548 -0
- package/src/viewer/render.ts +1 -5
- package/src/viewer/tui.ts +71 -6
- package/src/workflows/human-decision.ts +18 -2
- package/src/workflows/index.ts +0 -1
- package/src/workflows/settings.ts +1 -20
- package/src/workflows/store.ts +173 -489
- package/src/workflows/tool-input.ts +36 -1
- package/src/workflows/types.ts +5 -5
- package/src/workflows/workflow-message-content.ts +197 -0
- package/dist/extension/decision-channels.d.ts +0 -134
- package/dist/extension/decision-channels.js +0 -1307
- package/dist/extension/decision-channels.js.map +0 -1
- package/src/extension/decision-channels.ts +0 -1826
package/docs/SQLITE_STATE.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# SQLite state
|
|
2
2
|
|
|
3
|
+
Status: this is the implemented single-host database contract. The [workflow-message plan](2026-09-02-unify-workflow-messages-plan.md) records the schema version 1 hard cut that unified Pi message state and restored hosted behavior.
|
|
4
|
+
|
|
3
5
|
Pi Workflows stores all live durable state in one database:
|
|
4
6
|
|
|
5
7
|
```text
|
|
@@ -31,7 +33,7 @@ The database stores:
|
|
|
31
33
|
- run and controller queues, claims, retries, and continuations
|
|
32
34
|
- human-decision requests, submissions, resolutions, and cancellations
|
|
33
35
|
- controller resources, finalizers, effects, and child workflows
|
|
34
|
-
-
|
|
36
|
+
- workflow messages that Pi must add to origin conversations
|
|
35
37
|
- workflow settings, accepted JSON Patch changes, and post-completion follow-up prompts
|
|
36
38
|
- nonsecret channel cursors, inbox records, messages, and settlement receipts
|
|
37
39
|
- canonical JSON, text, and large text values
|
|
@@ -72,7 +74,7 @@ Four record groups provide the common lifecycle rules.
|
|
|
72
74
|
|
|
73
75
|
### Resources
|
|
74
76
|
|
|
75
|
-
`resources` identifies each mutable aggregate and holds its current revision. Runs, settings scopes, follow-up
|
|
77
|
+
`resources` identifies each mutable aggregate and holds its current revision. Runs, settings scopes, follow-up items, decisions, controller resources, effects, channels, workflow messages, and session segments have stable resource identities.
|
|
76
78
|
|
|
77
79
|
Every accepted domain command compares its expected revision and increments it once.
|
|
78
80
|
|
|
@@ -104,6 +106,8 @@ A domain row and its event are written in one transaction. Normal APIs never upd
|
|
|
104
106
|
|
|
105
107
|
Local effects use deterministic transactions. Run queue settlement effects are created only for runs that have a `run_queue` row; direct engine and controller-child runs do not create phantom queue work. External effects use provider idempotency or observation when available. An uncertain result becomes `ambiguous` and is not repeated without evidence.
|
|
106
108
|
|
|
109
|
+
Telegram delivery and settlement use these shared effect records. The host records one numbered attempt before it tells the supervised adapter child to act. A confirmed result stores Telegram message references in the effect result. `channel_messages` stores the decision feature's delivery or settlement receipt; it does not copy effect state or external message references.
|
|
110
|
+
|
|
107
111
|
## Domain tables
|
|
108
112
|
|
|
109
113
|
The shared records do not replace domain schemas. The following `STRICT` tables keep the state explicit:
|
|
@@ -116,15 +120,19 @@ The shared records do not replace domain schemas. The following `STRICT` tables
|
|
|
116
120
|
| Host protocol | `host_commands`, `run_workers`, `worker_messages`, `interactive_requests`, `interactive_submissions` |
|
|
117
121
|
| Workflows | `workflow_definitions`, `runs`, `run_sources`, `run_steps`, `run_bindings`, `run_queue`, `node_attempts`, `workflow_updates` |
|
|
118
122
|
| Live settings | `workflow_settings`, `workflow_setting_changes` |
|
|
119
|
-
| Post-run follow-ups | `
|
|
123
|
+
| Post-run follow-ups | `workflow_follow_ups` |
|
|
120
124
|
| Session capture | `session_segments`, `session_entries`, `attempt_entries`, `session_events` |
|
|
121
125
|
| Human decisions | `human_decisions`, `human_decision_resolutions`, `human_decision_submissions`, `continuations` |
|
|
122
126
|
| Controllers | `controller_resources`, `controller_finalizers`, `controller_queue`, `controller_workflows` |
|
|
123
127
|
| Effects | `effects`, `effect_attempts` |
|
|
124
|
-
| Pi
|
|
125
|
-
| Channels | `channels`, `channel_cursors`, `
|
|
128
|
+
| Pi messages | `workflow_messages` |
|
|
129
|
+
| Channels | `channels`, `channel_cursors`, `channel_messages` |
|
|
130
|
+
|
|
131
|
+
`workflow_messages` is the only table that owns adding workflow content to Pi. It stores the target session, message kind, source record, content digest, session order, `pending`, `sent`, or `cancelled` state, confirmed Pi entry ID, and creation and update times. The table stores no sender, send lease, `sending` state, or separate sent time. Active-branch evidence changes `pending` or `cancelled` to `sent`. Initial, reminder, and resumed prompts are all `step` messages; their custom details contain the reason. Interactive requests, decisions, terminal runs, notifications, follow-ups, and settings keep their own domain state.
|
|
132
|
+
|
|
133
|
+
`channels` stores configured channel resource identities. `channel_cursors` stores the last accepted external polling position. `channel_messages` stores immutable decision delivery and settlement records for audit and duplicate evidence. External application state and Telegram message references belong to `effects` and `effect_attempts`.
|
|
126
134
|
|
|
127
|
-
Foreign keys join projects, runs, attempts, decisions, controllers, effects, and channel records. Partial unique indexes enforce one active node attempt per run, one
|
|
135
|
+
Foreign keys join projects, runs, attempts, decisions, controllers, effects, and channel records. Partial unique indexes enforce one active node attempt per run, one pending step message per interaction request, one nonterminal interactive continuation-chain reservation per Pi session, one decision winner, and one deterministic effect key. A run waiting for a checkpoint or protected decision keeps that chain reservation. A parked waiting parent does not block its own continuation. Reserving that continuation transfers the reservation and settles the parked parent queue in the same transaction, so a failed reservation leaves the parent recoverable.
|
|
128
136
|
|
|
129
137
|
### Hosted commands and interactions
|
|
130
138
|
|
|
@@ -138,11 +146,7 @@ conflict.
|
|
|
138
146
|
process identity and terminal outcome. `worker_messages` deduplicates accepted
|
|
139
147
|
state-changing child messages.
|
|
140
148
|
|
|
141
|
-
`interactive_requests` owns durable origin-session work. It stores the run,
|
|
142
|
-
node attempt, target session, contract, presentation claim, accepted
|
|
143
|
-
submission, and revision. `interactive_submissions` stores the idempotency key,
|
|
144
|
-
payload, outcome, and receipt. Pi reload can adopt the saved presentation entry
|
|
145
|
-
without inserting another visible message.
|
|
149
|
+
`interactive_requests` owns the durable request contract and workflow state for origin-session work. It stores the run, node attempt, target session, contract, request status, accepted submission, `unproductiveTurnEnds`, and revision. Pause is stored once on the run and derived for its one pending interaction. `interactive_submissions` stores the idempotency key, payload, outcome, and receipt. It stores no Pi presentation claim or Pi session entry. `workflow_messages` owns those facts, and the extension reports the active Pi branch after reload.
|
|
146
150
|
|
|
147
151
|
## Content-addressed values
|
|
148
152
|
|
|
@@ -195,7 +199,7 @@ Reading or finding a row never gives write authority.
|
|
|
195
199
|
- A run owner may advance the run, apply automatic decision policy, create its continuation, settle its parent, and complete its queue work.
|
|
196
200
|
- A controller claim owner may update controller status, reserve effects, and start child workflows for that resource.
|
|
197
201
|
- A verified human channel actor may submit one answer candidate for the named decision. It does not gain run ownership.
|
|
198
|
-
-
|
|
202
|
+
- The host-owned channel adapter path may update only its channel cursor, decision delivery and settlement records, and exact managed effects.
|
|
199
203
|
- Control commands have narrow explicit operations, such as requesting cancellation or deletion.
|
|
200
204
|
- Model-originated workflow answers cannot resolve protected human decisions.
|
|
201
205
|
|
|
@@ -215,13 +219,13 @@ The same rule applies to run terminal outcomes, continuation admission, queue se
|
|
|
215
219
|
|
|
216
220
|
## Read contract
|
|
217
221
|
|
|
218
|
-
Durable status is a pure projection of domain rows, immutable facts, current leases,
|
|
222
|
+
Durable status is a pure projection of domain rows, immutable facts, current leases, effect results, and exact workflow-turn start and end reports. The host uses these facts to produce one live run view. An open workflow turn can change display status only. It cannot change workflow authority. Every renderer consumes the host-produced display status and allowed controls without running another status reducer.
|
|
219
223
|
|
|
220
224
|
A settings scope uses its resource revision as its public change number. Each accepted patch, current value, and node binding is saved in one transaction. A checkpoint continuation keeps the same settings resources and transfers them to the continuation run.
|
|
221
225
|
|
|
222
|
-
|
|
226
|
+
`workflow_follow_ups` records source acceptance order, removal, and cancellation. The source and message stay attached to the continuation-chain member that accepted them; rows are not rewritten when the chain continues. The host walks the chain to find its final outcome. `workflow_messages` owns message state and Pi entry evidence. Failure, timeout, and cancellation cancel unsent follow-up messages.
|
|
223
227
|
|
|
224
|
-
- A terminal run fact overrides stale
|
|
228
|
+
- A terminal run fact overrides stale message state.
|
|
225
229
|
- An accepted decision is accepted even if its continuation effect is still pending.
|
|
226
230
|
- A cancelled decision is cancelled even if parent cleanup is still pending.
|
|
227
231
|
- A stale owner is not shown as current.
|
package/docs/WORKFLOW_HOST.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Workflow host
|
|
2
2
|
|
|
3
|
-
Status:
|
|
3
|
+
Status: the out-of-process host, unified live client, workflow-message contract, and restored session behavior are implemented. [Unify workflow messages and restore hosted behavior](2026-09-02-unify-workflow-messages-plan.md), [run workflows outside Pi](2026-08-30-out-of-process-workflow-host-plan.md), [restore workflow session delivery and controls](2026-09-01-restore-session-delivery-controls-plan.md), and [unify live workflow clients](2026-09-01-unified-workflow-client-plan.md) record the design and implementation plans.
|
|
4
4
|
|
|
5
5
|
## Purpose
|
|
6
6
|
|
|
@@ -21,6 +21,7 @@ The host solves two different failures:
|
|
|
21
21
|
- **Generation:** A number increased each time a new owner claims a run. It fences older owners.
|
|
22
22
|
- **Durable boundary:** A committed node or lifecycle transition from which execution can resume.
|
|
23
23
|
- **Interactive request:** A durable agent or assistant-message step that must run in the origin Pi session.
|
|
24
|
+
- **Workflow message:** Host-owned content that Pi must add to an origin conversation, such as a step, reminder, decision, notification, terminal result, or follow-up.
|
|
24
25
|
- **Managed effect:** A side effect reserved and settled through an idempotent durable record.
|
|
25
26
|
- **Live run view:** The host's versioned, bounded projection of one run, including its durable state, current origin-session activity, allowed controls, and page cursors.
|
|
26
27
|
- **Renderer:** A Pi widget, status line, command-line view, Herdr adapter, or `piw` screen that displays or acts on a live run view without deriving workflow state.
|
|
@@ -45,10 +46,11 @@ piw ──────────┘
|
|
|
45
46
|
Remote piw ── SSH tunnel ── loopback WebSocket relay ────────┤
|
|
46
47
|
├── run worker B ── headless pi --mode rpc
|
|
47
48
|
├── controller worker
|
|
49
|
+
├── channel adapter child
|
|
48
50
|
└── source resolver
|
|
49
51
|
```
|
|
50
52
|
|
|
51
|
-
The local socket and loopback WebSocket relay carry the same logical client protocol and live run view. The relay reads no state and translates no domain contract. The host is the only production process that opens the live SQLite database.
|
|
53
|
+
The local socket and loopback WebSocket relay carry the same logical client protocol and live run view. The relay reads no state and translates no domain contract. The host is the only production process that opens the live SQLite database. Worker, channel-adapter, and source-resolver channels are private supervision protocols, not alternate client interfaces.
|
|
52
54
|
|
|
53
55
|
The host may manage runs from more than one project. Each run keeps its canonical project path and source identity.
|
|
54
56
|
|
|
@@ -56,6 +58,8 @@ The host process performs only bounded protocol handling, live-view projection,
|
|
|
56
58
|
|
|
57
59
|
A worker loads one workflow source and executes one run generation. It cannot receive a writable `WorkflowRunStore`. It proposes changes to the host over a private child channel. This is an architectural guard against accidental writes. It is not a security sandbox against code running as the same operating-system user.
|
|
58
60
|
|
|
61
|
+
A channel adapter child handles one approved external presentation channel. It receives only the rendered presentation and the private channel configuration needed for its work. It does not open SQLite or receive the decision subject. The host owns claims, answer verification, settlement, and process supervision.
|
|
62
|
+
|
|
59
63
|
## Host lifecycle
|
|
60
64
|
|
|
61
65
|
The package CLI owns host lifecycle commands:
|
|
@@ -71,7 +75,7 @@ pi-workflows host run
|
|
|
71
75
|
|
|
72
76
|
The host uses one global lock and one host epoch. Socket creation and the SQLite host claim must agree before the host accepts commands. A second live host refuses to start. After the old host lease expires, a new host increases the epoch before it handles work. Messages from an older epoch are rejected.
|
|
73
77
|
|
|
74
|
-
The host stays alive while it has a connected client, an active worker, a scheduled wake, a pending controller, or unsettled work. An idle host may exit after a documented idle period. A later client can start it again.
|
|
78
|
+
The host stays alive while it has a connected client, an active worker, a scheduled wake, a pending controller, a pending external-channel decision, or other unsettled work. An idle host may exit after a documented idle period. A later client can start it again.
|
|
75
79
|
|
|
76
80
|
## Claim rules
|
|
77
81
|
|
|
@@ -214,7 +218,7 @@ Each message uses one envelope:
|
|
|
214
218
|
}
|
|
215
219
|
```
|
|
216
220
|
|
|
217
|
-
The `type` is `hello`, `request`, `response`, or `event`. A response repeats the request ID and includes its outcome, revision, receipt, or bounded safe error. An event names its subscription and carries one revisioned run-list snapshot, run-view snapshot, patch, page, origin-session
|
|
221
|
+
The `type` is `hello`, `request`, `response`, or `event`. A response repeats the request ID and includes its outcome, revision, receipt, or bounded safe error. An event names its subscription and carries one revisioned run-list snapshot, run-view snapshot, patch, page, origin-session workflow-message change, or availability change. Valid command outcomes remain `accepted`, `adopted`, `rejected`, `conflict`, `notFound`, `claimLost`, and `unavailable`.
|
|
218
222
|
|
|
219
223
|
The host commits a command receipt before it acknowledges success. The request ID identifies one transport attempt and is excluded from the durable fingerprint. The Pi extension sends state-changing commands through the durable client path. If a connection closes after commit but before response, a retry uses a new request ID with the same client ID, idempotency key, operation, and payload, then adopts the stored receipt. Reusing a request ID or idempotency key with another durable payload returns a conflict. An `interaction.submit` response stays pending while the supervised child validates the value and settles only after the durable outcome is `accepted`, `adopted`, or `rejected`. A reconnect with the same durable identity and payload waits for and returns that same outcome. Clients do not poll SQLite for submission results.
|
|
220
224
|
|
|
@@ -222,20 +226,24 @@ View and subscription reads do not create receipts. Reconnection restores desire
|
|
|
222
226
|
|
|
223
227
|
The protocol owns four operation groups:
|
|
224
228
|
|
|
225
|
-
- run and controller commands, including start, pause, resume, cancel,
|
|
226
|
-
- live views, including
|
|
227
|
-
-
|
|
228
|
-
- state maintenance, including status, verification, backup, and
|
|
229
|
+
- run and controller commands, including start, pause, resume, cancel, restart, decisions, updates, submissions, settings, follow-ups, reconciliation, and host control;
|
|
230
|
+
- live views and recording, including run lists, snapshots, subscriptions, pages, referenced content, origin-session workflow messages, terminal-view clear, and batched session events;
|
|
231
|
+
- active-branch and model-turn reports;
|
|
232
|
+
- state and channel maintenance, including status, verification, backup, prune, channel status, channel reload, and explicit channel recovery against the active database. Backup and applied prune use one fresh CLI idempotency key per user invocation. An automatic reconnect retry keeps that key and uses a new request ID. A later invocation gets a new key. The host finishes an in-flight operation after a disconnect, stores its accepted or rejected receipt before response, waits for it during shutdown, and adopts an exact retry.
|
|
229
233
|
|
|
230
|
-
`
|
|
234
|
+
`workflowMessage.reportBranch` reports workflow message IDs and Pi entry IDs from the complete origin-session view window together with `isIdle` and `hasPendingMessages`. The host adopts matching entries, changes a matching pending or cancelled message to `sent`, closes proved-lost turns, and creates one missing message of the source's own kind after a branch change. `workflowTurn.report` records exact model-turn starts and ends. The host keeps one active coordinator connection and process-local epoch for each origin session. A replacement connection fences the old one. Only the active epoch receives the next eligible pending message or can report branch and turn state. Polling alone creates no durable command.
|
|
231
235
|
|
|
232
236
|
### Live run view
|
|
233
237
|
|
|
234
238
|
The host returns one canonical `pi-workflows.run-view.v1` document. It contains the existing bounded workflow projection and page cursors plus a `display` object. The queue field contains display metadata only. It does not repeat the input, launch options, worker affinity, or claim capability; the complete input remains reachable through the state projection. The `display` object contains the effective status, current activity kind, allowed controls, and the stored reason when action is required. A reason above the shared 16 KiB inline-content threshold uses a small `reason` notice and a digest-bound `reasonContent` reference, so one diagnostic cannot exceed the 1 MiB protocol frame while the complete reason remains available. Renderers use this object directly. They must not combine separate queries or infer status from durable rows.
|
|
235
239
|
|
|
240
|
+
The unfinished node-attempt row is the one durable source for the current node. A running run exposes it as `currentNode`. A parked interactive run exposes the same node as `waitingOn`. A checkpoint has no unfinished attempt, so its completed checkpoint node supplies `waitingOn`. During an exact origin-session model turn, the host `display` changes that waiting node to running for presentation only. It does not infer another node or change the durable run state.
|
|
241
|
+
|
|
236
242
|
Generated referenced content is stored directly in `run_view_content` under its exact run ID, content digest, and media type. It does not share general state-blob media metadata. A content read must match all three values, so a reference from another run or another media representation is unavailable.
|
|
237
243
|
|
|
238
|
-
The origin-session response contains
|
|
244
|
+
The origin-session response contains the active run view. When no run is active, it keeps the most recent terminal run visible while its terminal workflow message is pending or its first model turn is open, and then for 60 seconds after that turn ends. A newer run or `sessionView.clearTerminal` removes the retained terminal view. `/workflow clear` and the matching `piw` action call that control without changing workflow state.
|
|
245
|
+
|
|
246
|
+
The response also contains an ordered byte-bounded window of all nonterminal workflow messages and open sent messages needed for recovery, their complete count, and the next eligible pending message ID only for the active coordinator epoch. Message records include the source, content reference, order, state, and Pi entry needed by the shared coordinator. A branch report can name only IDs from this complete window. The host returns all these facts from one consistent read. The extension materializes the complete run revision and message content before it updates the widget or coordinator. After every host connection, it reports the active branch before it sends a workflow message or reports a model turn. Polling an idle session creates no durable command.
|
|
239
247
|
|
|
240
248
|
Each history page has both an item limit and an encoded byte budget. Oversized values become digest-bound content references. Large workflow topology uses bounded node, edge, graph-step, and transition projections plus references for the complete original definition and complete graph history. Before the host advertises a generated reference, it stores the bytes under the exact run ID, content digest, and media type in `run_view_content`. It does not share media metadata with general state blobs. Memory-cache eviction cannot make a reference unavailable. `view.content` returns bounded chunks until the client has the complete value. The client verifies the assembled bytes against both the response digest and the digest in the advertised reference. TypeScript clients assemble every run-history page for one revision and hydrate the complete definition, complete graph history, and all referenced content before they emit a complete non-interactive view or update the Pi widget. Rust automatically requests and verifies the complete referenced definition and graph history, decodes the complete values, and then builds its graph layout. Session-event pages include the replay checkpoint immediately before the first event in the page. A large checkpoint is also a referenced value. TypeScript hydrates it with the run view, and Rust requests and resolves it before replay. A step-centered trace page selects the exact stored attempt first and uses the node ID only if that attempt has no trace event. The run list reads only status facts and never loads complete run histories.
|
|
241
249
|
|
|
@@ -244,9 +252,9 @@ The closed `display.status` set is `queued`, `running`, `waiting`, `paused`, `co
|
|
|
244
252
|
The host computes effective status in this order:
|
|
245
253
|
|
|
246
254
|
1. A durable ambiguous external effect that requires explicit review is `ambiguous`. An effect that is still applying under a live worker is not ambiguous.
|
|
247
|
-
2.
|
|
248
|
-
3. A durable
|
|
249
|
-
4. A
|
|
255
|
+
2. A live supervised worker or an exact active origin-session workflow turn is `running`.
|
|
256
|
+
3. A durable terminal result keeps its terminal label after its presentation turn ends.
|
|
257
|
+
4. A durable pause is `paused` after its active Pi turn ends.
|
|
250
258
|
5. A pending interaction, decision, or presentation with no exact active turn is `waiting`.
|
|
251
259
|
6. Parked resumable work with no pending interaction is `queued`.
|
|
252
260
|
7. Admitted work that has not started is `queued`.
|
|
@@ -255,9 +263,15 @@ Host connection failure is the client condition `unavailable`, not a `display.st
|
|
|
255
263
|
|
|
256
264
|
### Origin-session activity
|
|
257
265
|
|
|
258
|
-
|
|
266
|
+
`agent_start` has no message payload. The extension binds it through the current origin-session view. The latest sent step is open while its interaction remains pending and its run is not paused. Any turn that starts in that state is workflow work. A terminal or follow-up message is open only until its first turn ends. Decisions and notifications never open a turn. The host rejects a start against a closed message.
|
|
267
|
+
|
|
268
|
+
Each report names the sent workflow message, workflow turn ID, run, and origin session. The extension creates the turn ID at start and keeps it through the matching end and host reconnect. If the session view or message receipt is still loading, it buffers start and end and reports them in order when the message becomes available.
|
|
259
269
|
|
|
260
|
-
|
|
270
|
+
At `agent_end`, the extension derives `completed`, `aborted`, or `error` from the documented assistant messages. It reads response-entry evidence from `ctx.sessionManager.getBranch()`; the entry ID can be null. The host applies the end, activity update, pause, unproductive-turn counter, and pending step-message cancellation in one transaction. A repeated report adopts that result. A stale turn ID cannot clear newer activity.
|
|
271
|
+
|
|
272
|
+
An aborted turn sets the run pause, cancels pending step messages, and does not increment `unproductiveTurnEnds`. The interaction derives its paused state from the run. Resuming that submitted-output step atomically clears the pause, increments the interaction revision, and creates one step message with reason `resumed`. Pi starts a fresh model turn from that message. A protected decision does not start a model turn, so pause and resume do not change its interaction revision or create another decision message. A completed, recoverably failed, or proved-lost turn increments the counter only when the submitted-output step remains pending, not paused, and has no accepted or validating submission. Values one and two create one step message with reason `reminder`; a value above two fails the attempt. At most one pending reminder-reason step exists. Acceptance, pause, cancellation, timeout, and branch re-presentation cancel pending step messages.
|
|
273
|
+
|
|
274
|
+
The process-local coordinator epoch ends on client disconnect, but an open reported workflow turn does not end. Host startup does not close Pi turns. On `session_start`, `workflowMessage.reportBranch` closes an unended open message as `lost` only when Pi is idle. A busy Pi session re-reports the same started turn. A lost step follows the unproductive-turn rule. A lost terminal or follow-up closes after its first turn. Follow-up activity controls ordering but does not show the completed workflow as `running`. Activity cannot grant workflow authority or settle a workflow request.
|
|
261
275
|
|
|
262
276
|
### Renderers and controls
|
|
263
277
|
|
|
@@ -290,6 +304,24 @@ Every worker message includes the worker launch schema, run ID, generation, work
|
|
|
290
304
|
|
|
291
305
|
The host checks the generation and epoch before it reads the payload. A stale worker gets one claim-loss response and must exit. The host stores receipts for accepted state-changing messages so a retry receives the same answer.
|
|
292
306
|
|
|
307
|
+
## Supervised channel adapters
|
|
308
|
+
|
|
309
|
+
The host launches one transport-only child for each configured Telegram profile. The child receives only the complete operator presentation, allowed Telegram identities, and the one profile credential that it needs. It does not receive the canonical decision subject, open SQLite, load workflow code, or change run state.
|
|
310
|
+
|
|
311
|
+
The private version-1 channel protocol has these message kinds:
|
|
312
|
+
|
|
313
|
+
- `channel.ready`;
|
|
314
|
+
- `channel.present`;
|
|
315
|
+
- `channel.answer`;
|
|
316
|
+
- `channel.settle`; and
|
|
317
|
+
- `channel.exiting`.
|
|
318
|
+
|
|
319
|
+
Each message includes the adapter epoch, profile, sequence, expected channel revision, and stable attempt ID. The host validates these values before it accepts a result or answer. A stale adapter or stale attempt cannot settle newer work.
|
|
320
|
+
|
|
321
|
+
Before the child sends or edits an external message, the host records a managed effect in `effects` and `effect_attempts`. A confirmed result stores its Telegram message references in the effect result. A known rejection can start a bounded new attempt. If the host or adapter stops while an exact attempt is applying, only that in-flight attempt becomes `ambiguous`; the host does not send it again automatically.
|
|
322
|
+
|
|
323
|
+
The operator checks Telegram before resolving an ambiguous attempt. `/workflow-channel recover <message-id> confirm` records that the external work happened. `/workflow-channel recover <message-id> retry` starts a new numbered attempt and warns that a duplicate is possible. `channel_messages` remains the decision feature record for delivery and settlement; it does not duplicate the external-effect state or Telegram references.
|
|
324
|
+
|
|
293
325
|
## Durable protocol records
|
|
294
326
|
|
|
295
327
|
Reuse current rows when they already own a fact:
|
|
@@ -298,9 +330,11 @@ Reuse current rows when they already own a fact:
|
|
|
298
330
|
- `node_attempts` owns node execution state and resolved wall-clock deadlines.
|
|
299
331
|
- `human_decisions` and resolution tables own checkpoints.
|
|
300
332
|
- `effects` and `effect_attempts` own side effects and ambiguous outcomes.
|
|
301
|
-
- `
|
|
333
|
+
- `workflow_messages` owns all content that Pi must add to an origin conversation.
|
|
302
334
|
- `run_bindings` owns origin session and execution mode.
|
|
303
335
|
|
|
336
|
+
`workflow_messages` contains the target session, message kind, source record, content digest, session order, state, confirmed Pi entry ID, and timestamps. Its states are `pending`, `sent`, and `cancelled`; it has no separate sent timestamp. Active-branch evidence changes a matching pending or cancelled message to `sent`. Message kind determines its renderer, turn behavior, and host eligibility rule. A partial unique index allows at most one pending step message for one interactive request. The table stores no sender, send lease, duplicate flag, or message-to-message pointer.
|
|
337
|
+
|
|
304
338
|
Add only these records if implementation proves the current rows cannot hold the contract:
|
|
305
339
|
|
|
306
340
|
### Host commands
|
|
@@ -309,7 +343,7 @@ Add only these records if implementation proves the current rows cannot hold the
|
|
|
309
343
|
|
|
310
344
|
### Interactive requests
|
|
311
345
|
|
|
312
|
-
`interactive_requests` stores request ID, run ID, attempt ID, target session ID, kind, contract hash, pending or settled status, accepted submission ID, and timestamps. One attempt has at most one request. The linked node attempt stores its resolved wall-clock deadline.
|
|
346
|
+
`interactive_requests` stores request ID, run ID, attempt ID, target session ID, kind, contract hash, pending or settled status, accepted submission ID, `unproductiveTurnEnds`, and timestamps. Pause is stored once on the run and derived for its interaction. One attempt has at most one request. The linked node attempt stores its resolved wall-clock deadline.
|
|
313
347
|
|
|
314
348
|
`interactive_submissions` stores request ID, submission ID, idempotency key, payload hash, validating, accepted, or rejected outcome, receipt hash, and submission time. Repeated keys return the same receipt.
|
|
315
349
|
|
|
@@ -325,9 +359,13 @@ Agent and assistant-message steps for an interactive run execute in the origin P
|
|
|
325
359
|
|
|
326
360
|
The worker commits the node's resolved wall-clock deadline before it proposes `interaction.requested`. The host commits the request, changes the node attempt to waiting, parks the queue row, releases the claim, and acknowledges the worker. The worker then exits. The host continues to enforce the durable deadline while no worker exists. If the deadline passes, one control claim atomically closes the stale request and schedules a supervised timeout-resume child. The child preserves the same attempt and deadline, records `timed_out`, and follows any `$result.outcome` edge. A run with no timeout recovery edge becomes terminal and releases its session reservation. Restart recovery starts this timeout path before it schedules other work.
|
|
327
361
|
|
|
328
|
-
The extension finds
|
|
362
|
+
The extension finds eligible workflow messages during `session_start`, after model turns settle, and once per second while the session is open. The same poll also establishes the one session subscription when initial host startup or connection fails. It keeps at most one connection attempt and one active subscription, so the open Pi session recovers without a restart and without duplicate coordinators. One `WorkflowMessageCoordinator` handles every message kind. After every host connection, it waits for the complete origin-session view and reports the active branch before it sends a workflow message or reports a model turn. The host view names the next eligible pending message only to the active coordinator epoch.
|
|
363
|
+
|
|
364
|
+
The coordinator waits until Pi is idle and has no queued user input, keeps the message ID in its in-memory queued map, and searches the active branch for that hidden ID. It reports a matching entry before any send. Otherwise, it rechecks synchronously that Pi is idle, has no pending input, the message is absent, and its connection still owns the active epoch. It calls documented `pi.sendMessage()` with no `await` between the final check and call. A poll can discover work, but it cannot send an ID already in the queued map.
|
|
365
|
+
|
|
366
|
+
After a send, the coordinator waits for the matching Pi entry and reports the active branch so the host records its entry ID and marks the message `sent`. Branch evidence marks a matching message `sent` even if its source cancelled it after the send. If Pi emits `agent_start` before that report or before the session view loads, the coordinator buffers the start and matching end, records the message first, and then reports the turn events in order.
|
|
329
367
|
|
|
330
|
-
|
|
368
|
+
Active-branch absence is usable only when the branch has no matching ID, Pi is idle, and Pi has no pending messages. If Pi or the extension disappears after the send call but before inspection, the message stays `pending`. A replacement extension reports the branch before another send. Documented Pi APIs do not prove cross-branch absence or exactly-once model execution.
|
|
331
369
|
|
|
332
370
|
The extension subscribes to the active origin-session live run view and projects it into Pi's documented widget and status APIs. It never opens SQLite, runs workflow code, or derives a display status. `Shift+Up` and `Shift+Down` scroll the widget. When Herdr is available, the widget also shows `Ctrl+Shift+R piw`, and `/piw` remains the command fallback. Both actions open or focus the exact run from the same view.
|
|
333
371
|
|
|
@@ -335,11 +373,11 @@ A tool update or submission goes to the host. It includes the exact request, nod
|
|
|
335
373
|
|
|
336
374
|
An ordinary checkpoint accepts the model-facing `answer` action and starts a continuation run. A protected human decision never accepts that tool action. The extension displays the decision without starting a model turn, and a person answers it with `/workflow answer` through `decision.answer`. When a protected decision reaches its saved `onTimeout` deadline, the host takes a control claim on the waiting parent, atomically records the validated default, closes the pending interaction, releases the parent claim, and reserves the continuation. A human answer cannot win after that deadline.
|
|
337
375
|
|
|
338
|
-
The session keeps normal Pi entries for prompts, tools, and replies. Pi Workflows stores the public session entry ID used for presentation adoption. It does not edit the Pi session file or schema.
|
|
376
|
+
The session keeps normal Pi entries for prompts, tools, and replies. Pi Workflows stores the public session entry ID used for presentation adoption. It does not edit the Pi session file or schema. A normal worker continuation leaves an active session capture open until the matching Pi turn ends. Only proved interruption can fail that capture; worker handoff alone cannot report that the host stopped.
|
|
339
377
|
|
|
340
|
-
One session
|
|
378
|
+
One session sends one workflow message at a time. Messages keep acceptance order, but an earlier ineligible or cancelled message does not block unrelated eligible work. Source state and message kind decide eligibility. A reload clears only process-local queued state. `workflowMessage.reportBranch` adopts existing entries and closes lost turns. When a pending source has no entry on the active branch, it creates one message of that source's own kind: a step with reason `resumed` for an interaction, or a decision for a protected decision. Repeating a report or returning to a branch that already contains that source creates no new message.
|
|
341
379
|
|
|
342
|
-
|
|
380
|
+
A notify node creates a passive `notification` message in the same transaction as its node result. The final leaf of an interactive checkpoint-continuation chain creates one terminal message with its terminal outcome; parent runs settled by continuation do not. Initial, reminder, and resumed prompts are one `step` kind. Protected decisions and follow-ups use the same table and coordinator. Their feature records keep validation, authority, timeout, counters, and result state.
|
|
343
381
|
|
|
344
382
|
## Detached execution
|
|
345
383
|
|
|
@@ -351,7 +389,7 @@ The run binding records `interactive` or `headless` execution mode. Viewers show
|
|
|
351
389
|
|
|
352
390
|
## Pause and cancellation
|
|
353
391
|
|
|
354
|
-
|
|
392
|
+
An explicit pause command atomically commits `paused = 1` on the run, parks the queue, releases the exact claim, cancels pending step messages, and stores the command receipt. The fenced worker process group then stops. When Escape aborts an origin-session turn, the extension sends one `workflowTurn.report` end message with `stopReason: "aborted"`. The host atomically ends that exact activity, sets the run pause, derives the pending interaction as paused, and cancels its pending step messages. The extension does not send a second pause command. A parked interaction has no worker or live run claim. While its run is paused, updates, submissions, and decision answers are rejected. Resume clears the run pause; work for the same pending interaction continues in place, while other paused work takes a new generation and starts another worker from the last durable boundary. An uncommitted pure node can run again after resume.
|
|
355
393
|
|
|
356
394
|
Cancellation against a live worker atomically commits terminal cancellation, cancels pending attempt and interaction state, settles effect recovery state, releases the exact claim, and stores the command receipt. A pending effect becomes cancelled. An applying effect becomes ambiguous because the host cannot prove its external outcome. The host then stops the fenced worker process group. A host crash after the receipt cannot resume the cancelled run or retry the ambiguous effect. If the child does not stop by the deadline, the host kills its process group.
|
|
357
395
|
|
|
@@ -369,10 +407,11 @@ At startup the host:
|
|
|
369
407
|
4. Reads managed effect state before deciding whether work can repeat.
|
|
370
408
|
5. Parks uncertain effects for manual review.
|
|
371
409
|
6. Makes pure and fully settled work claimable.
|
|
372
|
-
7. Restores pending interactive requests and scheduled controller work.
|
|
373
|
-
8. Starts supervised timeout recovery for pending interactive requests
|
|
410
|
+
7. Restores pending interactive requests, workflow messages, external-channel decisions, and scheduled controller work without changing Pi message or turn state.
|
|
411
|
+
8. Starts supervised timeout recovery for pending interactive requests only when their durable deadline expired during a reported model turn from an active connected session. A disconnect suspends the timer, and a new branch report resumes it without losing the prior active time. Message delivery, waiting, paused time, host downtime, and a closed Pi session do not consume the node timeout.
|
|
374
412
|
9. Resumes any remaining provisional `validating` submission in a new supervised child.
|
|
375
|
-
10.
|
|
413
|
+
10. Waits for the extension's active-branch report before it confirms pending entries as sent, closes a turn as `lost`, or creates a branch-specific replacement. The extension sends this report after every host connection.
|
|
414
|
+
11. Starts no model turn until a matching Pi session connects or headless mode is declared.
|
|
376
415
|
|
|
377
416
|
Recovery resumes from the last committed boundary. An uncommitted compute node may run again because compute is pure. An action with a stored effect receipt adopts that receipt. An effect in `ambiguous` state requires explicit recovery.
|
|
378
417
|
|
|
@@ -455,18 +494,44 @@ The implementation conforms when:
|
|
|
455
494
|
- an expired or replaced owner cannot write;
|
|
456
495
|
- a blocked worker cannot stop host renewal;
|
|
457
496
|
- Pi can restart while work computes or waits;
|
|
497
|
+
- an open Pi session reconnects after initial host startup or connection fails;
|
|
458
498
|
- the host can restart and recover from committed state;
|
|
459
499
|
- run, queue, attempt, decision, lease, event, and viewer projections remain consistent after injected crashes;
|
|
460
500
|
- an expired running row can be resumed or cancelled safely;
|
|
461
501
|
- duplicate commands and submissions return stored receipts;
|
|
462
502
|
- an interactive request appears once in the origin session and survives reload;
|
|
463
|
-
-
|
|
503
|
+
- every workflow-message kind uses one active coordinator epoch, active-branch report, and turn-report contract;
|
|
504
|
+
- initial, reminder, and resumed prompts use one step-message kind and one request counter;
|
|
505
|
+
- a busy Pi session with a pending message does not queue duplicate messages or model turns;
|
|
506
|
+
- two Pi processes cannot send for one origin session because only one coordinator epoch is active;
|
|
507
|
+
- active-branch absence requires no hidden message ID, an idle Pi session, and no pending Pi messages;
|
|
508
|
+
- every host connection reports the active branch before any workflow-message send or turn report;
|
|
509
|
+
- a crash after send leaves the message pending until branch evidence adopts it;
|
|
510
|
+
- active-branch evidence changes a matching pending or cancelled message to sent;
|
|
511
|
+
- host restart alone never closes an active Pi turn as `lost`;
|
|
512
|
+
- a branch change creates at most one source-kind message when that source has no entry on the active branch;
|
|
513
|
+
- a partial unique index allows at most one pending step message for each interactive request;
|
|
514
|
+
- pause is stored once on the run and derived for its interaction;
|
|
515
|
+
- resuming an aborted submitted-output step creates one new resumed message and one fresh origin-session model turn;
|
|
516
|
+
- pausing and resuming a protected decision does not invalidate its answer revision or create a duplicate decision message;
|
|
517
|
+
- follow-ups wait for the final continuation outcome, its terminal turn, earlier follow-ups, and release of the origin-session reservation;
|
|
518
|
+
- only the final leaf in a checkpoint continuation chain receives a terminal workflow message;
|
|
464
519
|
- effects are deduplicated or marked ambiguous;
|
|
520
|
+
- external channel delivery and settlement use the same managed-effect and attempt records;
|
|
521
|
+
- a channel child is transport-only and cannot open SQLite, load workflow code, or change run state;
|
|
522
|
+
- a stale adapter epoch or attempt cannot settle newer channel work;
|
|
523
|
+
- an interrupted exact in-flight channel attempt becomes ambiguous and is never retried without explicit recovery;
|
|
524
|
+
- explicit confirmation records observed success, while explicit retry creates a new attempt and warns about possible duplication;
|
|
465
525
|
- the extension and host run no workflow or controller code in their own event loops;
|
|
466
526
|
- the production package contains no embedded execution fallback;
|
|
467
527
|
- the host is the only production process that opens live SQLite state;
|
|
468
528
|
- the widget, status line, Herdr actions, CLI, and `piw` render the same host-produced status and controls;
|
|
469
|
-
-
|
|
529
|
+
- running and waiting projections identify the current workflow node from the same unfinished attempt, while checkpoint waits use the completed checkpoint node;
|
|
530
|
+
- an exact origin-session model turn presents that same waiting node as running without changing its durable identity;
|
|
531
|
+
- a busy origin session displays `running` for the full exact workflow turn, including a terminal or pausing turn, and a stale turn-end report cannot clear newer activity;
|
|
532
|
+
- normal worker continuation does not fail an active Pi session capture or report a false host interruption;
|
|
533
|
+
- `paused` appears only after a durable pause and matching turn end;
|
|
534
|
+
- a terminal run remains in the origin-session view while its terminal message is pending or its first turn is open, and then for 60 seconds after that turn ends, without retaining execution authority;
|
|
470
535
|
- a TypeScript-created live database is viewable by the matching Rust `piw` through the client protocol without a duplicated SQLite digest;
|
|
471
536
|
- no removed host, replay, or direct SQLite client path remains selectable;
|
|
472
537
|
- real Pi end-to-end tests, repository checks, reviewer checks, and CI pass.
|