@@ -15,6 +15,7 @@ import {
1515 type MemoryChunk ,
1616 type MemorySource ,
1717} from "openclaw/plugin-sdk/memory-core-host-engine-storage" ;
18+ import { MAX_TIMER_TIMEOUT_MS , resolveTimerTimeoutMs } from "openclaw/plugin-sdk/number-runtime" ;
1819import {
1920 MEMORY_BATCH_FAILURE_LIMIT ,
2021 recordMemoryBatchFailure ,
@@ -54,6 +55,17 @@ const EMBEDDING_BATCH_TIMEOUT_LOCAL_MS = 10 * 60_000;
5455
5556const log = createSubsystemLogger ( "memory" ) ;
5657
58+ function resolveEmbeddingSecondsTimeoutMs ( seconds : number ) : number {
59+ if ( ! Number . isFinite ( seconds ) ) {
60+ return MAX_TIMER_TIMEOUT_MS ;
61+ }
62+ const timeoutMs = Math . floor ( seconds * 1000 ) ;
63+ return resolveTimerTimeoutMs (
64+ Number . isFinite ( timeoutMs ) ? timeoutMs : MAX_TIMER_TIMEOUT_MS ,
65+ MAX_TIMER_TIMEOUT_MS ,
66+ ) ;
67+ }
68+
5769type MemoryIndexEntry = {
5870 path : string ;
5971 absPath : string ;
@@ -77,7 +89,7 @@ export function resolveEmbeddingTimeoutMs(params: {
7789 if ( params . kind === "query" ) {
7890 const runtimeTimeoutMs = params . providerRuntime ?. inlineQueryTimeoutMs ;
7991 if ( typeof runtimeTimeoutMs === "number" && runtimeTimeoutMs > 0 ) {
80- return runtimeTimeoutMs ;
92+ return resolveTimerTimeoutMs ( runtimeTimeoutMs , EMBEDDING_QUERY_TIMEOUT_REMOTE_MS ) ;
8193 }
8294 return params . providerId === "local"
8395 ? EMBEDDING_QUERY_TIMEOUT_LOCAL_MS
@@ -86,11 +98,11 @@ export function resolveEmbeddingTimeoutMs(params: {
8698
8799 const configuredTimeoutSeconds = params . configuredBatchTimeoutSeconds ;
88100 if ( typeof configuredTimeoutSeconds === "number" && configuredTimeoutSeconds > 0 ) {
89- return configuredTimeoutSeconds * 1000 ;
101+ return resolveEmbeddingSecondsTimeoutMs ( configuredTimeoutSeconds ) ;
90102 }
91103 const runtimeTimeoutMs = params . providerRuntime ?. inlineBatchTimeoutMs ;
92104 if ( typeof runtimeTimeoutMs === "number" && runtimeTimeoutMs > 0 ) {
93- return runtimeTimeoutMs ;
105+ return resolveTimerTimeoutMs ( runtimeTimeoutMs , EMBEDDING_BATCH_TIMEOUT_REMOTE_MS ) ;
94106 }
95107 return params . providerId === "local"
96108 ? EMBEDDING_BATCH_TIMEOUT_LOCAL_MS
@@ -121,13 +133,14 @@ export async function runEmbeddingOperationWithTimeout<T>(params: {
121133 if ( ! Number . isFinite ( params . timeoutMs ) || params . timeoutMs <= 0 ) {
122134 return await params . run ( controller . signal ) ;
123135 }
136+ const timeoutMs = resolveTimerTimeoutMs ( params . timeoutMs , 1 ) ;
124137 let timer : NodeJS . Timeout | null = null ;
125138 const timeoutPromise = new Promise < never > ( ( _ , reject ) => {
126139 timer = setTimeout ( ( ) => {
127140 const error = new Error ( params . message ) ;
128141 reject ( error ) ;
129142 controller . abort ( error ) ;
130- } , params . timeoutMs ) ;
143+ } , timeoutMs ) ;
131144 timer . unref ?.( ) ;
132145 } ) ;
133146 try {
@@ -453,9 +466,10 @@ export abstract class MemoryManagerEmbeddingOps extends MemoryManagerSyncOps {
453466 if ( ! Number . isFinite ( timeoutMs ) || timeoutMs <= 0 ) {
454467 return await promise ;
455468 }
469+ const resolvedTimeoutMs = resolveTimerTimeoutMs ( timeoutMs , 1 ) ;
456470 let timer : NodeJS . Timeout | null = null ;
457471 const timeoutPromise = new Promise < never > ( ( _ , reject ) => {
458- timer = setTimeout ( ( ) => reject ( new Error ( message ) ) , timeoutMs ) ;
472+ timer = setTimeout ( ( ) => reject ( new Error ( message ) ) , resolvedTimeoutMs ) ;
459473 } ) ;
460474 try {
461475 return ( await Promise . race ( [ promise , timeoutPromise ] ) ) as T ;
0 commit comments