Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2251,22 +2251,24 @@ const memoryLanceDBProPlugin = {
await new Promise(resolve => setTimeout(resolve, ms));
}

async function retrieveWithRetry(params: {
query: string;
limit: number;
scopeFilter?: string[];
category?: string;
source?: "manual" | "auto-recall" | "cli";
}) {
async function retrieveWithRetry(params: {
query: string;
limit: number;
scopeFilter?: string[];
category?: string;
source?: "manual" | "auto-recall" | "cli";
signal?: AbortSignal;
}) {
let results = await retriever.retrieve(params);
if (results.length === 0) {
await sleep(75);
if (params.signal?.aborted) return results;
results = await retriever.retrieve(params);
}
return results;
}

async function runRecallLifecycle(
async function runRecallLifecycle(
results: Array<{ entry: { id: string; text: string; category: "preference" | "fact" | "decision" | "entity" | "other"; scope: string; importance: number; timestamp: number; metadata?: string } }>,
scopeFilter?: string[],
): Promise<Map<string, string>> {
Expand Down Expand Up @@ -2755,9 +2757,14 @@ const memoryLanceDBProPlugin = {
// (embedding → rerank → lifecycle), which can silently drop messages on
// channels like Telegram when subsequent requests hit lock timeouts.
// See: https://github.com/CortexReach/memory-lancedb-pro/issues/253
// The timeout also aborts the in-flight embedding HTTP call via the
// abortController below, so the underlying work doesn't continue to hold
// resources (lancedb connection, per-agent memory-runtime mutex) past
// the timeout boundary.
const abortController = new AbortController();
let autoRecallTimedOut = false;
let lateAutoRecallLogged = false;
const recallWork = async (): Promise<{ prependContext: string; ephemeral?: boolean } | undefined> => {
const recallWork = async (signal: AbortSignal): Promise<{ prependContext: string; ephemeral?: boolean } | undefined> => {
// Determine agent ID and accessible scopes
const agentId = resolveHookAgentId(ctx?.agentId, (event as any).sessionKey);
if (isInvalidAgentIdFormat(agentId, config.declaredAgents)) {
Expand Down Expand Up @@ -2814,6 +2821,7 @@ const memoryLanceDBProPlugin = {
limit: retrieveLimit,
scopeFilter: accessibleScopes,
source: "auto-recall",
signal,
}), config.workspaceBoundary);

if (shouldDropLateAutoRecall("post-retrieve")) return;
Expand Down Expand Up @@ -3060,9 +3068,12 @@ const memoryLanceDBProPlugin = {
let timeoutId: ReturnType<typeof setTimeout> | undefined;
try {
const result = await Promise.race([
recallWork().then((r) => { clearTimeout(timeoutId); return r; }),
recallWork(abortController.signal).then((r) => { clearTimeout(timeoutId); return r; }),
new Promise<undefined>((resolve) => {
timeoutId = setTimeout(() => {
// Cancel in-flight embedding/retrieval HTTP calls so they don't
// keep holding resources after we've given up on the result.
abortController.abort(new Error("auto-recall timeout"));
autoRecallTimedOut = true;
api.logger.warn(
`memory-lancedb-pro: auto-recall timed out after ${AUTO_RECALL_TIMEOUT_MS}ms; skipping memory injection to avoid stalling agent startup`,
Expand All @@ -3074,7 +3085,15 @@ const memoryLanceDBProPlugin = {
return result;
} catch (err) {
clearTimeout(timeoutId);
api.logger.warn(`memory-lancedb-pro: recall failed: ${String(err)}`);
// Downgrade to debug only when OUR controller aborted (i.e. the
// timeout callback fired). Aborts originating elsewhere — e.g. the
// embedder's own internal timeout — keep warn visibility so real
// failures aren't silenced.
if (abortController.signal.aborted) {
api.logger.debug?.(`memory-lancedb-pro: recall aborted by timeout: ${String(err)}`);
} else {
api.logger.warn(`memory-lancedb-pro: recall failed: ${String(err)}`);
}
}
}, { priority: 10 });

Expand Down
9 changes: 5 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"skills/**/*.md"
],
"scripts": {
"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 test/strip-envelope-metadata.test.mjs && node test/cli-smoke.mjs && node test/functional-e2e.mjs && node --test test/per-agent-auto-recall.test.mjs && node test/retriever-rerank-regression.mjs && node test/smart-memory-lifecycle.mjs && node test/smart-extractor-branches.mjs && node --test test/regex-fallback-bulk-store.test.mjs && node test/plugin-manifest-regression.mjs && node --test test/session-summary-before-reset.test.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-update-metadata-refresh.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 && node --test test/clawteam-scope.test.mjs && node --test test/cross-process-lock.test.mjs && node --test test/preference-slots.test.mjs && node test/is-latest-auto-supersede.test.mjs && node --test test/temporal-awareness.test.mjs && node --test test/command-reflection-guard.test.mjs && node --test test/tier1-counters.test.mjs",
"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 test/strip-envelope-metadata.test.mjs && node test/cli-smoke.mjs && node test/functional-e2e.mjs && node --test test/per-agent-auto-recall.test.mjs && node test/retriever-rerank-regression.mjs && node test/smart-memory-lifecycle.mjs && node test/smart-extractor-branches.mjs && node --test test/regex-fallback-bulk-store.test.mjs && node test/plugin-manifest-regression.mjs && node --test test/session-summary-before-reset.test.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-update-metadata-refresh.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 && node --test test/clawteam-scope.test.mjs && node --test test/cross-process-lock.test.mjs && node --test test/preference-slots.test.mjs && node test/is-latest-auto-supersede.test.mjs && node --test test/temporal-awareness.test.mjs && node --test test/command-reflection-guard.test.mjs && node --test test/tier1-counters.test.mjs",
"test:cli-smoke": "node scripts/run-ci-tests.mjs --group cli-smoke",
"test:core-regression": "node scripts/run-ci-tests.mjs --group core-regression",
"test:storage-and-schema": "node scripts/run-ci-tests.mjs --group storage-and-schema",
Expand Down Expand Up @@ -67,7 +67,7 @@
},
"devDependencies": {
"commander": "^14.0.0",
"jiti": "^2.6.1",
"jiti": "^2.7.0",
"typescript": "^5.9.3"
}
}
Loading
Loading