fix(server): settling a parent settles its tasks on other machines #28344
Closedfelixleopold(GitHub profile, opens in a new tab)wants to merge 1 commit into
main fromrefs/pull/28344/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- @@ -759,3 +765,18 @@759765 },760766 );761767768+ /**769+ * Settles the task's thread there while its parent here stays settled. Clients list that thread770+ * under its parent only while they hold the parent, and a settled parent drops out of their771+ * snapshots once newer threads settle, so an unsettled task would resurface as active there.772+ */773+ const settleThere = Effect.fn("RemoteDelegation.settleThere")(774+ function* (parentThreadId: ThreadId, taskId: NodeId) {775+ const { thread, task } = yield* readTask(parentThreadId, taskId);776+ const remote = task?.remoteChild;777+ if (thread.settledOverride !== "settled" || remote === undefined) return;778+ const scope = followScope(779+ { threadId: parentThreadId, providerInstanceId: thread.providerInstanceId },780+ remote,781+ );782+ yield* forwarding.call(scope, ThreadToolkit.tools.t3_thread_organize, remote.environmentId, {@@ -761,0 +783,21 @@783+ threadId: remote.threadId,784+ action: "settle",785+ });786+ },787+ // A task still running there refuses until it ends; a machine asleep, until it wakes.788+ Effect.retry({789+ schedule: followRetry.pipe(Schedule.upTo({ duration: SETTLE_RETRY_WINDOW })),790+ while: (error) =>791+ isMcpFailure(error) &&792+ error.code !== "invalid_request" &&793+ !(isFinal(error) || isModeRefusal(error)),794+ }),795+ Effect.ignoreCause({ log: true }),796+ );797+798+ // Each retrying settle re-reads its parent, so a repeated settle here needs no second one.799+ const settling = new Set<NodeId>();800+801+ const settleAllThere = Effect.fn("RemoteDelegation.settleAllThere")(802+ function* (parentThreadId: ThreadId) {803+ const { subagents } = yield* threads.getThreadRecords(parentThreadId, ["subagents"]);
juliusmarminge added labelsbugfix
juliusmarminge added labelspr:needs-julius
tanstack-source added labelsbug
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes