effect-durable-agent 0.1.0-alpha.4 → 0.1.0-alpha.6
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 +19 -18
- package/dist/{command-queues-CV7O-51r.d.ts → command-queues-C8muEqeQ.d.ts} +2 -2
- package/dist/{compaction-zbvLREI8.d.ts → compaction-F4HEWzuI.d.ts} +5 -5
- package/dist/{context-projection-n6Rdup0N.d.ts → context-projection-C43pyxn2.d.ts} +2 -2
- package/dist/domain/command-queues.d.ts +1 -1
- package/dist/domain/context-projection.d.ts +1 -1
- package/dist/domain/message-transcript.d.ts +1 -1
- package/dist/domain/reduced-state.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/{message-transcript-DiOPBY3l.d.ts → message-transcript-DsKTT47f.d.ts} +3 -3
- package/dist/{prompt-projector-C1IbkHr0.d.ts → prompt-projector-hqPh5-NI.d.ts} +4 -4
- package/dist/{reducer-registry-CjSJBPKo.d.ts → reducer-registry--vQFATXb.d.ts} +16 -6
- package/dist/{runtime-DOgmAKsO.d.ts → runtime-BO9KJq_Y.d.ts} +7 -5
- package/dist/services/compaction.d.ts +1 -1
- package/dist/services/prompt-projector.d.ts +1 -1
- package/dist/services/reducer-registry.d.ts +2 -2
- package/dist/services/reducer-registry.js +7 -3
- package/dist/services/reducer-registry.js.map +1 -1
- package/dist/services/runtime-layer.d.ts +12 -9
- package/dist/services/runtime-layer.js +6 -4
- package/dist/services/runtime-layer.js.map +1 -1
- package/dist/services/runtime.d.ts +1 -1
- package/dist/services/runtime.js +3 -2
- package/dist/services/runtime.js.map +1 -1
- package/dist/services/session-event-observer.d.ts +2 -0
- package/dist/services/session-event-observer.js +13 -0
- package/dist/services/session-event-observer.js.map +1 -0
- package/dist/services/session-query.d.ts +2 -2
- package/dist/services/session-query.js +20 -3
- package/dist/services/session-query.js.map +1 -1
- package/dist/services/session-state.d.ts +1 -1
- package/dist/services/session-state.js +1 -1
- package/dist/services/session-store.d.ts +1 -1
- package/dist/services/sink-checkpoint-store.d.ts +1 -1
- package/dist/services/sink-registry.d.ts +1 -1
- package/dist/services/sink-registry.js +1 -1
- package/dist/services/span-names.d.ts +1 -1
- package/dist/services/span-names.js +1 -0
- package/dist/services/span-names.js.map +1 -1
- package/dist/services/tool-registry.d.ts +1 -1
- package/dist/services/tracing.js +23 -2
- package/dist/services/tracing.js.map +1 -1
- package/dist/session-event-observer-D_aoFnQs.d.ts +24 -0
- package/dist/{session-query-C-C4m1eq.d.ts → session-query-_Z3Kw6jj.d.ts} +15 -8
- package/dist/{session-state-CjOSvWbe.d.ts → session-state-BfoXKafd.d.ts} +11 -11
- package/dist/{session-state-SStf0KUo.js → session-state-C4m0j6CJ.js} +2 -2
- package/dist/{session-state-SStf0KUo.js.map → session-state-C4m0j6CJ.js.map} +1 -1
- package/dist/{session-store-DZZUffUy.d.ts → session-store-ofm8FFxs.d.ts} +2 -2
- package/dist/{sink-checkpoint-store-BZmQFTRE.d.ts → sink-checkpoint-store-BQVbI9DQ.d.ts} +2 -2
- package/dist/{sink-registry-D13eUO_c.js → sink-registry-DH6uiEgP.js} +19 -21
- package/dist/sink-registry-DH6uiEgP.js.map +1 -0
- package/dist/{sink-registry-Cf79ICdW.d.ts → sink-registry-PRYbj6dp.d.ts} +18 -14
- package/dist/testkit/layers.d.ts +10 -10
- package/dist/testkit/layers.js +3 -3
- package/dist/testkit/layers.js.map +1 -1
- package/dist/{tool-registry-B7Wona6N.d.ts → tool-registry-ClHdr_G5.d.ts} +2 -2
- package/dist/{websocket-wire-QD2SquQE.d.ts → websocket.d.ts} +335 -12
- package/dist/websocket.js +428 -0
- package/dist/websocket.js.map +1 -0
- package/package.json +15 -31
- package/testing/offline-trace/README.md +2 -1
- package/CHANGELOG.md +0 -34
- package/CONTRIBUTING.md +0 -26
- package/SECURITY.md +0 -7
- package/dist/host/websocket-protocol.d.ts +0 -229
- package/dist/host/websocket-protocol.js +0 -99
- package/dist/host/websocket-protocol.js.map +0 -1
- package/dist/host/websocket-wire.d.ts +0 -2
- package/dist/host/websocket-wire.js +0 -105
- package/dist/host/websocket-wire.js.map +0 -1
- package/dist/services/websocket-subscriber.d.ts +0 -54
- package/dist/services/websocket-subscriber.js +0 -190
- package/dist/services/websocket-subscriber.js.map +0 -1
- package/dist/sink-registry-D13eUO_c.js.map +0 -1
- package/docs/assets/architecture.svg +0 -216
- package/docs/assets/event-sequence.svg +0 -133
- package/docs/assets/gcp-trace.png +0 -0
- package/docs/assets/hero.svg +0 -33
- package/docs/message-steering.md +0 -831
- package/docs/releasing.md +0 -114
- package/docs/spec.md +0 -777
- package/docs/subagents.md +0 -725
- package/docs/testing.md +0 -64
- package/docs/ui-projection.md +0 -742
- package/docs/websocket-protocol.md +0 -639
package/docs/spec.md
DELETED
|
@@ -1,777 +0,0 @@
|
|
|
1
|
-
# effect-durable-agent — Current Implementation
|
|
2
|
-
|
|
3
|
-
Status: current
|
|
4
|
-
Runtime: EDAGiaAgent
|
|
5
|
-
Last reviewed: 2026-07-15
|
|
6
|
-
|
|
7
|
-
This is the agent-facing implementation guide for EDA. It should describe what the runtime **does today**. Product-specific UI and subagent proposals belong in the downstream-consumer documents under `docs/` listed at the end.
|
|
8
|
-
|
|
9
|
-
If a claim in this document is not backed by code in this package, move it to the specific
|
|
10
|
-
future-state proposal that owns it or delete it.
|
|
11
|
-
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
## 1. One-page mental model
|
|
15
|
-
|
|
16
|
-
EDA is an Effect-native agent harness modeled as one durable state machine per session.
|
|
17
|
-
|
|
18
|
-
```text
|
|
19
|
-
mutating input
|
|
20
|
-
-> durable command/app events
|
|
21
|
-
-> pure reducers
|
|
22
|
-
-> live client stream
|
|
23
|
-
-> Effect workflows for model/tool/sink work
|
|
24
|
-
-> deterministic replay/recovery from the durable log
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
The core idea is simple:
|
|
28
|
-
|
|
29
|
-
- **Durable events are facts.** They are persisted, sequenced, replayable, and are the crash/recovery source of truth.
|
|
30
|
-
- **Reducers derive state.** Framework state and app state are pure folds over the same ordered event stream.
|
|
31
|
-
- **`SessionState` is the live-process authority.** Every durable append, durable fold, ephemeral position allocation, active-execution mutation, and live publish flows through it.
|
|
32
|
-
- **Effect owns execution.** Model streams, tools, sinks, interruption, scopes, retries, finalizers, and observability are Effect workflows, not detached promises.
|
|
33
|
-
- **The host is pluggable.** The current production host is Cloudflare Durable Objects with Durable Object SQLite, WebSockets, alarms, and RPC, but the core runtime depends on small service boundaries.
|
|
34
|
-
|
|
35
|
-
EDA exists because callback-first agent loops do not define the hard boundaries: command admission, event ordering, reconnect, multi-client sync, stop semantics, tool lifecycle, durable side effects, and crash recovery. EDA makes those boundaries first-class.
|
|
36
|
-
|
|
37
|
-
---
|
|
38
|
-
|
|
39
|
-
## 2. Current package/API grounding
|
|
40
|
-
|
|
41
|
-
The implementation is grounded in the versions installed by this package. Check `package.json`
|
|
42
|
-
and local `node_modules` before changing API-shaped docs.
|
|
43
|
-
|
|
44
|
-
| Package | Version | Current role |
|
|
45
|
-
| --- | --- | --- |
|
|
46
|
-
| `effect` | `4.0.0-beta.102` | Core Effect modules and `effect/unstable/ai`. |
|
|
47
|
-
| `@effect/ai-openai` | `4.0.0-beta.102` | OpenAI provider adapter. |
|
|
48
|
-
|
|
49
|
-
Important version facts:
|
|
50
|
-
|
|
51
|
-
- Services use `Context.Service<Self, Shape>()("key")`, not newer `ServiceMap.Service` examples.
|
|
52
|
-
- Effect AI is imported from `effect/unstable/ai`; there is no separate local `@effect/ai` package.
|
|
53
|
-
- EDA exposes model tools through upstream `Tool` / `Toolkit` values and calls `LanguageModel.streamText(..., { disableToolCallResolution: true })` so the harness owns tool lifecycle.
|
|
54
|
-
- Newly minted lifecycle ids are UUIDv7; session ids also accept UUIDv4 for migrated callers.
|
|
55
|
-
|
|
56
|
-
---
|
|
57
|
-
|
|
58
|
-
## 3. Runtime map
|
|
59
|
-
|
|
60
|
-
```text
|
|
61
|
-
Host route / RPC / WebSocket
|
|
62
|
-
|
|
|
63
|
-
v
|
|
64
|
-
Host adapter (`effect-durable-agent-cloudflare` or `effect-durable-agent-celld`)
|
|
65
|
-
|
|
|
66
|
-
v
|
|
67
|
-
ManagedRuntime<Effect services> for one session
|
|
68
|
-
|
|
|
69
|
-
+--> EDARuntime public facade
|
|
70
|
-
|
|
|
71
|
-
+--> SessionState <---- all writes, active execution, recovery
|
|
72
|
-
| |
|
|
73
|
-
| +--> EDASessionStore durable event log + checkpoints
|
|
74
|
-
| +--> LiveEventBus live fanout + active-turn ephemeral replay
|
|
75
|
-
| +--> command-control loop run/turn scheduling
|
|
76
|
-
|
|
|
77
|
-
+--> TurnRunner / InferenceRunner / ToolExecutor
|
|
78
|
-
|
|
|
79
|
-
+--> EDAReducerRegistry / EDASinkRegistry
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
### Important files
|
|
83
|
-
|
|
84
|
-
| Area | Files |
|
|
85
|
-
| --- | --- |
|
|
86
|
-
| Public runtime | `src/services/runtime.ts`, `src/services/runtime-layer.ts` |
|
|
87
|
-
| Durable store port + Cloudflare/celld implementation | `src/services/session-store.ts`, `packages/cloudflare/src/durable-object-storage.ts`, `packages/cloudflare/src/durable-object-store.ts` |
|
|
88
|
-
| Session authority | `services/session-state.ts` |
|
|
89
|
-
| Query/read APIs | `services/session-query.ts` |
|
|
90
|
-
| Live stream/WebSocket | `src/services/live-event-bus.ts`, `src/services/websocket-subscriber.ts`, `src/host/websocket-wire.ts`, `src/host/websocket-protocol.ts` |
|
|
91
|
-
| Pure reducers/policies | `domain/reduced-state.ts`, `domain/command-queues.ts`, `domain/dispatch-policy.ts`, `domain/run-continuation-policy.ts`, `domain/inference-state.ts` |
|
|
92
|
-
| Model/turn/tool execution | `services/turn-runner.ts`, `services/inference-runner.ts`, `services/tool-executor.ts`, `services/tool-registry.ts` |
|
|
93
|
-
| Extension points | `services/reducer-registry.ts`, `services/sink-registry.ts` |
|
|
94
|
-
| Compaction | `services/compaction.ts`, `domain/context-projection.ts` |
|
|
95
|
-
| Cloudflare/celld host adapters | `packages/cloudflare/src/durable-object-runtime.ts`, `packages/cloudflare/src/durable-object-keepalive.ts`, `packages/cloudflare/src/durable-object-sink-checkpoints.ts` |
|
|
96
|
-
| Examples | `packages/cloudflare/examples/` |
|
|
97
|
-
|
|
98
|
-
---
|
|
99
|
-
|
|
100
|
-
## 4. Current terms
|
|
101
|
-
|
|
102
|
-
- **Session** — one durable agent conversation. Current production host stores one session per Durable Object.
|
|
103
|
-
- **Command** — mutating user/control input. Current commands include
|
|
104
|
-
`SubmitMessage`, `CancelPendingMessage`, `PromotePendingMessage`, and
|
|
105
|
-
`StopTurn`; `ResumePendingMessages` is framework-internal recovery work.
|
|
106
|
-
- **Run** — lifecycle started by a command. At most one active run per session.
|
|
107
|
-
- **Turn** — one scheduler unit inside a run. At most one active turn per active run.
|
|
108
|
-
- **Inference** — one concrete model stream execution inside a turn. In the happy path there is one inference per turn. Tool continuation, rejected-tool feedback, or later scheduler policy creates later turns rather than nesting multiple model calls under one turn.
|
|
109
|
-
- **Tool call** — one model-requested framework-owned tool invocation with durable lifecycle events.
|
|
110
|
-
- **Durable event** — persisted event with monotonic per-session `seq` and replay semantics.
|
|
111
|
-
- **Ephemeral event** — live-only event positioned against the latest durable head but not persisted.
|
|
112
|
-
- **Reducer** — pure fold over durable events. Framework and app reducers share the same log.
|
|
113
|
-
- **Sink** — app integration worker over durable or ephemeral events. Durable sinks have durable checkpoints and at-least-once semantics.
|
|
114
|
-
- **Host** — adapter that supplies ingress, storage, sockets, clock/id services, scheduler/keep-alive hooks, and provider bindings.
|
|
115
|
-
|
|
116
|
-
---
|
|
117
|
-
|
|
118
|
-
## 5. Non-negotiable invariants
|
|
119
|
-
|
|
120
|
-
These are the current implementation rules worth preserving during edits:
|
|
121
|
-
|
|
122
|
-
1. **Durable commit before live publish.** A durable event is never published live until `EDASessionStore.append` succeeds.
|
|
123
|
-
2. **`SessionState` is the write authority.** No runtime component writes durable events, publishes ephemerals, mutates active execution, or allocates live positions outside `SessionState` / `SessionEventSink` paths.
|
|
124
|
-
3. **One active run and one active turn.** This is derived from durable reduced state and enforced by `SessionState` active execution.
|
|
125
|
-
4. **`seq` is the only persisted ordering clock.** Durable events are `(seq, 0)`; ephemerals are `(anchorSeq, subSeq)` and live-only.
|
|
126
|
-
5. **Pure decisions stay pure.** Reducers, dispatch policy, run continuation policy, and inference-state transitions do not read clocks, refs, stores, services, sockets, or model streams.
|
|
127
|
-
6. **Effect owns resources and interruption.** Runners, tools, subscribers, sinks, and finalizers are scoped workflows.
|
|
128
|
-
7. **Started boundaries must terminalize.** In a live process, abnormal exits commit matching failure/interruption/cancellation terminals. Host eviction is repaired by recovery.
|
|
129
|
-
8. **No lifecycle events from app code.** Applications emit app events and tool results; framework lifecycle boundaries remain framework-owned.
|
|
130
|
-
9. **Durable store transactions do not suspend.** The Cloudflare SQLite append kernel is synchronous and contains no external I/O.
|
|
131
|
-
10. **Reducer checkpoints are caches.** Missing/stale checkpoints are repaired by replaying durable events after the checkpoint cursor.
|
|
132
|
-
11. **Prompt prefixes are immutable outside compaction.** After model-facing context has been sent, later turns append rather than rewrite it. Compaction creates a new context version.
|
|
133
|
-
|
|
134
|
-
---
|
|
135
|
-
|
|
136
|
-
## 6. Public runtime surface
|
|
137
|
-
|
|
138
|
-
`EDARuntime` is the host-facing facade for one session runtime.
|
|
139
|
-
|
|
140
|
-
Current methods:
|
|
141
|
-
|
|
142
|
-
- `submit(command)` — admit one command and return the committed `CommandAdmitted` event.
|
|
143
|
-
- `submit(items)` — commit an ordered durable batch of commands and/or app durable events.
|
|
144
|
-
- `submitAndBlock(command)` — admit a command and wait for its terminal command event.
|
|
145
|
-
- `blockOnCommand(commandId, afterSeq?)` — wait for `CommandCompleted | CommandFailed | CommandCancelled`.
|
|
146
|
-
- `snapshot()` — read current framework/app reducer snapshot.
|
|
147
|
-
- `messages()` — read durable user/assistant transcript messages.
|
|
148
|
-
- `eventsAfter(afterSeq)` — return a reconnect-safe stream combining durable backfill, same-process active-turn ephemeral replay, buffered live prefix, and future live events.
|
|
149
|
-
|
|
150
|
-
Normal long-running ingress should prefer `submit` then observe the event stream rather than blocking a request for model completion.
|
|
151
|
-
|
|
152
|
-
---
|
|
153
|
-
|
|
154
|
-
## 7. Commands and scheduling
|
|
155
|
-
|
|
156
|
-
### Commands
|
|
157
|
-
|
|
158
|
-
`SubmitMessage` fields:
|
|
159
|
-
|
|
160
|
-
- optional framework `commandId` (normal callers omit it; EDA mints UUIDv7)
|
|
161
|
-
- optional caller-owned `idempotencyKey`
|
|
162
|
-
- `disposition: "queue" | "steer" | "interrupt"`
|
|
163
|
-
- `content` aligned to Effect AI user message content (`TextPart | FilePart`, or string shorthand)
|
|
164
|
-
|
|
165
|
-
`StopTurn` fields:
|
|
166
|
-
|
|
167
|
-
- optional framework `commandId`
|
|
168
|
-
- optional caller-owned `idempotencyKey`
|
|
169
|
-
|
|
170
|
-
### Command dispositions
|
|
171
|
-
|
|
172
|
-
- **`queue`** — message starts a run when idle or waits as a durable pending
|
|
173
|
-
message. Explicit stop/interrupt pauses remaining queued work.
|
|
174
|
-
- **`steer`** — message starts a run when idle or joins the active run at its
|
|
175
|
-
next turn boundary. All eligible steers at that boundary are consumed in FIFO
|
|
176
|
-
order in one continuation turn.
|
|
177
|
-
- **`interrupt`** — closes the active turn/run and starts replacement work from the interrupting message.
|
|
178
|
-
|
|
179
|
-
### Ingress flow
|
|
180
|
-
|
|
181
|
-
```text
|
|
182
|
-
host decodes command
|
|
183
|
-
-> EDARuntime.submit
|
|
184
|
-
-> SessionState.admitCommand
|
|
185
|
-
-> mint commandId / dedupe by idempotencyKey
|
|
186
|
-
-> CommandAdmitted durable event
|
|
187
|
-
-> store assigns seq
|
|
188
|
-
-> SessionState folds ReducedState + app reducers
|
|
189
|
-
-> LiveEventBus publishes (seq, 0)
|
|
190
|
-
-> command-control loop drains runnable durable work
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
The ingress signal is only a wakeup. The durable event log and authoritative in-memory reduced state decide what runs.
|
|
194
|
-
|
|
195
|
-
### Control loop ownership
|
|
196
|
-
|
|
197
|
-
`SessionState` owns the command-control loop. It starts commands, creates run/turn scopes, applies stop/steer/interrupt policy, observes active turn fibers, and terminalizes runs/commands. It does not hand state-dependent mutation to callers after `snapshot()`; decisions that mutate state happen inside the serialized session boundary.
|
|
198
|
-
|
|
199
|
-
Current routing highlights:
|
|
200
|
-
|
|
201
|
-
- `SubmitMessage{queue|steer}` atomically admits the command and
|
|
202
|
-
`UserMessageSubmitted`, making the pending message immediately renderable.
|
|
203
|
-
- Idle `SubmitMessage` starts a run and consumes that admitted message through
|
|
204
|
-
`TurnStarted.inputMessageIds`.
|
|
205
|
-
- Idle/stale `StopTurn` commits `CommandStarted` then `CommandCancelled { reason: "no active turn" }`.
|
|
206
|
-
- Active `SubmitMessage{queue}` remains pending until the active run completes or is interrupted.
|
|
207
|
-
- Active `SubmitMessage{steer}` remains pending until the next turn boundary;
|
|
208
|
-
it never mutates an in-flight provider request.
|
|
209
|
-
- Active `SubmitMessage{interrupt}` closes and terminalizes the active run,
|
|
210
|
-
pauses remaining pending messages, then starts the replacement message.
|
|
211
|
-
- Active `StopTurn` commits `StopTurnRequested`, interrupts the active scope, then commits stop/run/command terminal events.
|
|
212
|
-
- Completed turn + pending steers consumes the entire eligible steer batch in
|
|
213
|
-
another turn in the same run; otherwise the run and active command complete.
|
|
214
|
-
|
|
215
|
-
---
|
|
216
|
-
|
|
217
|
-
## 8. Event model
|
|
218
|
-
|
|
219
|
-
### Position
|
|
220
|
-
|
|
221
|
-
```ts
|
|
222
|
-
type Position = { seq: number; subSeq: number }
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
- Durable event: `(seq, 0)` where `seq` is a per-session monotonic durable ordinal.
|
|
226
|
-
- Ephemeral event: `(anchorSeq, subSeq >= 1)` where `anchorSeq` is the latest authoritative durable head in the live process.
|
|
227
|
-
- Reconnect resumes by durable `seq` only. `subSeq` is not persisted and has no meaning after process loss.
|
|
228
|
-
|
|
229
|
-
### Envelope
|
|
230
|
-
|
|
231
|
-
All events share an envelope:
|
|
232
|
-
|
|
233
|
-
```ts
|
|
234
|
-
type EventEnvelope = {
|
|
235
|
-
namespace: EventNamespace
|
|
236
|
-
type: EventType
|
|
237
|
-
schemaVersion: number
|
|
238
|
-
durability: "durable" | "ephemeral"
|
|
239
|
-
eventId: EventId
|
|
240
|
-
sessionId: SessionId
|
|
241
|
-
createdAtMs: number
|
|
242
|
-
payload: unknown
|
|
243
|
-
}
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
`EventFactory` is the framework construction path: it attaches session identity, mints `eventId`, and stamps `createdAtMs`. Framework-owned decoding routes by `(namespace, type, schemaVersion)`. Current framework schemas are `schemaVersion = 1`.
|
|
247
|
-
|
|
248
|
-
### Current durable framework events
|
|
249
|
-
|
|
250
|
-
- Command: `CommandAdmitted`, `CommandStarted`, `CommandCompleted`, `CommandFailed`, `CommandCancelled`
|
|
251
|
-
- Message/context: `SystemMessageCommitted`, `UserMessageSubmitted`,
|
|
252
|
-
`UserMessagePromoted`, `UserMessageCancelled`, `PendingMessagesPaused`,
|
|
253
|
-
`UserMessageCommitted`, `AssistantMessageCommitted`,
|
|
254
|
-
`AssistantPartialCommitted`. Legacy steering events remain replay-compatible.
|
|
255
|
-
- Run: `RunStarted`, `RunCompleted`, `RunFailed`; legacy replay also accepts deprecated `RunInterrupted`
|
|
256
|
-
- Turn: `TurnStarted`, `TurnCompleted`, `TurnFailed`; legacy replay also accepts deprecated `TurnStopped`
|
|
257
|
-
- Inference: `InferenceStarted`, `InferenceCompleted`, `InferenceFailed`
|
|
258
|
-
- Tool: `ToolCallCreated`, `ToolCallRejected`, `ToolCallStarted`, `ToolCallCompleted`, `ToolCallFailed`
|
|
259
|
-
- Stop: `StopTurnRequested`, `StopTurnApplied`
|
|
260
|
-
- Compaction: `CompactionRequested`, `CompactionStarted`, `SummaryCreated`, `ContextRebased`, `CompactionCompleted`, `CompactionFailed`
|
|
261
|
-
|
|
262
|
-
Reserved but not currently emitted in normal runtime paths: `ContextProjected`, `BaseStateRequested`, `BaseStateCreated`, `BaseStateFailed`.
|
|
263
|
-
|
|
264
|
-
### Current ephemeral framework events
|
|
265
|
-
|
|
266
|
-
- `TextDelta`
|
|
267
|
-
- `ReasoningDelta`
|
|
268
|
-
- `ToolParamsStart`
|
|
269
|
-
- `ToolParamsDelta`
|
|
270
|
-
- `ToolParamsEnd`
|
|
271
|
-
|
|
272
|
-
Ephemeral events are live-only. The current reconnect story keeps a bounded raw active-turn ephemeral replay buffer in memory for the current process; Durable Object eviction loses that buffer.
|
|
273
|
-
|
|
274
|
-
---
|
|
275
|
-
|
|
276
|
-
## 9. Durable store
|
|
277
|
-
|
|
278
|
-
`EDASessionStore` is the semantic storage port. Runtime services depend on this port, not raw SQL.
|
|
279
|
-
|
|
280
|
-
Current API:
|
|
281
|
-
|
|
282
|
-
```ts
|
|
283
|
-
interface EDASessionStore {
|
|
284
|
-
append(batch): Effect<ReadonlyArray<CommittedDurableEvent>, EDASessionStoreError>
|
|
285
|
-
eventsAfter(afterSeq): Stream<CommittedDurableEvent, EDASessionStoreError>
|
|
286
|
-
loadCommittedEventsBySeq(seqs): Effect<ReadonlyArray<CommittedDurableEvent>, EDASessionStoreError>
|
|
287
|
-
findCommandAdmission(input): Effect<CommittedDurableEvent | undefined, EDASessionStoreError>
|
|
288
|
-
loadSummaryArtifact(summaryId): Effect<CompactionSummaryArtifact | undefined, EDASessionStoreError>
|
|
289
|
-
loadReducerCheckpoint(name): Effect<EDAReducerCheckpoint | undefined, EDASessionStoreError>
|
|
290
|
-
saveReducerCheckpoint(checkpoint): Effect<void, EDASessionStoreError>
|
|
291
|
-
saveReducerCheckpoints(checkpoints): Effect<void, EDASessionStoreError>
|
|
292
|
-
}
|
|
293
|
-
```
|
|
294
|
-
|
|
295
|
-
### Current production store
|
|
296
|
-
|
|
297
|
-
Production uses Cloudflare Durable Object SQLite. One Durable Object stores one EDA session.
|
|
298
|
-
|
|
299
|
-
Foundational tables:
|
|
300
|
-
|
|
301
|
-
- `_eda_schema_migrations` — applied host/store migrations.
|
|
302
|
-
- `_eda_event_log` — ordered durable occurrences; `seq INTEGER PRIMARY KEY AUTOINCREMENT`.
|
|
303
|
-
- `_eda_command_state` — command status and command idempotency lookup.
|
|
304
|
-
- `_eda_command_inputs` — submitted command bodies kept out of event-log JSON.
|
|
305
|
-
- `_eda_context_messages` — model-visible message bodies.
|
|
306
|
-
- `_eda_context_summaries` — compaction summaries.
|
|
307
|
-
- `_eda_reducer_checkpoints` — framework `_eda.framework.reduced-state` and app reducer checkpoints.
|
|
308
|
-
- `_eda_sink_cursors` — durable sink checkpoints (cursor plus versioned sink-owned payload).
|
|
309
|
-
|
|
310
|
-
Logical durable events are canonical. The DO store may physically normalize large framework fields into sidecar tables, but `eventsAfter` reconstructs full logical events before returning them to reducers, sinks, query APIs, and live catch-up.
|
|
311
|
-
|
|
312
|
-
There is intentionally no separate privileged session-state table. Framework `ReducedState` is persisted through the same reducer-checkpoint mechanism as app reducers; `_eda.framework.reduced-state` is reserved for framework-owned state, while app reducers use non-`_eda.` names.
|
|
313
|
-
|
|
314
|
-
Foreign/app namespace events are currently stored as full logical payloads in `_eda_event_log.fact_json`; there is no app physical sidecar codec registration.
|
|
315
|
-
|
|
316
|
-
### Append rule
|
|
317
|
-
|
|
318
|
-
Each durable append is one synchronous store transaction. In the Cloudflare host this means `ctx.storage.transactionSync(() => { ... })` around synchronous `ctx.storage.sql.exec(...)` calls only.
|
|
319
|
-
|
|
320
|
-
Inside append:
|
|
321
|
-
|
|
322
|
-
1. Insert event-log rows; SQLite allocates `seq`.
|
|
323
|
-
2. Write framework sidecar bodies/projections.
|
|
324
|
-
3. Update synchronous command metadata.
|
|
325
|
-
4. Return committed logical events with positions.
|
|
326
|
-
|
|
327
|
-
No `await`, model/tool calls, publishing, or external I/O may occur inside the transaction. Live publish happens after append succeeds and is owned by `SessionState`.
|
|
328
|
-
|
|
329
|
-
### Current limits
|
|
330
|
-
|
|
331
|
-
- Serialized JSON payloads are guarded below Cloudflare’s 2 MB SQL value/row limit (current hard cap around 1.5 MB).
|
|
332
|
-
- Oversized command inputs, messages, summaries, app events, and tool/app results fail before commit; callers should store large data by reference.
|
|
333
|
-
- Storage pruning/BaseState is not implemented. Compaction changes model context; it does not delete retained event/body rows.
|
|
334
|
-
|
|
335
|
-
---
|
|
336
|
-
|
|
337
|
-
## 10. Live delivery and reconnect
|
|
338
|
-
|
|
339
|
-
`LiveEventBus` is in-memory fanout. It is downstream of `SessionState` and never defines durable truth.
|
|
340
|
-
|
|
341
|
-
Durable write path:
|
|
342
|
-
|
|
343
|
-
```text
|
|
344
|
-
EventFactory durable event
|
|
345
|
-
-> SessionState.appendDurable / appendDurableBatch
|
|
346
|
-
-> EDASessionStore.append
|
|
347
|
-
-> fold ReducedState + app reducers
|
|
348
|
-
-> write reducer checkpoints
|
|
349
|
-
-> LiveEventBus.publish (seq, 0)
|
|
350
|
-
```
|
|
351
|
-
|
|
352
|
-
Ephemeral path:
|
|
353
|
-
|
|
354
|
-
```text
|
|
355
|
-
EventFactory ephemeral event
|
|
356
|
-
-> SessionState.publishEphemeral
|
|
357
|
-
-> anchor on ReducedState.lastSeq
|
|
358
|
-
-> allocate subSeq
|
|
359
|
-
-> LiveEventBus.publish (anchorSeq, subSeq)
|
|
360
|
-
```
|
|
361
|
-
|
|
362
|
-
### `eventsAfter(afterSeq)`
|
|
363
|
-
|
|
364
|
-
`EDARuntime.eventsAfter(afterSeq)` / `EDASessionQuery.eventsAfter(afterSeq)` returns a reconnect-safe merged stream:
|
|
365
|
-
|
|
366
|
-
1. Subscribe to `LiveEventBus` first.
|
|
367
|
-
2. Capture finite durable `replayHead` from the authoritative `SessionState` snapshot.
|
|
368
|
-
3. Replay durable events with `afterSeq < seq <= replayHead`.
|
|
369
|
-
4. Include same-process active-turn ephemeral replay buffer.
|
|
370
|
-
5. Drain buffered live prefix, de-duplicate durable events at/before `replayHead`, keep ephemerals, and sort that finite prefix by position.
|
|
371
|
-
6. Forward future live events.
|
|
372
|
-
|
|
373
|
-
Pure durable replay remains `EDASessionStore.eventsAfter(seq)`.
|
|
374
|
-
|
|
375
|
-
### WebSocket subscriber behavior
|
|
376
|
-
|
|
377
|
-
The current WebSocket transport is described in detail in `docs/websocket-protocol.md`. Current implementation facts:
|
|
378
|
-
|
|
379
|
-
- Server frames are versioned and batch-capable; current sender emits one event per frame.
|
|
380
|
-
- Clients ACK `events` frames after applying them.
|
|
381
|
-
- Heartbeats are not ACKed.
|
|
382
|
-
- Each subscriber has a bounded buffer and ACK-gated sender.
|
|
383
|
-
- Slow subscribers are closed independently; they do not backpressure `SessionState`, the durable append path, model streams, tools, sinks, or other subscribers.
|
|
384
|
-
- Cloudflare WebSocket attachment stores the last ACKed durable `seq` for hibernation restore.
|
|
385
|
-
|
|
386
|
-
### Active-turn ephemeral replay
|
|
387
|
-
|
|
388
|
-
`LiveEventBus` keeps raw active-turn ephemerals only while a turn is open:
|
|
389
|
-
|
|
390
|
-
- `TurnStarted` opens the buffer.
|
|
391
|
-
- Ephemerals emitted during the active turn are retained up to the current capacity (`4096`, newest retained on overflow).
|
|
392
|
-
- `TurnCompleted`, `TurnStopped`, or `TurnFailed` clears it.
|
|
393
|
-
- Durable Object eviction loses it.
|
|
394
|
-
|
|
395
|
-
There is no current coalesced live-state snapshot or generic UI projection layer.
|
|
396
|
-
|
|
397
|
-
---
|
|
398
|
-
|
|
399
|
-
## 11. Execution flow
|
|
400
|
-
|
|
401
|
-
### Turn and inference flow
|
|
402
|
-
|
|
403
|
-
```text
|
|
404
|
-
SessionState starts turn
|
|
405
|
-
-> TurnStarted
|
|
406
|
-
-> TurnRunner
|
|
407
|
-
-> InferenceRunner
|
|
408
|
-
-> InferenceStarted
|
|
409
|
-
-> LanguageModel.streamText(... disableToolCallResolution: true)
|
|
410
|
-
-> InferenceState.step for each Response.StreamPart
|
|
411
|
-
-> ephemerals during streaming
|
|
412
|
-
-> ToolCallCreated/Rejected decisions + InferenceCompleted after finish
|
|
413
|
-
-> ToolExecutor for valid framework-owned tool calls
|
|
414
|
-
-> TurnCompleted/TurnFailed, or later turn scheduling when continuation is needed
|
|
415
|
-
-> SessionState consumes steering or terminalizes run/command
|
|
416
|
-
```
|
|
417
|
-
|
|
418
|
-
`InferenceState` is pure. It owns text/reasoning accumulation, speculative tool-parameter drafts, final tool-call decisions, finish sealing, and payload-only emissions. `InferenceRunner` is the effectful shell that mints IDs, validates tool params, constructs envelopes, publishes ephemerals, and commits durable finalization.
|
|
419
|
-
|
|
420
|
-
### Current stream-part handling
|
|
421
|
-
|
|
422
|
-
- `text-delta` / `reasoning-delta` → ephemeral `TextDelta` / `ReasoningDelta` and inference-local accumulation.
|
|
423
|
-
- `tool-params-start/delta/end` → ephemeral speculative tool-param UI state.
|
|
424
|
-
- final `tool-call` → validate params and stage `ToolCallCreated` or `ToolCallRejected` decision.
|
|
425
|
-
- `response-metadata` → record provider response/model metadata.
|
|
426
|
-
- `finish` → seal the inference and commit staged tool decisions plus `InferenceCompleted`.
|
|
427
|
-
- `file` / `source` → counted/dropped with debug logging; first-class content-reference schemas are future work.
|
|
428
|
-
- provider-executed tool calls/results → explicit unsupported failure path; EDA does not replay or project provider-executed tools.
|
|
429
|
-
|
|
430
|
-
After an inference seals:
|
|
431
|
-
|
|
432
|
-
- Visible assistant text/reasoning is committed as `AssistantMessageCommitted` before tool continuation when present.
|
|
433
|
-
- Valid tool calls execute through `ToolExecutor`.
|
|
434
|
-
- Tool results are projected into continuation prompts in original model-call order, even though completion events commit in actual completion order.
|
|
435
|
-
- Rejected tool feedback can trigger a corrective turn.
|
|
436
|
-
- When no continuation is needed, `TurnCompleted` commits with usage rollup when known.
|
|
437
|
-
|
|
438
|
-
---
|
|
439
|
-
|
|
440
|
-
## 12. Tools
|
|
441
|
-
|
|
442
|
-
EDA does not invent a second model-visible tool schema. Tools are upstream Effect AI `Tool` / `Toolkit` values plus EDA lifecycle ownership.
|
|
443
|
-
|
|
444
|
-
Current `EDAToolRegistry` responsibilities:
|
|
445
|
-
|
|
446
|
-
1. `getModelToolkit()` returns provider-visible tool definitions.
|
|
447
|
-
2. `getParamsSchema(toolName)` validates final provider tool-call params.
|
|
448
|
-
3. `execute(toolName, params, context)` runs a sealed framework-owned tool call after `ToolCallCreated` commits.
|
|
449
|
-
|
|
450
|
-
Current `EDAToolExecutionContext` provides:
|
|
451
|
-
|
|
452
|
-
- `sessionId`
|
|
453
|
-
- `toolCallId`
|
|
454
|
-
- `makeEventId()`
|
|
455
|
-
- `emitDurable(event)` for app durable facts
|
|
456
|
-
|
|
457
|
-
There is no current public direct tool `emitEphemeral`, per-tool retry policy object, coalescer registration, or detached background scope in the tool context.
|
|
458
|
-
|
|
459
|
-
Tool lifecycle boundaries are framework-owned:
|
|
460
|
-
|
|
461
|
-
```text
|
|
462
|
-
ToolCallCreated | ToolCallRejected
|
|
463
|
-
ToolCallStarted
|
|
464
|
-
ToolCallCompleted | ToolCallFailed
|
|
465
|
-
```
|
|
466
|
-
|
|
467
|
-
Tools may emit app durable facts, but they do not emit framework tool lifecycle events directly.
|
|
468
|
-
|
|
469
|
-
### Current `runBash` integration
|
|
470
|
-
|
|
471
|
-
Gia’s `runBash` returns bounded stdout/stderr presentation plus
|
|
472
|
-
exit/timing/sandbox metadata in the framework tool result. It requests a shared
|
|
473
|
-
50 KiB / 2,000-line tail policy from `idempotent-exec`; if output exceeds that
|
|
474
|
-
budget, the terminal snapshot replaces streamed prefixes and names the
|
|
475
|
-
sandbox-local complete stdout/stderr artifacts. Framework `ToolCall*` events and
|
|
476
|
-
that result are the complete command lifecycle. Gia emits one durable E2B
|
|
477
|
-
`SandboxCreated` fact whenever a physical sandbox becomes authoritative; it
|
|
478
|
-
does not duplicate per-command lifecycle events.
|
|
479
|
-
|
|
480
|
-
Live stdout/stderr tailing, file-change events, and lazy artifact APIs are
|
|
481
|
-
future work.
|
|
482
|
-
|
|
483
|
-
---
|
|
484
|
-
|
|
485
|
-
## 13. App extension model
|
|
486
|
-
|
|
487
|
-
EDA has no lifecycle callbacks such as `onMessage`, `onChunk`, or `onToolStart`. Applications extend the state machine with typed data and Effect capabilities.
|
|
488
|
-
|
|
489
|
-
Current extension points:
|
|
490
|
-
|
|
491
|
-
- **App durable events** under app namespaces.
|
|
492
|
-
- **App reducers** via `EDAReducerRegistry`.
|
|
493
|
-
- **Durable sinks** and **ephemeral sinks** via `EDASinkRegistry`.
|
|
494
|
-
- **Tools** via `EDAToolRegistry` / Effect AI `Toolkit`.
|
|
495
|
-
- **Provider/model layers** and runtime config.
|
|
496
|
-
- **Prompt projection policy** through host/app layers.
|
|
497
|
-
- **Compaction policy/executor layers**.
|
|
498
|
-
|
|
499
|
-
Apps bind their custom durable-event union to the live protocol once with
|
|
500
|
-
`makeEDAWebSocketWireProtocol({ appEvents })`. The binding automatically includes
|
|
501
|
-
all framework durable and ephemeral events, configures strict host encoding, and
|
|
502
|
-
exports explicit `domain` and `wire` event/frame schema surfaces. Apps pass the
|
|
503
|
-
binding's `host` adapter to the EDA host and share its `wire` schemas with browser
|
|
504
|
-
or other WebSocket consumers. Its typed `encodeServerFrame` accepts only the
|
|
505
|
-
app-bound domain frame type.
|
|
506
|
-
Framework-only hosts reject unregistered app events rather than widening their
|
|
507
|
-
payloads to `unknown`.
|
|
508
|
-
|
|
509
|
-
### App durable events and reducers
|
|
510
|
-
|
|
511
|
-
Apps can submit durable app events alongside commands:
|
|
512
|
-
|
|
513
|
-
```ts
|
|
514
|
-
await runtime.submit([
|
|
515
|
-
new SubmitMessageCommand({ idempotencyKey, disposition: "queue", content }),
|
|
516
|
-
SlackEvents.messageReceived({ relatedCommandIdempotencyKey: idempotencyKey, ...slack }),
|
|
517
|
-
])
|
|
518
|
-
```
|
|
519
|
-
|
|
520
|
-
This commits one ordered batch. Same-batch app events should reference caller-owned ids such as `idempotencyKey` when they need to correlate with framework IDs that EDA mints at admission. Reducers can resolve the key after folding `CommandAdmitted`.
|
|
521
|
-
|
|
522
|
-
`EDAReducerRegistry` holds pure reducers. App reducer names must not start with reserved `_eda.`. Reducer state is checkpointed in `_eda_reducer_checkpoints` and also exposed in `EDASessionSnapshot.reducerStates`.
|
|
523
|
-
|
|
524
|
-
An app defines a discriminated serialized reducer-state union and registers its
|
|
525
|
-
complete reducer map once with `defineEDAReducerRegistry`. That registry supplies
|
|
526
|
-
the runtime reducer list and the schema-checked snapshot serializer. Adding,
|
|
527
|
-
removing, or renaming a reducer—or changing its state type—therefore produces a
|
|
528
|
-
type error at the app registration point and in consumers of the serialized
|
|
529
|
-
snapshot union.
|
|
530
|
-
|
|
531
|
-
The current examples show the intended shape:
|
|
532
|
-
|
|
533
|
-
- `packages/cloudflare/examples/002-slack-bridge` — idempotent Slack ingress, reducer correlation across framework/app events, and durable sink delivery.
|
|
534
|
-
- `packages/cloudflare/examples/003-sandbox-lifecycle` — framework tool events + app sandbox events reduced into one UI model, including SSR handoff math.
|
|
535
|
-
|
|
536
|
-
### Sinks
|
|
537
|
-
|
|
538
|
-
`EDASinkRegistry` has two lanes.
|
|
539
|
-
|
|
540
|
-
Durable lane:
|
|
541
|
-
|
|
542
|
-
- named sink with one durable checkpoint in `_eda_sink_cursors`
|
|
543
|
-
- reads durable windows after its cursor
|
|
544
|
-
- folds framework `ReducedState` and app reducer states through the batch
|
|
545
|
-
- filters by `interests`
|
|
546
|
-
- calls `process(batch, ctx)`
|
|
547
|
-
- exposes `ctx.checkpoint.get(schema, initial)` and `ctx.checkpoint.save(schema, state)` for typed sink-owned state
|
|
548
|
-
- serializes state-only saves with cursor commits, including writes from scoped background sink work
|
|
549
|
-
- commits staged durable events after success
|
|
550
|
-
- atomically commits the current sink-owned payload when advancing the cursor after successful processing/staged commits
|
|
551
|
-
- retries failures with capped exponential backoff + jitter
|
|
552
|
-
|
|
553
|
-
Ephemeral lane:
|
|
554
|
-
|
|
555
|
-
- live-only, best-effort
|
|
556
|
-
- optional interests and buffer policy
|
|
557
|
-
- no cursor and no correctness guarantee
|
|
558
|
-
|
|
559
|
-
Durable sinks are at-least-once. External side effects must be idempotent because a host can die after a remote success but before the local checkpoint write. Existing cursor rows whose payload predates typed checkpoint state retain their cursor and initialize sink-owned state from the supplied default. A stateful sink and the checkpoint-aware runner must roll out together because an older runner can replace the payload while advancing its cursor.
|
|
560
|
-
|
|
561
|
-
---
|
|
562
|
-
|
|
563
|
-
## 14. Prompt/context and compaction
|
|
564
|
-
|
|
565
|
-
Current prompt context is derived from durable state:
|
|
566
|
-
|
|
567
|
-
- durable system message from optional `EDARuntimeConfig.systemPrompt`, committed once as `SystemMessageCommitted` when a new session initializes;
|
|
568
|
-
- optional current cumulative summary from compaction;
|
|
569
|
-
- retained durable prompt/context-visible messages after the summary cursor.
|
|
570
|
-
|
|
571
|
-
Prompt hydration preserves model-facing prefix fidelity. Durable assistant/tool transcript events store exact typed prompt parts in stable model-facing order. Semantic UI/query views derive from those parts rather than rewriting the model-facing history.
|
|
572
|
-
|
|
573
|
-
### Current compaction implementation
|
|
574
|
-
|
|
575
|
-
Compaction is implemented as model-context rebase, not storage pruning.
|
|
576
|
-
|
|
577
|
-
Lifecycle:
|
|
578
|
-
|
|
579
|
-
```text
|
|
580
|
-
CompactionRequested
|
|
581
|
-
CompactionStarted
|
|
582
|
-
SummaryCreated
|
|
583
|
-
ContextRebased
|
|
584
|
-
CompactionCompleted | CompactionFailed
|
|
585
|
-
```
|
|
586
|
-
|
|
587
|
-
`ContextRebased` makes a summary current by updating context metadata. After a rebase, prompt hydration reads:
|
|
588
|
-
|
|
589
|
-
```text
|
|
590
|
-
system message + current summary + retained tail messages
|
|
591
|
-
```
|
|
592
|
-
|
|
593
|
-
Current runtime ships disabled/no-op defaults plus injectable policy/executor layers and common presets:
|
|
594
|
-
|
|
595
|
-
- approximate token threshold policy;
|
|
596
|
-
- language-model summary executor.
|
|
597
|
-
|
|
598
|
-
Compaction never deletes event/body rows. BaseState/storage pruning is not implemented.
|
|
599
|
-
|
|
600
|
-
---
|
|
601
|
-
|
|
602
|
-
## 15. Stop and recovery
|
|
603
|
-
|
|
604
|
-
### StopTurn
|
|
605
|
-
|
|
606
|
-
Stop is a durable control transition, not just a client-side stream abort.
|
|
607
|
-
|
|
608
|
-
Current flow:
|
|
609
|
-
|
|
610
|
-
1. `StopTurn` is admitted and `StopTurnRequested` commits.
|
|
611
|
-
2. `SessionState` closes the active turn scope with interruption.
|
|
612
|
-
3. Interruption propagates through turn, inference, provider stream, and running tools.
|
|
613
|
-
4. Inference/tool finalizers preserve durable partials/terminals they own:
|
|
614
|
-
- `AssistantPartialCommitted` when visible partial text/reasoning exists;
|
|
615
|
-
- `InferenceFailed` with interruption failure details;
|
|
616
|
-
- `ToolCallFailed` with `error.code = "tool.interrupted"` for unfinished tools.
|
|
617
|
-
5. `SessionState` commits scheduler-owned terminals:
|
|
618
|
-
- `TurnFailed` with `error.code = "turn.interrupted"`;
|
|
619
|
-
- `RunFailed` with `error.code = "run.interrupted"`;
|
|
620
|
-
- active command cancellation/failure;
|
|
621
|
-
- `StopTurnApplied`;
|
|
622
|
-
- stop-command completion.
|
|
623
|
-
6. Queued commands remain durable. Unexpected run failure preserves unconsumed
|
|
624
|
-
steers and schedules framework-owned recovery; explicit stop/interrupt
|
|
625
|
-
converts unconsumed work into a paused queue.
|
|
626
|
-
|
|
627
|
-
A stop is complete only after the durable stop/turn/run/command terminal events commit.
|
|
628
|
-
|
|
629
|
-
### Durable commit failure during finalization
|
|
630
|
-
|
|
631
|
-
Finalization regions prevent user interruption from tearing down lifecycle writes, but storage can still fail. If a required durable lifecycle commit fails, the active runtime treats that as fatal: it stops making later lifecycle claims and lets recovery inspect the incomplete durable log. It must not swallow the store error and then commit misleading later events.
|
|
632
|
-
|
|
633
|
-
### Recovery
|
|
634
|
-
|
|
635
|
-
Recovery is deterministic durable repair before new execution starts.
|
|
636
|
-
|
|
637
|
-
On startup `SessionState`:
|
|
638
|
-
|
|
639
|
-
1. hydrates framework `ReducedState` from the `_eda.framework.reduced-state` reducer checkpoint plus event-log tail;
|
|
640
|
-
2. hydrates registered app reducers from checkpoints plus tail;
|
|
641
|
-
3. calls the pure `planSessionRecovery` policy to classify every incomplete lifecycle, pending stop, open compaction, and ownerless steer;
|
|
642
|
-
4. interprets that complete plan as one atomic durable event batch, including a replacement `RunStarted` for eligible interrupted `SubmitMessage` or `ResumePendingMessages` work and a final `RecoveryCompleted` barrier;
|
|
643
|
-
5. refolds state and requires recovery to reach either an empty plan or the single intentionally continued command/run;
|
|
644
|
-
6. checkpoints the repaired state, starts the replacement turn with only its unconsumed source messages and eligible steers, and only then forks the long-lived control loop.
|
|
645
|
-
|
|
646
|
-
The synchronous startup pass is part of the host wakeup contract: a Durable Object alarm that cold-starts a session runtime does not return from runtime construction until stale lifecycle repair has had a chance to commit durable terminal events. After that finite pass, the long-lived control loop handles live ingress and active-turn completion.
|
|
647
|
-
|
|
648
|
-
`RecoveryCompleted` is emitted only when startup recovery commits at least one
|
|
649
|
-
lifecycle repair, stop application, compaction repair, message resumption, or
|
|
650
|
-
replacement run. An idle cold start emits no recovery event. The event is last
|
|
651
|
-
in the same atomic batch as the repairs, so its presence is the durable boundary
|
|
652
|
-
for a completed recovery transaction. Its optional `continuation` payload
|
|
653
|
-
records `{ commandId, interruptedRunId, replacementRunId }` when recovery
|
|
654
|
-
transparently resumes a command. “Completed” describes the repair transaction,
|
|
655
|
-
not the later completion of resumed agent work.
|
|
656
|
-
|
|
657
|
-
The post-recovery live loop does not silently repair stale active durable work. Once startup recovery has completed, durable replay and in-memory execution state must agree: an active durable command must have an in-memory execution owner. If that invariant is violated in a warm runtime, EDA treats it as a fatal runtime error and relies on the dedicated startup recovery path after a clean rebuild rather than patching over it inline.
|
|
658
|
-
|
|
659
|
-
The recovery functional core has no storage, fibers, clocks, or event minting.
|
|
660
|
-
The startup imperative shell owns those effects and is the only code that
|
|
661
|
-
interprets a recovery plan. Open-compaction handling is part of this same plan,
|
|
662
|
-
not a second repair pass. Normal live model/tool/run failures remain ordinary
|
|
663
|
-
domain transitions while an in-memory owner exists.
|
|
664
|
-
|
|
665
|
-
Current recovery behavior includes:
|
|
666
|
-
|
|
667
|
-
- started tool calls without terminal → `ToolCallFailed`;
|
|
668
|
-
- open inferences → `InferenceFailed`;
|
|
669
|
-
- open turns/runs → `TurnFailed` / `RunFailed` with interruption-coded failure metadata;
|
|
670
|
-
- one eligible active user-work command remains open and continues in an atomically scheduled replacement run; any additional stale active commands are cancelled;
|
|
671
|
-
- pending `StopTurnRequested` takes precedence, cancels the targeted work, pauses pending messages, and prevents transparent continuation;
|
|
672
|
-
- completed tool calls are not rerun blindly;
|
|
673
|
-
- pending queued commands remain pending;
|
|
674
|
-
- eligible pending steers join the replacement turn boundary; other ownerless steers receive one framework-owned `ResumePendingMessages` command;
|
|
675
|
-
- open compactions are failed or completed according to their durable record;
|
|
676
|
-
- stale stop commands targeting no active turn are cancelled rather than throwing.
|
|
677
|
-
|
|
678
|
-
This gives reconnecting clients a durable explanation of stale work before replacement live activity begins.
|
|
679
|
-
|
|
680
|
-
---
|
|
681
|
-
|
|
682
|
-
## 16. Cloudflare host and pluggability
|
|
683
|
-
|
|
684
|
-
Current production host:
|
|
685
|
-
|
|
686
|
-
- concrete subclasses of `EDASessionDurableObject` are registered in Wrangler;
|
|
687
|
-
- one Durable Object instance/database stores one session;
|
|
688
|
-
- host startup runs EDA schema migrations via `ctx.blockConcurrencyWhile(...)`;
|
|
689
|
-
- host entrypoints expose RPC methods for submit, submitBatch, submitAndBlock, blockOnCommand, snapshot, messages, backup/destroy, alarm, and WebSocket events;
|
|
690
|
-
- `EDASessionDurableObjectHost` owns the scoped `ManagedRuntime` for the session;
|
|
691
|
-
- runtime construction retries after a failed hydration/build instead of pinning the warm isolate to a rejected promise;
|
|
692
|
-
- `EDAKeepAlive` integrates with Durable Object alarms/leases so active control/model/sink work can keep the object awake enough to finish or reschedule;
|
|
693
|
-
- session destruction shuts down in-memory keep-alive state and deletes the Durable Object alarm before deleting storage;
|
|
694
|
-
- WebSocket hibernation restores subscribers from serialized attachment state.
|
|
695
|
-
|
|
696
|
-
The Cloudflare host imports Cloudflare APIs. Core domain/runtime code depends on services such as `EDASessionStore`, `SessionContext`, `IdGenerator`, `EDAKeepAlive`, model/tool layers, and live subscriber abstractions.
|
|
697
|
-
|
|
698
|
-
The host boundary supports multiple deployments. The Cloudflare and celld packages provide the same semantics: one ordered durable session log, atomic append, per-session coordination, resumable live delivery, durable sink checkpoints, clock/id services, and wakeup/keep-alive hooks.
|
|
699
|
-
|
|
700
|
-
---
|
|
701
|
-
|
|
702
|
-
## 17. Observability and tests
|
|
703
|
-
|
|
704
|
-
### Observability
|
|
705
|
-
|
|
706
|
-
Current tracing uses compact `eda.*` attributes from `services/tracing.ts`. Spans belong on meaningful runtime boundaries:
|
|
707
|
-
|
|
708
|
-
- host RPC/WebSocket entrypoints;
|
|
709
|
-
- runtime submit/block;
|
|
710
|
-
- durable store append/replay/hydration;
|
|
711
|
-
- session control drain/start/stop/recovery;
|
|
712
|
-
- turn/inference execution;
|
|
713
|
-
- tool execution;
|
|
714
|
-
- sink drains;
|
|
715
|
-
- compaction policy/execution.
|
|
716
|
-
|
|
717
|
-
Avoid instrumentation noise on pure helpers, refs, and pass-through query helpers.
|
|
718
|
-
|
|
719
|
-
### Tests
|
|
720
|
-
|
|
721
|
-
The current suite includes:
|
|
722
|
-
|
|
723
|
-
- pure domain tests and property tests;
|
|
724
|
-
- in-memory runtime tests;
|
|
725
|
-
- Durable Object host/storage tests;
|
|
726
|
-
- WebSocket subscriber tests;
|
|
727
|
-
- sink/reducer tests;
|
|
728
|
-
- compaction tests;
|
|
729
|
-
- crash/recovery simulations;
|
|
730
|
-
- example scenario tests.
|
|
731
|
-
|
|
732
|
-
Future hardening work should stay out of this current-state doc unless it is clearly marked in the specific proposal document that owns it.
|
|
733
|
-
|
|
734
|
-
---
|
|
735
|
-
|
|
736
|
-
## 18. Current-state checklist
|
|
737
|
-
|
|
738
|
-
EDA currently provides:
|
|
739
|
-
|
|
740
|
-
- durable command admission with command idempotency lookup;
|
|
741
|
-
- one active run/turn per session;
|
|
742
|
-
- `queue`, `steer`, and `interrupt` message semantics;
|
|
743
|
-
- durable system/user/assistant/partial message commits;
|
|
744
|
-
- exact model-facing prompt parts for assistant/tool transcript replay;
|
|
745
|
-
- Effect AI model streaming with framework-owned tool resolution;
|
|
746
|
-
- ephemeral text/reasoning/tool-parameter live deltas;
|
|
747
|
-
- durable run/turn/inference/tool/stop lifecycle boundaries;
|
|
748
|
-
- Effect-scoped tool execution and interruption;
|
|
749
|
-
- custom app durable events, reducers, and reducer checkpoints;
|
|
750
|
-
- durable sinks with at-least-once cursor semantics;
|
|
751
|
-
- best-effort ephemeral sinks;
|
|
752
|
-
- Cloudflare Durable Object SQLite store and WebSocket host;
|
|
753
|
-
- reconnect-safe `eventsAfter` merged stream;
|
|
754
|
-
- deterministic recovery of incomplete durable lifecycles;
|
|
755
|
-
- model-context compaction/rebase without storage pruning;
|
|
756
|
-
- testkit layers for in-memory model/store/host-style tests.
|
|
757
|
-
|
|
758
|
-
EDA currently does **not** provide:
|
|
759
|
-
|
|
760
|
-
- storage pruning/BaseState;
|
|
761
|
-
- generic persisted UI projection items/pagination;
|
|
762
|
-
- coalesced live-state snapshots for reconnect;
|
|
763
|
-
- direct tool ephemerals or per-tool retry policy objects;
|
|
764
|
-
- provider-executed tool projection/replay;
|
|
765
|
-
- durable stdout/stderr chunks or file-change artifacts for sandbox tools;
|
|
766
|
-
- app-side physical payload sidecars/chunking;
|
|
767
|
-
- additional production hosts beyond the Cloudflare-compatible contract.
|
|
768
|
-
|
|
769
|
-
---
|
|
770
|
-
|
|
771
|
-
## 19. Adjacent documents
|
|
772
|
-
|
|
773
|
-
- `docs/message-steering.md` — current durable message queue and steering semantics.
|
|
774
|
-
- `docs/websocket-protocol.md` — current WebSocket protocol plus marked future hardening notes.
|
|
775
|
-
- `docs/testing.md` — test archetypes and fidelity ownership.
|
|
776
|
-
- `docs/ui-projection.md` — future generic UI projection proposal, not current runtime behavior.
|
|
777
|
-
- `docs/subagents.md` — future EDA/Gia subagent proposal, not current runtime behavior.
|