fix(server): OpenCode 2 stops subagents a dropped background reply started #14760
Mergedjuliusmarmingemerged 16 commits into
v2/oc2-7-continuation-wake-identity fromrefs/pull/14760/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
juliusmarminge added labelsmacroscope-review
- apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.ts line 3350OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -3323,2 +3330,21 @@33233330 });332433313332+ /**3333+ * Drops held executions no turn will take. The subagents one started are3334+ * named only by its replay, so they are forgotten (their requests no3335+ * longer reach the thread) and stopped. A subagent that registered its own3336+ * call outside the held execution is the thread's, and is left alone.3337+ */3338+ const discardWakes = Effect.fnUntraced(function* (wakes: ReadonlyArray<Wake>) {3339+ const orphans: Array<string> = [];3340+ for (const wake of wakes) {3341+ wake.dropped = true;3342+ for (const childId of wake.children) {3343+ if (!announced.has(childId)) continue;3344+ announced.delete(childId);3345+ childOwners.delete(childId);3346+ orphans.push(childId);3347+ }3348+ }3349+ for (const childId of orphans) {3350+ yield* client.sessionapps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.ts line 3343OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -3322,3 +3329,15 @@33223329 for (const event of wake.events) yield* route(event, sessionOfEvent(event));33233330 });332433313332+ /**3333+ * Drops held executions no turn will take. The subagents one started are3334+ * named only by its replay, so they are forgotten (their requests no3335+ * longer reach the thread) and stopped. A subagent that registered its own3336+ * call outside the held execution is the thread's, and is left alone.3337+ */3338+ const discardWakes = Effect.fnUntraced(function* (wakes: ReadonlyArray<Wake>) {3339+ const orphans: Array<string> = [];3340+ for (const wake of wakes) {3341+ wake.dropped = true;3342+ for (const childId of wake.children) {3343+ if (!announced.has(childId)) continue;
- apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.ts line 3365OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -3322,3 +3349,17 @@33223349 for (const event of wake.events) yield* route(event, sessionOfEvent(event));33233350 });332433513352+ /**3353+ * Drops held executions no turn will take. The subagents one started are3354+ * named only by its replay, so they stop routing to the thread at once and3355+ * become strays for {@link stopStrays}. A subagent that registered its own3356+ * call outside the held execution is the thread's, and is left alone.3357+ */3358+ const discardWakes = (caller: ThreadState, wakes: ReadonlyArray<Wake>) => {3359+ for (const wake of wakes) {3360+ wake.dropped = true;3361+ for (const childId of wake.children) {3362+ if (!announced.has(childId)) continue;3363+ announced.delete(childId);3364+ childOwners.delete(childId);3365+ strays.set(childId, caller);apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.ts line 922OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -879,3 +884,7 @@879884 const childOwners = new Map<string, ThreadState>();880885 // What OpenCode announced about a subagent's session, until its call names it.881886 const announced = new Map<string, EventOf<"session.created">["data"]>();887+ // Subagent sessions a dropped held execution started, by the session that888+ // called them. Nothing names them, so they no longer route to its thread;889+ // they stay here until a Stop of that thread stops them or they are gone.890+ const strays = new Map<string, ThreadState>();
- apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.ts line 3375OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -3322,3 +3358,18 @@33223358 for (const event of wake.events) yield* route(event, sessionOfEvent(event));33233359 });332433603361+ /**3362+ * Drops held executions no turn will take. The subagents one started are3363+ * named only by its replay, so they stop routing to the thread at once and3364+ * become strays for {@link stopStrays}. A subagent that registered its own3365+ * call outside the held execution is the thread's, and is left alone.3366+ */3367+ const discardWakes = (caller: ThreadState, wakes: ReadonlyArray<Wake>) => {3368+ for (const wake of wakes) {3369+ wake.dropped = true;3370+ for (const childId of wake.children) {3371+ const info = announced.get(childId);3372+ if (info === undefined) continue;3373+ announced.delete(childId);3374+ childOwners.delete(childId);3375+ strays.set(childId, caller);
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
juliusmarminge merged thisa7034aa
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed