@@ -31,9 +31,7 @@ function isCompactionMetadata(meta: unknown): meta is CompactionMetadata {
3131 */
3232export class MessageQueue {
3333 private messages : string [ ] = [ ] ;
34- // muxMetadata from first message (preserved, never overwritten)
3534 private firstMuxMetadata ?: unknown ;
36- // Latest options (for model, etc.)
3735 private latestOptions ?: SendMessageOptions ;
3836 private accumulatedImages : ImagePart [ ] = [ ] ;
3937
@@ -80,13 +78,10 @@ export class MessageQueue {
8078 if ( options ) {
8179 const { imageParts, ...restOptions } = options ;
8280
83- // Preserve first muxMetadata (critical for compaction)
84- // This ensures compaction metadata isn't lost when follow-ups are added
81+ // Preserve first muxMetadata (see class docblock for rationale)
8582 if ( options . muxMetadata !== undefined && this . firstMuxMetadata === undefined ) {
8683 this . firstMuxMetadata = options . muxMetadata ;
8784 }
88-
89- // Always update latest options (for model changes, etc.)
9085 this . latestOptions = restOptions ;
9186
9287 if ( imageParts && imageParts . length > 0 ) {
@@ -125,26 +120,16 @@ export class MessageQueue {
125120
126121 /**
127122 * Get combined message and options for sending.
128- * Returns joined messages with options (using preserved muxMetadata).
129123 */
130124 produceMessage ( ) : {
131125 message : string ;
132126 options ?: SendMessageOptions & { imageParts ?: ImagePart [ ] } ;
133127 } {
134128 const joinedMessages = this . messages . join ( "\n" ) ;
135-
136- // Merge latest options with preserved muxMetadata
137- // Use preserved first muxMetadata if available (critical for compaction)
138- // Falls back to latest options' muxMetadata if no first was stored
139- const effectiveMuxMetadata =
140- this . firstMuxMetadata !== undefined
141- ? this . firstMuxMetadata
142- : ( this . latestOptions ?. muxMetadata as unknown ) ;
143-
144129 const options = this . latestOptions
145130 ? {
146131 ...this . latestOptions ,
147- muxMetadata : effectiveMuxMetadata ,
132+ muxMetadata : this . firstMuxMetadata ?? this . latestOptions . muxMetadata ,
148133 imageParts : this . accumulatedImages . length > 0 ? this . accumulatedImages : undefined ,
149134 }
150135 : undefined ;
0 commit comments