Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8042,7 +8042,9 @@ describe("AcpAdapterV2", () => {
});
const events = yield* Queue.unbounded<ProviderAdapter.ProviderAdapterV2Event>();
yield* runtime.events.pipe(
Stream.runForEach((event) => Queue.offer(events, event)),
Stream.runForEach((event) =>
Queue.offerAll(events, ProviderAdapter.providerEventMembers(event)),
),
Effect.forkScoped,
);
const providerThread = yield* runtime.ensureThread({
Expand Down Expand Up @@ -8223,7 +8225,9 @@ describe("AcpAdapterV2", () => {
const hasPendingBackgroundWork = runtime.hasPendingBackgroundWork;
const events = yield* Queue.unbounded<ProviderAdapter.ProviderAdapterV2Event>();
yield* runtime.events.pipe(
Stream.runForEach((event) => Queue.offer(events, event)),
Stream.runForEach((event) =>
Queue.offerAll(events, ProviderAdapter.providerEventMembers(event)),
),
Effect.forkScoped,
);
const providerThread = yield* runtime.ensureThread({
Expand Down Expand Up @@ -8411,7 +8415,9 @@ describe("AcpAdapterV2", () => {
const hasPendingBackgroundWork = runtime.hasPendingBackgroundWork;
const events = yield* Queue.unbounded<ProviderAdapter.ProviderAdapterV2Event>();
yield* runtime.events.pipe(
Stream.runForEach((event) => Queue.offer(events, event)),
Stream.runForEach((event) =>
Queue.offerAll(events, ProviderAdapter.providerEventMembers(event)),
),
Effect.forkScoped,
);
const providerThread = yield* runtime.ensureThread({
Expand Down Expand Up @@ -8653,7 +8659,9 @@ describe("AcpAdapterV2", () => {
const hasPendingBackgroundWork = runtime.hasPendingBackgroundWork;
const events = yield* Queue.unbounded<ProviderAdapter.ProviderAdapterV2Event>();
yield* runtime.events.pipe(
Stream.runForEach((event) => Queue.offer(events, event)),
Stream.runForEach((event) =>
Queue.offerAll(events, ProviderAdapter.providerEventMembers(event)),
),
Effect.forkScoped,
);
const providerThread = yield* runtime.ensureThread({
Expand Down Expand Up @@ -8930,7 +8938,9 @@ describe("AcpAdapterV2", () => {
});
const events = yield* Queue.unbounded<ProviderAdapter.ProviderAdapterV2Event>();
yield* runtime.events.pipe(
Stream.runForEach((event) => Queue.offer(events, event)),
Stream.runForEach((event) =>
Queue.offerAll(events, ProviderAdapter.providerEventMembers(event)),
),
Effect.forkScoped,
);
const providerThread = yield* runtime.ensureThread({
Expand Down Expand Up @@ -11108,7 +11118,9 @@ describe("AcpAdapterV2", () => {
});
const events = yield* Queue.unbounded<ProviderAdapter.ProviderAdapterV2Event>();
yield* runtime.events.pipe(
Stream.runForEach((event) => Queue.offer(events, event)),
Stream.runForEach((event) =>
Queue.offerAll(events, ProviderAdapter.providerEventMembers(event)),
),
Effect.forkScoped,
);
const providerThread = yield* runtime.ensureThread({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,9 @@ const openClaudeReplaySession = Effect.fn("openClaudeReplaySession")(function* (
}
const events = yield* Queue.unbounded<ProviderAdapter.ProviderAdapterV2Event>();
yield* runtime.events.pipe(
Stream.runForEach((event) => Queue.offer(events, event)),
Stream.runForEach((event) =>
Queue.offerAll(events, ProviderAdapter.providerEventMembers(event)),
),
Effect.forkScoped,
);
const providerThread = yield* runtime.ensureThread({ threadId, modelSelection, runtimePolicy });
Expand Down
10 changes: 10 additions & 0 deletions apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17834,6 +17834,16 @@ describe("ClaudeAdapterV2 background wake turns", () => {
event.subagent.progress === "Reading the last commits",
),
);
const progressUpdate = harness.events.find(
(event) =>
event.type === "subagent.updated" &&
event.subagent.progress === "Reading the last commits",
);
// A progress-only update carries its item, so ingestion stores both in one commit.
assert.equal(
progressUpdate?.type === "subagent.updated" ? progressUpdate.turnItem?.progress : undefined,
"Reading the last commits",
);
const routing = subagentRouting(harness.events, [STRADDLING_BASH, IDLE_BASH]);
assert.deepEqual(routing.assistantTexts(routing.childThreadId), ["Still auditing."]);
const straddling = latestToolItem(STRADDLING_BASH);
Expand Down
77 changes: 42 additions & 35 deletions apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ import {
type OrchestrationV2RuntimeRequest,
type OrchestrationV2UserInputQuestion,
type OrchestrationV2Subagent,
type OrchestrationV2SubagentTurnItem,
type OrchestrationV2AppThread,
type OrchestrationV2SubagentWorkflow,
type OrchestrationV2WorkflowRunHandles,
Expand Down Expand Up @@ -8120,11 +8121,45 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
},
});
}
const turnItem = {
id: subagent.turnItemId,
threadId: task.threadId,
runId: task.runId,
nodeId: task.id,
providerThreadId: input.context.input.providerThread.id,
providerTurnId: input.context.providerTurnId,
nativeItemRef: task.nativeTaskRef,
parentItemId: null,
ordinal: subagent.turnItemOrdinal,
status: task.status,
title: task.title,
startedAt: task.startedAt,
completedAt: task.completedAt,
updatedAt: task.updatedAt,
type: "subagent",
subagentId: task.id,
origin: task.origin,
driver: task.driver,
providerInstanceId: task.providerInstanceId,
childThreadId: task.childThreadId,
prompt: task.prompt,
...(task.progress === undefined ? {} : { progress: task.progress }),
result: task.result,
} satisfies OrchestrationV2SubagentTurnItem;
const promptNativeItemId =
existingSubagent === undefined
? `${nativeItemId}:prompt`
: resumeToolUseId === null
? null
: `${nativeItemId}:prompt:${resumeToolUseId}`;
const itemFollowsRecord =
!lifecycleChanged && promptNativeItemId === null && workflowWithThreads === undefined;
// Emit before child records so the resumed run can adopt the child thread.
yield* emitProviderEvent({
type: "subagent.updated",
driver: CLAUDE_PROVIDER,
subagent: task,
...(itemFollowsRecord ? { turnItem } : {}),
});
if (lifecycleChanged) {
yield* emitProviderEvent({
Expand All @@ -8149,12 +8184,6 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
},
});
}
const promptNativeItemId =
existingSubagent === undefined
? `${nativeItemId}:prompt`
: resumeToolUseId === null
? null
: `${nativeItemId}:prompt:${resumeToolUseId}`;
if (promptNativeItemId !== null) {
yield* emitSubagentConversationMessage({
nativeItemId: promptNativeItemId,
Expand All @@ -8178,35 +8207,13 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
});
if ((yield* Ref.get(sessionSubagentsByTaskId)).get(input.taskId) !== subagent) return;
}
yield* emitProviderEvent({
type: "turn_item.updated",
driver: CLAUDE_PROVIDER,
turnItem: {
id: subagent.turnItemId,
threadId: task.threadId,
runId: task.runId,
nodeId: task.id,
providerThreadId: input.context.input.providerThread.id,
providerTurnId: input.context.providerTurnId,
nativeItemRef: task.nativeTaskRef,
parentItemId: null,
ordinal: subagent.turnItemOrdinal,
status: task.status,
title: task.title,
startedAt: task.startedAt,
completedAt: task.completedAt,
updatedAt: task.updatedAt,
type: "subagent",
subagentId: task.id,
origin: task.origin,
driver: task.driver,
providerInstanceId: task.providerInstanceId,
childThreadId: task.childThreadId,
prompt: task.prompt,
...(task.progress === undefined ? {} : { progress: task.progress }),
result: task.result,
},
});
if (!itemFollowsRecord) {
yield* emitProviderEvent({
type: "turn_item.updated",
driver: CLAUDE_PROVIDER,
turnItem,
});
}

if (input.nativeOutcome !== undefined && subagent.confirmedOutcome !== undefined) {
const outcome = subagentStopOutcomes.get(input.taskId);
Expand Down
4 changes: 0 additions & 4 deletions apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2972,10 +2972,6 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
type: "subagent.updated",
driver: CODEX_PROVIDER,
subagent: task,
});
yield* emitProviderEvent({
type: "turn_item.updated",
driver: CODEX_PROVIDER,
turnItem: {
id: input.subagent.turnItemId,
threadId: task.threadId,
Expand Down
Loading
Loading