Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): background subagents can delegate after their parent's turn ends #38869

MergedBil0000(GitHub profile, opens in a new tab)merged 5 commits intomain fromrefs/pull/38869/headmerged by Yash-Singh1(GitHub profile, opens in a new tab) View on GitHub

Showing 7 changed files with 61 additions and 9 deletions (loading 4).

x
0 of 7 viewed, 7 left
24 additions and 3 deletionsapps/server/src/mcp/OrchestratorMcpService.tsModified
View file
@@ -1471,6 +1471,27 @@
: Effect.void;
+ // A background subagent keeps calling tools after the run that started it settles. Its
+ // delegations join that latest run, whose completion cohort wakes the thread once they finish.
+ const backgroundSubagentRun = Effect.fn("OrchestratorMcpService.backgroundSubagentRun")(
+ function* (scope: McpInvocationScope, threadId: ThreadId) {
+ const shell = yield* threadManagement
+ .getThreadShell(threadId)
+ .pipe(Effect.mapError(threadManagementFailure));
+ if (
+ shell?.activeRunId !== null ||
+ shell.latestRunId === null ||
+ !isLiveCallerShell(shell, scope.thread?.providerInstanceId)
+ ) {
+ return undefined;
+ }
+ const { runs } = yield* loadThreadRecords(threadId, ["runs"], {
+ runIds: [shell.latestRunId],
+ });
+ return runs[0];
+ },
+ );
+​
const loadReadableThread = Effect.fn("OrchestratorMcpService.loadReadableThread")(function* (
scope: McpInvocationScope,
threadId: ThreadId,
@@ -2703,9 +2724,9 @@