@@ -141,6 +141,7 @@ vi.mock("../../state/threads", () => ({
141141} ) ) ;
142142
143143import { useArchivedThreadListActions , useThreadListActions } from "./useThreadListActions" ;
144+ import { scopedThreadKey } from "../../lib/scopedEntities" ;
144145
145146const primaryEnvironmentId = EnvironmentId . make ( "primary" ) ;
146147const otherEnvironmentId = EnvironmentId . make ( "other" ) ;
@@ -183,6 +184,49 @@ beforeEach(() => {
183184
184185afterEach ( ( ) => vi . unstubAllEnvs ( ) ) ;
185186
187+ describe ( "thread arrangement save recovery" , ( ) => {
188+ it ( "retries failed moves without repeating confirmed moves from another environment" , async ( ) => {
189+ const primary = makeThread ( {
190+ pinnedAt : "2026-10-15T00:00:00.000Z" ,
191+ pinOrderKey : "a" ,
192+ } ) ;
193+ const other = makeThread ( { ...primary , environmentId : otherEnvironmentId } ) ;
194+ state . shells = [ primary , other ] ;
195+ const drafts = new Map ( [
196+ [ scopedThreadKey ( primary . environmentId , primary . id ) , { pinOrderKey : "c" } ] ,
197+ [ scopedThreadKey ( other . environmentId , other . id ) , { pinOrderKey : "d" } ] ,
198+ ] ) ;
199+ state . afterRequest = ( ) => {
200+ state . shells = [ { ...primary , pinOrderKey : "c" } , other ] ;
201+ } ;
202+ const { saveThreadArrangement } = useThreadListActions ( ) ;
203+
204+ expect ( await saveThreadArrangement ( drafts ) ) . toBe ( false ) ;
205+ expect ( state . dropBusy ) . toBe ( false ) ;
206+ expect ( state . requests ) . toEqual ( [
207+ {
208+ action : "reorderPin" ,
209+ environmentId : primaryEnvironmentId ,
210+ input : { threadId : primary . id , orderKey : "c" } ,
211+ } ,
212+ ] ) ;
213+
214+ state . requests = [ ] ;
215+ state . scopes . get ( otherEnvironmentId ) ! . add ( AuthOrchestrationOperateScope ) ;
216+ state . afterRequest = undefined ;
217+
218+ expect ( await saveThreadArrangement ( drafts ) ) . toBe ( true ) ;
219+ expect ( state . dropBusy ) . toBe ( false ) ;
220+ expect ( state . requests ) . toEqual ( [
221+ {
222+ action : "reorderPin" ,
223+ environmentId : otherEnvironmentId ,
224+ input : { threadId : other . id , orderKey : "d" } ,
225+ } ,
226+ ] ) ;
227+ } ) ;
228+ } ) ;
229+
186230describe ( "thread list operation permissions" , ( ) => {
187231 it . each ( mutationCases ) (
188232 "%s rejects a retained callback after its environment loses permission" ,
0 commit comments