effect-durable-agent 0.1.0-alpha.1 → 0.1.0-alpha.10

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.
Files changed (183) hide show
  1. package/README.md +140 -136
  2. package/dist/{command-queues-CQ9cwRP7.d.ts → command-queues-CQi4Xc7u.d.ts} +109 -21
  3. package/dist/{commands-Ce1ec6kH.d.ts → commands-p8venTWs.d.ts} +10 -2
  4. package/dist/compaction-0k8zCJgB.js +473 -0
  5. package/dist/compaction-0k8zCJgB.js.map +1 -0
  6. package/dist/{compaction-YayFKo_1.d.ts → compaction-BhLSSXJ-.d.ts} +28 -7
  7. package/dist/context-projection-mCuvcO2W.d.ts +140 -0
  8. package/dist/{core-Hv3cFydL.d.ts → core-C-6xHzRx.d.ts} +6 -3
  9. package/dist/domain/command-queues.d.ts +1 -1
  10. package/dist/domain/command-queues.js +1 -1
  11. package/dist/domain/command-queues.js.map +1 -1
  12. package/dist/domain/context-projection.d.ts +2 -0
  13. package/dist/domain/context-projection.js +32 -0
  14. package/dist/domain/context-projection.js.map +1 -0
  15. package/dist/domain/message-transcript.d.ts +1 -1
  16. package/dist/domain/model-usage.d.ts +2 -0
  17. package/dist/domain/model-usage.js +59 -0
  18. package/dist/domain/model-usage.js.map +1 -0
  19. package/dist/domain/reduced-state-schema.d.ts +14 -18
  20. package/dist/domain/reduced-state-schema.js +7 -11
  21. package/dist/domain/reduced-state-schema.js.map +1 -1
  22. package/dist/domain/reduced-state.d.ts +3 -2
  23. package/dist/domain/reduced-state.js +3 -2
  24. package/dist/domain/run-scheduling.d.ts +2 -0
  25. package/dist/domain/run-scheduling.js +127 -0
  26. package/dist/domain/run-scheduling.js.map +1 -0
  27. package/dist/{durable-C3Rz7kg3.js → durable-BPHVFVvV.js} +74 -83
  28. package/dist/durable-BPHVFVvV.js.map +1 -0
  29. package/dist/{durable-DlScwmCy.d.ts → durable-DeLCAvbw.d.ts} +1256 -104
  30. package/dist/envelope-DkZyMIgp.d.ts +191 -0
  31. package/dist/envelope-DxQzo5rN.js +82 -0
  32. package/dist/envelope-DxQzo5rN.js.map +1 -0
  33. package/dist/{keep-alive-DYDsH6qN.d.ts → event-factory-KaeDSfeP.d.ts} +11 -31
  34. package/dist/{keep-alive-p8dIcSVy.js → event-factory-QuC_UvyP.js} +8 -10
  35. package/dist/event-factory-QuC_UvyP.js.map +1 -0
  36. package/dist/{events-Bb9-Cu-7.d.ts → events-LZFNoESe.d.ts} +2 -188
  37. package/dist/{id-generator-C2Q15uZM.d.ts → id-generator--x6itQZ2.d.ts} +3 -2
  38. package/dist/index.d.ts +7 -6
  39. package/dist/index.js +5 -4
  40. package/dist/keep-alive-Chl5SJxy.d.ts +29 -0
  41. package/dist/{message-transcript-BCHdHAe2.d.ts → message-transcript-6PEzaEGn.d.ts} +4 -4
  42. package/dist/model-resolver-BPPJAsuh.d.ts +18 -0
  43. package/dist/model-usage-CdBEkTwU.d.ts +55 -0
  44. package/dist/{prompt-projector-9_02lk5-.d.ts → prompt-projector-CNhqUsEr.d.ts} +15 -16
  45. package/dist/{reduced-state-C4nVVzz9.js → reduced-state-Bz68V2H8.js} +65 -32
  46. package/dist/reduced-state-Bz68V2H8.js.map +1 -0
  47. package/dist/{reducer-registry-C0svUa63.d.ts → reducer-registry-CCSzc4h8.d.ts} +16 -6
  48. package/dist/run-scheduler-DcS_okUH.d.ts +43 -0
  49. package/dist/run-scheduling-wakeup-CeHrvXie.d.ts +25 -0
  50. package/dist/{runtime-C56FQxiL.d.ts → runtime-WL_gKqxn.d.ts} +16 -7
  51. package/dist/services/compaction.d.ts +1 -1
  52. package/dist/services/compaction.js +1 -425
  53. package/dist/services/id-generator.d.ts +1 -1
  54. package/dist/services/id-generator.js +2 -1
  55. package/dist/services/id-generator.js.map +1 -1
  56. package/dist/services/keep-alive.d.ts +2 -0
  57. package/dist/services/keep-alive.js +13 -0
  58. package/dist/services/keep-alive.js.map +1 -0
  59. package/dist/services/model-resolver.d.ts +2 -0
  60. package/dist/services/model-resolver.js +17 -0
  61. package/dist/services/model-resolver.js.map +1 -0
  62. package/dist/services/prompt-projector.d.ts +2 -2
  63. package/dist/services/prompt-projector.js +20 -10
  64. package/dist/services/prompt-projector.js.map +1 -1
  65. package/dist/services/reducer-registry.d.ts +2 -2
  66. package/dist/services/reducer-registry.js +7 -3
  67. package/dist/services/reducer-registry.js.map +1 -1
  68. package/dist/services/run-scheduler.d.ts +3 -0
  69. package/dist/services/run-scheduler.js +25 -0
  70. package/dist/services/run-scheduler.js.map +1 -0
  71. package/dist/services/run-scheduling-wakeup.d.ts +2 -0
  72. package/dist/services/run-scheduling-wakeup.js +13 -0
  73. package/dist/services/run-scheduling-wakeup.js.map +1 -0
  74. package/dist/services/runtime-layer.d.ts +67 -0
  75. package/dist/services/runtime-layer.js +47 -0
  76. package/dist/services/runtime-layer.js.map +1 -0
  77. package/dist/services/runtime.d.ts +1 -1
  78. package/dist/services/runtime.js +21 -14
  79. package/dist/services/runtime.js.map +1 -1
  80. package/dist/services/session-event-observer.d.ts +2 -0
  81. package/dist/services/session-event-observer.js +13 -0
  82. package/dist/services/session-event-observer.js.map +1 -0
  83. package/dist/services/session-query.d.ts +2 -2
  84. package/dist/services/session-query.js +140 -1
  85. package/dist/services/session-query.js.map +1 -0
  86. package/dist/services/session-state.d.ts +2 -0
  87. package/dist/services/session-state.js +2 -0
  88. package/dist/services/session-store.d.ts +2 -2
  89. package/dist/services/session-store.js +182 -2
  90. package/dist/services/session-store.js.map +1 -0
  91. package/dist/services/sink-checkpoint-store.d.ts +2 -0
  92. package/dist/services/sink-checkpoint-store.js +49 -0
  93. package/dist/services/sink-checkpoint-store.js.map +1 -0
  94. package/dist/services/sink-registry.d.ts +1 -1
  95. package/dist/services/sink-registry.js +1 -1
  96. package/dist/services/span-names.d.ts +1 -1
  97. package/dist/services/span-names.js +3 -0
  98. package/dist/services/span-names.js.map +1 -1
  99. package/dist/services/tool-registry.d.ts +1 -1
  100. package/dist/services/tracing.d.ts +1 -1
  101. package/dist/services/tracing.js +23 -2
  102. package/dist/services/tracing.js.map +1 -1
  103. package/dist/session-event-observer-DaFMKKNc.d.ts +24 -0
  104. package/dist/session-query-DfW_4KC0.d.ts +47 -0
  105. package/dist/{session-query-DOc1KanA.js → session-state-BIZ2SYaP.js} +350 -183
  106. package/dist/session-state-BIZ2SYaP.js.map +1 -0
  107. package/dist/{session-query-DlRo5Ufc.d.ts → session-state-BeR2rZRR.d.ts} +144 -46
  108. package/dist/{session-store-D2Ore1QC.d.ts → session-store-J_Un45kW.d.ts} +7 -96
  109. package/dist/sink-checkpoint-store-C9hUxfH0.d.ts +40 -0
  110. package/dist/{sink-registry-CFC6xjsN.js → sink-registry-Bbqhtdnx.js} +27 -67
  111. package/dist/sink-registry-Bbqhtdnx.js.map +1 -0
  112. package/dist/{sink-registry-CIU0LD3m.d.ts → sink-registry-DuDkNXjZ.d.ts} +24 -49
  113. package/dist/testkit/layers.d.ts +24 -14
  114. package/dist/testkit/layers.js +18 -11
  115. package/dist/testkit/layers.js.map +1 -1
  116. package/dist/{tool-registry-CcnkAAQK.d.ts → tool-registry-BDmJe_Wr.d.ts} +4 -4
  117. package/dist/types/commands.d.ts +2 -2
  118. package/dist/types/commands.js +7 -2
  119. package/dist/types/commands.js.map +1 -1
  120. package/dist/types/core.d.ts +2 -2
  121. package/dist/types/core.js +4 -2
  122. package/dist/types/core.js.map +1 -1
  123. package/dist/types/events/durable.d.ts +2 -2
  124. package/dist/types/events/durable.js +2 -2
  125. package/dist/types/events.d.ts +4 -3
  126. package/dist/types/events.js +3 -2
  127. package/dist/types/events.js.map +1 -1
  128. package/dist/websocket.d.ts +2776 -0
  129. package/dist/websocket.js +498 -0
  130. package/dist/websocket.js.map +1 -0
  131. package/package.json +68 -43
  132. package/testing/offline-trace/README.md +2 -1
  133. package/CHANGELOG.md +0 -10
  134. package/CONTRIBUTING.md +0 -26
  135. package/SECURITY.md +0 -8
  136. package/dist/durable-C3Rz7kg3.js.map +0 -1
  137. package/dist/durable-object-runtime-B7jwBY2R.js +0 -1494
  138. package/dist/durable-object-runtime-B7jwBY2R.js.map +0 -1
  139. package/dist/durable-object-runtime-pWv0ohlz.d.ts +0 -257
  140. package/dist/durable-object-storage-Czy7IPrh.d.ts +0 -41
  141. package/dist/host/durable-object-runtime.d.ts +0 -2
  142. package/dist/host/durable-object-runtime.js +0 -2
  143. package/dist/host/durable-object-storage.d.ts +0 -2
  144. package/dist/host/durable-object-storage.js +0 -0
  145. package/dist/host/durable-object.d.ts +0 -83
  146. package/dist/host/durable-object.js +0 -191
  147. package/dist/host/durable-object.js.map +0 -1
  148. package/dist/host/websocket-wire.d.ts +0 -2
  149. package/dist/host/websocket-wire.js +0 -88
  150. package/dist/host/websocket-wire.js.map +0 -1
  151. package/dist/keep-alive-p8dIcSVy.js.map +0 -1
  152. package/dist/reduced-state-C4nVVzz9.js.map +0 -1
  153. package/dist/services/compaction.js.map +0 -1
  154. package/dist/session-query-DOc1KanA.js.map +0 -1
  155. package/dist/session-store-pYxQW9qh.js +0 -214
  156. package/dist/session-store-pYxQW9qh.js.map +0 -1
  157. package/dist/sink-registry-CFC6xjsN.js.map +0 -1
  158. package/dist/websocket-wire-DvOu_6BJ.d.ts +0 -16773
  159. package/docs/assets/architecture.svg +0 -106
  160. package/docs/assets/event-sequence.svg +0 -143
  161. package/docs/assets/gcp-trace.png +0 -0
  162. package/docs/message-steering.md +0 -831
  163. package/docs/releasing.md +0 -57
  164. package/docs/spec.md +0 -774
  165. package/docs/subagents.md +0 -725
  166. package/docs/testing.md +0 -64
  167. package/docs/ui-projection.md +0 -742
  168. package/docs/websocket-protocol.md +0 -613
  169. package/examples/001-no-tools/README.md +0 -65
  170. package/examples/001-no-tools/worker.ts +0 -79
  171. package/examples/002-slack-bridge/README.md +0 -134
  172. package/examples/002-slack-bridge/events.ts +0 -115
  173. package/examples/002-slack-bridge/reducer.ts +0 -216
  174. package/examples/002-slack-bridge/scenario.test.ts +0 -223
  175. package/examples/002-slack-bridge/sinks.ts +0 -109
  176. package/examples/002-slack-bridge/worker.ts +0 -140
  177. package/examples/003-sandbox-lifecycle/README.md +0 -78
  178. package/examples/003-sandbox-lifecycle/events.ts +0 -203
  179. package/examples/003-sandbox-lifecycle/reducer.ts +0 -305
  180. package/examples/003-sandbox-lifecycle/scenario.test.ts +0 -202
  181. package/examples/_shared/event-id.ts +0 -12
  182. package/examples/_shared/http.ts +0 -27
  183. package/examples/_shared/openai.ts +0 -33
