@@ -377,6 +377,117 @@ describe("ThreadPullRequestServiceV2 reads", () => {
377377 ) ,
378378 ) ;
379379
380+ it . effect (
381+ "backfills only the last seven days of settled threads and keeps discovering unsettled threads" ,
382+ ( ) =>
383+ Effect . scoped (
384+ Effect . gen ( function * ( ) {
385+ yield * TestClock . setTime ( DateTime . toEpochMillis ( NOW ) ) ;
386+ const boundary = DateTime . subtract ( NOW , { days : 7 } ) ;
387+ const old = DateTime . subtract ( boundary , { milliseconds : 1 } ) ;
388+ const threads = [
389+ { id : "recent" , settledAt : NOW } ,
390+ { id : "boundary" , settledAt : boundary } ,
391+ { id : "old" , settledAt : old , updatedAt : old } ,
392+ // Auto-settle records old activity in settledAt but updates updatedAt now.
393+ { id : "auto-settled" , settledAt : old , updatedAt : NOW } ,
394+ { id : "old-unsettled" , updatedAt : old } ,
395+ { id : "recent-override" , settledOverride : "settled" as const , updatedAt : NOW } ,
396+ { id : "old-override" , settledOverride : "settled" as const , updatedAt : old } ,
397+ ] . map ( ( { id, ...overrides } ) => ( {
398+ ...threadShell ( id ) ,
399+ ...overrides ,
400+ branch : id ,
401+ } ) ) satisfies ReadonlyArray < OrchestrationV2ThreadShell > ;
402+ const project : OrchestrationProjectShell = {
403+ id : ProjectId . make ( "project-1" ) ,
404+ title : "Project" ,
405+ workspaceRoot : "/workspace/project" ,
406+ defaultModelSelection : null ,
407+ scripts : [ ] ,
408+ createdAt : "2026-08-01T00:00:00.000Z" ,
409+ updatedAt : "2026-08-01T00:00:00.000Z" ,
410+ } ;
411+ const activation = yield * Deferred . make < void > ( ) ;
412+ const sweeps = yield * Queue . unbounded < void > ( ) ;
413+ const branches : Array < string > = [ ] ;
414+ const layerDependencies = Layer . mergeAll (
415+ Layer . mock ( Orchestrator . OrchestratorV2 ) ( {
416+ streamDomainEvents : Stream . never ,
417+ getShellSnapshot : ( options ) =>
418+ Queue . offer ( sweeps , undefined ) . pipe (
419+ Effect . as ( {
420+ schemaVersion : 2 ,
421+ snapshotSequence : 1 ,
422+ threads : options ?. unsettledOnly
423+ ? threads . filter (
424+ ( thread ) =>
425+ thread . settledAt === null && thread . settledOverride !== "settled" ,
426+ )
427+ : threads ,
428+ archivedThreads : [ ] ,
429+ } ) ,
430+ ) ,
431+ } ) ,
432+ Layer . mock ( ProjectStore . ProjectStoreV2 ) ( {
433+ listShells : ( ) => Effect . succeed ( [ project ] ) ,
434+ } ) ,
435+ Layer . mock ( GitManager . GitManager ) ( {
436+ branchPullRequest : ( { branch } ) =>
437+ Effect . sync ( ( ) => {
438+ branches . push ( branch ) ;
439+ return null ;
440+ } ) ,
441+ } ) ,
442+ Layer . mock ( PullRequestService . PullRequestService ) ( { } ) ,
443+ Layer . mock ( RepositoryIdentityResolver . RepositoryIdentityResolver ) ( {
444+ resolve : ( ) =>
445+ Effect . succeed ( {
446+ canonicalKey : "github.com/acme/project" ,
447+ locator : {
448+ source : "git-remote" as const ,
449+ remoteName : "origin" ,
450+ remoteUrl :
"[email protected] :acme/project.git" , 451+ } ,
452+ provider : "github" as const ,
453+ owner : "acme" ,
454+ name : "project" ,
455+ } ) ,
456+ } ) ,
457+ Layer . succeed ( ServerActivation . ServerActivation , Deferred . await ( activation ) ) ,
458+ Layer . succeed (
459+ Crypto . Crypto ,
460+ Crypto . make ( {
461+ randomBytes : ( size ) => new Uint8Array ( size ) . fill ( 1 ) ,
462+ digest : ( _algorithm , data ) => Effect . succeed ( data ) ,
463+ } ) ,
464+ ) ,
465+ FileSystem . layerNoop ( { } ) ,
466+ ) ;
467+
468+ yield * Effect . gen ( function * ( ) {
469+ const service = yield * ThreadPullRequestService . make ;
470+ yield * service . start ( ) ;
471+ yield * Deferred . succeed ( activation , undefined ) ;
472+ yield * Queue . take ( sweeps ) ;
473+ yield * service . drain ;
474+ const startupBranches = branches . splice ( 0 ) . sort ( ) ;
475+
476+ yield * TestClock . adjust ( "1 minute" ) ;
477+ yield * Queue . take ( sweeps ) ;
478+ yield * service . drain ;
479+ expect ( branches ) . toEqual ( [ "old-unsettled" ] ) ;
480+ expect ( startupBranches ) . toEqual ( [
481+ "boundary" ,
482+ "old-unsettled" ,
483+ "recent" ,
484+ "recent-override" ,
485+ ] ) ;
486+ } ) . pipe ( Effect . provide ( layerDependencies ) ) ;
487+ } ) ,
488+ ) ,
489+ ) ;
490+
380491 it . effect ( "periodic sweeps read only unsettled threads once backfill is done" , ( ) =>
381492 Effect . scoped (
382493 Effect . gen ( function * ( ) {
0 commit comments