From 06829caa73a40173d0528c8ee3042ec12732be15 Mon Sep 17 00:00:00 2001 From: Shivam Sharma <91240327+shivamhwp@users.noreply.github.com> Date: Wed, 29 Jul 2026 01:52:21 +0530 Subject: [PATCH] refactor(orchestration-v2): hoist the new schema decoders to module scope The lint rule the CI Check job enforces flags a compiled decoder rebuilt on every call. The activation payload decoder and the subagent decoders this PR added were inline, which took the branch from the base's 67 lint warnings to 73 and failed the job. Co-Authored-By: Claude Opus 5 (1M context) --- .../src/orchestration-v2/ProjectionStore.ts | 7 +++-- .../contracts/src/orchestrationV2.test.ts | 26 ++++++++++++------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/apps/server/src/orchestration-v2/ProjectionStore.ts b/apps/server/src/orchestration-v2/ProjectionStore.ts index 83642b7d23..72521c4511 100644 --- a/apps/server/src/orchestration-v2/ProjectionStore.ts +++ b/apps/server/src/orchestration-v2/ProjectionStore.ts @@ -493,10 +493,9 @@ 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 decodeSubagentActivationPayload = Schema.decodeUnknownEffect( + Schema.fromJsonString(OrchestrationV2SubagentActivationJsonSchema), +); const decodeProviderSessionPayload = (json: string) => Schema.decodeUnknownEffect(Schema.fromJsonString(OrchestrationV2ProviderSessionJsonSchema))(json); const decodeProviderThreadPayload = (json: string) => diff --git a/packages/contracts/src/orchestrationV2.test.ts b/packages/contracts/src/orchestrationV2.test.ts index 318617e268..cdf34e9121 100644 --- a/packages/contracts/src/orchestrationV2.test.ts +++ b/packages/contracts/src/orchestrationV2.test.ts @@ -47,6 +47,16 @@ const LegacyShellStreamItem = Schema.Union([ const decodeLegacyShellStreamItem = Schema.decodeUnknownSync(LegacyShellStreamItem); const decodeOrchestrationV2Command = Schema.decodeUnknownSync(OrchestrationV2Command); const decodeOrchestrationV2TurnItem = Schema.decodeUnknownSync(OrchestrationV2TurnItem); +const decodeOrchestrationV2Subagent = Schema.decodeUnknownSync(OrchestrationV2Subagent); +const decodeOrchestrationV2SubagentActivation = Schema.decodeUnknownSync( + OrchestrationV2SubagentActivation, +); +const decodeOrchestrationV2DomainEventJson = Schema.decodeUnknownSync( + OrchestrationV2DomainEventJson, +); +const decodeStoredOrchestrationV2Subagent = Schema.decodeUnknownSync( + Schema.fromJsonString(OrchestrationV2SubagentJson), +); describe("orchestration V2 contracts", () => { it("lets legacy snapshot decoders ignore enrichment metadata", () => { @@ -397,7 +407,7 @@ describe("orchestration V2 contracts", () => { }); it("decodes provider-native subagent lifecycle records and timeline items", () => { - const subagent = Schema.decodeUnknownSync(OrchestrationV2Subagent)({ + const subagent = decodeOrchestrationV2Subagent({ id: "node-subagent-1", threadId: "thread-1", runId: "run-1", @@ -436,7 +446,7 @@ describe("orchestration V2 contracts", () => { completedAt: now, updatedAt: now, }); - const activation = Schema.decodeUnknownSync(OrchestrationV2SubagentActivation)({ + const activation = decodeOrchestrationV2SubagentActivation({ id: "node-subagent-1:activation:2", threadId: "thread-1", subagentId: subagent.id, @@ -460,8 +470,8 @@ describe("orchestration V2 contracts", () => { recentActivity: _recentActivity, ...legacySubagent } = subagent; - const decodedLegacySubagent = Schema.decodeUnknownSync(OrchestrationV2Subagent)(legacySubagent); - const decodedLegacyEvent = Schema.decodeUnknownSync(OrchestrationV2DomainEventJson)({ + const decodedLegacySubagent = decodeOrchestrationV2Subagent(legacySubagent); + const decodedLegacyEvent = decodeOrchestrationV2DomainEventJson({ id: "event-legacy-subagent", type: "subagent.updated", threadId: "thread-1", @@ -477,7 +487,7 @@ describe("orchestration V2 contracts", () => { updatedAt: DateTime.formatIso(now), }, }); - const decodedActivityEvent = Schema.decodeUnknownSync(OrchestrationV2DomainEventJson)({ + const decodedActivityEvent = decodeOrchestrationV2DomainEventJson({ id: "event-subagent-activity", type: "subagent.updated", threadId: "thread-1", @@ -579,9 +589,7 @@ describe("orchestration V2 contracts", () => { }); // The projection reads stored rows through exactly this schema. - const decoded = Schema.decodeUnknownSync(Schema.fromJsonString(OrchestrationV2SubagentJson))( - legacyPayloadJson, - ); + const decoded = decodeStoredOrchestrationV2Subagent(legacyPayloadJson); expect(decoded.kind).toBe("subagent"); expect(decoded.role).toEqual({ name: "general-purpose", source: "app_default" }); @@ -615,7 +623,7 @@ describe("orchestration V2 contracts", () => { completedAt: null, updatedAt: now, }; - const decode = Schema.decodeUnknownSync(OrchestrationV2Subagent); + const decode = decodeOrchestrationV2Subagent; // Legacy records predate the field and must behave as settled_only. expect(decode(appOwnedSubagent).completionWake).toBeUndefined();