feat(orchestration-v2): add subagent observability data model
Introduces the schema, storage, and migration for richer subagent tracking. Nothing produces the new data yet — adapters populate neutral defaults so every subagent row remains valid — which keeps this change reviewable as a pure data-model step. Contracts gain a reusable subagent identity: per-activation records (SubagentActivationId, OrchestrationV2SubagentActivation), cumulative usage, a role, recent activity, and workflow grouping. A subagent may now also rest at "idle" between activations. Because a subagent status is not a turn item status, the two are bridged by an explicit mapping rather than a copy. The Record type makes that total: adding a subagent status without giving it a timeline meaning is a compile error. Without it, a producer can emit a turn item whose own schema cannot decode it, which is unrecoverable — the projection rebuild then fails on every subsequent startup and the server cannot boot. Migration 043 backfills existing rows so old events stay readable. Its riskiest path is a partially-migrated row, where already-present JSON is round-tripped through COALESCE; a test pins that structured values keep their JSON subtype rather than being rewritten as quoted strings. Also narrows event-envelope attribution in ProviderEventIngestor: a payload carrying an explicit null run or node id now keeps that null instead of inheriting the ambient run. Activations legitimately have no run id, and the envelope is persistence metadata only — routing reads payload fields — but this does change stored metadata for existing event types that already pass explicit nulls.
This commit is contained in:
1 parent
378615bb51
commit
c1929c2b5b
29 files changed
+1032
-11
No files matched your search
@@ -2085,6 +2085,14 @@ export function makeAcpAdapterV2(options: AcpAdapterV2Options): ProviderAdapterV
|
||||
prompt: update.prompt,
|
||||
title: update.title,
|
||||
model: update.model,
|
||||
kind: "subagent",
|
||||
role: { name: "general-purpose", source: "app_default" },
|
||||
usage: null,
|
||||
currentActivationId: null,
|
||||
activationCount: 1,
|
||||
workflow: null,
|
||||
workflowMembership: null,
|
||||
recentActivity: [],
|
||||
result: null,
|
||||
startedAt: now,
|
||||
}),
|
||||
|
||||
@@ -2343,6 +2343,14 @@ export function makeClaudeAdapterV2(
|
||||
prompt: input.prompt ?? "",
|
||||
title: input.title ?? null,
|
||||
model: input.context.input.modelSelection.model,
|
||||
kind: "subagent" as const,
|
||||
role: { name: "general-purpose", source: "app_default" as const },
|
||||
usage: null,
|
||||
currentActivationId: null,
|
||||
activationCount: 1,
|
||||
workflow: null,
|
||||
workflowMembership: null,
|
||||
recentActivity: [],
|
||||
result: null,
|
||||
startedAt: now,
|
||||
}),
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { CodexSettings, defaultInstanceIdForDriver, ProviderDriverKind } from "@t3tools/contracts";
|
||||
import {
|
||||
CodexSettings,
|
||||
defaultInstanceIdForDriver,
|
||||
orchestrationV2SubagentStatusAsTurnItemStatus,
|
||||
ProviderDriverKind,
|
||||
} from "@t3tools/contracts";
|
||||
import { HostProcessEnvironment } from "@t3tools/shared/hostProcess";
|
||||
import { getModelSelectionStringOptionValue } from "@t3tools/shared/model";
|
||||
import { resolveSpawnCommand } from "@t3tools/shared/shell";
|
||||
@@ -100,6 +105,7 @@ import {
|
||||
makeSubagentConversationArtifacts,
|
||||
subagentThreadTitle,
|
||||
} from "../SubagentProjection.ts";
|
||||
import { defaultSubagentRole } from "../SubagentObservability.ts";
|
||||
|
||||
const CODEX_PROVIDER = ProviderDriverKind.make("codex");
|
||||
export const CODEX_DRIVER_KIND = CODEX_PROVIDER;
|
||||
@@ -1774,7 +1780,7 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi
|
||||
nativeItemRef: task.nativeTaskRef,
|
||||
parentItemId: null,
|
||||
ordinal: input.subagent.turnItemOrdinal,
|
||||
status: task.status,
|
||||
status: orchestrationV2SubagentStatusAsTurnItemStatus[task.status],
|
||||
title: task.title,
|
||||
startedAt: task.startedAt,
|
||||
completedAt: task.completedAt,
|
||||
@@ -2021,8 +2027,16 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi
|
||||
prompt: input.prompt,
|
||||
title: input.title,
|
||||
model: input.model,
|
||||
kind: "subagent",
|
||||
role: defaultSubagentRole(),
|
||||
status: "running",
|
||||
result: null,
|
||||
usage: null,
|
||||
currentActivationId: null,
|
||||
activationCount: 1,
|
||||
workflow: null,
|
||||
workflowMembership: null,
|
||||
recentActivity: [],
|
||||
startedAt: now,
|
||||
completedAt: null,
|
||||
updatedAt: now,
|
||||
|
||||
@@ -1494,6 +1494,14 @@ export function makeCursorAdapterV2(
|
||||
prompt: args.prompt,
|
||||
title: args.description,
|
||||
model: args.model ?? input.context.input.modelSelection.model,
|
||||
kind: "subagent",
|
||||
role: { name: "general-purpose", source: "app_default" },
|
||||
usage: null,
|
||||
currentActivationId: null,
|
||||
activationCount: 1,
|
||||
workflow: null,
|
||||
workflowMembership: null,
|
||||
recentActivity: [],
|
||||
result: null,
|
||||
startedAt: now,
|
||||
}),
|
||||
|
||||
@@ -1215,6 +1215,14 @@ export function makeOpenCodeAdapterV2(options: OpenCodeAdapterV2Options): Provid
|
||||
prompt,
|
||||
title,
|
||||
model: context.model,
|
||||
kind: "subagent",
|
||||
role: { name: "general-purpose", source: "app_default" },
|
||||
usage: null,
|
||||
currentActivationId: null,
|
||||
activationCount: 1,
|
||||
workflow: null,
|
||||
workflowMembership: null,
|
||||
recentActivity: [],
|
||||
status: subagentStatus,
|
||||
result: context.result,
|
||||
startedAt: context.startedAt,
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
ProviderThreadId,
|
||||
RunAttemptId,
|
||||
RunId,
|
||||
SubagentActivationId,
|
||||
ThreadId,
|
||||
TurnItemId,
|
||||
} from "@t3tools/contracts";
|
||||
@@ -409,6 +410,7 @@ it.layer(TestLayer)("orchestration V2 foundation persistence", (it) => {
|
||||
const eventSink = yield* EventSinkV2;
|
||||
const projectionStore = yield* ProjectionStoreV2;
|
||||
const maintenance = yield* ProjectionMaintenanceV2;
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
const now = yield* DateTime.now;
|
||||
const parentThreadId = ThreadId.make("thread:foundation-cross-thread:parent");
|
||||
const childThreadId = ThreadId.make("thread:foundation-cross-thread:child");
|
||||
@@ -416,6 +418,9 @@ it.layer(TestLayer)("orchestration V2 foundation persistence", (it) => {
|
||||
"provider-thread:foundation-cross-thread:child",
|
||||
);
|
||||
const subagentId = NodeId.make("subagent:foundation-cross-thread");
|
||||
const activationId = SubagentActivationId.make(
|
||||
"subagent:foundation-cross-thread:activation:1",
|
||||
);
|
||||
const spawnTransferId = ContextTransferId.make("transfer:foundation-cross-thread:spawn");
|
||||
const resultTransferId = ContextTransferId.make("transfer:foundation-cross-thread:result");
|
||||
const parentThread = makeThread(parentThreadId, now);
|
||||
@@ -464,8 +469,37 @@ it.layer(TestLayer)("orchestration V2 foundation persistence", (it) => {
|
||||
prompt: "Inspect the child flow",
|
||||
title: "Cross-thread child",
|
||||
model: modelSelection.model,
|
||||
kind: "subagent",
|
||||
role: { name: "general-purpose", source: "app_default" },
|
||||
status: "completed",
|
||||
result: "done",
|
||||
usage: null,
|
||||
currentActivationId: null,
|
||||
activationCount: 1,
|
||||
workflow: null,
|
||||
workflowMembership: null,
|
||||
recentActivity: [],
|
||||
startedAt: now,
|
||||
completedAt: now,
|
||||
updatedAt: now,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: EventId.make("event:foundation-cross-thread:subagent-activation"),
|
||||
type: "subagent-activation.updated",
|
||||
threadId: parentThreadId,
|
||||
nodeId: subagentId,
|
||||
providerInstanceId,
|
||||
occurredAt: now,
|
||||
payload: {
|
||||
id: activationId,
|
||||
threadId: parentThreadId,
|
||||
subagentId,
|
||||
runId: null,
|
||||
providerTurnId: null,
|
||||
ordinal: 1,
|
||||
status: "completed",
|
||||
usage: { totalTokens: 240, toolUses: 2 },
|
||||
startedAt: now,
|
||||
completedAt: now,
|
||||
updatedAt: now,
|
||||
@@ -566,11 +600,57 @@ it.layer(TestLayer)("orchestration V2 foundation persistence", (it) => {
|
||||
[childProviderThreadId],
|
||||
);
|
||||
assert.equal(child.thread.activeProviderThreadId, childProviderThreadId);
|
||||
assert.deepEqual(
|
||||
parent.subagentActivations.map((activation) => ({
|
||||
id: activation.id,
|
||||
totalTokens: activation.usage?.totalTokens,
|
||||
})),
|
||||
[
|
||||
{
|
||||
id: activationId,
|
||||
totalTokens: 240,
|
||||
},
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
yield* assertCrossThreadProjection;
|
||||
assert.isTrue((yield* maintenance.verify).valid);
|
||||
yield* sql`
|
||||
INSERT INTO orchestration_v2_projection_subagent_activations (
|
||||
activation_id,
|
||||
thread_id,
|
||||
subagent_id,
|
||||
run_id,
|
||||
provider_turn_id,
|
||||
ordinal,
|
||||
status,
|
||||
started_at,
|
||||
completed_at,
|
||||
updated_at,
|
||||
payload_json
|
||||
)
|
||||
VALUES (
|
||||
'activation:foundation-cross-thread:stale',
|
||||
${parentThreadId},
|
||||
${subagentId},
|
||||
NULL,
|
||||
NULL,
|
||||
99,
|
||||
'completed',
|
||||
NULL,
|
||||
NULL,
|
||||
'2026-07-26T00:00:00.000Z',
|
||||
'{}'
|
||||
)
|
||||
`;
|
||||
assert.isTrue((yield* maintenance.rebuild).valid);
|
||||
const staleActivationRows = yield* sql<{ readonly count: number }>`
|
||||
SELECT COUNT(*) AS count
|
||||
FROM orchestration_v2_projection_subagent_activations
|
||||
WHERE activation_id = 'activation:foundation-cross-thread:stale'
|
||||
`;
|
||||
assert.equal(staleActivationRows[0]?.count, 0);
|
||||
yield* assertCrossThreadProjection;
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
type OrchestrationV2ThreadShellSnapshot,
|
||||
type OrchestrationV2StoredEvent,
|
||||
type OrchestrationV2Subagent,
|
||||
type OrchestrationV2SubagentActivation,
|
||||
type OrchestrationV2ThreadProjection,
|
||||
type OrchestrationV2TurnItem,
|
||||
ProviderInstanceId,
|
||||
@@ -63,6 +64,7 @@ import {
|
||||
subagentResultForRun,
|
||||
subagentThreadTitle,
|
||||
} from "./SubagentProjection.ts";
|
||||
import { defaultSubagentRole, subagentActivationId } from "./SubagentObservability.ts";
|
||||
import { ThreadForkServiceV2 } from "./ThreadForkService.ts";
|
||||
|
||||
export class OrchestratorDispatchError extends Schema.TaggedErrorClass<OrchestratorDispatchError>()(
|
||||
@@ -294,7 +296,10 @@ function isTerminalDelegatedTaskStatus(status: OrchestrationV2Subagent["status"]
|
||||
|
||||
function delegatedTaskTerminalStatus(
|
||||
status: OrchestrationV2Run["status"],
|
||||
): OrchestrationV2Subagent["status"] | null {
|
||||
): Extract<
|
||||
OrchestrationV2Subagent["status"],
|
||||
"completed" | "failed" | "cancelled" | "interrupted"
|
||||
> | null {
|
||||
switch (status) {
|
||||
case "completed":
|
||||
case "failed":
|
||||
@@ -312,6 +317,12 @@ function delegatedTaskTerminalStatus(
|
||||
}
|
||||
}
|
||||
|
||||
const isTerminalSubagentActivation = (activation: OrchestrationV2SubagentActivation) =>
|
||||
activation.status === "completed" ||
|
||||
activation.status === "failed" ||
|
||||
activation.status === "cancelled" ||
|
||||
activation.status === "interrupted";
|
||||
|
||||
function nextQueuedRun(
|
||||
projection: OrchestrationV2ThreadProjection,
|
||||
): OrchestrationV2Run | undefined {
|
||||
@@ -3941,6 +3952,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
|
||||
runtimeMode: command.runtimeMode,
|
||||
interactionMode: command.interactionMode,
|
||||
};
|
||||
const activationId = subagentActivationId(taskNodeId, 1);
|
||||
const task: OrchestrationV2Subagent = {
|
||||
id: taskNodeId,
|
||||
threadId: command.parentThreadId,
|
||||
@@ -3957,8 +3969,16 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
|
||||
title: command.title ?? null,
|
||||
model: command.modelSelection.model,
|
||||
...(command.completionWake === undefined ? {} : { completionWake: command.completionWake }),
|
||||
kind: "subagent",
|
||||
role: defaultSubagentRole("delegated-worker"),
|
||||
status: "running",
|
||||
result: null,
|
||||
usage: null,
|
||||
currentActivationId: activationId,
|
||||
activationCount: 1,
|
||||
workflow: null,
|
||||
workflowMembership: null,
|
||||
recentActivity: [],
|
||||
startedAt: now,
|
||||
completedAt: null,
|
||||
updatedAt: now,
|
||||
@@ -3981,6 +4001,19 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
|
||||
completedAt: null,
|
||||
};
|
||||
const parentProviderTurn = providerTurnForRun(parentProjection, parentRun);
|
||||
const activation = {
|
||||
id: activationId,
|
||||
threadId: command.parentThreadId,
|
||||
subagentId: taskNodeId,
|
||||
runId: parentRun.id,
|
||||
providerTurnId: parentProviderTurn?.id ?? null,
|
||||
ordinal: 1,
|
||||
status: "running",
|
||||
usage: null,
|
||||
startedAt: now,
|
||||
completedAt: null,
|
||||
updatedAt: now,
|
||||
} satisfies OrchestrationV2SubagentActivation;
|
||||
const taskTurnItem: OrchestrationV2TurnItem = {
|
||||
id: taskTurnItemId,
|
||||
threadId: command.parentThreadId,
|
||||
@@ -4035,6 +4068,16 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
|
||||
occurredAt: now,
|
||||
payload: task,
|
||||
});
|
||||
yield* emitEvent({
|
||||
type: "subagent-activation.updated",
|
||||
threadId: command.parentThreadId,
|
||||
runId: parentRun.id,
|
||||
nodeId: taskNodeId,
|
||||
driver: targetAdapter.driver,
|
||||
providerInstanceId: command.modelSelection.instanceId,
|
||||
occurredAt: now,
|
||||
payload: activation,
|
||||
});
|
||||
yield* emitEvent({
|
||||
type: "turn-item.updated",
|
||||
threadId: command.parentThreadId,
|
||||
@@ -5475,9 +5518,41 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
|
||||
providerThreadId: childRun.providerThreadId,
|
||||
status: terminalStatus,
|
||||
result: result.text,
|
||||
currentActivationId: null,
|
||||
completedAt: now,
|
||||
updatedAt: now,
|
||||
};
|
||||
const currentActivation =
|
||||
task.currentActivationId === null
|
||||
? undefined
|
||||
: parentProjection.subagentActivations.find(
|
||||
(activation) => activation.id === task.currentActivationId,
|
||||
);
|
||||
const terminalActivation =
|
||||
task.currentActivationId === null || currentActivation?.status === terminalStatus
|
||||
? null
|
||||
: currentActivation === undefined
|
||||
? ({
|
||||
id: task.currentActivationId,
|
||||
threadId: task.threadId,
|
||||
subagentId: task.id,
|
||||
runId: task.runId,
|
||||
providerTurnId: null,
|
||||
ordinal: Math.max(1, task.activationCount),
|
||||
status: terminalStatus,
|
||||
usage: task.usage,
|
||||
startedAt: task.startedAt,
|
||||
completedAt: now,
|
||||
updatedAt: now,
|
||||
} satisfies OrchestrationV2SubagentActivation)
|
||||
: isTerminalSubagentActivation(currentActivation)
|
||||
? null
|
||||
: ({
|
||||
...currentActivation,
|
||||
status: terminalStatus,
|
||||
completedAt: now,
|
||||
updatedAt: now,
|
||||
} satisfies OrchestrationV2SubagentActivation);
|
||||
const resultTransferId = yield* idAllocator.allocate.contextTransfer({
|
||||
sourceThreadId: childThreadId,
|
||||
targetThreadId: parentThreadId,
|
||||
@@ -5562,6 +5637,19 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
|
||||
occurredAt: now,
|
||||
payload: updatedTask,
|
||||
},
|
||||
...(terminalActivation === null
|
||||
? []
|
||||
: [
|
||||
{
|
||||
type: "subagent-activation.updated" as const,
|
||||
threadId: parentThreadId,
|
||||
...(task.runId === null ? {} : { runId: task.runId }),
|
||||
nodeId: task.id,
|
||||
driver: task.driver,
|
||||
occurredAt: now,
|
||||
payload: terminalActivation,
|
||||
},
|
||||
]),
|
||||
...(parentNode === undefined
|
||||
? []
|
||||
: [
|
||||
|
||||
@@ -160,6 +160,7 @@ export const layer: Layer.Layer<
|
||||
yield* sql`DELETE FROM orchestration_v2_projection_provider_threads`;
|
||||
yield* sql`DELETE FROM orchestration_v2_projection_provider_session_bindings`;
|
||||
yield* sql`DELETE FROM orchestration_v2_projection_provider_sessions`;
|
||||
yield* sql`DELETE FROM orchestration_v2_projection_subagent_activations`;
|
||||
yield* sql`DELETE FROM orchestration_v2_projection_subagents`;
|
||||
yield* sql`DELETE FROM orchestration_v2_projection_nodes`;
|
||||
yield* sql`DELETE FROM orchestration_v2_projection_run_attempts`;
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
OrchestrationV2RunJson as OrchestrationV2RunJsonSchema,
|
||||
OrchestrationV2RuntimeRequestJson as OrchestrationV2RuntimeRequestJsonSchema,
|
||||
OrchestrationV2SubagentJson as OrchestrationV2SubagentJsonSchema,
|
||||
OrchestrationV2SubagentActivationJson as OrchestrationV2SubagentActivationJsonSchema,
|
||||
OrchestrationV2TurnItemJson as OrchestrationV2TurnItemJsonSchema,
|
||||
RunId,
|
||||
ThreadId,
|
||||
@@ -124,7 +125,7 @@ export class ProjectionStoreV2 extends Context.Service<ProjectionStoreV2, Projec
|
||||
"t3/orchestration-v2/ProjectionStore/ProjectionStoreV2",
|
||||
) {}
|
||||
|
||||
export const ORCHESTRATION_V2_PROJECTION_SCHEMA_VERSION = 2;
|
||||
export const ORCHESTRATION_V2_PROJECTION_SCHEMA_VERSION = 3;
|
||||
|
||||
function upsertById<T extends { readonly id: string }>(items: ReadonlyArray<T>, next: T): Array<T> {
|
||||
const index = items.findIndex((item) => item.id === next.id);
|
||||
@@ -146,6 +147,7 @@ export function emptyProjection(
|
||||
attempts: [],
|
||||
nodes: [],
|
||||
subagents: [],
|
||||
subagentActivations: [],
|
||||
providerSessions: [],
|
||||
providerThreads: [],
|
||||
providerTurns: [],
|
||||
@@ -223,6 +225,11 @@ export function applyToProjection(
|
||||
...base,
|
||||
subagents: upsertById(base.subagents, event.payload),
|
||||
};
|
||||
case "subagent-activation.updated":
|
||||
return {
|
||||
...base,
|
||||
subagentActivations: upsertById(base.subagentActivations, event.payload),
|
||||
};
|
||||
case "provider-session.attached":
|
||||
case "provider-session.updated":
|
||||
return {
|
||||
@@ -439,6 +446,9 @@ const encodeNodePayload = Schema.encodeEffect(
|
||||
const encodeSubagentPayload = Schema.encodeEffect(
|
||||
Schema.fromJsonString(OrchestrationV2SubagentJsonSchema),
|
||||
);
|
||||
const encodeSubagentActivationPayload = Schema.encodeEffect(
|
||||
Schema.fromJsonString(OrchestrationV2SubagentActivationJsonSchema),
|
||||
);
|
||||
const encodeProviderSessionPayload = Schema.encodeEffect(
|
||||
Schema.fromJsonString(OrchestrationV2ProviderSessionJsonSchema),
|
||||
);
|
||||
@@ -483,6 +493,10 @@ const decodeNodePayload = (json: string) =>
|
||||
Schema.decodeUnknownEffect(Schema.fromJsonString(OrchestrationV2ExecutionNodeJsonSchema))(json);
|
||||
const decodeSubagentPayload = (json: string) =>
|
||||
Schema.decodeUnknownEffect(Schema.fromJsonString(OrchestrationV2SubagentJsonSchema))(json);
|
||||
const decodeSubagentActivationPayload = (json: string) =>
|
||||
Schema.decodeUnknownEffect(Schema.fromJsonString(OrchestrationV2SubagentActivationJsonSchema))(
|
||||
json,
|
||||
);
|
||||
const decodeProviderSessionPayload = (json: string) =>
|
||||
Schema.decodeUnknownEffect(Schema.fromJsonString(OrchestrationV2ProviderSessionJsonSchema))(json);
|
||||
const decodeProviderThreadPayload = (json: string) =>
|
||||
@@ -1293,6 +1307,51 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
|
||||
`;
|
||||
break;
|
||||
}
|
||||
case "subagent-activation.updated": {
|
||||
const payloadJson = yield* encodeSubagentActivationPayload(event.payload);
|
||||
const payload = parseEncodedPayload(payloadJson);
|
||||
yield* sql`
|
||||
INSERT INTO orchestration_v2_projection_subagent_activations (
|
||||
activation_id,
|
||||
thread_id,
|
||||
subagent_id,
|
||||
run_id,
|
||||
provider_turn_id,
|
||||
ordinal,
|
||||
status,
|
||||
started_at,
|
||||
completed_at,
|
||||
updated_at,
|
||||
payload_json
|
||||
)
|
||||
VALUES (
|
||||
${event.payload.id},
|
||||
${event.payload.threadId},
|
||||
${event.payload.subagentId},
|
||||
${event.payload.runId},
|
||||
${event.payload.providerTurnId},
|
||||
${event.payload.ordinal},
|
||||
${event.payload.status},
|
||||
${nullableStringField(payload, "startedAt")},
|
||||
${nullableStringField(payload, "completedAt")},
|
||||
${stringField(payload, "updatedAt")},
|
||||
${payloadJson}
|
||||
)
|
||||
ON CONFLICT(activation_id)
|
||||
DO UPDATE SET
|
||||
thread_id = excluded.thread_id,
|
||||
subagent_id = excluded.subagent_id,
|
||||
run_id = excluded.run_id,
|
||||
provider_turn_id = excluded.provider_turn_id,
|
||||
ordinal = excluded.ordinal,
|
||||
status = excluded.status,
|
||||
started_at = excluded.started_at,
|
||||
completed_at = excluded.completed_at,
|
||||
updated_at = excluded.updated_at,
|
||||
payload_json = excluded.payload_json
|
||||
`;
|
||||
break;
|
||||
}
|
||||
case "provider-session.attached":
|
||||
case "provider-session.updated": {
|
||||
const payloadJson = yield* encodeProviderSessionPayload(event.payload);
|
||||
@@ -1869,6 +1928,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
|
||||
attemptRows,
|
||||
nodeRows,
|
||||
subagentRows,
|
||||
subagentActivationRows,
|
||||
providerSessionRows,
|
||||
providerThreadRows,
|
||||
providerTurnRows,
|
||||
@@ -1906,6 +1966,12 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
|
||||
WHERE thread_id = ${threadId}
|
||||
ORDER BY COALESCE(started_at, ''), subagent_id ASC
|
||||
`,
|
||||
sql<PayloadRow>`
|
||||
SELECT payload_json
|
||||
FROM orchestration_v2_projection_subagent_activations
|
||||
WHERE thread_id = ${threadId}
|
||||
ORDER BY subagent_id ASC, ordinal ASC
|
||||
`,
|
||||
sql<PayloadRow>`
|
||||
SELECT sessions.payload_json
|
||||
FROM orchestration_v2_projection_provider_sessions AS sessions
|
||||
@@ -1992,6 +2058,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
|
||||
attempts,
|
||||
nodes,
|
||||
subagents,
|
||||
subagentActivations,
|
||||
providerSessions,
|
||||
providerThreads,
|
||||
providerTurns,
|
||||
@@ -2008,6 +2075,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
|
||||
decodeRows(decodeRunAttemptPayload, threadId)(attemptRows),
|
||||
decodeRows(decodeNodePayload, threadId)(nodeRows),
|
||||
decodeRows(decodeSubagentPayload, threadId)(subagentRows),
|
||||
decodeRows(decodeSubagentActivationPayload, threadId)(subagentActivationRows),
|
||||
decodeRows(decodeProviderSessionPayload, threadId)(providerSessionRows),
|
||||
decodeRows(decodeProviderThreadPayload, threadId)(providerThreadRows),
|
||||
decodeRows(decodeProviderTurnPayload, threadId)(providerTurnRows),
|
||||
@@ -2027,6 +2095,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
|
||||
attempts,
|
||||
nodes,
|
||||
subagents,
|
||||
subagentActivations,
|
||||
providerSessions,
|
||||
providerThreads,
|
||||
providerTurns,
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
OrchestrationV2ProviderTurn,
|
||||
OrchestrationV2RuntimeRequest,
|
||||
OrchestrationV2Subagent,
|
||||
OrchestrationV2SubagentActivation,
|
||||
OrchestrationV2TurnItem,
|
||||
ProviderApprovalDecision,
|
||||
ProviderInteractionMode,
|
||||
@@ -31,6 +32,7 @@ import {
|
||||
RunAttemptId,
|
||||
RunId,
|
||||
ThreadId,
|
||||
TurnItemId,
|
||||
} from "@t3tools/contracts";
|
||||
import * as Context from "effect/Context";
|
||||
import * as Schema from "effect/Schema";
|
||||
@@ -104,6 +106,11 @@ export const ProviderAdapterV2Event = Schema.Union([
|
||||
driver: ProviderDriverKind,
|
||||
subagent: OrchestrationV2Subagent,
|
||||
}),
|
||||
Schema.Struct({
|
||||
type: Schema.Literal("subagent_activation.updated"),
|
||||
driver: ProviderDriverKind,
|
||||
activation: OrchestrationV2SubagentActivation,
|
||||
}),
|
||||
Schema.Struct({
|
||||
type: Schema.Literal("message.updated"),
|
||||
driver: ProviderDriverKind,
|
||||
|
||||
@@ -8,6 +8,8 @@ import {
|
||||
type OrchestrationV2ProviderThread,
|
||||
ProviderDriverKind,
|
||||
ProviderInstanceId,
|
||||
RunId,
|
||||
SubagentActivationId,
|
||||
} from "@t3tools/contracts";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
import * as Effect from "effect/Effect";
|
||||
@@ -383,4 +385,83 @@ layer("ProviderEventIngestorV2", (it) => {
|
||||
assert.equal(messageEvents[0]?.threadId, childThreadId);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("does not replace explicit null run and node overrides with ambient ids", () =>
|
||||
Effect.gen(function* () {
|
||||
const now = yield* DateTime.now;
|
||||
const ingestor = yield* ProviderEventIngestorV2;
|
||||
const idAllocator = yield* IdAllocatorV2;
|
||||
const projectId = yield* idAllocator.allocate.project({
|
||||
fixtureName: "provider-event-null-overrides",
|
||||
});
|
||||
const threadId = yield* idAllocator.allocate.thread({
|
||||
fixtureName: "provider-event-null-overrides",
|
||||
projectId,
|
||||
});
|
||||
const providerSessionId = yield* idAllocator.allocate.providerSession({
|
||||
providerInstanceId: modelSelection.instanceId,
|
||||
threadId,
|
||||
});
|
||||
const ambientRunId = RunId.make("run:provider-event-null-overrides");
|
||||
const ambientNodeId = NodeId.make("node:provider-event-null-overrides");
|
||||
const subagentId = NodeId.make("node:provider-event-null-overrides:subagent");
|
||||
|
||||
const activationEvents = yield* ingestor.normalize({
|
||||
providerSessionId,
|
||||
providerInstanceId: modelSelection.instanceId,
|
||||
threadId,
|
||||
runId: ambientRunId,
|
||||
nodeId: ambientNodeId,
|
||||
event: {
|
||||
type: "subagent_activation.updated",
|
||||
driver: CODEX_DRIVER,
|
||||
activation: {
|
||||
id: SubagentActivationId.make(
|
||||
"node:provider-event-null-overrides:subagent:activation:1",
|
||||
),
|
||||
threadId,
|
||||
subagentId,
|
||||
runId: null,
|
||||
providerTurnId: null,
|
||||
ordinal: 1,
|
||||
status: "completed",
|
||||
usage: null,
|
||||
startedAt: now,
|
||||
completedAt: now,
|
||||
updatedAt: now,
|
||||
},
|
||||
},
|
||||
});
|
||||
const messageEvents = yield* ingestor.normalize({
|
||||
providerSessionId,
|
||||
providerInstanceId: modelSelection.instanceId,
|
||||
threadId,
|
||||
runId: ambientRunId,
|
||||
nodeId: ambientNodeId,
|
||||
event: {
|
||||
type: "message.updated",
|
||||
driver: CODEX_DRIVER,
|
||||
message: {
|
||||
createdBy: "agent",
|
||||
creationSource: "provider",
|
||||
id: MessageId.make("message:provider-event-null-overrides"),
|
||||
threadId,
|
||||
runId: null,
|
||||
nodeId: null,
|
||||
role: "assistant",
|
||||
text: "Detached provider message",
|
||||
attachments: [],
|
||||
streaming: false,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
assert.isUndefined(activationEvents[0]?.runId);
|
||||
assert.equal(activationEvents[0]?.nodeId, subagentId);
|
||||
assert.isUndefined(messageEvents[0]?.runId);
|
||||
assert.isUndefined(messageEvents[0]?.nodeId);
|
||||
}),
|
||||
);
|
||||
});
|
||||
@@ -125,8 +125,8 @@ export const layer: Layer.Layer<ProviderEventIngestorV2, never, EventSinkV2 | Id
|
||||
id: eventId,
|
||||
type: payloadInput.type,
|
||||
threadId,
|
||||
runId: payloadInput.runId ?? input.runId,
|
||||
nodeId: payloadInput.nodeId ?? input.nodeId,
|
||||
runId: "runId" in payloadInput ? (payloadInput.runId ?? undefined) : input.runId,
|
||||
nodeId: "nodeId" in payloadInput ? (payloadInput.nodeId ?? undefined) : input.nodeId,
|
||||
driver: input.event.driver,
|
||||
providerInstanceId: input.providerInstanceId,
|
||||
rawEventId: input.rawEventId,
|
||||
@@ -191,6 +191,16 @@ export const layer: Layer.Layer<ProviderEventIngestorV2, never, EventSinkV2 | Id
|
||||
nodeId: input.event.subagent.id,
|
||||
}),
|
||||
];
|
||||
case "subagent_activation.updated":
|
||||
return [
|
||||
yield* makeDomainEvent(input, {
|
||||
type: "subagent-activation.updated",
|
||||
threadId: input.event.activation.threadId,
|
||||
payload: input.event.activation,
|
||||
runId: input.event.activation.runId,
|
||||
nodeId: input.event.activation.subagentId,
|
||||
}),
|
||||
];
|
||||
case "message.updated":
|
||||
return [
|
||||
yield* makeDomainEvent(input, {
|
||||
|
||||
@@ -93,6 +93,7 @@ function makeProjection(input: {
|
||||
],
|
||||
nodes: [],
|
||||
subagents: [],
|
||||
subagentActivations: [],
|
||||
providerSessions: [],
|
||||
providerThreads: [input.providerThread],
|
||||
providerTurns: [
|
||||
|
||||
@@ -1311,6 +1311,14 @@ it.effect("cascade helper is provider-neutral for Claude and Codex-shaped child
|
||||
prompt: "hold",
|
||||
title: "hold",
|
||||
model: null,
|
||||
kind: "subagent",
|
||||
role: { name: "general-purpose", source: "app_default" },
|
||||
usage: null,
|
||||
currentActivationId: null,
|
||||
activationCount: 1,
|
||||
workflow: null,
|
||||
workflowMembership: null,
|
||||
recentActivity: [],
|
||||
status: "running",
|
||||
progress: "partial progress",
|
||||
result: "partial result",
|
||||
@@ -1865,6 +1873,14 @@ function makeRunOwnedSubagentFixture(input: {
|
||||
prompt: "hold",
|
||||
title: "Live-test subagent hold",
|
||||
model: null,
|
||||
kind: "subagent",
|
||||
role: { name: "general-purpose", source: "app_default" },
|
||||
usage: null,
|
||||
currentActivationId: null,
|
||||
activationCount: 1,
|
||||
workflow: null,
|
||||
workflowMembership: null,
|
||||
recentActivity: [],
|
||||
status: input.status,
|
||||
result: null,
|
||||
startedAt: now,
|
||||
|
||||
@@ -361,6 +361,8 @@ export function routeProviderEvent(
|
||||
}
|
||||
case "subagent.updated":
|
||||
return [ownsRun(event.subagent.runId) || ownsChildThread(event.subagent.threadId), state];
|
||||
case "subagent_activation.updated":
|
||||
return [ownsRun(event.activation.runId) || ownsChildThread(event.activation.threadId), state];
|
||||
case "message.updated":
|
||||
return [ownsRun(event.message.runId) || ownsChildThread(event.message.threadId), state];
|
||||
case "turn_item.updated":
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
import { NodeId } from "@t3tools/contracts";
|
||||
|
||||
import { defaultSubagentRole, subagentActivationId } from "./SubagentObservability.ts";
|
||||
|
||||
describe("subagent observability", () => {
|
||||
it("marks a fallback role as app-provided so provider roles stay distinguishable", () => {
|
||||
expect(defaultSubagentRole()).toEqual({ name: "general-purpose", source: "app_default" });
|
||||
expect(defaultSubagentRole("workflow-worker")).toEqual({
|
||||
name: "workflow-worker",
|
||||
source: "app_default",
|
||||
});
|
||||
});
|
||||
|
||||
it("derives activation ids that are stable and unique per ordinal", () => {
|
||||
const subagentId = NodeId.make("node:provider:codex:native-item:call_abc");
|
||||
expect(subagentActivationId(subagentId, 1)).toBe(`${subagentId}:activation:1`);
|
||||
// Stable derivation means a replayed activation updates its own row rather
|
||||
// than inserting a duplicate.
|
||||
expect(subagentActivationId(subagentId, 2)).toBe(subagentActivationId(subagentId, 2));
|
||||
expect(subagentActivationId(subagentId, 1)).not.toBe(subagentActivationId(subagentId, 2));
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
import {
|
||||
SubagentActivationId,
|
||||
type NodeId,
|
||||
type OrchestrationV2SubagentRole,
|
||||
} from "@t3tools/contracts";
|
||||
|
||||
export const defaultSubagentRole = (name = "general-purpose"): OrchestrationV2SubagentRole => ({
|
||||
name,
|
||||
source: "app_default",
|
||||
});
|
||||
|
||||
export const subagentActivationId = (subagentId: NodeId, ordinal: number) =>
|
||||
SubagentActivationId.make(`${subagentId}:activation:${ordinal}`);
|
||||
@@ -93,6 +93,7 @@ it.effect("keeps a fork awake when its source thread is snoozed", () =>
|
||||
attempts: [],
|
||||
nodes: [],
|
||||
subagents: [],
|
||||
subagentActivations: [],
|
||||
providerSessions: [],
|
||||
providerThreads: [],
|
||||
providerTurns: [],
|
||||
|
||||
@@ -57,6 +57,7 @@ import Migration0041 from "./Migrations/041_ApplicationEventSource.ts";
|
||||
import Migration0042 from "./Migrations/042_OrchestrationV2EffectCancellation.ts";
|
||||
import Migration0043 from "./Migrations/043_ScheduledTasks.ts";
|
||||
import Migration0044 from "./Migrations/044_LegacyV1ImportState.ts";
|
||||
import Migration0045 from "./Migrations/045_OrchestrationV2SubagentObservability.ts";
|
||||
|
||||
/**
|
||||
* Migration loader with all migrations defined inline.
|
||||
@@ -113,6 +114,7 @@ export const migrationEntries = [
|
||||
[42, "OrchestrationV2EffectCancellation", Migration0042],
|
||||
[43, "ScheduledTasks", Migration0043],
|
||||
[44, "LegacyV1ImportState", Migration0044],
|
||||
[45, "OrchestrationV2SubagentObservability", Migration0045],
|
||||
] as const;
|
||||
|
||||
export const migrationManifest = migrationEntries.map(([id, name]) => [id, name] as const);
|
||||
|
||||
@@ -190,7 +190,7 @@ it.effect("upgrades a database already at released main migration 034", () =>
|
||||
}>`
|
||||
SELECT migration_id, name
|
||||
FROM effect_sql_migrations
|
||||
WHERE migration_id BETWEEN 34 AND 44
|
||||
WHERE migration_id BETWEEN 34 AND 45
|
||||
ORDER BY migration_id
|
||||
`;
|
||||
assert.deepStrictEqual(
|
||||
@@ -207,6 +207,7 @@ it.effect("upgrades a database already at released main migration 034", () =>
|
||||
[42, "OrchestrationV2EffectCancellation"],
|
||||
[43, "ScheduledTasks"],
|
||||
[44, "LegacyV1ImportState"],
|
||||
[45, "OrchestrationV2SubagentObservability"],
|
||||
],
|
||||
);
|
||||
|
||||
|
||||
+222
@@ -0,0 +1,222 @@
|
||||
import { assert, it } from "@effect/vitest";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as SqlClient from "effect/unstable/sql/SqlClient";
|
||||
|
||||
import { runMigrations } from "../Migrations.ts";
|
||||
import * as NodeSqliteClient from "../NodeSqliteClient.ts";
|
||||
|
||||
const layer = it.layer(Layer.mergeAll(NodeSqliteClient.layerMemory()));
|
||||
|
||||
layer("044_OrchestrationV2SubagentObservability", (it) => {
|
||||
it.effect("backfills old subagents and installs activation persistence", () =>
|
||||
Effect.gen(function* () {
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
yield* runMigrations({ toMigrationInclusive: 43 });
|
||||
yield* sql`
|
||||
INSERT INTO orchestration_v2_projection_subagents (
|
||||
subagent_id,
|
||||
thread_id,
|
||||
run_id,
|
||||
parent_node_id,
|
||||
provider,
|
||||
provider_thread_id,
|
||||
child_thread_id,
|
||||
origin,
|
||||
status,
|
||||
started_at,
|
||||
completed_at,
|
||||
updated_at,
|
||||
payload_json
|
||||
) VALUES (
|
||||
'node:legacy-subagent',
|
||||
'thread:legacy-subagent',
|
||||
'run:legacy-subagent',
|
||||
'node:legacy-root',
|
||||
'codex',
|
||||
NULL,
|
||||
NULL,
|
||||
'provider_native',
|
||||
'completed',
|
||||
'2026-07-26T00:00:00.000Z',
|
||||
'2026-07-26T00:01:00.000Z',
|
||||
'2026-07-26T00:01:00.000Z',
|
||||
'{"id":"node:legacy-subagent","status":"completed"}'
|
||||
)
|
||||
`;
|
||||
yield* sql`
|
||||
INSERT INTO orchestration_v2_projection_subagents (
|
||||
subagent_id,
|
||||
thread_id,
|
||||
run_id,
|
||||
parent_node_id,
|
||||
provider,
|
||||
provider_thread_id,
|
||||
child_thread_id,
|
||||
origin,
|
||||
status,
|
||||
started_at,
|
||||
completed_at,
|
||||
updated_at,
|
||||
payload_json
|
||||
) VALUES (
|
||||
'node:current-subagent',
|
||||
'thread:current-subagent',
|
||||
'run:current-subagent',
|
||||
'node:current-root',
|
||||
'claudeAgent',
|
||||
NULL,
|
||||
NULL,
|
||||
'provider_native',
|
||||
'running',
|
||||
'2026-07-26T00:00:00.000Z',
|
||||
NULL,
|
||||
'2026-07-26T00:01:00.000Z',
|
||||
'{"id":"node:current-subagent","status":"running","kind":"workflow_agent","role":{"name":"researcher","source":"provider"},"usage":{"totalTokens":12},"currentActivationId":"activation:current","activationCount":2,"workflow":null,"workflowMembership":null,"recentActivity":[{"at":"2026-07-26T00:00:30.000Z","summary":"kept"}]}'
|
||||
)
|
||||
`;
|
||||
|
||||
// Half-migrated: `role` and `recentActivity` already exist as structured
|
||||
// JSON, while `kind`, `usage`, and `activationCount` are still missing.
|
||||
yield* sql`
|
||||
INSERT INTO orchestration_v2_projection_subagents (
|
||||
subagent_id,
|
||||
thread_id,
|
||||
run_id,
|
||||
parent_node_id,
|
||||
provider,
|
||||
provider_thread_id,
|
||||
child_thread_id,
|
||||
origin,
|
||||
status,
|
||||
started_at,
|
||||
completed_at,
|
||||
updated_at,
|
||||
payload_json
|
||||
) VALUES (
|
||||
'node:mixed-subagent',
|
||||
'thread:mixed-subagent',
|
||||
'run:mixed-subagent',
|
||||
'node:mixed-root',
|
||||
'codex',
|
||||
NULL,
|
||||
NULL,
|
||||
'provider_native',
|
||||
'running',
|
||||
'2026-07-26T00:00:00.000Z',
|
||||
NULL,
|
||||
'2026-07-26T00:01:00.000Z',
|
||||
'{"id":"node:mixed-subagent","status":"running","role":{"name":"reviewer","source":"provider"},"recentActivity":[{"at":"2026-07-26T00:00:30.000Z","summary":"kept"}]}'
|
||||
)
|
||||
`;
|
||||
|
||||
yield* runMigrations({ toMigrationInclusive: 44 });
|
||||
|
||||
const rows = yield* sql<{
|
||||
readonly kind: string;
|
||||
readonly role_name: string;
|
||||
readonly role_source: string;
|
||||
readonly activation_count: number;
|
||||
readonly usage_type: string;
|
||||
readonly activity_count: number;
|
||||
}>`
|
||||
SELECT
|
||||
json_extract(payload_json, '$.kind') AS kind,
|
||||
json_extract(payload_json, '$.role.name') AS role_name,
|
||||
json_extract(payload_json, '$.role.source') AS role_source,
|
||||
json_extract(payload_json, '$.activationCount') AS activation_count,
|
||||
json_type(payload_json, '$.usage') AS usage_type,
|
||||
json_array_length(json_extract(payload_json, '$.recentActivity')) AS activity_count
|
||||
FROM orchestration_v2_projection_subagents
|
||||
WHERE subagent_id = 'node:legacy-subagent'
|
||||
`;
|
||||
assert.deepStrictEqual(rows, [
|
||||
{
|
||||
kind: "subagent",
|
||||
role_name: "general-purpose",
|
||||
role_source: "app_default",
|
||||
activation_count: 1,
|
||||
usage_type: "null",
|
||||
activity_count: 0,
|
||||
},
|
||||
]);
|
||||
|
||||
const currentRows = yield* sql<{
|
||||
readonly kind: string;
|
||||
readonly role_name: string;
|
||||
readonly role_source: string;
|
||||
readonly total_tokens: number;
|
||||
readonly current_activation_id: string;
|
||||
readonly activation_count: number;
|
||||
readonly activity_summary: string;
|
||||
}>`
|
||||
SELECT
|
||||
json_extract(payload_json, '$.kind') AS kind,
|
||||
json_extract(payload_json, '$.role.name') AS role_name,
|
||||
json_extract(payload_json, '$.role.source') AS role_source,
|
||||
json_extract(payload_json, '$.usage.totalTokens') AS total_tokens,
|
||||
json_extract(payload_json, '$.currentActivationId') AS current_activation_id,
|
||||
json_extract(payload_json, '$.activationCount') AS activation_count,
|
||||
json_extract(payload_json, '$.recentActivity[0].summary') AS activity_summary
|
||||
FROM orchestration_v2_projection_subagents
|
||||
WHERE subagent_id = 'node:current-subagent'
|
||||
`;
|
||||
assert.deepStrictEqual(currentRows, [
|
||||
{
|
||||
kind: "workflow_agent",
|
||||
role_name: "researcher",
|
||||
role_source: "provider",
|
||||
total_tokens: 12,
|
||||
current_activation_id: "activation:current",
|
||||
activation_count: 2,
|
||||
activity_summary: "kept",
|
||||
},
|
||||
]);
|
||||
|
||||
// A partially-migrated row is the only one that both matches the WHERE
|
||||
// clause and round-trips already-present JSON through COALESCE. If the
|
||||
// JSON subtype were lost there, structured values would be rewritten as
|
||||
// quoted strings and the payload would stop decoding — the same
|
||||
// unreadable-event failure this migration exists to avoid.
|
||||
const mixedRows = yield* sql<{
|
||||
readonly role_type: string;
|
||||
readonly role_name: string;
|
||||
readonly activity_type: string;
|
||||
readonly activity_summary: string;
|
||||
readonly usage_type: string;
|
||||
readonly kind: string;
|
||||
readonly activation_count: number;
|
||||
}>`
|
||||
SELECT
|
||||
json_type(payload_json, '$.role') AS role_type,
|
||||
json_extract(payload_json, '$.role.name') AS role_name,
|
||||
json_type(payload_json, '$.recentActivity') AS activity_type,
|
||||
json_extract(payload_json, '$.recentActivity[0].summary') AS activity_summary,
|
||||
json_type(payload_json, '$.usage') AS usage_type,
|
||||
json_extract(payload_json, '$.kind') AS kind,
|
||||
json_extract(payload_json, '$.activationCount') AS activation_count
|
||||
FROM orchestration_v2_projection_subagents
|
||||
WHERE subagent_id = 'node:mixed-subagent'
|
||||
`;
|
||||
assert.deepStrictEqual(mixedRows, [
|
||||
{
|
||||
role_type: "object",
|
||||
role_name: "reviewer",
|
||||
activity_type: "array",
|
||||
activity_summary: "kept",
|
||||
usage_type: "null",
|
||||
kind: "subagent",
|
||||
activation_count: 1,
|
||||
},
|
||||
]);
|
||||
|
||||
const activationTable = yield* sql<{ readonly name: string }>`
|
||||
SELECT name
|
||||
FROM sqlite_master
|
||||
WHERE type = 'table'
|
||||
AND name = 'orchestration_v2_projection_subagent_activations'
|
||||
`;
|
||||
assert.lengthOf(activationTable, 1);
|
||||
}),
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,50 @@
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as SqlClient from "effect/unstable/sql/SqlClient";
|
||||
|
||||
export default Effect.gen(function* () {
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
|
||||
yield* sql`
|
||||
CREATE TABLE orchestration_v2_projection_subagent_activations (
|
||||
activation_id TEXT PRIMARY KEY,
|
||||
thread_id TEXT NOT NULL,
|
||||
subagent_id TEXT NOT NULL,
|
||||
run_id TEXT,
|
||||
provider_turn_id TEXT,
|
||||
ordinal INTEGER NOT NULL,
|
||||
status TEXT NOT NULL,
|
||||
started_at TEXT,
|
||||
completed_at TEXT,
|
||||
updated_at TEXT NOT NULL,
|
||||
payload_json TEXT NOT NULL
|
||||
)
|
||||
`;
|
||||
yield* sql`CREATE INDEX orchestration_v2_projection_subagent_activations_thread_idx ON orchestration_v2_projection_subagent_activations(thread_id, subagent_id, ordinal)`;
|
||||
yield* sql`CREATE INDEX orchestration_v2_projection_subagent_activations_run_idx ON orchestration_v2_projection_subagent_activations(run_id, status)`;
|
||||
|
||||
yield* sql`
|
||||
UPDATE orchestration_v2_projection_subagents
|
||||
SET payload_json = json_set(
|
||||
payload_json,
|
||||
'$.kind', COALESCE(json_extract(payload_json, '$.kind'), 'subagent'),
|
||||
'$.role', COALESCE(
|
||||
json_extract(payload_json, '$.role'),
|
||||
json_object('name', 'general-purpose', 'source', 'app_default')
|
||||
),
|
||||
'$.usage', json_extract(payload_json, '$.usage'),
|
||||
'$.currentActivationId', json_extract(payload_json, '$.currentActivationId'),
|
||||
'$.activationCount', COALESCE(json_extract(payload_json, '$.activationCount'), 1),
|
||||
'$.workflow', json_extract(payload_json, '$.workflow'),
|
||||
'$.workflowMembership', json_extract(payload_json, '$.workflowMembership'),
|
||||
'$.recentActivity', COALESCE(json_extract(payload_json, '$.recentActivity'), json_array())
|
||||
)
|
||||
WHERE json_type(payload_json, '$.kind') IS NULL
|
||||
OR json_type(payload_json, '$.role') IS NULL
|
||||
OR json_type(payload_json, '$.usage') IS NULL
|
||||
OR json_type(payload_json, '$.currentActivationId') IS NULL
|
||||
OR json_type(payload_json, '$.activationCount') IS NULL
|
||||
OR json_type(payload_json, '$.workflow') IS NULL
|
||||
OR json_type(payload_json, '$.workflowMembership') IS NULL
|
||||
OR json_type(payload_json, '$.recentActivity') IS NULL
|
||||
`;
|
||||
});
|
||||
Reference in new issue
Block a user