@@ -26,6 +26,7 @@ import {
2626 TurnId ,
2727} from "@t3tools/contracts" ;
2828import * as Clock from "effect/Clock" ;
29+ import * as ConfigProvider from "effect/ConfigProvider" ;
2930import * as Deferred from "effect/Deferred" ;
3031import * as Effect from "effect/Effect" ;
3132import * as Exit from "effect/Exit" ;
@@ -271,6 +272,7 @@ describe("ProviderRuntimeIngestion", () => {
271272 threadTitle ?: string ;
272273 workspaceSubdirectory ?: string ;
273274 isGitRepository ?: CheckpointStore . CheckpointStore [ "Service" ] [ "isGitRepository" ] ;
275+ strictProviderLifecycleGuard ?: boolean ;
274276 } ) {
275277 const repositoryRoot = makeTempDir ( "t3-provider-project-" ) ;
276278 NodeChildProcess . execFileSync ( "git" , [ "init" , "--initial-branch=main" ] , {
@@ -342,6 +344,20 @@ describe("ProviderRuntimeIngestion", () => {
342344 ) ,
343345 Layer . provideMerge ( VcsProcess . layer ) ,
344346 Layer . provideMerge ( ServerConfig . layerTest ( process . cwd ( ) , process . cwd ( ) ) ) ,
347+ Layer . provideMerge (
348+ ConfigProvider . layer (
349+ ConfigProvider . fromEnv ( {
350+ env :
351+ options ?. strictProviderLifecycleGuard === undefined
352+ ? { }
353+ : {
354+ T3CODE_STRICT_PROVIDER_LIFECYCLE_GUARD : String (
355+ options . strictProviderLifecycleGuard ,
356+ ) ,
357+ } ,
358+ } ) ,
359+ ) ,
360+ ) ,
345361 Layer . provideMerge ( NodeServices . layer ) ,
346362 Layer . provideMerge ( Layer . succeed ( Tracer . Tracer , sqlCounter . tracer ) ) ,
347363 ) ;
@@ -1359,6 +1375,39 @@ describe("ProviderRuntimeIngestion", () => {
13591375 ) ;
13601376 } ) ;
13611377
1378+ it ( "applies non-active lifecycle events when strict guarding is disabled" , async ( ) => {
1379+ const harness = await createHarness ( { strictProviderLifecycleGuard : false } ) ;
1380+ const now = "2026-01-01T00:00:00.000Z" ;
1381+
1382+ harness . emit ( {
1383+ type : "turn.started" ,
1384+ eventId : asEventId ( "evt-turn-started-non-strict" ) ,
1385+ provider : ProviderDriverKind . make ( "codex" ) ,
1386+ createdAt : now ,
1387+ threadId : asThreadId ( "thread-1" ) ,
1388+ turnId : asTurnId ( "turn-non-strict-main" ) ,
1389+ } ) ;
1390+ await waitForThread (
1391+ harness . readModel ,
1392+ ( thread ) => thread . session ?. activeTurnId === "turn-non-strict-main" ,
1393+ ) ;
1394+
1395+ harness . emit ( {
1396+ type : "turn.completed" ,
1397+ eventId : asEventId ( "evt-turn-completed-non-strict" ) ,
1398+ provider : ProviderDriverKind . make ( "codex" ) ,
1399+ createdAt : now ,
1400+ threadId : asThreadId ( "thread-1" ) ,
1401+ turnId : asTurnId ( "turn-non-strict-other" ) ,
1402+ status : "completed" ,
1403+ } ) ;
1404+
1405+ await waitForThread (
1406+ harness . readModel ,
1407+ ( thread ) => thread . session ?. status === "ready" && thread . session ?. activeTurnId === null ,
1408+ ) ;
1409+ } ) ;
1410+
13621411 it ( "ignores provider content deltas that cannot change thread state" , async ( ) => {
13631412 const harness = await createHarness ( ) ;
13641413 const initial = await harness . readModel ( ) ;
0 commit comments