@@ -21,10 +21,15 @@ import {
2121import * as DateTime from "effect/DateTime" ;
2222import * as Effect from "effect/Effect" ;
2323import * as Layer from "effect/Layer" ;
24+ import * as Metric from "effect/Metric" ;
2425import * as Result from "effect/Result" ;
2526import * as Stream from "effect/Stream" ;
2627import * as TestClock from "effect/testing/TestClock" ;
2728import * as SqlClient from "effect/sql/SqlClient" ;
29+ import {
30+ orchestrationCommandDuration ,
31+ orchestrationCommandsTotal ,
32+ } from "../observability/Metrics.ts" ;
2833import * as SqlitePersistence from "../persistence/Sqlite.ts" ;
2934import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts" ;
3035import * as DelegatedTaskQuestionReactor from "./DelegatedTaskQuestionReactor.ts" ;
@@ -1368,3 +1373,38 @@ it.effect("explicit settle clears snooze atomically and stays idempotent after r
13681373 assert . deepInclude ( ( yield * projections . getThreadProjection ( threadId ) ) . thread , active ) ;
13691374 } ) . pipe ( Effect . provide ( layerTest ) ) ,
13701375) ;
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+ ) ;
0 commit comments