@@ -57,8 +57,7 @@ function lastUserQuery(ctx) {
5757 parts
5858 . map ( ( p ) => ( typeof p === "string" ? p : p ?. text ?? "" ) )
5959 . filter ( Boolean )
60- . join ( "\n" )
61- . slice ( 0 , 500 ) ,
60+ . join ( "\n" ) ,
6261 500
6362 ) ;
6463 }
@@ -223,19 +222,23 @@ export function createInjector(ctx, service, settings, config) {
223222 // CHANGELOG 开着开关,实际什么都不会发生。本次按 v0.7.2 语义原样恢复:键名、
224223 // 默认值(false)、格式 `[当前时间: YYYY-MM-DD 周X HH:MM]` 全部不变,存量
225224 // feature_flags 里的配置恢复即生效。
226- const WEEKDAYS = [ "周日" , "周一" , "周二" , "周三" , "周四" , "周五" , "周六" ] ;
227- let timePrefixSession = null ;
225+ // 已注入过时间前缀的会话集合(#335 review:单值闩锁在 A→B→A 交替渲染下会
226+ // 重复注入)。上限 500 防长驻进程无界增长,超限逐出最早记录。
227+ const timePrefixDone = new Set ( ) ;
228+ let timePrefixBare = false ;
228229
229230 function renderTimePrefix ( ctx ) {
230231 if ( config . injectTimePrefix !== true ) return "" ;
231232 const sessionId = ctx ?. agent ?. session ?. id ;
232233 if ( sessionId === undefined ) {
233- if ( timePrefixSession !== null ) return "" ;
234- timePrefixSession = true ;
234+ if ( timePrefixBare ) return "" ;
235+ timePrefixBare = true ;
235236 } else {
236- if ( sessionId === timePrefixSession ) return "" ;
237- timePrefixSession = sessionId ;
237+ if ( timePrefixDone . has ( sessionId ) ) return "" ;
238+ if ( timePrefixDone . size >= 500 ) timePrefixDone . delete ( timePrefixDone . keys ( ) . next ( ) . value ) ;
239+ timePrefixDone . add ( sessionId ) ;
238240 }
241+ const WEEKDAYS = [ "周日" , "周一" , "周二" , "周三" , "周四" , "周五" , "周六" ] ;
239242 const now = new Date ( ) ;
240243 const pad = ( n ) => String ( n ) . padStart ( 2 , "0" ) ;
241244 const date = `${ now . getFullYear ( ) } -${ pad ( now . getMonth ( ) + 1 ) } -${ pad ( now . getDate ( ) ) } ` ;
0 commit comments