@@ -41,7 +41,7 @@ import * as ServerActivation from "../serverActivation.ts";
4141import * as Orchestrator from "./Orchestrator.ts" ;
4242import * as ProjectionStore from "./ProjectionStore.ts" ;
4343import * as PullRequestSyncReactor from "./PullRequestSyncReactor.ts" ;
44- import type { PullRequestTestThread } from "./testkit/pullRequestFixtures.ts" ;
44+ import { type PullRequestTestThread , v2PullRequestThread } from "./testkit/pullRequestFixtures.ts" ;
4545
4646const NOW = "2026-08-28T12:00:00.000Z" ;
4747const PROJECT_ID = ProjectId . make ( "sync-project" ) ;
@@ -161,6 +161,14 @@ function makeSummary(
161161 } ;
162162}
163163
164+ const missingSummary = Effect . fail (
165+ new PullRequestOperationError ( {
166+ operation : "summary" ,
167+ detail : "Pull request not found" ,
168+ reason : "not-found" ,
169+ } ) ,
170+ ) ;
171+
164172interface HarnessOptions {
165173 readonly invalidate ?: PullRequestService . PullRequestService [ "Service" ] [ "invalidate" ] ;
166174 readonly snapshot : TestShellSnapshot ;
@@ -1262,7 +1270,11 @@ describe("PullRequestSyncReactor", () => {
12621270 makeThread ( "settled" , {
12631271 settledOverride : "settled" ,
12641272 settledAt : "2026-08-21T00:00:00.000Z" ,
1265- pullRequests : [ makeLink ( 5 , { state : "open" } ) , makeLink ( 6 , { state : "closed" } ) ] ,
1273+ pullRequests : [
1274+ makeLink ( 5 , { state : "open" } ) ,
1275+ makeLink ( 6 , { state : "closed" } ) ,
1276+ makeLink ( 7 ) ,
1277+ ] ,
12661278 } ) ,
12671279 ] ) ,
12681280 } ) ;
@@ -1283,7 +1295,7 @@ describe("PullRequestSyncReactor", () => {
12831295 yield * sweepAgain ( fixture , reactor ) ;
12841296 assert . deepStrictEqual (
12851297 ( yield * Ref . get ( fixture . summaryCalls ) ) . map ( ( call ) => call . number ) . toSorted ( ) ,
1286- [ 5 , 6 ] ,
1298+ [ 5 , 6 , 7 ] ,
12871299 ) ;
12881300 } ) . pipe ( Effect . provide ( fixture . layer ) ) ;
12891301 } ) ,
@@ -1519,6 +1531,152 @@ describe("PullRequestSyncReactor", () => {
15191531 ) ,
15201532 ) ;
15211533
1534+ it . effect (
1535+ "retries missing links every fifteen minutes and resumes normal reads after recovery" ,
1536+ ( ) =>
1537+ Effect . scoped (
1538+ Effect . gen ( function * ( ) {
1539+ yield * TestClock . setTime ( Date . parse ( NOW ) ) ;
1540+ const found = yield * Ref . make ( false ) ;
1541+ const fixture = yield * makeHarness ( {
1542+ snapshot : makeSnapshot ( [
1543+ makeThread ( "missing" , { pullRequests : [ makeLink ( 9 ) , makeLink ( 10 , { } ) ] } ) ,
1544+ ] ) ,
1545+ summary : ( input ) =>
1546+ Ref . get ( found ) . pipe (
1547+ Effect . flatMap ( ( available ) =>
1548+ available ? Effect . succeed ( makeSummary ( input ) ) : missingSummary ,
1549+ ) ,
1550+ ) ,
1551+ } ) ;
1552+ yield * Effect . gen ( function * ( ) {
1553+ const reactor = yield * startAndSweep ( fixture ) ;
1554+ assert . strictEqual ( ( yield * Ref . get ( fixture . summaryCalls ) ) . length , 2 ) ;
1555+ for ( let index = 0 ; index < 14 ; index += 1 ) yield * sweepAgain ( fixture , reactor ) ;
1556+ assert . strictEqual ( ( yield * Ref . get ( fixture . summaryCalls ) ) . length , 2 ) ;
1557+ yield * sweepAgain ( fixture , reactor ) ;
1558+ assert . strictEqual ( ( yield * Ref . get ( fixture . summaryCalls ) ) . length , 4 ) ;
1559+ assert . deepStrictEqual ( yield * Ref . get ( fixture . syncCommands ) , [ ] ) ;
1560+
1561+ yield * Ref . set ( found , true ) ;
1562+ for ( let index = 0 ; index < 14 ; index += 1 ) yield * sweepAgain ( fixture , reactor ) ;
1563+ assert . strictEqual ( ( yield * Ref . get ( fixture . summaryCalls ) ) . length , 4 ) ;
1564+ yield * sweepAgain ( fixture , reactor ) ;
1565+ const commands = yield * Ref . get ( fixture . syncCommands ) ;
1566+ assert . deepStrictEqual (
1567+ commands . map ( ( command ) => command . number ) ,
1568+ [ 9 ] ,
1569+ ) ;
1570+ yield * Ref . update ( fixture . snapshots , ( snapshot ) => applySync ( snapshot , commands ) ) ;
1571+ // Recovered quiet open pull requests return to the five-minute cadence.
1572+ for ( let index = 0 ; index < 5 ; index += 1 ) yield * sweepAgain ( fixture , reactor ) ;
1573+ assert . deepStrictEqual (
1574+ ( yield * Ref . get ( fixture . summaryCalls ) )
1575+ . map ( ( call ) => call . number )
1576+ . toSorted ( ( left , right ) => left - right ) ,
1577+ [ 9 , 9 , 9 , 9 , 10 , 10 , 10 , 10 ] ,
1578+ ) ;
1579+ } ) . pipe ( Effect . provide ( fixture . layer ) ) ;
1580+ } ) ,
1581+ ) ,
1582+ ) ;
1583+
1584+ it . effect (
1585+ "holds missing links through sibling and link updates but honors a reader refresh" ,
1586+ ( ) =>
1587+ Effect . scoped (
1588+ Effect . gen ( function * ( ) {
1589+ yield * TestClock . setTime ( Date . parse ( NOW ) ) ;
1590+ const fixture = yield * makeHarness ( {
1591+ snapshot : makeSnapshot ( [ makeThread ( "missing" , { pullRequests : [ makeLink ( 9 ) ] } ) ] ) ,
1592+ summary : ( input ) =>
1593+ input . number === 9 ? missingSummary : Effect . succeed ( makeSummary ( input ) ) ,
1594+ } ) ;
1595+ const missingReads = Ref . get ( fixture . summaryCalls ) . pipe (
1596+ Effect . map ( ( calls ) => calls . filter ( ( call ) => call . number === 9 ) . length ) ,
1597+ ) ;
1598+ yield * Effect . gen ( function * ( ) {
1599+ const reactor = yield * startAndSweep ( fixture ) ;
1600+ const linked = makeThread ( "missing" , { pullRequests : [ makeLink ( 9 ) , makeLink ( 8 ) ] } ) ;
1601+ yield * Ref . set ( fixture . snapshots , makeSnapshot ( [ linked ] ) ) ;
1602+ yield * Queue . offer ( fixture . domainEvents , {
1603+ type : "thread.pull-request-synced" ,
1604+ id : EventId . make ( "sibling-synced" ) ,
1605+ threadId : linked . id ,
1606+ occurredAt : DateTime . makeUnsafe ( NOW ) ,
1607+ payload : { ...v2PullRequestThread ( linked ) , lastVisitedAt : null } ,
1608+ } ) ;
1609+ yield * Queue . take ( fixture . snapshotReads ) ;
1610+ yield * reactor . drain ;
1611+ const afterSiblingSync = yield * missingReads ;
1612+ assert . deepStrictEqual (
1613+ ( yield * Ref . get ( fixture . syncCommands ) ) . map ( ( command ) => command . number ) ,
1614+ [ 8 ] ,
1615+ ) ;
1616+
1617+ yield * Queue . offer ( fixture . domainEvents , {
1618+ type : "thread.pull-request-link-updated" ,
1619+ id : EventId . make ( "missing-link-updated" ) ,
1620+ threadId : linked . id ,
1621+ occurredAt : DateTime . makeUnsafe ( NOW ) ,
1622+ payload : makeLink ( 9 ) ,
1623+ } ) ;
1624+ // Let the event consumer finish even when it correctly queues no sweep.
1625+ yield * TestClock . adjust ( 0 ) ;
1626+ yield * reactor . drain ;
1627+ const afterLinkUpdate = yield * missingReads ;
1628+
1629+ yield * Queue . offer ( fixture . stateChanges , makeLink ( 9 ) ) ;
1630+ yield * TestClock . adjust ( 0 ) ;
1631+ yield * reactor . drain ;
1632+ const afterReaderRefresh = yield * missingReads ;
1633+ yield * sweepAgain ( fixture , reactor ) ;
1634+ assert . deepStrictEqual (
1635+ {
1636+ afterSiblingSync,
1637+ afterLinkUpdate,
1638+ afterReaderRefresh,
1639+ afterSweep : yield * missingReads ,
1640+ } ,
1641+ { afterSiblingSync : 1 , afterLinkUpdate : 1 , afterReaderRefresh : 2 , afterSweep : 2 } ,
1642+ ) ;
1643+ } ) . pipe ( Effect . provide ( fixture . layer ) ) ;
1644+ } ) ,
1645+ ) ,
1646+ ) ;
1647+
1648+ it . effect ( "a pending stack retry respects the missing summary backoff" , ( ) =>
1649+ Effect . scoped (
1650+ Effect . gen ( function * ( ) {
1651+ yield * TestClock . setTime ( Date . parse ( NOW ) ) ;
1652+ const found = yield * Ref . make ( true ) ;
1653+ const fixture = yield * makeHarness ( {
1654+ snapshot : makeSnapshot ( [ makeThread ( "missing" , { pullRequests : [ makeLink ( 4 ) ] } ) ] ) ,
1655+ summary : ( input ) =>
1656+ Ref . get ( found ) . pipe (
1657+ Effect . flatMap ( ( available ) =>
1658+ available ? Effect . succeed ( makeSummary ( input ) ) : missingSummary ,
1659+ ) ,
1660+ ) ,
1661+ stack : ( ) =>
1662+ Effect . fail ( new PullRequestOperationError ( { operation : "stack" , detail : "host down" } ) ) ,
1663+ } ) ;
1664+ yield * Effect . gen ( function * ( ) {
1665+ const reactor = yield * startAndSweep ( fixture ) ;
1666+ assert . strictEqual ( ( yield * Ref . get ( fixture . stackCalls ) ) . length , 1 ) ;
1667+ yield * Ref . set ( found , false ) ;
1668+ yield * sweepAgain ( fixture , reactor ) ;
1669+ assert . strictEqual ( ( yield * Ref . get ( fixture . summaryCalls ) ) . length , 2 ) ;
1670+ for ( let index = 0 ; index < 14 ; index += 1 ) yield * sweepAgain ( fixture , reactor ) ;
1671+ assert . strictEqual ( ( yield * Ref . get ( fixture . summaryCalls ) ) . length , 2 ) ;
1672+ yield * sweepAgain ( fixture , reactor ) ;
1673+ assert . strictEqual ( ( yield * Ref . get ( fixture . summaryCalls ) ) . length , 3 ) ;
1674+ assert . strictEqual ( ( yield * Ref . get ( fixture . stackCalls ) ) . length , 1 ) ;
1675+ } ) . pipe ( Effect . provide ( fixture . layer ) ) ;
1676+ } ) ,
1677+ ) ,
1678+ ) ;
1679+
15221680 it . effect . each ( [
15231681 "gh pr merge 7 --squash 2>&1 | tail -3" ,
15241682 "cafe pr merge 7 --squash" ,
0 commit comments