@@ -16,6 +16,7 @@ const state = vi.hoisted(() => ({
1616 connectedEnvironmentIds : [ ] as EnvironmentId [ ] ,
1717 pendingOrder : null as object | null ,
1818 dropBusy : false ,
19+ holdingRows : false ,
1920 failedAction : null as string | null ,
2021 archivedRefreshes : [ ] as string [ ] ,
2122 scopes : new Map < string , Set < string > > ( ) ,
@@ -78,26 +79,28 @@ vi.mock("../../state/atom-registry", () => ({
7879 ? state . connectedEnvironmentIds
7980 : atom === "thread-drop-busy"
8081 ? state . dropBusy
81- : atom === "thread-shells"
82- ? state . shells
83- : atom === "queued-thread-keys"
84- ? new Set < string > ( )
85- : new Map (
86- [ ...state . scopes . keys ( ) ] . map ( ( environmentId ) => [
87- environmentId ,
88- {
89- environment : {
90- capabilities : {
91- threadSettlement : true ,
92- threadSnooze : true ,
93- threadPinning : true ,
94- threadPinReorder : true ,
95- threadTitleRegeneration : true ,
82+ : atom === "steady-shells-holding"
83+ ? state . holdingRows
84+ : atom === "thread-shells"
85+ ? state . shells
86+ : atom === "queued-thread-keys"
87+ ? new Set < string > ( )
88+ : new Map (
89+ [ ...state . scopes . keys ( ) ] . map ( ( environmentId ) => [
90+ environmentId ,
91+ {
92+ environment : {
93+ capabilities : {
94+ threadSettlement : true ,
95+ threadSnooze : true ,
96+ threadPinning : true ,
97+ threadPinReorder : true ,
98+ threadTitleRegeneration : true ,
99+ } ,
96100 } ,
97101 } ,
98- } ,
99- ] ) ,
100- ) ,
102+ ] ) ,
103+ ) ,
101104 } ,
102105} ) ) ;
103106vi . mock ( "../../state/use-atom-command" , ( ) => ( {
@@ -121,10 +124,9 @@ vi.mock("../../state/thread-order", () => ({
121124 } ,
122125} ) ) ;
123126vi . mock ( "../../state/threads" , ( ) => ( {
124- environmentThreadShells : {
125- threadShellsAtom : "thread-shells" ,
126- navigationThreadShellsAtom : "thread-shells" ,
127- } ,
127+ environmentThreadShells : { threadShellsAtom : "thread-shells" } ,
128+ steadyNavigationThreadShellsAtom : "thread-shells" ,
129+ steadyShellsHoldingAtom : "steady-shells-holding" ,
128130 threadEnvironment : Object . fromEntries (
129131 [
130132 "archive" ,
@@ -193,6 +195,7 @@ beforeEach(() => {
193195 state . archivedRefreshes = [ ] ;
194196 state . pendingOrder = null ;
195197 state . dropBusy = false ;
198+ state . holdingRows = false ;
196199 state . scopes = new Map ( [
197200 [ primaryEnvironmentId , new Set ( [ AuthOrchestrationOperateScope ] ) ] ,
198201 [ otherEnvironmentId , new Set < string > ( ) ] ,
@@ -274,6 +277,12 @@ describe("pinned thread operation permissions", () => {
274277 } ) ,
275278 ] ;
276279
280+ // Rows that wait to show can hold order keys the server has replaced.
281+ state . holdingRows = true ;
282+ expect ( await useThreadListActions ( ) . moveThread ( moved , "up" ) ) . toBe ( false ) ;
283+ expect ( state . requests ) . toEqual ( [ ] ) ;
284+ state . holdingRows = false ;
285+
277286 expect ( await useThreadListActions ( ) . moveThread ( moved , "up" ) ) . toBe ( true ) ;
278287 expect ( state . requests ) . toEqual ( [
279288 expect . objectContaining ( { action : "reorderPin" , environmentId : primaryEnvironmentId } ) ,
@@ -494,6 +503,25 @@ describe("thread action undo", () => {
494503 } ,
495504 ) ;
496505
506+ it . each ( [ "settleThread" , "unpinThread" ] as const ) (
507+ "%s plans its undo from the live row when the list holds an older one" ,
508+ async ( handler ) => {
509+ const held = makeThread ( { pinnedAt : "2026-09-02T00:00:00.000Z" , pinOrderKey : "m" } ) ;
510+ const live = makeThread ( {
511+ pinnedAt : "2026-09-02T00:00:00.000Z" ,
512+ pinOrderKey : "t" ,
513+ snoozedUntil : "2099-01-01T09:00:00.000Z" ,
514+ } ) ;
515+ state . shells = [ live ] ;
516+ await useThreadListActions ( ) [ handler ] ( held ) ;
517+ await readThreadUndoNotice ( ) ! . undo ( ) ;
518+ expect ( state . requests . slice ( - 2 ) ) . toMatchObject ( [
519+ { action : "pin" , input : { threadId : live . id , orderKey : "t" } } ,
520+ { action : "snooze" , input : { threadId : live . id , snoozedUntil : live . snoozedUntil } } ,
521+ ] ) ;
522+ } ,
523+ ) ;
524+
497525 // regression: #21401 restore archive and thread action undo
498526 it ( "does not restore snooze if undoing an unpin fails" , async ( ) => {
499527 const thread = makeThread ( {
@@ -570,5 +598,10 @@ describe("thread archive guard", () => {
570598 expect ( state . requests ) . toEqual ( [ ] ) ;
571599 expect ( state . archivedRefreshes ) . toEqual ( [ ] ) ;
572600 expect ( state . alerts . at ( - 1 ) ?. title ) . toBe ( "Could not archive thread" ) ;
601+
602+ // A list can hold a row from before the run started.
603+ state . shells = [ thread ] ;
604+ expect ( await useThreadListActions ( ) . archiveThread ( makeThread ( ) ) ) . toBe ( false ) ;
605+ expect ( state . requests ) . toEqual ( [ ] ) ;
573606 } ) ;
574607} ) ;
0 commit comments