@devries-cameron20 / t3code Mirror · read-only / commits / 1646a47140
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 17:00 UTC

fix(server): orchestrator records command count and duration again (#23966)

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com> Co-authored-by: Julius Marminge <julius0216@outlook.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Yordis Prieto committed Oct 25, 2026 at 17:06 UTC 1646a471409d977eec983cf43277144e606dba84
6 files changed +97 -2
apps/server/src/observability/Metrics.ts
+19
@@ -15,6 +15,14 @@ export const rpcRequestDuration = Metric.timer("t3_rpc_request_duration", {
15 description: "RPC request handling duration.",
16 });
17
18 +export const orchestrationCommandsTotal = Metric.counter("t3_orchestration_commands_total", {
19 + description: "Total orchestration commands dispatched, by outcome.",
20 +});
21 +
22 +export const orchestrationCommandDuration = Metric.timer("t3_orchestration_command_duration", {
23 + description: "Orchestration command handling duration, excluding thread dispatch lock wait.",
24 +});
25 +
26 export const orchestrationEffectClaimsTotal = Metric.counter(
27 "t3_orchestration_effect_claims_total",
28 {
@@ -186,3 +194,14 @@ export const withMetrics: {
194 ): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
195 <A, E, R>(effect: Effect.Effect<A, E, R>, options: WithMetricsOptions): Effect.Effect<A, E, R>;
196 } = dual(2, withMetricsImpl);
197 +
198 +// Shaped as an `Effect.fn` combinator: the command is the instrumented function's argument.
199 +export const withCommandMetrics = <A, E, R>(
200 + effect: Effect.Effect<A, E, R>,
201 + command: { readonly type: string },
202 +): Effect.Effect<A, E, R> =>
203 + withMetrics(effect, {
204 + counter: orchestrationCommandsTotal,
205 + timer: orchestrationCommandDuration,
206 + attributes: { commandType: command.type },
207 + });
apps/server/src/orchestration-v2/Orchestrator.control-reads.test.ts
+40
@@ -21,10 +21,15 @@ import {
21 import * as DateTime from "effect/DateTime";
22 import * as Effect from "effect/Effect";
23 import * as Layer from "effect/Layer";
24 +import * as Metric from "effect/Metric";
25 import * as Result from "effect/Result";
26 import * as Stream from "effect/Stream";
27 import * as TestClock from "effect/testing/TestClock";
28 import * as SqlClient from "effect/sql/SqlClient";
29 +import {
30 + orchestrationCommandDuration,
31 + orchestrationCommandsTotal,
32 +} from "../observability/Metrics.ts";
33 import * as SqlitePersistence from "../persistence/Sqlite.ts";
34 import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts";
35 import * as DelegatedTaskQuestionReactor from "./DelegatedTaskQuestionReactor.ts";
@@ -1368,3 +1373,38 @@ it.effect("explicit settle clears snooze atomically and stays idempotent after r
1373 assert.deepInclude((yield* projections.getThreadProjection(threadId)).thread, active);
1374 }).pipe(Effect.provide(layerTest)),
1375 );
1376 +
1377 +it.effect("dispatch records the command outcome and its duration", () =>
1378 + Effect.gen(function* () {
1379 + const orchestrator = yield* Orchestrator.OrchestratorV2;
1380 + const successes = Metric.value(
1381 + Metric.withAttributes(orchestrationCommandsTotal, {
1382 + commandType: "thread.create",
1383 + outcome: "success",
1384 + }),
1385 + );
1386 + const durations = Metric.value(
1387 + Metric.withAttributes(orchestrationCommandDuration, { commandType: "thread.create" }),
1388 + );
1389 + const successesBefore = (yield* successes).count;
1390 + const durationsBefore = (yield* durations).count;
1391 +
1392 + yield* orchestrator.dispatch({
1393 + type: "thread.create",
1394 + commandId: CommandId.make("create-dispatch-metrics"),
1395 + threadId: ThreadId.make("thread:dispatch-metrics"),
1396 + projectId: ProjectId.make("project:dispatch-metrics"),
1397 + title: "Dispatch metrics",
1398 + modelSelection,
1399 + runtimeMode: "full-access",
1400 + interactionMode: "default",
1401 + branch: null,
1402 + worktreePath: null,
1403 + createdBy: "user",
1404 + creationSource: "web",
1405 + });
1406 +
1407 + assert.strictEqual((yield* successes).count - successesBefore, 1);
1408 + assert.strictEqual((yield* durations).count - durationsBefore, 1);
1409 + }).pipe(Effect.provide(layerTest)),
1410 +);
apps/server/src/orchestration-v2/Orchestrator.ts
+2 -1
@@ -118,6 +118,7 @@ import {
118 type GuestShareCommand,
119 } from "./GuestShareDecider.ts";
120 import * as EffectOutbox from "./EffectOutbox.ts";
121 +import { withCommandMetrics } from "../observability/Metrics.ts";
122 import type { OrchestrationEffectRequestV2, PendingOrchestrationEffectV2 } from "./EffectOutbox.ts";
123 import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
124 import * as ThreadCommandExecutor from "./ThreadCommandExecutor.ts";
@@ -12116,7 +12117,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
12117 storedEvents: committed.storedEvents,
12118 ...(committed.committed ? {} : { replayed: true as const }),
12119 } satisfies OrchestratorV2DispatchResult;
12119 - });
12120 + }, withCommandMetrics);
12121
12122 // dispatchWithReceiptEffect owns the dispatch span; this wrapper selects the thread locks.
12123 const dispatchWithReceipt = Effect.fnUntraced(function* (command: OrchestrationV2ServerCommand) {
apps/server/src/project/ProjectService.test.ts
+32
@@ -5,12 +5,17 @@ import * as Deferred from "effect/Deferred";
5 import * as Effect from "effect/Effect";
6 import * as Fiber from "effect/Fiber";
7 import * as Layer from "effect/Layer";
8 +import * as Metric from "effect/Metric";
9 import * as Option from "effect/Option";
10 import * as Ref from "effect/Ref";
11 import { TestClock } from "effect/testing";
12 import * as SqlClient from "effect/sql/SqlClient";
13
14 import * as ServerConfig from "../config.ts";
15 +import {
16 + orchestrationCommandDuration,
17 + orchestrationCommandsTotal,
18 +} from "../observability/Metrics.ts";
19 import * as EventSink from "../orchestration-v2/EventSink.ts";
20 import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
21 import * as LegacyV1ThreadImporter from "../orchestration-v2/legacy/LegacyV1ThreadImporter.ts";
@@ -203,6 +208,33 @@ it.layer(layerTest)("ProjectService", (it) => {
208 }),
209 );
210
211 + it.effect("records the outcome and duration of a committed project command", () =>
212 + Effect.gen(function* () {
213 + const service = yield* ProjectService.ProjectService;
214 + const successes = Metric.value(
215 + Metric.withAttributes(orchestrationCommandsTotal, {
216 + commandType: "project.create",
217 + outcome: "success",
218 + }),
219 + );
220 + const durations = Metric.value(
221 + Metric.withAttributes(orchestrationCommandDuration, { commandType: "project.create" }),
222 + );
223 + const successesBefore = (yield* successes).count;
224 + const durationsBefore = (yield* durations).count;
225 +
226 + yield* service.create({
227 + commandId: CommandId.make("command:metrics:create"),
228 + projectId: ProjectId.make("project:metrics"),
229 + title: "Metrics",
230 + workspaceRoot: "/work/metrics",
231 + });
232 +
233 + assert.strictEqual((yield* successes).count - successesBefore, 1);
234 + assert.strictEqual((yield* durations).count - durationsBefore, 1);
235 + }),
236 + );
237 +
238 it.effect("auto-bootstraps a workspace exactly once", () =>
239 Effect.gen(function* () {
240 const service = yield* ProjectService.ProjectService;
apps/server/src/project/ProjectService.ts
+2 -1
@@ -17,6 +17,7 @@ import * as Option from "effect/Option";
17 import * as Result from "effect/Result";
18 import * as Schema from "effect/Schema";
19
20 +import { withCommandMetrics } from "../observability/Metrics.ts";
21 import * as EventSink from "../orchestration-v2/EventSink.ts";
22 import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
23 import * as LegacyV1ThreadImporter from "../orchestration-v2/legacy/LegacyV1ThreadImporter.ts";
@@ -283,7 +284,7 @@ export const make = Effect.gen(function* () {
284 rejection ?? receipt.error ?? "The command was previously rejected.",
285 );
286 }
286 - });
287 + }, withCommandMetrics);
288
289 const readCommitted = Effect.fn("ProjectService.readCommitted")(function* (projectId: ProjectId) {
290 const row = yield* readRow(projectId, { includeDeleted: true });
docs/operations/observability.md
+2
@@ -393,12 +393,14 @@ Traces are best for one request. Metrics are best for trends.
393 Good metric families to watch:
394
395 - `t3_rpc_request_duration`
396 +- `t3_orchestration_command_duration`
397 - `t3_provider_turn_duration` (how long the provider adapter takes to start a turn, not the turn's run time)
398 - `t3_git_command_duration`
399
400 Counters tell you volume and failure rate:
401
402 - `t3_rpc_requests_total`
403 +- `t3_orchestration_commands_total`
404 - `t3_provider_turns_total`
405 - `t3_git_commands_total`
406