Commit e51f68b
authored
Fix nested subagent hierarchy: re-parent depth>=2 subagents to their spawner (#1320)
Fixes #1246. Supersedes #1247.
Claude Code stores nested subagents in one flat directory, so path-based parsing can attach deeper children to the top-level session instead of the session that actually spawned them. This change reconciles effective parents from recorded spawn edges, which also puts nested usage rollups under the right session.
Conflicting edges resolve deterministically using normalized start times and immutable parser provenance. Before exclusions or message replacement can erase an edge, sync persists the affected child IDs in SQLite; repair and queue cleanup then commit together. Failed writes or repairs remain retryable across later syncs, process restarts, and archive rebuilds.
SQLite migration and provenance backfill are atomic. PostgreSQL now mirrors parser provenance through schema compatibility, reads, writes, conflict checks, and fingerprints, while a v2 backfill marker makes existing mirrors republish unchanged legacy rows once. Global work stays bounded by spawn edges, and incremental work stays scoped to affected sessions.
One conservative limit remains: if an edge disappears while the recorded parent still exists and no competing edge remains, the historical parent is retained because the archive cannot prove whether it came from the removed edge or parser provenance. Broader copy and fork provenance remains tracked in #1250.
Reviewers should start with `internal/db/sessions.go`, then follow sync orchestration in `internal/sync/engine.go` and PostgreSQL propagation in `internal/postgres/`.
Co-authored-by: Wes McKinney <wesm@users.noreply.github.com>1 parent eabb9be commit e51f68b
17 files changed
Lines changed: 2933 additions & 85 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1763 | 1763 | | |
1764 | 1764 | | |
1765 | 1765 | | |
| 1766 | + | |
| 1767 | + | |
| 1768 | + | |
| 1769 | + | |
| 1770 | + | |
| 1771 | + | |
| 1772 | + | |
| 1773 | + | |
1766 | 1774 | | |
1767 | 1775 | | |
1768 | 1776 | | |
| |||
2160 | 2168 | | |
2161 | 2169 | | |
2162 | 2170 | | |
2163 | | - | |
2164 | | - | |
2165 | | - | |
2166 | | - | |
2167 | | - | |
| 2171 | + | |
| 2172 | + | |
| 2173 | + | |
| 2174 | + | |
| 2175 | + | |
| 2176 | + | |
| 2177 | + | |
| 2178 | + | |
| 2179 | + | |
| 2180 | + | |
| 2181 | + | |
| 2182 | + | |
| 2183 | + | |
| 2184 | + | |
| 2185 | + | |
| 2186 | + | |
| 2187 | + | |
| 2188 | + | |
| 2189 | + | |
| 2190 | + | |
2168 | 2191 | | |
2169 | 2192 | | |
2170 | 2193 | | |
| |||
2411 | 2434 | | |
2412 | 2435 | | |
2413 | 2436 | | |
2414 | | - | |
| 2437 | + | |
2415 | 2438 | | |
2416 | 2439 | | |
2417 | 2440 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1285 | 1285 | | |
1286 | 1286 | | |
1287 | 1287 | | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
1288 | 1317 | | |
1289 | 1318 | | |
1290 | 1319 | | |
| |||
5588 | 5617 | | |
5589 | 5618 | | |
5590 | 5619 | | |
5591 | | - | |
| 5620 | + | |
5592 | 5621 | | |
5593 | 5622 | | |
5594 | 5623 | | |
| |||
5601 | 5630 | | |
5602 | 5631 | | |
5603 | 5632 | | |
| 5633 | + | |
| 5634 | + | |
| 5635 | + | |
| 5636 | + | |
| 5637 | + | |
5604 | 5638 | | |
5605 | 5639 | | |
5606 | 5640 | | |
| |||
5629 | 5663 | | |
5630 | 5664 | | |
5631 | 5665 | | |
| 5666 | + | |
| 5667 | + | |
| 5668 | + | |
| 5669 | + | |
| 5670 | + | |
| 5671 | + | |
| 5672 | + | |
| 5673 | + | |
| 5674 | + | |
| 5675 | + | |
| 5676 | + | |
| 5677 | + | |
| 5678 | + | |
| 5679 | + | |
| 5680 | + | |
5632 | 5681 | | |
5633 | 5682 | | |
5634 | 5683 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
227 | 227 | | |
228 | 228 | | |
229 | 229 | | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 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 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
230 | 320 | | |
231 | 321 | | |
232 | 322 | | |
| |||
0 commit comments