@@ -159,6 +159,7 @@ describe("ProviderCommandReactor", () => {
159159 readonly titleRegenerationBeforeStart ?: "one" | "two" ;
160160 readonly interruptTurnEffect ?: ( ) => Effect . Effect < void , ProviderAdapterRequestError > ;
161161 readonly stopSessionEffect ?: ( ) => Effect . Effect < void , ProviderAdapterRequestError > ;
162+ readonly compactThreadEffect ?: ( ) => Effect . Effect < void , ProviderAdapterRequestError > ;
162163 readonly startSessionEffect ?: (
163164 session : ProviderSession ,
164165 ) => Effect . Effect < ProviderSession , ProviderAdapterRequestError > ;
@@ -244,6 +245,9 @@ describe("ProviderCommandReactor", () => {
244245 turnId : asTurnId ( "turn-1" ) ,
245246 } ) ,
246247 ) ;
248+ const compactThread = vi . fn < ProviderServiceShape [ "compactThread" ] > (
249+ ( ) => input ?. compactThreadEffect ?.( ) ?? Effect . void ,
250+ ) ;
247251 const interruptTurn = vi . fn ( ( _ : unknown ) => input ?. interruptTurnEffect ?.( ) ?? Effect . void ) ;
248252 const respondToRequest = vi . fn < ProviderServiceShape [ "respondToRequest" ] > ( ( ) => Effect . void ) ;
249253 const respondToUserInput = vi . fn < ProviderServiceShape [ "respondToUserInput" ] > ( ( ) => Effect . void ) ;
@@ -330,6 +334,7 @@ describe("ProviderCommandReactor", () => {
330334 const service : ProviderServiceShape = {
331335 startSession : startSession as ProviderServiceShape [ "startSession" ] ,
332336 sendTurn : sendTurn as ProviderServiceShape [ "sendTurn" ] ,
337+ compactThread,
333338 interruptTurn : interruptTurn as ProviderServiceShape [ "interruptTurn" ] ,
334339 respondToRequest : respondToRequest as ProviderServiceShape [ "respondToRequest" ] ,
335340 respondToUserInput : respondToUserInput as ProviderServiceShape [ "respondToUserInput" ] ,
@@ -560,6 +565,7 @@ describe("ProviderCommandReactor", () => {
560565 readModel : ( ) => Effect . runPromise ( snapshotQuery . getSnapshot ( ) ) ,
561566 startSession,
562567 sendTurn,
568+ compactThread,
563569 interruptTurn,
564570 respondToRequest,
565571 respondToUserInput,
@@ -665,6 +671,73 @@ describe("ProviderCommandReactor", () => {
665671 expect ( thread ?. session ?. runtimeMode ) . toBe ( "approval-required" ) ;
666672 } ) ;
667673
674+ it ( "routes /compact through provider compaction without starting a normal turn" , async ( ) => {
675+ const harness = await createHarness ( ) ;
676+ const threadId = ThreadId . make ( "thread-1" ) ;
677+ const now = "2026-01-01T00:00:00.000Z" ;
678+
679+ await harness . runEffect (
680+ harness . engine . dispatch ( {
681+ type : "thread.turn.start" ,
682+ commandId : CommandId . make ( "cmd-before-compact" ) ,
683+ threadId,
684+ message : {
685+ messageId : asMessageId ( "message-before-compact" ) ,
686+ role : "user" ,
687+ text : "Build the feature" ,
688+ } ,
689+ interactionMode : DEFAULT_PROVIDER_INTERACTION_MODE ,
690+ runtimeMode : "approval-required" ,
691+ createdAt : now ,
692+ } ) ,
693+ ) ;
694+ await waitFor ( ( ) => harness . sendTurn . mock . calls . length === 1 ) ;
695+ await harness . runEffect (
696+ harness . engine . dispatch ( {
697+ type : "thread.session.set" ,
698+ commandId : CommandId . make ( "cmd-ready-before-compact" ) ,
699+ threadId,
700+ session : {
701+ threadId,
702+ status : "ready" ,
703+ providerName : "codex" ,
704+ providerInstanceId : ProviderInstanceId . make ( "codex" ) ,
705+ runtimeMode : "approval-required" ,
706+ activeTurnId : null ,
707+ lastError : null ,
708+ updatedAt : "2026-01-01T00:00:01.000Z" ,
709+ } ,
710+ createdAt : "2026-01-01T00:00:01.000Z" ,
711+ } ) ,
712+ ) ;
713+
714+ await harness . runEffect (
715+ harness . engine . dispatch ( {
716+ type : "thread.turn.start" ,
717+ commandId : CommandId . make ( "cmd-compact" ) ,
718+ threadId,
719+ message : {
720+ messageId : asMessageId ( "message-compact" ) ,
721+ role : "user" ,
722+ text : "/compact" ,
723+ } ,
724+ interactionMode : DEFAULT_PROVIDER_INTERACTION_MODE ,
725+ runtimeMode : "approval-required" ,
726+ createdAt : "2026-01-01T00:00:02.000Z" ,
727+ } ) ,
728+ ) ;
729+
730+ await waitFor ( ( ) => harness . compactThread . mock . calls . length === 1 ) ;
731+ await harness . drain ( ) ;
732+ expect ( harness . compactThread ) . toHaveBeenCalledWith (
733+ threadId ,
734+ undefined ,
735+ asMessageId ( "message-compact" ) ,
736+ ) ;
737+ expect ( harness . sendTurn ) . toHaveBeenCalledTimes ( 1 ) ;
738+ await waitFor ( async ( ) => ( await harness . readModel ( ) ) . threads [ 0 ] ?. session ?. status === "ready" ) ;
739+ } ) ;
740+
668741 effectIt . effect ( "projects starting before a slow provider session finishes" , ( ) =>
669742 Effect . gen ( function * ( ) {
670743 const releaseStart = yield * Deferred . make < void > ( ) ;
0 commit comments