GeezerVison is showing github.com — fix(client): an opened idle subagent reads its family once · scuttletoby/t3code@2b59d9f
File treeExpand file treeCollapse file tree Open diff view settings packages/client-runtime/src/state
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/client-runtime/src/state/threadFamilies.test.ts +13-9Lines changed: 13 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -235,22 +235,26 @@ describe("createThreadFamilyAtoms", () => { | 235 | 235 | expect(threadFamilyRead(registry.get(family))).toBe("settled"); | 236 | 236 | expect(mergedIds()).toEqual(["parent", "idle-child"]); | 237 | 237 |
| 238 | | - // A child that woke after the shell left out its idle parent reads its family unmounted. | | 238 | + // Children that woke after the shell left out their idle parent arrive as deltas, and | | 239 | + // read their family unmounted, once for the root. | 239 | 240 | release(); | 240 | 241 | const woken = row("woken", "woken", child.id, parent.id); | 241 | | - registry.set(shellState, AsyncResult.success(shellAt(3, [parent, woken]))); | | 242 | + const sibling = row("woken-sibling", "woken-sibling", child.id, parent.id); | | 243 | + registry.set(shellState, AsyncResult.success(shellAt(2, [parent, woken, sibling]))); | 242 | 244 | yield* Queue.offer( | 243 | 245 | replies, | 244 | | - Effect.succeed({ snapshotSequence: 6, threads: [parent, child, woken] }), | | 246 | + Effect.succeed({ snapshotSequence: 6, threads: [parent, child, woken, sibling] }), | 245 | 247 | ); | 246 | | - yield* settle; | 247 | | - expect(mergedIds()).toEqual(["parent", "woken", "idle-child"]); | | 248 | + const wokenFamily = families.familyAtom(TARGET.environmentId, woken.id); | | 249 | + yield* AtomRegistry.getResult(registry, wokenFamily, { suspendOnWaiting: true }).pipe( | | 250 | + Effect.tap(() => Effect.yieldNow), | | 251 | + ); | | 252 | + expect(mergedIds()).toEqual(["parent", "woken", "woken-sibling", "idle-child"]); | 248 | 253 |
| 249 | | - // That read is settled, but a caller waiting on its own mount sees it only once mounted. | 250 | | - const mountedRead = families.mountedReadAtom(TARGET.environmentId, parent.id); | 251 | | - expect(threadFamilyRead(registry.get(family))).toBe("settled"); | | 254 | + // Opening the woken child mounts that same read. It answers only once it is mounted. | | 255 | + const mountedRead = families.mountedReadAtom(TARGET.environmentId, woken.id); | 252 | 256 | expect(registry.get(mountedRead)).toBe("pending"); | 253 | | - families.mount(registry, TARGET.environmentId, parent.id); | | 257 | + families.mount(registry, TARGET.environmentId, woken.id); | 254 | 258 | expect(registry.get(mountedRead)).toBe("settled"); | 255 | 259 | }), | 256 | 260 | ), | |
Collapse file Copy file name to clipboardExpand all lines: packages/client-runtime/src/state/threadFamilies.ts +14-10Lines changed: 14 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -66,21 +66,25 @@ export function threadFamilyRowsMissingFromShell(input: { | 66 | 66 | } | 67 | 67 |
| 68 | 68 | /** | 69 | | - * Roots of subagents and side chats whose parent row the shell left out. A shell sent with | 70 | | - * `omitIdleSubagentParents` drops idle chains, so a child that wakes later arrives without them. | | 69 | + * Subagents and side chats whose parent row the shell left out, one per root. A shell sent with | | 70 | + * `omitIdleSubagentParents` drops idle chains, so a child that wakes or is opened later arrives | | 71 | + * without them. The family is read by the child, the read an open thread's mount already made. | 71 | 72 | */ | 72 | | -function rootsWithMissingParents( | | 73 | +function threadsWithMissingParents( | 73 | 74 | threads: ReadonlyArray<OrchestrationV2ThreadShell>, | 74 | 75 | ): ReadonlyArray<ThreadId> { | 75 | 76 | const present = new Set<ThreadId>(threads.map((thread) => thread.id)); | 76 | | - const roots = new Set<ThreadId>(); | 77 | | - for (const { lineage } of threads) { | | 77 | + const byRoot = new Map<ThreadId, ThreadId>(); | | 78 | + for (const { id, lineage } of threads) { | 78 | 79 | if (lineage.parentThreadId === null || present.has(lineage.parentThreadId)) continue; | 79 | | - if (lineage.relationshipToParent === "subagent" || lineage.sideChat === true) { | 80 | | - roots.add(lineage.rootThreadId); | | 80 | + if ( | | 81 | + (lineage.relationshipToParent === "subagent" || lineage.sideChat === true) && | | 82 | + !byRoot.has(lineage.rootThreadId) | | 83 | + ) { | | 84 | + byRoot.set(lineage.rootThreadId, id); | 81 | 85 | } | 82 | 86 | } | 83 | | - return [...roots]; | | 87 | + return [...byRoot.values()]; | 84 | 88 | } | 85 | 89 |
| 86 | 90 | /** | @@ -241,8 +245,8 @@ export function createThreadFamilyAtoms<R, ER, E>( | 241 | 245 | if (orphans?.threads !== snapshot.threads) { | 242 | 246 | orphans = { | 243 | 247 | threads: snapshot.threads, | 244 | | - rows: rootsWithMissingParents(snapshot.threads).map((root) => | 245 | | - familyRowsAtom(familyKey(environmentId, root)), | | 248 | + rows: threadsWithMissingParents(snapshot.threads).map((threadId) => | | 249 | + familyRowsAtom(familyKey(environmentId, threadId)), | 246 | 250 | ), | 247 | 251 | }; | 248 | 252 | } | |
|