@@ -13,7 +13,11 @@ import {
1313} from "openclaw/plugin-sdk/agent-runtime" ;
1414import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts" ;
1515import { closeActiveMemorySearchManager } from "openclaw/plugin-sdk/memory-host-search" ;
16- import { parseStrictPositiveInteger } from "openclaw/plugin-sdk/number-runtime" ;
16+ import {
17+ asDateTimestampMs ,
18+ parseStrictPositiveInteger ,
19+ resolveExpiresAtMsFromDurationMs ,
20+ } from "openclaw/plugin-sdk/number-runtime" ;
1721import {
1822 resolveLivePluginConfigObject ,
1923 resolvePluginConfigObject ,
@@ -1360,27 +1364,40 @@ function getCachedResult(cacheKey: string): ActiveRecallResult | undefined {
13601364 if ( ! cached ) {
13611365 return undefined ;
13621366 }
1363- if ( cached . expiresAt <= Date . now ( ) ) {
1367+ const now = asDateTimestampMs ( Date . now ( ) ) ;
1368+ if (
1369+ now === undefined ||
1370+ asDateTimestampMs ( cached . expiresAt ) === undefined ||
1371+ cached . expiresAt <= now
1372+ ) {
13641373 activeRecallCache . delete ( cacheKey ) ;
13651374 return undefined ;
13661375 }
13671376 return cached . result ;
13681377}
13691378
13701379function setCachedResult ( cacheKey : string , result : ActiveRecallResult , ttlMs : number ) : void {
1371- const now = Date . now ( ) ;
1380+ const rawNow = Date . now ( ) ;
1381+ const now = asDateTimestampMs ( rawNow ) ;
13721382 if (
13731383 activeRecallCache . size >= DEFAULT_MAX_CACHE_ENTRIES ||
1374- now - lastActiveRecallCacheSweepAt >= CACHE_SWEEP_INTERVAL_MS
1384+ ( now !== undefined && now - lastActiveRecallCacheSweepAt >= CACHE_SWEEP_INTERVAL_MS )
13751385 ) {
13761386 sweepExpiredCacheEntries ( now ) ;
1377- lastActiveRecallCacheSweepAt = now ;
1387+ if ( now !== undefined ) {
1388+ lastActiveRecallCacheSweepAt = now ;
1389+ }
1390+ }
1391+ const expiresAt = resolveExpiresAtMsFromDurationMs ( ttlMs , { nowMs : rawNow } ) ;
1392+ if ( expiresAt === undefined ) {
1393+ activeRecallCache . delete ( cacheKey ) ;
1394+ return ;
13781395 }
13791396 if ( activeRecallCache . has ( cacheKey ) ) {
13801397 activeRecallCache . delete ( cacheKey ) ;
13811398 }
13821399 activeRecallCache . set ( cacheKey , {
1383- expiresAt : now + ttlMs ,
1400+ expiresAt,
13841401 result,
13851402 } ) ;
13861403 while ( activeRecallCache . size > DEFAULT_MAX_CACHE_ENTRIES ) {
@@ -1392,9 +1409,13 @@ function setCachedResult(cacheKey: string, result: ActiveRecallResult, ttlMs: nu
13921409 }
13931410}
13941411
1395- function sweepExpiredCacheEntries ( now = Date . now ( ) ) : void {
1412+ function sweepExpiredCacheEntries ( now = asDateTimestampMs ( Date . now ( ) ) ) : void {
1413+ if ( now === undefined ) {
1414+ activeRecallCache . clear ( ) ;
1415+ return ;
1416+ }
13961417 for ( const [ cacheKey , cached ] of activeRecallCache . entries ( ) ) {
1397- if ( cached . expiresAt <= now ) {
1418+ if ( asDateTimestampMs ( cached . expiresAt ) === undefined || cached . expiresAt <= now ) {
13981419 activeRecallCache . delete ( cacheKey ) ;
13991420 }
14001421 }
0 commit comments