Commit c6c9afd
authored
feat: model Codex subagent result events (#247)
Closes #233.
Supersedes #242.
## Summary
- model Codex subagent terminal status as first-class
`tool_result_events` in SQLite and PostgreSQL
- keep `tool_calls.result_content` as a derived/latest compatibility
summary instead of the canonical storage shape
- render the latest summary by default and expose full chronological
subagent result history in the tool block UI
- preserve event history across full resyncs, PG pushes, and orphan-copy
recovery
## How This Differs From #242
`#242` tried to solve Codex subagent workflows inside the existing
single-result model by:
- rebinding `wait` / `<subagent_notification>` output into one mutable
`tool_calls.result_content`
- synthesizing tool-result-like transcript rows to preserve some
ordering information
- adding parser heuristics to decide which source should "own" the final
blob
That approach improved the raw JSON problem, but it kept running into
ownership and chronology edge cases because Codex subagent status is not
actually a single final blob.
This PR switches to a different model:
- add additive `tool_result_events` tables in both SQLite and PostgreSQL
- attach chronological result events directly to the originating tool
call
- derive `tool_calls.result_content` from those events for
compatibility/search/compact UI
- keep the existing subagent session linkage on `spawn_agent`
Practical effect:
- chronology is preserved without retroactively mutating older
transcript rows
- `wait` output and fallback notifications are stored as canonical event
history
- PG-backed multi-host views and local SQLite views share the same
result-event model
## Details
- `spawn_agent` remains a `Task` tool call and still maps to
`subagent_session_id`
- terminal `wait` output becomes `tool_result_events`
- terminal `<subagent_notification>` messages also become
`tool_result_events`
- blocked categories are enforced server-side for event history as well
as the compact summary
- orphan-copy / resync paths preserve stored event history for sessions
whose source files no longer exist
## Upgrade / Rollout
- SQLite: additive schema change plus `dataVersion` bump
- PostgreSQL: additive schema change, no drop/recreate required
- exporters should upgrade and run `agentsview pg push --full` once, or
let the normal full-sync path re-export after resync
Known limit:
- sessions whose original Codex JSONL source is already gone can only
preserve event history that was already stored in SQLite; they cannot
derive brand new history from missing raw files
## Test Plan
- `CC=/usr/bin/gcc CXX=/usr/bin/g++ CGO_ENABLED=1 go test -tags fts5
./internal/parser ./internal/sync ./internal/db ./internal/postgres
-count=1`
- `cd frontend && npm test -- --run
src/lib/components/content/ToolBlock.test.ts
src/lib/utils/messages.test.ts`
## Local Review
- local `codex`, `claude-code`, and `gemini` review runs covered both
`default` and `security`
- the first v2 pass surfaced issues around stale `tool_result_events`,
blocked-category history leakage, and same-ordinal orphan chronology
- those follow-up fixes are included in this branch1 parent c85aa95 commit c6c9afd
File tree
20 files changed
+2674
-32
lines changed- frontend/src/lib
- api/types
- components/content
- internal
- db
- parser
- postgres
- sync
- testjsonl
20 files changed
+2674
-32
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
44 | 57 | | |
45 | 58 | | |
46 | 59 | | |
| |||
51 | 64 | | |
52 | 65 | | |
53 | 66 | | |
| 67 | + | |
54 | 68 | | |
55 | 69 | | |
56 | 70 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
| 26 | + | |
25 | 27 | | |
26 | 28 | | |
| 29 | + | |
27 | 30 | | |
28 | 31 | | |
29 | 32 | | |
| |||
41 | 44 | | |
42 | 45 | | |
43 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
44 | 50 | | |
45 | | - | |
| 51 | + | |
46 | 52 | | |
47 | 53 | | |
48 | 54 | | |
| 55 | + | |
49 | 56 | | |
50 | 57 | | |
51 | 58 | | |
| 59 | + | |
52 | 60 | | |
53 | 61 | | |
54 | 62 | | |
| |||
63 | 71 | | |
64 | 72 | | |
65 | 73 | | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
66 | 79 | | |
67 | 80 | | |
68 | 81 | | |
| |||
71 | 84 | | |
72 | 85 | | |
73 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
74 | 95 | | |
75 | 96 | | |
76 | 97 | | |
| |||
247 | 268 | | |
248 | 269 | | |
249 | 270 | | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
250 | 316 | | |
251 | 317 | | |
252 | 318 | | |
| |||
364 | 430 | | |
365 | 431 | | |
366 | 432 | | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
367 | 453 | | |
368 | 454 | | |
369 | 455 | | |
| |||
377 | 463 | | |
378 | 464 | | |
379 | 465 | | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
380 | 486 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
136 | 207 | | |
137 | 208 | | |
138 | 209 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| |||
0 commit comments