@@ -30,10 +30,7 @@ import { makeDrainableWorker } from "@t3tools/shared/DrainableWorker";
3030
3131import { resolveThreadWorkspaceCwd } from "../../checkpointing/Utils.ts" ;
3232import { increment , orchestrationEventsProcessedTotal } from "../../observability/Metrics.ts" ;
33- import {
34- ProviderAdapterRequestError ,
35- ProviderAdapterValidationError ,
36- } from "../../provider/Errors.ts" ;
33+ import { ProviderAdapterRequestError } from "../../provider/Errors.ts" ;
3734import type { ProviderServiceError } from "../../provider/Errors.ts" ;
3835import { TextGeneration } from "../../textGeneration/TextGeneration.ts" ;
3936import { ProviderService } from "../../provider/Services/ProviderService.ts" ;
@@ -53,7 +50,6 @@ import {
5350import { VcsStatusBroadcaster } from "../../vcs/VcsStatusBroadcaster.ts" ;
5451import { GitWorkflowService } from "../../git/GitWorkflowService.ts" ;
5552const isProviderAdapterRequestError = Schema . is ( ProviderAdapterRequestError ) ;
56- const isProviderAdapterValidationError = Schema . is ( ProviderAdapterValidationError ) ;
5753const isProviderDriverKind = Schema . is ( ProviderDriverKind ) ;
5854
5955type ProviderIntentEvent = Extract <
@@ -76,10 +72,6 @@ function toNonEmptyProviderInput(value: string | undefined): string | undefined
7672 return normalized && normalized . length > 0 ? normalized : undefined ;
7773}
7874
79- const isCompactCommandMessage = ( message : ThreadTitleMessage ) : boolean =>
80- message . role === "user" &&
81- ( message . attachments ?. length ?? 0 ) === 0 &&
82- message . text . trim ( ) . toLowerCase ( ) === "/compact" ;
8375function mapProviderSessionStatusToOrchestrationStatus (
8476 status : "connecting" | "ready" | "running" | "error" | "closed" ,
8577) : OrchestrationSession [ "status" ] {
@@ -340,7 +332,6 @@ const make = Effect.gen(function* () {
340332 ) ;
341333
342334 const threadModelSelections = new Map < string , ModelSelection > ( ) ;
343- const compactingThreadIds = new Set < ThreadId > ( ) ;
344335
345336 const appendProviderFailureActivity = ( input : {
346337 readonly threadId : ThreadId ;
@@ -384,11 +375,11 @@ const make = Effect.gen(function* () {
384375
385376 const formatFailureDetail = ( cause : Cause . Cause < unknown > ) : string => {
386377 const failReason = cause . reasons . find ( Cause . isFailReason ) ;
387- if ( isProviderAdapterRequestError ( failReason ?. error ) ) {
388- return failReason . error . detail ;
389- }
390- if ( isProviderAdapterValidationError ( failReason ?. error ) ) {
391- return failReason . error . issue ;
378+ const providerError = isProviderAdapterRequestError ( failReason ?. error )
379+ ? failReason . error
380+ : undefined ;
381+ if ( providerError ) {
382+ return providerError . detail ;
392383 }
393384 return Cause . pretty ( cause ) ;
394385 } ;
@@ -1146,6 +1137,7 @@ const make = Effect.gen(function* () {
11461137 if ( ! thread ) {
11471138 return ;
11481139 }
1140+
11491141 const message = thread . messages . find ( ( entry ) => entry . id === event . payload . messageId ) ;
11501142 if ( ! message || message . role !== "user" ) {
11511143 yield * appendProviderFailureActivity ( {
@@ -1155,28 +1147,15 @@ const make = Effect.gen(function* () {
11551147 detail : `User message '${ event . payload . messageId } ' was not found for turn start request.` ,
11561148 turnId : null ,
11571149 createdAt : event . payload . createdAt ,
1158- requestId : event . payload . messageId ,
11591150 } ) ;
11601151 return ;
11611152 }
1162- const appendTurnStartFailure = ( summary : string , detail : string ) =>
1163- appendProviderFailureActivity ( {
1164- threadId : event . payload . threadId ,
1165- kind : "provider.turn.start.failed" ,
1166- summary,
1167- detail,
1168- turnId : null ,
1169- createdAt : event . payload . createdAt ,
1170- requestId : event . payload . messageId ,
1171- } ) ;
11721153
11731154 yield * ensureThreadWorktree ( thread ) ;
11741155
1175- const isCompactCommand = isCompactCommandMessage ( message ) ;
1176- const nonCompactUserMessageCount = thread . messages . filter (
1177- ( entry ) => entry . role === "user" && ! isCompactCommandMessage ( entry ) ,
1178- ) . length ;
1179- if ( nonCompactUserMessageCount === 1 && ! isCompactCommand ) {
1156+ const isFirstUserMessageTurn =
1157+ thread . messages . filter ( ( entry ) => entry . role === "user" ) . length === 1 ;
1158+ if ( isFirstUserMessageTurn ) {
11801159 const project = yield * resolveProject ( thread . projectId ) ;
11811160 const generationCwd =
11821161 resolveThreadWorkspaceCwd ( {
@@ -1215,7 +1194,16 @@ const make = Effect.gen(function* () {
12151194 detail,
12161195 createdAt : event . payload . createdAt ,
12171196 } ) . pipe (
1218- Effect . flatMap ( ( ) => appendTurnStartFailure ( "Provider turn start failed" , detail ) ) ,
1197+ Effect . flatMap ( ( ) =>
1198+ appendProviderFailureActivity ( {
1199+ threadId : event . payload . threadId ,
1200+ kind : "provider.turn.start.failed" ,
1201+ summary : "Provider turn start failed" ,
1202+ detail,
1203+ turnId : null ,
1204+ createdAt : event . payload . createdAt ,
1205+ } ) ,
1206+ ) ,
12191207 Effect . asVoid ,
12201208 ) ;
12211209 } ;
@@ -1232,69 +1220,6 @@ const make = Effect.gen(function* () {
12321220 ) ,
12331221 ) ;
12341222
1235- const handleCompactionFailure = ( cause : Cause . Cause < unknown > ) => {
1236- if ( Cause . hasInterruptsOnly ( cause ) ) {
1237- return Effect . void ;
1238- }
1239- const detail = formatFailureDetail ( cause ) ;
1240- return appendTurnStartFailure ( "Context compaction failed" , detail ) . pipe ( Effect . asVoid ) ;
1241- } ;
1242- const recoverCompactionFailure = ( cause : Cause . Cause < unknown > ) =>
1243- handleCompactionFailure ( cause ) . pipe (
1244- Effect . catchCause ( ( recoveryCause ) =>
1245- Effect . logWarning ( "provider command reactor failed to recover compaction failure" , {
1246- eventType : event . type ,
1247- threadId : event . payload . threadId ,
1248- cause : Cause . pretty ( recoveryCause ) ,
1249- originalCause : Cause . pretty ( cause ) ,
1250- } ) ,
1251- ) ,
1252- ) ;
1253- if ( isCompactCommand ) {
1254- if ( nonCompactUserMessageCount === 0 ) {
1255- return yield * appendTurnStartFailure (
1256- "Context compaction failed" ,
1257- "Context compaction requires an existing conversation." ,
1258- ) ;
1259- }
1260- const latestThread = yield * resolveThread ( event . payload . threadId ) ;
1261- if (
1262- compactingThreadIds . has ( event . payload . threadId ) ||
1263- latestThread ?. session ?. status === "starting" ||
1264- latestThread ?. session ?. status === "running"
1265- ) {
1266- yield * appendTurnStartFailure (
1267- "Context compaction failed" ,
1268- "Context compaction is unavailable while a provider turn is running." ,
1269- ) ;
1270- return ;
1271- }
1272- compactingThreadIds . add ( event . payload . threadId ) ;
1273- yield * Effect . gen ( function * ( ) {
1274- yield * ensureSessionForThread (
1275- event . payload . threadId ,
1276- event . payload . createdAt ,
1277- event . payload . modelSelection !== undefined
1278- ? { modelSelection : event . payload . modelSelection }
1279- : undefined ,
1280- ) ;
1281- if ( event . payload . modelSelection !== undefined ) {
1282- threadModelSelections . set ( event . payload . threadId , event . payload . modelSelection ) ;
1283- }
1284- yield * providerService . compactThread ( event . payload . threadId , event . payload . modelSelection ) ;
1285- } ) . pipe (
1286- Effect . catchCause ( recoverCompactionFailure ) ,
1287- Effect . ensuring ( Effect . sync ( ( ) => void compactingThreadIds . delete ( event . payload . threadId ) ) ) ,
1288- Effect . forkScoped ,
1289- ) ;
1290- return ;
1291- }
1292- if ( compactingThreadIds . has ( event . payload . threadId ) ) {
1293- return yield * appendTurnStartFailure (
1294- "Provider turn start failed" ,
1295- "Wait for context compaction to finish before sending another message." ,
1296- ) ;
1297- }
12981223 const sendTurnRequest = yield * buildSendTurnRequestForThread ( {
12991224 threadId : event . payload . threadId ,
13001225 messageText : message . text ,
@@ -1315,7 +1240,7 @@ const make = Effect.gen(function* () {
13151240
13161241 yield * providerService
13171242 . sendTurn ( sendTurnRequest . value )
1318- . pipe ( Effect . asVoid , Effect . catchCause ( recoverTurnStartFailure ) , Effect . forkScoped ) ;
1243+ . pipe ( Effect . catchCause ( recoverTurnStartFailure ) , Effect . forkScoped ) ;
13191244 } ) ;
13201245
13211246 const processTurnInterruptRequested = Effect . fn ( "processTurnInterruptRequested" ) ( function * (
0 commit comments