@@ -2,6 +2,7 @@ import { CommandId, ThreadId, type ChatAttachment, type ProjectId } from "@t3too
22import { isTemporaryWorktreeBranch } from "@t3tools/shared/git" ;
33import { resolveProjectSettings } from "@t3tools/shared/projectSettings" ;
44import * as Context from "effect/Context" ;
5+ import * as Duration from "effect/Duration" ;
56import * as Effect from "effect/Effect" ;
67import * as Layer from "effect/Layer" ;
78import * as Ref from "effect/Ref" ;
@@ -27,7 +28,6 @@ type NamingInput = {
2728 readonly message : {
2829 readonly text : string ;
2930 readonly attachments : ReadonlyArray < ChatAttachment > ;
30- readonly context ?: string ;
3131 } ;
3232} ;
3333
@@ -83,7 +83,6 @@ const make = Effect.gen(function* () {
8383 cwd,
8484 message : input . message . text ,
8585 attachments : input . message . attachments ,
86- ...( input . message . context ? { context : input . message . context } : { } ) ,
8786 modelSelection,
8887 } ) ;
8988 const sharing = ( branch : string ) =>
@@ -150,9 +149,29 @@ const make = Effect.gen(function* () {
150149 newBranch : oldBranch ,
151150 exactName : true ,
152151 } ) ;
153- for ( const thread of yield * sharing ( renamed . branch ) ) {
154- yield * update ( thread . id , renamed . branch , oldBranch , "branch-rollback" ) ;
155- }
152+ // Git is already restored; retry only metadata reads and guarded writes.
153+ yield * Effect . gen ( function * ( ) {
154+ const visited = new Set < ThreadId > ( ) ;
155+ while ( true ) {
156+ const remaining = yield * sharing ( renamed . branch ) ;
157+ if ( remaining . length === 0 ) break ;
158+ for ( const thread of remaining ) {
159+ if ( visited . has ( thread . id ) )
160+ return yield * new BranchMetadataPublicationStalled ( { threadId : thread . id } ) ;
161+ visited . add ( thread . id ) ;
162+ yield * update ( thread . id , renamed . branch , oldBranch , "branch-rollback" ) ;
163+ }
164+ }
165+ } ) . pipe (
166+ Effect . retry ( {
167+ while : ( error ) => error . _tag !== "BranchMetadataPublicationStalled" ,
168+ schedule : Schedule . exponential ( "100 millis" ) . pipe (
169+ Schedule . modifyDelay ( ( { duration } ) =>
170+ Effect . succeed ( Math . min ( Duration . toMillis ( duration ) , 5000 ) ) ,
171+ ) ,
172+ ) ,
173+ } ) ,
174+ ) ;
156175 return yield * Effect . failCause ( cause ) ;
157176 } ) ,
158177 ) ,
0 commit comments