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
16 changes: 15 additions & 1 deletion apps/memos-local-plugin/core/llm/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ import type {

const DEFAULT_MAX_TOKENS = 1024;

// Singleton controller for background work that inherited an aborted signal.
// Creating a fresh controller per call would leak memory; reusing one singleton
// ensures background LLM calls can proceed without accumulating detached controllers.
const neverAbortController = new AbortController();

// ─── Factory ─────────────────────────────────────────────────────────────────

export function createLlmClient(config: LlmConfig): LlmClient {
Expand Down Expand Up @@ -287,13 +292,22 @@ export function createLlmClientWithProvider(
}

function makeCtx(opts: LlmCallOptions | undefined, pLog: LlmProviderLogger): LlmProviderCtx {
// Detach aborted signals from foreground context (fixes #2412)
// When L3 or retrieval runs in background, they may inherit an
// already-aborted signal → all HTTP requests fail with "This operation
// was aborted". Replace aborted signals with a singleton never-abort
// signal so background work can proceed.
const sanitizedSignal = opts?.signal?.aborted
? neverAbortController.signal
: opts?.signal;

return {
config: {
...config,
timeoutMs: opts?.timeoutMs ?? config.timeoutMs,
},
log: pLog,
signal: opts?.signal,
signal: sanitizedSignal,
deadlineAt: opts?.deadlineAt,
};
}
Expand Down
6 changes: 6 additions & 0 deletions apps/memos-local-plugin/core/util/foreground-resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ export function createForegroundResources(
const shutdownController = new AbortController();

function signalFor(signal?: AbortSignal): AbortSignal {
// If the input signal is already aborted (e.g. from a turn that ended),
// ignore it and only use the pipeline shutdown signal. Background work
// should not inherit turn-scoped abort signals.
if (signal?.aborted) {
return shutdownController.signal;
}
return signal
? AbortSignal.any([signal, shutdownController.signal])
: shutdownController.signal;
Expand Down
Loading
Loading