From 1391f9447024b208e3c4e0ecd56e41be79e9eb8f Mon Sep 17 00:00:00 2001 From: Shivam Sharma <91240327+shivamhwp@users.noreply.github.com> Date: Thu, 6 Aug 2026 02:22:39 +0530 Subject: [PATCH] fix: reconcile the observability series with the rebased v2 base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The base rebased onto main again, renumbering migrations (subagent observability moves 045 to 046) and reworking three paths this series extends: Claude's background-task lookup, ACP's terminal-status helper, and turn-item routing for inherited background items. Each merge keeps both intents — the base's newer mechanism with this branch's activation, identity-proof, and completedAt semantics. ProviderTurnStartService.test.ts was added on both sides as different files; rebuilt as the base's suite plus this branch's rehydration tests. Test mocks and fixtures gain the members the observability types now require. Co-Authored-By: Claude Fable 5 --- .../orchestration-v2/Adapters/AcpAdapterV2.ts | 7 +- .../Adapters/ClaudeAdapterV2.test.ts | 7 ++ .../DelegatedCompletionDelivery.test.ts | 8 ++ .../orchestration-v2/ProjectionStore.test.ts | 8 ++ .../ProviderEventIngestor.test.ts | 1 - .../ProviderTurnStartService.test.ts | 100 +++++++++--------- .../orchestration-v2/RunExecutionService.ts | 3 +- .../041_042_OrchestrationV2.test.ts | 2 +- 8 files changed, 79 insertions(+), 57 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.ts index 735f4c24dc..0da6d7e8e5 100644 --- a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.ts +++ b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.ts @@ -3,6 +3,7 @@ import * as NodeFS from "node:fs"; import * as NodePath from "node:path"; import { + orchestrationV2SubagentStatusAsTurnItemStatus, type ChatAttachment, type ModelSelection, type OrchestrationV2ConversationMessage, @@ -4043,7 +4044,7 @@ export function makeAcpAdapterV2(options: AcpAdapterV2Options): ProviderAdapterV parentNodeId: subagent.task.parentNodeId, rootNodeId: subagent.task.parentNodeId, kind: "subagent", - status, + status: orchestrationV2SubagentStatusAsTurnItemStatus[status], countsForRun: false, providerThreadId: parentProviderThreadId, providerTurnId: subagent.providerTurnId, @@ -4064,7 +4065,7 @@ export function makeAcpAdapterV2(options: AcpAdapterV2Options): ProviderAdapterV parentNodeId: null, rootNodeId: subagent.childRootNodeId, kind: "root_turn", - status, + status: orchestrationV2SubagentStatusAsTurnItemStatus[status], countsForRun: false, providerThreadId: subagent.task.providerThreadId, providerTurnId: null, @@ -4093,7 +4094,7 @@ export function makeAcpAdapterV2(options: AcpAdapterV2Options): ProviderAdapterV nativeItemRef, parentItemId: null, ordinal: subagent.turnItemOrdinal, - status, + status: orchestrationV2SubagentStatusAsTurnItemStatus[status], title: subagent.task.title, startedAt: subagent.task.startedAt, completedAt, diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts index bec7d5a07e..626c7c7e34 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts @@ -1679,6 +1679,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { offer: () => Effect.void, setModel: () => Effect.void, interrupt: Effect.void, + stopTask: () => Effect.void, // End the message stream so interruptTurn's closed wait resolves // via stream exit finalize (interrupted status clears roster). close: Queue.shutdown(sdkMessages), @@ -1804,6 +1805,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { offer: () => Effect.void, setModel: () => Effect.void, interrupt: Effect.void, + stopTask: () => Effect.void, close: Queue.shutdown(queue), }; }), @@ -3798,6 +3800,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { offer: () => Effect.void, setModel: () => Effect.void, interrupt: Effect.void, + stopTask: () => Effect.void, // End this process stream so openQuery can replace it. close: Queue.shutdown(sdkMessages), }; @@ -4064,6 +4067,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { offer: () => Effect.void, setModel: () => Effect.void, interrupt: Effect.void, + stopTask: () => Effect.void, close: Queue.shutdown(sdkMessages), }; }), @@ -4296,6 +4300,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { offer: () => Effect.void, setModel: () => Effect.void, interrupt: Effect.void, + stopTask: () => Effect.void, close: Queue.shutdown(sdkMessages), }; }), @@ -4492,6 +4497,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { offer: () => Effect.void, setModel: () => Effect.void, interrupt: Effect.void, + stopTask: () => Effect.void, close: Queue.shutdown(sdkMessages), }; }); @@ -4628,6 +4634,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { offer: () => Effect.void, setModel: () => Effect.void, interrupt: Effect.void, + stopTask: () => Effect.void, close: Queue.shutdown(sdkMessages), }; }); diff --git a/apps/server/src/orchestration-v2/DelegatedCompletionDelivery.test.ts b/apps/server/src/orchestration-v2/DelegatedCompletionDelivery.test.ts index 0f17608abb..a98865e627 100644 --- a/apps/server/src/orchestration-v2/DelegatedCompletionDelivery.test.ts +++ b/apps/server/src/orchestration-v2/DelegatedCompletionDelivery.test.ts @@ -246,6 +246,14 @@ const seedParentWithTerminalTask = (input: { occurredAt: input.now, payload: { id: input.taskId, + kind: "subagent" as const, + role: { name: "general-purpose", source: "app_default" as const }, + usage: null, + currentActivationId: null, + activationCount: 1, + workflow: null, + workflowMembership: null, + recentActivity: [], threadId: input.threadId, runId: input.runId, parentNodeId: input.rootNodeId, diff --git a/apps/server/src/orchestration-v2/ProjectionStore.test.ts b/apps/server/src/orchestration-v2/ProjectionStore.test.ts index 98cec43d2b..d4fbca8028 100644 --- a/apps/server/src/orchestration-v2/ProjectionStore.test.ts +++ b/apps/server/src/orchestration-v2/ProjectionStore.test.ts @@ -214,6 +214,14 @@ it.layer(TestLayer)("ProjectionStoreV2", (it) => { }; const task = { id: taskId, + kind: "subagent" as const, + role: { name: "general-purpose", source: "app_default" as const }, + usage: null, + currentActivationId: null, + activationCount: 1, + workflow: null, + workflowMembership: null, + recentActivity: [], threadId, runId, parentNodeId: rootNodeId, diff --git a/apps/server/src/orchestration-v2/ProviderEventIngestor.test.ts b/apps/server/src/orchestration-v2/ProviderEventIngestor.test.ts index 77a9baeac0..e7f5ac538d 100644 --- a/apps/server/src/orchestration-v2/ProviderEventIngestor.test.ts +++ b/apps/server/src/orchestration-v2/ProviderEventIngestor.test.ts @@ -13,7 +13,6 @@ import { RunAttemptId, RunId, TurnItemId, - RunId, SubagentActivationId, } from "@t3tools/contracts"; import * as DateTime from "effect/DateTime"; diff --git a/apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts b/apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts index a038ade361..2a39d0321f 100644 --- a/apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts +++ b/apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts @@ -1,4 +1,3 @@ -import { expect, it, vi } from "vite-plus/test"; import { assert, it } from "@effect/vitest"; import { CheckpointScopeId, @@ -12,19 +11,35 @@ import { RunAttemptId, RunId, ThreadId, - type OrchestrationV2ThreadProjection, + TurnItemId, } from "@t3tools/contracts"; +import * as DateTime from "effect/DateTime"; import * as Effect from "effect/Effect"; import * as Layer from "effect/Layer"; +import * as Ref from "effect/Ref"; +import { expect, vi } from "vite-plus/test"; import * as ContextHandoffService from "./ContextHandoffService.ts"; +import { ContextHandoffServiceV2 } from "./ContextHandoffService.ts"; import * as EventSink from "./EventSink.ts"; +import { EventSinkV2 } from "./EventSink.ts"; import * as IdAllocator from "./IdAllocator.ts"; +import type { ProviderAdapterV2SessionRuntime } from "./ProviderAdapter.ts"; import * as ProjectionStore from "./ProjectionStore.ts"; +import { + ProjectionStoreReadError, + ProjectionStoreThreadNotFoundError, + ProjectionStoreV2, + type ProjectionStoreV2Error, +} from "./ProjectionStore.ts"; import * as ProviderSessionManager from "./ProviderSessionManager.ts"; +import { ProviderSessionManagerV2 } from "./ProviderSessionManager.ts"; import * as ProviderTurnStart from "./ProviderTurnStartService.ts"; +import * as ProviderTurnStartService from "./ProviderTurnStartService.ts"; import * as RunExecutionService from "./RunExecutionService.ts"; +import { RunExecutionServiceV2 } from "./RunExecutionService.ts"; import * as RuntimePolicy from "./RuntimePolicy.ts"; +import { RuntimePolicyV2 } from "./RuntimePolicy.ts"; it("does not commit running state when inherited background routing cannot be read", async () => { const threadId = ThreadId.make("thread_provider_turn_start_projection_failure"); @@ -46,55 +61,6 @@ it("does not commit running state when inherited background routing cannot be re runs: [ { id: runId, - TurnItemId, -} from "@t3tools/contracts"; -import * as DateTime from "effect/DateTime"; -import * as Effect from "effect/Effect"; -import * as Layer from "effect/Layer"; -import * as Ref from "effect/Ref"; - -import { ContextHandoffServiceV2 } from "./ContextHandoffService.ts"; -import { EventSinkV2 } from "./EventSink.ts"; -import * as IdAllocator from "./IdAllocator.ts"; -import type { ProviderAdapterV2SessionRuntime } from "./ProviderAdapter.ts"; -import { - ProjectionStoreReadError, - ProjectionStoreThreadNotFoundError, - ProjectionStoreV2, - type ProjectionStoreV2Error, -} from "./ProjectionStore.ts"; -import { ProviderSessionManagerV2 } from "./ProviderSessionManager.ts"; -import * as ProviderTurnStartService from "./ProviderTurnStartService.ts"; -import { RunExecutionServiceV2 } from "./RunExecutionService.ts"; -import { RuntimePolicyV2 } from "./RuntimePolicy.ts"; - -const driver = ProviderDriverKind.make("codex"); -const threadId = ThreadId.make("thread:provider-turn-start"); -const childThreadId = ThreadId.make("thread:provider-turn-start:child"); -const runId = RunId.make("run:provider-turn-start"); -const rootNodeId = NodeId.make("node:provider-turn-start:root"); -const subagentId = NodeId.make("node:provider-turn-start:subagent"); -const attemptId = RunAttemptId.make("attempt:provider-turn-start"); -const providerThreadId = ProviderThreadId.make("provider-thread:provider-turn-start"); -const childProviderThreadId = ProviderThreadId.make("provider-thread:provider-turn-start:child"); -const providerSessionId = ProviderSessionId.make("provider-session:provider-turn-start"); -const providerInstanceId = ProviderInstanceId.make("codex"); -const messageId = MessageId.make("message:provider-turn-start"); -const checkpointScopeId = CheckpointScopeId.make("checkpoint-scope:provider-turn-start"); - -function makeRootProjection(now: DateTime.Utc): OrchestrationV2ThreadProjection { - return { - thread: { - id: threadId, - runtimeMode: "full-access", - interactionMode: "default", - worktreePath: "/tmp/provider-turn-start", - }, - runs: [ - { - id: runId, - threadId, - ordinal: 1, status: "starting", rootNodeId, activeAttemptId: attemptId, @@ -154,6 +120,38 @@ function makeRootProjection(now: DateTime.Utc): OrchestrationV2ThreadProjection expect(startRootRun).not.toHaveBeenCalled(); }).pipe(Effect.provide(layer), Effect.runPromise); }); + +const driver = ProviderDriverKind.make("codex"); +const threadId = ThreadId.make("thread:provider-turn-start"); +const childThreadId = ThreadId.make("thread:provider-turn-start:child"); +const runId = RunId.make("run:provider-turn-start"); +const rootNodeId = NodeId.make("node:provider-turn-start:root"); +const subagentId = NodeId.make("node:provider-turn-start:subagent"); +const attemptId = RunAttemptId.make("attempt:provider-turn-start"); +const providerThreadId = ProviderThreadId.make("provider-thread:provider-turn-start"); +const childProviderThreadId = ProviderThreadId.make("provider-thread:provider-turn-start:child"); +const providerSessionId = ProviderSessionId.make("provider-session:provider-turn-start"); +const providerInstanceId = ProviderInstanceId.make("codex"); +const messageId = MessageId.make("message:provider-turn-start"); +const checkpointScopeId = CheckpointScopeId.make("checkpoint-scope:provider-turn-start"); + +function makeRootProjection(now: DateTime.Utc): OrchestrationV2ThreadProjection { + return { + thread: { + id: threadId, + runtimeMode: "full-access", + interactionMode: "default", + worktreePath: "/tmp/provider-turn-start", + }, + runs: [ + { + id: runId, + threadId, + ordinal: 1, + status: "starting", + rootNodeId, + activeAttemptId: attemptId, + providerThreadId, providerInstanceId, userMessageId: messageId, modelSelection: { instanceId: providerInstanceId }, diff --git a/apps/server/src/orchestration-v2/RunExecutionService.ts b/apps/server/src/orchestration-v2/RunExecutionService.ts index 35f13aaea6..1daf1e9f26 100644 --- a/apps/server/src/orchestration-v2/RunExecutionService.ts +++ b/apps/server/src/orchestration-v2/RunExecutionService.ts @@ -578,7 +578,8 @@ export function routeProviderEvent( ownsChildThread(event.turnItem.threadId) || // A reused subagent's row and its timeline item are emitted together; // routing only the row would advance the agent while its item stayed - // frozen on the spawning run. + // frozen on the spawning run. Proof of driving is required for the + // same reason as the row route. (event.turnItem.type === "subagent" && drivesSubagent(event.turnItem.subagentId)) ) { return [true, state]; diff --git a/apps/server/src/persistence/Migrations/041_042_OrchestrationV2.test.ts b/apps/server/src/persistence/Migrations/041_042_OrchestrationV2.test.ts index c24e8808ec..b51102d442 100644 --- a/apps/server/src/persistence/Migrations/041_042_OrchestrationV2.test.ts +++ b/apps/server/src/persistence/Migrations/041_042_OrchestrationV2.test.ts @@ -13,7 +13,7 @@ layer("038_039_OrchestrationV2", (it) => { Effect.sync(() => { assert.deepStrictEqual( migrationEntries.map(([id]) => id), - Array.from({ length: 49 }, (_, index) => index + 1), + Array.from({ length: 50 }, (_, index) => index + 1), ); }), );