fix(orchestration-v2): address subagent observability review findings

- Treat pending/waiting workflow agents as active in the session-registry
  write guard and wake-buffer pre-open, so concurrent active transitions
  are not dropped and wake task_started cannot force a false resume.
- Preserve the first-recorded activation completion time on duplicate
  terminal frames (Claude in-place update and ACP rebuilt emits).
- Let a blocked/waiting first snapshot of a new attempt reopen a settled
  workflow agent entry instead of silently dropping its status and usage.
- Settle still-active workflow members when their coordinator
  terminalizes, and expect the Implementer completed in claude_workflow.

Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
T3 Code TestandClaude Fable 5 committed 2026-08-14 15:04:11 +05:30
1 parent 39bc22bb2e
commit cdfbb9ac64
3 files changed
+52 -13

No files matched your search

@@ -2353,7 +2353,9 @@ export function makeAcpAdapterV2(options: AcpAdapterV2Options): ProviderAdapterV
status: taskStatus,
usage: null,
startedAt: subagent.task.startedAt,
completedAt: settled ? now : null,
// Keep the activation aligned with the subagent record instead
// of re-stamping the completion time on rebuilt emits.
completedAt: settled ? (subagent.task.completedAt ?? now) : null,
updatedAt: now,
} satisfies OrchestrationV2SubagentActivation,
});
@@ -3035,7 +3035,9 @@ export function makeClaudeAdapterV2(
...existingSubagent.activation,
status: input.status,
usage: mergeCumulativeSubagentUsage(existingSubagent.activation.usage, input.usage),
completedAt: settled ? now : null,
// A duplicate terminal frame must not re-stamp the completion
// time the first terminal frame recorded.
completedAt: settled ? (existingSubagent.activation.completedAt ?? now) : null,
updatedAt: now,
} satisfies OrchestrationV2SubagentActivation);
task.currentActivationId = settled ? null : activation.id;
@@ -3071,9 +3073,13 @@ export function makeClaudeAdapterV2(
// re-open must not clobber its result.
yield* Ref.update(sessionSubagentsByTaskId, (current) => {
const registered = current.get(input.taskId);
if (
const registeredSettled =
registered !== undefined &&
registered.task.status !== "running" &&
(registered.task.status === "completed" ||
registered.task.status === "failed" ||
registered.task.status === "cancelled");
if (
registeredSettled &&
activeStart &&
!(isReopen && registered === existingSubagent)
) {
@@ -3804,7 +3810,12 @@ export function makeClaudeAdapterV2(
const now = yield* DateTime.now;
yield* Ref.update(sessionSubagentsByTaskId, (current) => {
const registered = current.get(message.task_id);
if (registered === undefined || registered.task.status === "running") {
if (
registered === undefined ||
registered.task.status === "running" ||
registered.task.status === "pending" ||
registered.task.status === "waiting"
) {
return current;
}
const { progress: _staleProgress, ...priorTask } = registered.task;
@@ -4186,7 +4197,8 @@ export function makeClaudeAdapterV2(
const existingWorker =
context.subagentsByTaskId.get(workerTaskId) ??
(yield* Ref.get(sessionSubagentsByTaskId)).get(workerTaskId);
const activeWorker = status === "pending" || status === "running";
const activeWorker =
status === "pending" || status === "running" || status === "waiting";
const reopen =
activeWorker &&
existingWorker !== undefined &&
@@ -4236,19 +4248,44 @@ export function makeClaudeAdapterV2(
});
if (!wasBackgroundTask && !context.ignoredTaskIds.has(message.task_id)) {
const usage = claudeSubagentUsage(message.usage);
const terminalStatus =
message.status === "completed"
? ("completed" as const)
: message.status === "stopped"
? ("cancelled" as const)
: ("failed" as const);
yield* updateClaudeSubagentNode({
context,
taskId: message.task_id,
...(message.tool_use_id === undefined ? {} : { toolUseId: message.tool_use_id }),
result: message.summary,
...(usage === undefined ? {} : { usage }),
status:
message.status === "completed"
? "completed"
: message.status === "stopped"
? "cancelled"
: "failed",
status: terminalStatus,
});
// Workflow members only ever settle through workflow snapshots;
// once the coordinator terminalizes, any member left active
// would stay "running" forever, so settle it alongside.
const workerPrefix = `${message.task_id}:workflow:`;
const registeredWorkers = new Map([
...(yield* Ref.get(sessionSubagentsByTaskId)),
...context.subagentsByTaskId,
]);
for (const [workerTaskId, worker] of registeredWorkers) {
if (!workerTaskId.startsWith(workerPrefix)) continue;
const workerStatus = worker.task.status;
if (
workerStatus !== "pending" &&
workerStatus !== "running" &&
workerStatus !== "waiting"
) {
continue;
}
yield* updateClaudeSubagentNode({
context,
taskId: workerTaskId,
status: terminalStatus,
});
}
}
// Replay tombstone only needs to outlive buffering until this
// drained/live classification runs; drop it so it cannot leak.
@@ -45,7 +45,7 @@ export function assertClaudeWorkflowOutput(
]),
[
["Researcher", "completed", 0, "claude-sonnet-4-6", 400],
["Implementer", "running", 1, "claude-opus-4-1", 500],
["Implementer", "completed", 1, "claude-opus-4-1", 500],
],
);
// Membership must point at the coordinator that actually reached the