@@ -1856,13 +1856,36 @@ function migratePersistedComposerDraftStoreState(
18561856function partializeComposerDraftStoreState (
18571857 state : ComposerDraftStoreState ,
18581858) : PersistedComposerDraftStoreState {
1859+ // Draft sessions worth persisting: mapped (a new-thread flow targets
1860+ // them), promoting (mid-send), or holding real user content (they back a
1861+ // sidebar row). Everything else is a zombie — and its composer blob must
1862+ // be dropped WITH it, or model/mode-only entries would persist forever
1863+ // keyed to a session that no longer exists.
1864+ const mappedDraftKeys = new Set (
1865+ Object . values ( state . logicalProjectDraftThreadKeyByLogicalProjectKey ) ,
1866+ ) ;
1867+ const keptSessionKeys = new Set (
1868+ Object . entries ( state . draftThreadsByThreadKey )
1869+ . filter (
1870+ ( [ threadKey , draftThread ] ) =>
1871+ mappedDraftKeys . has ( threadKey ) ||
1872+ isDraftThreadPromoting ( draftThread ) ||
1873+ composerDraftHasUserContent ( state . draftsByThreadKey [ threadKey ] ) ,
1874+ )
1875+ . map ( ( [ threadKey ] ) => threadKey ) ,
1876+ ) ;
18591877 const persistedDraftsByThreadKey : DeepMutable <
18601878 PersistedComposerDraftStoreState [ "draftsByThreadKey" ]
18611879 > = { } ;
18621880 for ( const [ threadKey , draft ] of Object . entries ( state . draftsByThreadKey ) ) {
18631881 if ( typeof threadKey !== "string" || threadKey . length === 0 ) {
18641882 continue ;
18651883 }
1884+ // Composer content keyed to a dropped draft session goes with it.
1885+ // Server-thread keys have no session entry and are unaffected.
1886+ if ( state . draftThreadsByThreadKey [ threadKey ] !== undefined && ! keptSessionKeys . has ( threadKey ) ) {
1887+ continue ;
1888+ }
18661889 const hasModelData =
18671890 Object . keys ( draft . modelSelectionByProvider ) . length > 0 || draft . activeProvider !== null ;
18681891 if (
@@ -1936,24 +1959,11 @@ function partializeComposerDraftStoreState(
19361959 } ;
19371960 persistedDraftsByThreadKey [ threadKey ] = persistedDraft ;
19381961 }
1939- // Unmapped sessions exist only to back a sidebar draft row, so a session
1940- // that is neither mapped, nor promoting, nor backed by real user content
1941- // has nothing left to resume — drop it instead of persisting a zombie.
1942- // The user-content predicate matters: a persisted composer entry can hold
1943- // only ambient model/mode data, which is not a reason to keep a session
1944- // no row will ever show.
1945- const mappedDraftKeys = new Set (
1946- Object . values ( state . logicalProjectDraftThreadKeyByLogicalProjectKey ) ,
1947- ) ;
19481962 const persistedDraftThreadsByThreadKey : DeepMutable <
19491963 PersistedComposerDraftStoreState [ "draftThreadsByThreadKey" ]
19501964 > = { } ;
19511965 for ( const [ threadKey , draftThread ] of Object . entries ( state . draftThreadsByThreadKey ) ) {
1952- if (
1953- ! mappedDraftKeys . has ( threadKey ) &&
1954- ! isDraftThreadPromoting ( draftThread ) &&
1955- ! composerDraftHasUserContent ( state . draftsByThreadKey [ threadKey ] )
1956- ) {
1966+ if ( ! keptSessionKeys . has ( threadKey ) ) {
19571967 continue ;
19581968 }
19591969 persistedDraftThreadsByThreadKey [ threadKey ] = draftThread ;
0 commit comments