Skip to content

Commit fb79b56

Browse files
author
Hi-Jiajun
committed
fix: complete PR CortexReach#238 reviewer follow-up
1 parent f21488b commit fb79b56

File tree

4 files changed

+116
-248
lines changed

4 files changed

+116
-248
lines changed

package-lock.json

Lines changed: 0 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
]
3737
},
3838
"scripts": {
39-
"test": "node test/embedder-error-hints.test.mjs && node test/cjk-recursion-regression.test.mjs && node test/migrate-legacy-schema.test.mjs && node --test test/config-session-strategy-migration.test.mjs && node --test test/recall-text-cleanup.test.mjs && node test/update-consistency-lancedb.test.mjs && node test/cli-smoke.mjs && node test/functional-e2e.mjs && node test/retriever-rerank-regression.mjs && node test/smart-memory-lifecycle.mjs && node test/smart-extractor-branches.mjs && node test/plugin-manifest-regression.mjs && node --test test/sync-plugin-version.test.mjs && node test/smart-metadata-v2.mjs && node test/vector-search-cosine.test.mjs && node test/context-support-e2e.mjs && node test/temporal-facts.test.mjs && node test/memory-update-supersede.test.mjs && node test/memory-upgrader-diagnostics.test.mjs && node --test test/workflow-fork-guards.test.mjs",
39+
"test": "node test/embedder-error-hints.test.mjs && node test/cjk-recursion-regression.test.mjs && node test/migrate-legacy-schema.test.mjs && node --test test/config-session-strategy-migration.test.mjs && node --test test/scope-access-undefined.test.mjs && node --test test/reflection-bypass-hook.test.mjs && node --test test/smart-extractor-scope-filter.test.mjs && node --test test/store-empty-scope-filter.test.mjs && node --test test/recall-text-cleanup.test.mjs && node test/update-consistency-lancedb.test.mjs && node test/cli-smoke.mjs && node test/functional-e2e.mjs && node test/retriever-rerank-regression.mjs && node test/smart-memory-lifecycle.mjs && node test/smart-extractor-branches.mjs && node test/plugin-manifest-regression.mjs && node --test test/sync-plugin-version.test.mjs && node test/smart-metadata-v2.mjs && node test/vector-search-cosine.test.mjs && node test/context-support-e2e.mjs && node test/temporal-facts.test.mjs && node test/memory-update-supersede.test.mjs && node test/memory-upgrader-diagnostics.test.mjs && node --test test/llm-api-key-client.test.mjs && node --test test/llm-oauth-client.test.mjs && node --test test/cli-oauth-login.test.mjs && node --test test/workflow-fork-guards.test.mjs",
4040
"test:openclaw-host": "node test/openclaw-host-functional.mjs",
4141
"version": "node scripts/sync-plugin-version.mjs openclaw.plugin.json package.json && git add openclaw.plugin.json"
4242
},

src/embedder.ts

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -533,33 +533,11 @@ export class Embedder {
533533
return this.clients.length;
534534
}
535535

536-
/** FR-05: Wrap a promise with a global timeout using AbortSignal for TRUE cancellation.
537-
* @param promiseFactory - A function that receives an AbortSignal and returns a promise
538-
*/
539-
private withTimeout<T>(promiseFactory: (signal: AbortSignal) => Promise<T>, label: string): Promise<T> {
536+
/** Wrap a single embedding operation with a global timeout via AbortSignal. */
537+
private withTimeout<T>(promiseFactory: (signal: AbortSignal) => Promise<T>, _label: string): Promise<T> {
540538
const controller = new AbortController();
541539
const timeoutId = setTimeout(() => controller.abort(), EMBED_TIMEOUT_MS);
542-
543-
// Create the promise with the signal
544-
const promise = promiseFactory(controller.signal);
545-
546-
// Race between the original promise and timeout
547-
// When timeout fires, controller.abort() will:
548-
// 1. Trigger the abort event below to reject
549-
// 2. If embedWithRetry received the signal, it will cancel the underlying HTTP request
550-
const timeoutPromise = new Promise<never>((_, reject) => {
551-
controller.signal.addEventListener('abort', () => {
552-
clearTimeout(timeoutId);
553-
reject(new Error(
554-
`[memory-lancedb-pro] ${label} timed out after ${EMBED_TIMEOUT_MS}ms`
555-
));
556-
});
557-
});
558-
559-
return Promise.race([promise, timeoutPromise])
560-
.finally(() => {
561-
clearTimeout(timeoutId);
562-
}) as Promise<T>;
540+
return promiseFactory(controller.signal).finally(() => clearTimeout(timeoutId));
563541
}
564542

565543
// --------------------------------------------------------------------------
@@ -586,11 +564,11 @@ export class Embedder {
586564
// --------------------------------------------------------------------------
587565

588566
async embedQuery(text: string): Promise<number[]> {
589-
return this.withTimeout((signal) => this.embedSingle(text, this._taskQuery, signal), "embedQuery");
567+
return this.withTimeout((signal) => this.embedSingle(text, this._taskQuery, 0, signal), "embedQuery");
590568
}
591569

592570
async embedPassage(text: string): Promise<number[]> {
593-
return this.withTimeout((signal) => this.embedSingle(text, this._taskPassage, signal), "embedPassage");
571+
return this.withTimeout((signal) => this.embedSingle(text, this._taskPassage, 0, signal), "embedPassage");
594572
}
595573

596574
// Note: embedBatchQuery/embedBatchPassage are NOT wrapped with withTimeout because

0 commit comments

Comments
 (0)