@@ -260,7 +260,9 @@ function holdComposerRecovery(
260260 }
261261 for ( const item of queue ?? [ ] ) {
262262 const owner = item . attachmentPayload ?. recoveryScope ;
263- groups . set ( owner , [ ...( groups . get ( owner ) ?? [ ] ) , item ] ) ;
263+ const rows = groups . get ( owner ) ?? [ ] ;
264+ rows . push ( item ) ;
265+ groups . set ( owner , rows ) ;
264266 }
265267 for ( const [ owner , rows ] of groups ) {
266268 store . recovery [ `${ id } :${ JSON . stringify ( owner ?? null ) } ` ] = {
@@ -414,7 +416,9 @@ export function readStoredOutboxStore(
414416 ) {
415417 return true ;
416418 }
417- identified . set ( identifiedKey , [ ...( identified . get ( identifiedKey ) ?? [ ] ) , item ] ) ;
419+ const rows = identified . get ( identifiedKey ) ?? [ ] ;
420+ rows . push ( item ) ;
421+ identified . set ( identifiedKey , rows ) ;
418422 return false ;
419423 } ) ;
420424 for ( const [ identifiedKey , queue ] of identified ) {
@@ -547,13 +551,14 @@ export function writeStoredOutboxStore(
547551 if ( pendingLegacyTransfers . has ( store ) && retained . length < entries . length ) {
548552 throw new Error ( "Chat outbox migration exceeds retention; source retained" ) ;
549553 }
550- const payload = JSON . stringify ( {
554+ const retainedStore : StoredComposerState = {
551555 version : 4 ,
552556 gatewayOwner : target . gatewayOwner ,
553557 sessions : Object . fromEntries ( retained ) ,
554558 recovery : store . recovery ,
555559 ...( store . legacyReceipts ? { legacyReceipts : store . legacyReceipts } : { } ) ,
556- } ) ;
560+ } ;
561+ const payload = JSON . stringify ( retainedStore ) ;
557562 // Verification precedes deleting any legacy source, including quota/no-op writes.
558563 storage . setItem ( target . key , payload ) ;
559564 if ( storage . getItem ( target . key ) !== payload ) {
@@ -569,15 +574,15 @@ export function writeStoredOutboxStore(
569574 }
570575 }
571576 pendingLegacyTransfers . delete ( store ) ;
572- retireRemovedOutboxPayloads ( storage , target , previous , payload ) ;
577+ retireRemovedOutboxPayloads ( storage , target , previous , retainedStore ) ;
573578}
574579
575580// Cleanup follows a verified metadata commit, never a credential-filtered view.
576581function retireRemovedOutboxPayloads (
577582 storage : Storage ,
578583 target : ComposerStorageTarget ,
579584 previous : string | null ,
580- current : string | null ,
585+ current : StoredComposerState | null ,
581586) : void {
582587 if ( ! previous ) {
583588 return ;
@@ -592,11 +597,10 @@ function retireRemovedOutboxPayloads(
592597 ) {
593598 return ;
594599 }
595- const references = ( raw : string | null ) => {
596- if ( raw === null ) {
600+ const references = ( value : unknown ) => {
601+ if ( value === null ) {
597602 return [ ] ;
598603 }
599- const value : unknown = JSON . parse ( raw ) ;
600604 if (
601605 ! isRecord ( value ) ||
602606 value . version !== 4 ||
@@ -640,7 +644,7 @@ function retireRemovedOutboxPayloads(
640644 } ) ;
641645 } ;
642646 const remaining = new Set ( references ( current ) . map ( ( ref ) => ref . key ) ) ;
643- const removed = references ( previous ) . filter ( ( ref ) => ! remaining . has ( ref . key ) ) ;
647+ const removed = references ( JSON . parse ( previous ) ) . filter ( ( ref ) => ! remaining . has ( ref . key ) ) ;
644648 if ( removed . length ) {
645649 void removeOutboxPayloads ( removed ) ;
646650 }
0 commit comments