@@ -177,6 +177,9 @@ describe("ProviderCommandReactor", () => {
177177 const baseDir =
178178 input ?. baseDir ?? NodeFS . mkdtempSync ( NodePath . join ( NodeOS . tmpdir ( ) , "t3code-reactor-" ) ) ;
179179 createdBaseDirs . add ( baseDir ) ;
180+ const workspaceRoot = NodePath . join ( baseDir , "provider-project" ) ;
181+ const worktreeRoot = NodePath . join ( baseDir , "provider-project-worktree" ) ;
182+ NodeFS . mkdirSync ( workspaceRoot , { recursive : true } ) ;
180183 const { stateDir } = deriveServerPathsSync ( baseDir , undefined ) ;
181184 createdStateDirs . add ( stateDir ) ;
182185 const runtimeEventPubSub = Effect . runSync ( PubSub . unbounded < ProviderRuntimeEvent > ( ) ) ;
@@ -290,7 +293,10 @@ describe("ProviderCommandReactor", () => {
290293 const pruneWorktrees = vi . fn ( ( _ : { readonly cwd : string } ) => Effect . void ) ;
291294 const createWorktree = vi . fn (
292295 ( input : { readonly refName : string ; readonly path : string | null } ) =>
293- Effect . succeed ( { worktree : { path : input . path ?? "" , refName : input . refName } } ) ,
296+ Effect . sync ( ( ) => {
297+ if ( input . path ) NodeFS . mkdirSync ( input . path , { recursive : true } ) ;
298+ return { worktree : { path : input . path ?? "" , refName : input . refName } } ;
299+ } ) ,
294300 ) ;
295301 const refreshStatus = vi . fn ( ( _ : string ) =>
296302 Effect . succeed ( {
@@ -461,7 +467,7 @@ describe("ProviderCommandReactor", () => {
461467 commandId : CommandId . make ( "cmd-project-create" ) ,
462468 projectId : asProjectId ( "project-1" ) ,
463469 title : "Provider Project" ,
464- workspaceRoot : "/tmp/provider-project" ,
470+ workspaceRoot,
465471 defaultModelSelection : modelSelection ,
466472 createdAt : now ,
467473 } ) ,
@@ -544,6 +550,8 @@ describe("ProviderCommandReactor", () => {
544550 generateBranchName,
545551 generateThreadTitle,
546552 runtimeSessions,
553+ workspaceRoot,
554+ worktreeRoot,
547555 stateDir,
548556 drain,
549557 runEffect,
@@ -578,7 +586,7 @@ describe("ProviderCommandReactor", () => {
578586 await waitFor ( ( ) => harness . sendTurn . mock . calls . length === 1 ) ;
579587 expect ( harness . startSession . mock . calls [ 0 ] ?. [ 0 ] ) . toEqual ( ThreadId . make ( "thread-1" ) ) ;
580588 expect ( harness . startSession . mock . calls [ 0 ] ?. [ 1 ] ) . toMatchObject ( {
581- cwd : "/tmp/provider-project" ,
589+ cwd : harness . workspaceRoot ,
582590 modelSelection : {
583591 instanceId : ProviderInstanceId . make ( "codex" ) ,
584592 model : "gpt-5-codex" ,
@@ -593,6 +601,50 @@ describe("ProviderCommandReactor", () => {
593601 expect ( thread ?. session ?. runtimeMode ) . toBe ( "approval-required" ) ;
594602 } ) ;
595603
604+ it ( "reports a missing workspace before starting the provider" , async ( ) => {
605+ const harness = await createHarness ( ) ;
606+ const now = "2026-01-01T00:00:00.000Z" ;
607+ NodeFS . rmSync ( harness . workspaceRoot , { recursive : true } ) ;
608+
609+ await Effect . runPromise (
610+ harness . engine . dispatch ( {
611+ type : "thread.turn.start" ,
612+ commandId : CommandId . make ( "cmd-turn-start-missing-workspace" ) ,
613+ threadId : ThreadId . make ( "thread-1" ) ,
614+ message : {
615+ messageId : asMessageId ( "user-message-missing-workspace" ) ,
616+ role : "user" ,
617+ text : "continue in moved workspace" ,
618+ attachments : [ ] ,
619+ } ,
620+ interactionMode : DEFAULT_PROVIDER_INTERACTION_MODE ,
621+ runtimeMode : "approval-required" ,
622+ createdAt : now ,
623+ } ) ,
624+ ) ;
625+
626+ await waitFor ( async ( ) => {
627+ const readModel = await harness . readModel ( ) ;
628+ const thread = readModel . threads . find ( ( entry ) => entry . id === ThreadId . make ( "thread-1" ) ) ;
629+ return thread ?. session ?. status === "error" ;
630+ } ) ;
631+
632+ expect ( harness . startSession ) . not . toHaveBeenCalled ( ) ;
633+ expect ( harness . sendTurn ) . not . toHaveBeenCalled ( ) ;
634+ const readModel = await harness . readModel ( ) ;
635+ const thread = readModel . threads . find ( ( entry ) => entry . id === ThreadId . make ( "thread-1" ) ) ;
636+ expect ( thread ?. session ?. lastError ) . toBe (
637+ `This thread's workspace folder no longer exists: '${ harness . workspaceRoot } '. Restore the folder before retrying.` ,
638+ ) ;
639+ expect (
640+ thread ?. activities . find ( ( activity ) => activity . kind === "provider.turn.start.failed" ) ,
641+ ) . toMatchObject ( {
642+ payload : {
643+ detail : expect . stringContaining ( harness . workspaceRoot ) ,
644+ } ,
645+ } ) ;
646+ } ) ;
647+
596648 effectIt . effect ( "retains a turn dispatched immediately after start until activation" , ( ) =>
597649 Effect . gen ( function * ( ) {
598650 const activation = yield * Deferred . make < void > ( ) ;
@@ -869,7 +921,7 @@ describe("ProviderCommandReactor", () => {
869921
870922 expect ( harness . generateThreadTitle ) . toHaveBeenCalledTimes ( 1 ) ;
871923 expect ( harness . generateThreadTitle . mock . calls [ 0 ] ?. [ 0 ] ) . toMatchObject ( {
872- cwd : "/tmp/provider-project" ,
924+ cwd : harness . workspaceRoot ,
873925 previousTitle : "Investigate reconnect regressions" ,
874926 message : [
875927 "USER:" ,
@@ -1597,7 +1649,7 @@ describe("ProviderCommandReactor", () => {
15971649 commandId : CommandId . make ( "cmd-thread-branch" ) ,
15981650 threadId : ThreadId . make ( "thread-1" ) ,
15991651 branch : "t3code/1234abcd" ,
1600- worktreePath : "/tmp/provider-project-worktree" ,
1652+ worktreePath : harness . worktreeRoot ,
16011653 } ) ,
16021654 ) ;
16031655
@@ -1639,7 +1691,7 @@ describe("ProviderCommandReactor", () => {
16391691 `Add a safer reconnect backoff. ${ assistantQuoteText } ` ,
16401692 ) ;
16411693 expect ( harness . generateBranchName . mock . calls [ 0 ] ?. [ 0 ] . message ) . not . toContain ( "t3-citation://" ) ;
1642- expect ( harness . refreshStatus . mock . calls [ 0 ] ?. [ 0 ] ) . toBe ( "/tmp/provider-project-worktree" ) ;
1694+ expect ( harness . refreshStatus . mock . calls [ 0 ] ?. [ 0 ] ) . toBe ( harness . worktreeRoot ) ;
16431695 const readModel = await harness . readModel ( ) ;
16441696 expect (
16451697 readModel . threads
@@ -1681,9 +1733,9 @@ describe("ProviderCommandReactor", () => {
16811733 ) ;
16821734
16831735 await waitFor ( ( ) => harness . startSession . mock . calls . length === 1 ) ;
1684- expect ( harness . pruneWorktrees ) . toHaveBeenCalledWith ( { cwd : "/tmp/provider-project" } ) ;
1736+ expect ( harness . pruneWorktrees ) . toHaveBeenCalledWith ( { cwd : harness . workspaceRoot } ) ;
16851737 expect ( harness . createWorktree ) . toHaveBeenCalledWith ( {
1686- cwd : "/tmp/provider-project" ,
1738+ cwd : harness . workspaceRoot ,
16871739 refName : "feature/restore" ,
16881740 path : worktreePath ,
16891741 } ) ;
@@ -2182,15 +2234,16 @@ describe("ProviderCommandReactor", () => {
21822234 await waitFor ( ( ) => harness . startSession . mock . calls . length === 1 ) ;
21832235 await waitFor ( ( ) => harness . sendTurn . mock . calls . length === 1 ) ;
21842236 expect ( harness . startSession . mock . calls [ 0 ] ?. [ 1 ] ) . toMatchObject ( {
2185- cwd : "/tmp/provider-project" ,
2237+ cwd : harness . workspaceRoot ,
21862238 } ) ;
2239+ NodeFS . mkdirSync ( harness . worktreeRoot , { recursive : true } ) ;
21872240
21882241 await Effect . runPromise (
21892242 harness . engine . dispatch ( {
21902243 type : "thread.meta.update" ,
21912244 commandId : CommandId . make ( "cmd-thread-worktree-change" ) ,
21922245 threadId : ThreadId . make ( "thread-1" ) ,
2193- worktreePath : "/tmp/provider-project-worktree" ,
2246+ worktreePath : harness . worktreeRoot ,
21942247 } ) ,
21952248 ) ;
21962249
@@ -2216,7 +2269,7 @@ describe("ProviderCommandReactor", () => {
22162269 expect ( harness . stopSession . mock . calls . length ) . toBe ( 0 ) ;
22172270 expect ( harness . startSession . mock . calls [ 1 ] ?. [ 1 ] ) . toMatchObject ( {
22182271 threadId : ThreadId . make ( "thread-1" ) ,
2219- cwd : "/tmp/provider-project-worktree" ,
2272+ cwd : harness . worktreeRoot ,
22202273 resumeCursor : { opaque : "resume-1" } ,
22212274 modelSelection : {
22222275 instanceId : ProviderInstanceId . make ( "claudeAgent" ) ,
@@ -2961,7 +3014,7 @@ describe("ProviderCommandReactor", () => {
29613014 status : "ready" ,
29623015 runtimeMode : "approval-required" ,
29633016 threadId : ThreadId . make ( "thread-1" ) ,
2964- cwd : "/tmp/provider-project" ,
3017+ cwd : harness . workspaceRoot ,
29653018 resumeCursor : { opaque : "resume-without-instance" } ,
29663019 createdAt : now ,
29673020 updatedAt : now ,
0 commit comments