package/docs/subagents.md DELETED
@@ -1,725 +0,0 @@
1
- # EDA resumables and Gia subagents
2
-
3
- Status: future
4
- Runtime: EDAGiaAgent
5
- Last reviewed: 2026-07-07
6
-
7
- This is a proposal / docs-only design. It does not propose putting subagent
8
- orchestration into EDA core. The design split is:
9
-
10
- - **EDA core** owns generic session waiting/resume semantics and first-party token
11
- accounting.
12
- - **Gia** owns subagent orchestration as an extension backed by Durable Objects.
13
-
14
- The reason for the split is simple: EDA is a per-session runtime. Subagents are a
15
- cross-session, product-specific orchestration feature involving Gia session
16
- metadata, ACLs, root workspace and sandbox semantics, child creation, global
17
- concurrency, queue fairness, deadlines, and operator UI. Those concerns should
18
- not become framework core.
19
-
20
- ---
21
-
22
- ## 1. Position
23
-
24
- Subagents should be implemented as a **Gia extension**, not as an EDA-native
25
- workflow engine.
26
-
27
- The EDA core change we do want is a small, reusable primitive: a session can enter
28
- a durable **waiting** state on one or more **resumables**. A resumable is a
29
- durable continuation handle that can be resolved later by an external event,
30
- trusted route, or extension-owned Durable Object.
31
-
32
- This same primitive should serve:
33
-
34
- - a parent waiting on a subagent batch;
35
- - a tool waiting on human approval for an integration call;
36
- - a workflow waiting on an external webhook;
37
- - any future extension that needs hibernation without a live fiber.
38
-
39
- Subagent manifests, child state, join predicates, deadlines, broker leases, and
40
- result aggregation belong outside EDA in a Gia `SubagentOrchestrator` Durable
41
- Object.
42
-
43
- ---
44
-
45
- ## 2. Goals and Non-Goals
46
-
47
- ### Goals
48
-
49
- - Allow a Gia session to fan work out to child sessions and resume durably when a
50
- declared join condition is satisfied.
51
- - Keep the parent session hibernated while waiting. No live promise, fiber, Web
52
- Socket, or DO process is required for correctness.
53
- - Support nested subagents through lineage and policy.
54
- - Make waiting visible as first-class session state, not as "idle plus hidden app
55
- state."
56
- - Keep subagent orchestration outside EDA core while still using EDA's durable
57
- command/event model for parent pause and resume.
58
- - Track token usage as a framework-level fact in tokens, not dollars.
59
-
60
- ### Non-goals
61
-
62
- - Do not build a general DAG/workflow engine in EDA.
63
- - Do not make EDA core understand subagent manifests or join modes.
64
- - Do not add a model-facing `subagents` skill before `spawnSubagents` exists.
65
- - Do not guarantee exact budget cutoffs under concurrent in-flight model calls.
66
- Slight overspend from cancel latency is acceptable.
67
- - Do not solve workspace conflict prevention. Subagents share root project state;
68
- v1 relies on attribution and operator visibility, not locks.
69
-
70
- ---
71
-
72
- ## 3. Terminology
73
-
74
- | Term | Meaning |
75
- | --- | --- |
76
- | **Resumable** | A durable continuation handle opened by a tool, command, or extension. It represents external work whose result may later resume the session. |
77
- | **Waiting** | Scheduler-visible session state: the session has no active run, but one or more resumables are open. |
78
- | **Resolver** | The trusted actor that resolves, cancels, or expires a resumable. For subagents this is the Gia subagent orchestrator. For approvals this may be an approval route. |
79
- | **Subagent batch** | Gia extension concept: a manifest-defined group of child sessions plus join policy. |
80
- | **Subagent orchestrator** | Gia Durable Object that owns subagent manifest state, child lifecycle, deadlines, joins, and resume calls. |
81
- | **Root session** | Top-level Gia session whose workspace, sandbox, and token budget are shared by a subagent tree. |
82
- | **Parent session** | Session that spawned a child or batch. A child can itself be a parent. |
83
-
84
- Use **waiting** for the scheduler/UI state. Use **resumable** for the durable
85
- continuation object. A session is "waiting on resumables," not itself
86
- "resumable."
87
-
88
- ---
89
-
90
- ## 4. High-Level Architecture
91
-
92
- ```text
93
- Parent EDA session DO
94
- - model calls Gia spawnSubagents tool
95
- - tool opens an EDA resumable
96
- - tool emits Gia SubagentBatchRequested app event
97
- - run completes; session state becomes waiting
98
-
99
- Parent durable outbox sink
100
- - sees SubagentBatchRequested
101
- - idempotently enqueues manifest with SubagentOrchestrator DO
102
- - does not submit commands and does not own joins
103
-
104
- Gia SubagentOrchestrator DO
105
- - owns manifest state in DO SQLite
106
- - owns queue, deadlines, leases, token sub-budgets, and join predicates
107
- - creates child Gia EDA sessions through trusted server contract
108
- - receives child result/progress signals
109
- - resolves the parent resumable when join criteria hold
110
-
111
- Child Gia EDA session DO
112
- - ordinary EDA session with lineage
113
- - shares root workspace and sandbox
114
- - writes result artifacts by reference
115
- - reports terminal/progress facts to orchestrator
116
- ```
117
-
118
- The parent log should contain durable intent and durable resume facts. It should
119
- not need every child progress event to evaluate the join. The orchestrator owns
120
- that operational state.
121
-
122
- ---
123
-
124
- ## 5. EDA Core: Resumables
125
-
126
- EDA core should add a generic resumable event family and reducer. These events are
127
- framework events because dispatch policy and session state depend on them.
128
-
129
- ### 5.1 Core Events
130
-
131
- ```ts
132
- ResumableOpened = {
133
- resumableId: ResumableId
134
- kind: string // e.g. "gia.subagent.join", "approval.required"
135
- source: {
136
- commandId: CommandId
137
- runId?: RunId
138
- turnId?: TurnId
139
- inferenceId?: InferenceId
140
- toolCallId?: ToolCallId
141
- }
142
- resumePolicy: "auto" | "manual"
143
- interruptPolicy: "queue" | "allow-steer" | "allow-interrupt"
144
- deadlineMs?: number
145
- display?: {
146
- title: string
147
- summary?: string
148
- }
149
- }
150
-
151
- ResumableResolved = {
152
- resumableId: ResumableId
153
- resultRef?: string
154
- result?: unknown // small only; large results by reference
155
- }
156
-
157
- ResumableCancelled = {
158
- resumableId: ResumableId
159
- reason: string
160
- }
161
-
162
- ResumableExpired = {
163
- resumableId: ResumableId
164
- }
165
- ```
166
-
167
- The reducer tracks all open and terminal resumables. A session is **waiting** when
168
- there is no active command/run and at least one resumable is open.
169
-
170
- ### 5.2 Resumables Are Not Tool Calls
171
-
172
- A tool call should not remain open while waiting on external work. The tool should
173
- open a resumable, commit the durable fact, and then complete normally with a small
174
- handle:
175
-
176
- ```ts
177
- const handle = yield* ctx.openResumable({
178
- kind: "approval.required",
179
- source: { toolCallId: ctx.toolCallId },
180
- resumePolicy: "auto",
181
- interruptPolicy: "allow-interrupt",
182
- display: {
183
- title: "Approval required",
184
- summary: "Approve Salesforce write",
185
- },
186
- });
187
-
188
- return {
189
- status: "waiting",
190
- resumableId: handle.resumableId,
191
- };
192
- ```
193
-
194
- This keeps recovery simple. Tool lifecycle remains tool lifecycle. Resumable
195
- lifecycle is a separate continuation contract.
196
-
197
- ### 5.3 Multiple Resumables
198
-
199
- EDA should allow multiple open resumables. Core semantics stay intentionally
200
- small:
201
-
202
- - The session remains waiting while any resumable is open.
203
- - A resolved resumable with `resumePolicy: "auto"` may trigger a resume command.
204
- - The resumed model receives a compact context projection of resolved and still
205
- open resumables.
206
- - Complex joins such as all/k-of-n/quorum are not core. They are represented by
207
- one app-level resumable whose resolver owns the join logic.
208
-
209
- Examples:
210
-
211
- - One approval tool call opens one resumable.
212
- - Three independent approval tool calls open three resumables.
213
- - One subagent batch opens one resumable, even if the batch has 200 children.
214
- The Gia orchestrator owns the 200-child state and resolves the single parent
215
- resumable when its join predicate holds.
216
-
217
- ### 5.4 Dispatch Semantics
218
-
219
- EDA dispatch policy should distinguish three durable scheduler states:
220
-
221
- | State | Meaning |
222
- | --- | --- |
223
- | `running` | A command/run/turn is active. |
224
- | `waiting` | No active run, but at least one resumable is open. |
225
- | `idle` | No active run and no open resumables. |
226
-
227
- Command behavior while waiting:
228
-
229
- | Command | Waiting behavior |
230
- | --- | --- |
231
- | `SubmitMessage{queue}` | Allowed. It queues user work without resolving existing resumables. It should not start a run until policy says queued work may break waiting. |
232
- | `SubmitMessage{steer}` | Allowed only if the relevant resumables permit steering. Conservative default: record it as queued context but do not resume. |
233
- | `SubmitMessage{interrupt}` | Allowed. Default behavior: cancel or abandon open resumables according to policy, then start a replacement run. |
234
- | `StopTurn` | Cancels or abandons open resumables owned by the waiting session. For subagents this requests downstream cancellation. For approvals this closes pending approval requests. |
235
-
236
- The exact defaults should be conservative:
237
-
238
- - queue does not resume;
239
- - resolving an `auto` resumable resumes;
240
- - interrupt explicitly resumes/replaces;
241
- - stop explicitly cancels waiting work.
242
-
243
- ### 5.5 Required Core API Surface
244
-
245
- EDA needs a small API surface, not subagent-specific framework code:
246
-
247
- - `EDAToolExecutionContext.openResumable(...)`
248
- - trusted runtime/DO API to resolve/cancel/expire a resumable
249
- - reducer state for open/terminal resumables
250
- - dispatch policy support for `waiting`
251
- - prompt/UI projection hooks for resumable state
252
- - tests proving recovery after every prefix around open, resolve, cancel, and
253
- resume
254
-
255
- Sinks should not gain a general ability to submit commands as a side effect. A
256
- sink may forward durable facts to an extension-owned orchestrator. Resume should
257
- come back through the trusted resumable resolver API.
258
-
259
- ---
260
-
261
- ## 6. Gia Extension: Subagents
262
-
263
- Subagents are implemented as a Gia extension with a model-visible
264
- `spawnSubagents` tool and a `SubagentOrchestrator` Durable Object.
265
-
266
- ### 6.1 Spawn Tool Contract
267
-
268
- `spawnSubagents` runs inside a real Gia EDA session. It is visible only when the
269
- session principal has the `agent.spawn_subagent` capability.
270
-
271
- The tool:
272
-
273
- 1. Validates authorization and manifest schema.
274
- 2. Opens one EDA resumable with `kind: "gia.subagent.join"`.
275
- 3. Emits a Gia app event `SubagentBatchRequested` that carries the manifest and
276
- the `resumableId`.
277
- 4. Returns a small handle to the model.
278
- 5. Completes normally. The parent run then completes and the session becomes
279
- waiting.
280
-
281
- The tool is the only way to create a parent-joined subagent batch. The CLI may
282
- observe, wait, and abort, but it should not originate parent-joined work from
283
- outside a live harness session.
284
-
285
- ### 6.2 Manifest Shape
286
-
287
- The manifest belongs to Gia, not EDA core.
288
-
289
- ```ts
290
- SubagentBatchManifest = {
291
- batchId: string
292
- children: ReadonlyArray<{
293
- name: string
294
- prompt: UserMessageContent
295
- agentType?: string
296
- model?: ModelSelection
297
- inputRefs?: ReadonlyArray<WorkspaceRef>
298
- timeoutMs: number
299
- tokenBudget?: number
300
- maxDepth?: number
301
- }>
302
- join:
303
- | { mode: "all" }
304
- | { mode: "any-terminal" }
305
- | { mode: "any-success" }
306
- | { mode: "k-terminal"; k: number }
307
- | { mode: "k-success"; k: number }
308
- | { mode: "deadline" }
309
- parallelism: number
310
- batchDeadlineMs: number
311
- staleAfterMs?: number
312
- tokenBudget?: number
313
- resultMode: "summary" | "summary+artifacts"
314
- onEarlyJoin?: "cancel-rest" | "let-rest-finish"
315
- onChildFailure: "continue" | "fail-fast"
316
- }
317
- ```
318
-
319
- Results should be returned by reference. Child reports write to the shared root
320
- workspace or another durable artifact store and include compact refs in the join
321
- report.
322
-
323
- ### 6.3 Durable Outbox to Orchestrator
324
-
325
- The parent session should not synchronously call the orchestrator as the only
326
- launch path. A crash after opening the resumable but before the orchestrator call
327
- would lose the batch.
328
-
329
- Instead:
330
-
331
- - `SubagentBatchRequested` is durable in the parent log.
332
- - A Gia durable sink watches for that event and sends an idempotent enqueue to
333
- the `SubagentOrchestrator`.
334
- - The sink cursor advances only after the orchestrator acknowledges durable
335
- receipt.
336
-
337
- This is a durable outbox pattern. The sink is not evaluating joins and is not
338
- submitting commands. It only bridges parent durable intent to the orchestrator.
339
-
340
- ### 6.4 Orchestrator Responsibilities
341
-
342
- The `SubagentOrchestrator` DO owns:
343
-
344
- - manifest state and child ticket state in DO SQLite;
345
- - idempotent enqueue keyed by `(parentSessionId, batchId)`;
346
- - global or sharded concurrency permits;
347
- - weighted fairness across root sessions;
348
- - child launch through trusted Gia session-create APIs;
349
- - per-ticket admission timeout;
350
- - per-child timeout;
351
- - batch deadline;
352
- - stale/progress watchdog;
353
- - token sub-budget policy;
354
- - join evaluation;
355
- - cancellation and late-result reconciliation;
356
- - final parent resumable resolution.
357
-
358
- The orchestrator should be the operational source of truth for live subagent
359
- batch status. The parent EDA log remains the durable source of truth for "the
360
- parent requested this batch" and "the parent was resumed with this report."
361
-
362
- ### 6.5 Child Reporting
363
-
364
- Children are ordinary Gia EDA sessions with lineage. They report results to the
365
- orchestrator, not directly to the parent reducer.
366
-
367
- Recommended path:
368
-
369
- 1. Child writes result artifacts by reference.
370
- 2. Child emits a compact Gia app event such as `SubagentChildResultReady`.
371
- 3. A child durable sink forwards that fact to the orchestrator with an idempotency
372
- key.
373
- 4. The orchestrator folds the child result into batch state.
374
-
375
- The orchestrator also reconciles by deadline. If a child never reports, the
376
- orchestrator marks it timed out, releases its permit, and evaluates the join.
377
-
378
- ### 6.6 Resolving the Parent
379
-
380
- When the join predicate is satisfied, the orchestrator calls a trusted parent
381
- session route that appends, in one durable batch:
382
-
383
- - Gia app event `SubagentBatchResolved { batchId, reportRef, summary }`
384
- - EDA core event `ResumableResolved { resumableId, resultRef }`
385
-
386
- EDA then applies normal resumable dispatch rules. If the resumable has
387
- `resumePolicy: "auto"`, the parent resumes with a prompt projection of the join
388
- report.
389
-
390
- The idempotency key should be deterministic:
391
-
392
- ```text
393
- subagent-resolve:<parentSessionId>:<batchId>:<resumableId>
394
- ```
395
-
396
- Late child reports after resolution are accepted by the orchestrator for
397
- observability, but they do not cause a second parent resume.
398
-
399
- ---
400
-
401
- ## 7. Lineage and Metadata
402
-
403
- Gia should add lineage to agent metadata. Minimum fields:
404
-
405
- - `rootSessionId`
406
- - `parentSessionId`
407
-
408
- Recommended fields:
409
-
410
- - `sessionKind`: `"root" | "subagent"`
411
- - `depth`
412
- - `subagentName`
413
- - `subagentBatchId`
414
-
415
- For root sessions:
416
-
417
- ```text
418
- sessionId = rootSessionId
419
- parentSessionId = null
420
- sessionKind = root
421
- depth = 0
422
- ```
423
-
424
- For child sessions:
425
-
426
- ```text
427
- rootSessionId = parent.rootSessionId
428
- parentSessionId = parent.sessionId
429
- sessionKind = subagent
430
- depth = parent.depth + 1
431
- ```
432
-
433
- Lineage must be server-derived. Callers may request a parent, child name, and
434
- prompt, but they must not supply authoritative `rootSessionId` or
435
- `parentSessionId`.
436
-
437
- ### 7.1 Workspace and Sandbox Ownership
438
-
439
- Subagents share the root workspace and root sandbox:
440
-
441
- ```text
442
- workspace owner = rootSessionId
443
- sandbox id = gia-${rootSessionId}
444
- ```
445
-
446
- The current EDA Gia tool context only carries the current `sessionId`. Subagent
447
- work requires Gia tool inputs and opaque session-token credentials to carry both
448
- current and root identity so tools can attribute work to the child while routing
449
- workspace and sandbox access to the root.
450
-
451
- ### 7.2 Race Contract
452
-
453
- Subagents share mutable project state. v1 should not add filesystem locks,
454
- sandbox locks, patch reservations, or automatic merge conflict handling.
455
-
456
- The product contract is:
457
-
458
- - concurrent writes are allowed;
459
- - last writer wins for whole-file workspace writes unless a tool implements a
460
- stronger operation;
461
- - logs and artifacts must identify the writing session;
462
- - users can inspect which child changed what.
463
-
464
- ---
465
-
466
- ## 8. Authorization and Capability
467
-
468
- Add a Gia action:
469
-
470
- ```ts
471
- agent.spawn_subagent
472
- ```
473
-
474
- Use two-layer gating:
475
-
476
- - **Visibility:** only sessions with the action see `spawnSubagents`.
477
- - **Policy:** the tool re-checks authorization at execution time.
478
-
479
- The action should be allowed only for an in-harness session principal. A browser
480
- `web_cookie` or bare CLI OAuth principal may inspect or abort authorized batches,
481
- but cannot create parent-joined work because there is no live parent run to attach
482
- the resumable to.
483
-
484
- Recursion should be allowed only under explicit policy:
485
-
486
- - child sessions inherit user identity;
487
- - child sessions inherit or receive a delegated capability snapshot;
488
- - `maxDepth` is tighten-only;
489
- - a hard system ceiling caps depth;
490
- - per-child tool access can be reduced.
491
-
492
- Prefer delegated capability snapshots over "same owner email gets everything"
493
- when implementing sensitive integrations. That avoids turning one compromised
494
- child prompt into unbounded recursive authority.
495
-
496
- ---
497
-
498
- ## 9. Token Accounting and Budgets
499
-
500
- Token usage should become first-party EDA state. EDA already sees provider usage
501
- on inference completion; promote that into reducer state:
502
-
503
- - tokens by command/run/turn/inference;
504
- - rolling session total;
505
- - optional root/tree aggregate exposed to Gia;
506
- - no dollar calculations in EDA.
507
-
508
- EDA should track tokens, not cost. Rate cards change and belong outside the
509
- framework.
510
-
511
- Budget enforcement for subagents is Gia policy layered on top:
512
-
513
- - root/tree token budget;
514
- - batch token budget;
515
- - child token sub-budget;
516
- - model/provider max-token settings where available;
517
- - pre-admission checks before launching more children;
518
- - cancellation when observed usage exceeds budget.
519
-
520
- Exact cutoff is not guaranteed. Concurrent in-flight children may overspend
521
- slightly before cancellation propagates. The contract should be "bounded and
522
- observable," not "mathematically exact."
523
-
524
- ---
525
-
526
- ## 10. CLI and UI
527
-
528
- The CLI is a control plane, not the primary spawn transport.
529
-
530
- Allowed:
531
-
532
- ```bash
533
- gia subagent list --session <parent-session-id>
534
- gia subagent get --batch <batch-id>
535
- gia subagent wait --batch <batch-id>
536
- gia subagent abort --batch <batch-id>
537
- gia sessions wait --session <any-authorized-session>
538
- ```
539
-
540
- Not allowed:
541
-
542
- ```bash
543
- gia subagent run --manifest ./batch.json
544
- ```
545
-
546
- At least not for parent-joined batches. Creating parent-joined work should require
547
- a live session tool call that opens a resumable.
548
-
549
- UI should show:
550
-
551
- - session state: running, waiting, idle;
552
- - waiting reason cards from open resumables;
553
- - subagent batch status from the orchestrator;
554
- - child rows grouped under the root or parent session;
555
- - deadlines, queue position, token usage, failures, and result refs.
556
-
557
- ---
558
-
559
- ## 11. Liveness and Recovery
560
-
561
- The design relies on durable handoffs at each boundary:
562
-
563
- | Boundary | Durability mechanism |
564
- | --- | --- |
565
- | Tool opens parent wait | EDA `ResumableOpened` in parent log |
566
- | Tool requests subagent batch | Gia `SubagentBatchRequested` in parent log |
567
- | Parent intent reaches orchestrator | durable outbox sink with cursor |
568
- | Orchestrator stores manifest | DO SQLite idempotent enqueue |
569
- | Child sessions are launched | orchestrator ticket state and trusted session-create idempotency |
570
- | Child reports result | child durable event plus durable sink to orchestrator |
571
- | Child never reports | orchestrator deadline alarm and reconciliation |
572
- | Parent resumes | trusted resolver appends `SubagentBatchResolved` + `ResumableResolved` |
573
-
574
- No wait depends on a live fiber.
575
-
576
- Important liveness rules:
577
-
578
- - Every queued child ticket has an admission timeout.
579
- - Every launched child has a wall-clock timeout.
580
- - Every batch has a deadline.
581
- - Every lease has a TTL and reconciliation path.
582
- - Every resolver call is idempotent.
583
- - Resolving a resumable twice is harmless and produces one parent resume.
584
-
585
- ---
586
-
587
- ## 12. Observability
588
-
589
- All subagent logs and spans should include:
590
-
591
- - `sessionId`
592
- - `rootSessionId`
593
- - `parentSessionId`
594
- - `sessionKind`
595
- - `batchId`
596
- - `childSessionId`
597
- - `resumableId`
598
- - `ticketId`
599
- - `permitId`
600
- - `queueDepth`
601
- - `tokenInput`
602
- - `tokenOutput`
603
- - `tokenTotal`
604
-
605
- Operators should be able to answer:
606
-
607
- - why is this session waiting?
608
- - what external actor can resolve it?
609
- - what child sessions exist under this root?
610
- - which children are queued, running, terminal, timed out, or cancelled?
611
- - what budget has been consumed?
612
- - what event/resolver caused the parent to resume?
613
-
614
- ---
615
-
616
- ## 13. Implementation Plan
617
-
618
- 1. **EDA resumables**
619
- - Add event schemas, reducer state, dispatch state, prompt/UI projection, and
620
- trusted resolve/cancel/expire API.
621
- - Add tests for open, resolve, cancel, expire, multiple open resumables, and
622
- crash-prefix recovery.
623
-
624
- 2. **EDA token accounting**
625
- - Promote provider usage into reducer state.
626
- - Track tokens by inference/run/session.
627
- - Keep units as tokens only.
628
-
629
- 3. **Gia lineage metadata**
630
- - Add `rootSessionId` and `parentSessionId`; preferably also `sessionKind`,
631
- `depth`, `subagentName`, and `subagentBatchId`.
632
- - Update opaque session-token, tool context, workspace, and E2B routing to
633
- distinguish current session from root owner.
634
-
635
- 4. **Subagent extension skeleton**
636
- - Add `agent.spawn_subagent` capability.
637
- - Add `spawnSubagents` tool that opens a resumable and emits
638
- `SubagentBatchRequested`.
639
- - Add parent durable outbox sink to enqueue with a stub orchestrator.
640
-
641
- 5. **SubagentOrchestrator DO**
642
- - Implement manifest store, idempotent enqueue, ticket state, child launch,
643
- deadlines, leases, join evaluation, cancellation, and parent resolve.
644
-
645
- 6. **Child reporting**
646
- - Add child result artifact contract.
647
- - Add child durable sink to report terminal/progress facts to orchestrator.
648
-
649
- 7. **CLI/UI/observability**
650
- - Add read/wait/abort commands and waiting/subagent UI.
651
- - Add logs, spans, and query helpers.
652
-
653
- 8. **Load and recovery validation**
654
- - Multi-hour hundreds-child soak.
655
- - Parent DO eviction mid-wait.
656
- - Orchestrator eviction mid-batch.
657
- - Child timeout and late result.
658
- - Duplicate resolver calls.
659
- - Interrupt/stop while waiting.
660
-
661
- ---
662
-
663
- ## 14. Testing Requirements
664
-
665
- EDA core:
666
-
667
- - reducer folds multiple resumables correctly;
668
- - dispatch distinguishes running, waiting, and idle;
669
- - queue/steer/interrupt/stop semantics while waiting;
670
- - resolving one of many resumables resumes exactly once when policy says auto;
671
- - recovery from every durable prefix around resumable open/resolve;
672
- - token usage accumulates from provider usage events.
673
-
674
- Gia extension:
675
-
676
- - tool absent without `agent.spawn_subagent`;
677
- - tool execution opens resumable and completes normally;
678
- - durable outbox retries orchestrator enqueue without duplicate batch creation;
679
- - orchestrator launch is idempotent by ticket;
680
- - global concurrency cap is never exceeded;
681
- - admission timeout, child timeout, and batch deadline all terminalize state;
682
- - all join modes resolve the parent once;
683
- - late child reports do not re-resume the parent;
684
- - interrupt/stop while waiting cancels or abandons downstream work according to
685
- policy;
686
- - child workspace and sandbox access route to root ownership while logs attribute
687
- current child identity.
688
-
689
- ---
690
-
691
- ## 15. Open Questions
692
-
693
- - Should `queue` while waiting ever auto-resume, or should only resolve/interrupt
694
- start a run?
695
- - Should `steer` while waiting be supported in v1, or always degrade to queued
696
- context?
697
- - What is the default interrupt policy for approval resumables vs subagent
698
- resumables?
699
- - Should all resumables have deadlines, or are some manual approval waits allowed
700
- to be indefinite with operator-visible age?
701
- - Should child capability delegation snapshot all tool visibility at spawn time?
702
- - Should orchestrator state be one singleton, sharded by root session, or split
703
- into broker plus per-root orchestrators?
704
- - Where should large join reports live: root workspace, R2 session files, or a
705
- dedicated artifact table?
706
- - What exact UI grouping should subagent sessions use in the sidebar?
707
-
708
- ---
709
-
710
- ## 16. Design properties
711
-
712
- This proposal requires:
713
-
714
- - subagents are ordinary Gia sessions;
715
- - lineage is first-class;
716
- - root workspace and sandbox are shared;
717
- - callers do not supply authoritative lineage;
718
- - logs must support root-tree and child-level forensics.
719
-
720
- Completion notification uses a clear split:
721
-
722
- - EDA core provides generic resumables and waiting/resume semantics.
723
- - Gia subagent orchestration lives in a sidecar Durable Object.
724
- - The parent is resumed by resolving a durable resumable, not by a hidden Web
725
- Socket side effect, a blocked tool call, or a sink-submitted command.