Commit 367f492
committed
fix(session): preserve tool metadata across pending→running transition
The AI SDK fires tool execute() as a detached promise before the
processor handles the tool-call stream event. When execute() calls
ctx.metadata({sessionId}), the processor's tool-call handler
overwrites the DB with a fresh running state that has no metadata,
making subagent sessions unclickable in the TUI.
- Add synchronous toolMetadata side-channel on processor context
- setToolMetadata() on Handle writes to the map immediately
- tool-call handler reads and merges metadata from the side-channel
- prompt.ts metadata callback calls setToolMetadata() before the
async DB update, ensuring metadata is captured regardless of
event ordering
- Add E2E regression test using fake Anthropic HTTP server through
the real AI SDK streamText pipeline with gate-based assertion of
running-state metadata
Closes #201841 parent 2cc738f commit 367f492
File tree
4 files changed
+375
-8
lines changed- packages/opencode
- src/session
- test/session
4 files changed
+375
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
| 50 | + | |
49 | 51 | | |
50 | 52 | | |
51 | 53 | | |
| |||
89 | 91 | | |
90 | 92 | | |
91 | 93 | | |
| 94 | + | |
92 | 95 | | |
93 | 96 | | |
94 | 97 | | |
| |||
173 | 176 | | |
174 | 177 | | |
175 | 178 | | |
| 179 | + | |
| 180 | + | |
176 | 181 | | |
177 | 182 | | |
178 | 183 | | |
179 | | - | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
180 | 191 | | |
181 | 192 | | |
182 | 193 | | |
| |||
224 | 235 | | |
225 | 236 | | |
226 | 237 | | |
| 238 | + | |
227 | 239 | | |
228 | 240 | | |
229 | 241 | | |
| |||
243 | 255 | | |
244 | 256 | | |
245 | 257 | | |
| 258 | + | |
246 | 259 | | |
247 | 260 | | |
248 | 261 | | |
| |||
494 | 507 | | |
495 | 508 | | |
496 | 509 | | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
497 | 513 | | |
498 | 514 | | |
499 | 515 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
384 | 384 | | |
385 | 385 | | |
386 | 386 | | |
387 | | - | |
| 387 | + | |
388 | 388 | | |
389 | 389 | | |
390 | 390 | | |
| |||
399 | 399 | | |
400 | 400 | | |
401 | 401 | | |
402 | | - | |
403 | | - | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
404 | 405 | | |
405 | 406 | | |
406 | 407 | | |
407 | 408 | | |
408 | 409 | | |
409 | 410 | | |
| 411 | + | |
410 | 412 | | |
411 | 413 | | |
412 | | - | |
413 | | - | |
414 | | - | |
415 | 414 | | |
416 | 415 | | |
417 | 416 | | |
418 | | - | |
| 417 | + | |
| 418 | + | |
419 | 419 | | |
420 | 420 | | |
421 | 421 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
| 152 | + | |
152 | 153 | | |
153 | 154 | | |
154 | 155 | | |
| |||
0 commit comments