fix(tools): keep the forget-memory timeout when a caller passes a signal - #1567
Open
addyCooks wants to merge 1 commit into
Open
fix(tools): keep the forget-memory timeout when a caller passes a signal#1567addyCooks wants to merge 1 commit into
addyCooks wants to merge 1 commit into
Conversation
supermemoryai#1451 bounded `DELETE /v4/memories` with a 30s abort, but the two signals were selected between with `??`: signal: options?.signal ?? AbortSignal.timeout(FETCH_TIMEOUT_MS) so they were mutually exclusive. Any caller who passed a cancellation signal silently dropped the timeout and the request went unbounded again - exactly the hang supermemoryai#1451 set out to remove - and there was no way to ask for both through the API. No production call site passes options today (ai-sdk.ts and openai/tools.ts both omit it), so this was latent. Composes the two with `AbortSignal.any` instead, so a caller signal cancels the request and the 30s ceiling still applies. The timeout signal is built once and reused for the bare case. Verified against a server that never responds: before this change the caller-signal path hangs indefinitely; after it, it rejects with TimeoutError at the deadline, an early caller abort still wins with AbortError, and an already-aborted signal rejects immediately. tool-operations.test.ts replaces the case that asserted the old select-one behaviour with five: the caller signal is composed rather than substituted and its abort reason reaches the request, the timeout still fires while the caller signal stays open, an already-aborted caller signal is forwarded, the bare path still gets the 30s timeout signal itself, and an aborted fetch surfaces to the caller. Each case was checked against mutants of the fix - dropping the timeout from AbortSignal.any, composing with a signal that never fires, reverting to ??, and shortening the timeout - and every mutant fails at least one of them.
addyCooks
force-pushed
the
fix/forget-memory-signal-timeout
branch
from
August 19, 2026 18:47
349a821 to
73cf9f4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1549
Problem
#1451 bounded
DELETE /v4/memorieswith a 30-second abort, but the callersignal and the timeout were selected between with
??:They were mutually exclusive. Passing a cancellation signal silently dropped
the timeout and the request became unbounded again - the exact hang #1451 set
out to remove - with no way to ask for both through the API. Latent today
(
ai-sdk.ts:332andopenai/tools.ts:490both omitoptions), live themoment anyone wires up cancellation.
Fix
Compose the two with
AbortSignal.any, building the timeout signal once sothe bare path reuses it.
AbortSignal.anyis available in Node 20+ (therepo's engines floor), Bun, and workerd.
Test
tool-operations.test.tsreplaces the case that asserted the old select-onebehaviour with five:
reaches the request
fetchsurfaces to the caller rather than being swallowed18 tests in the file pass. The timeout case spies on
AbortSignal.timeout(shortened to 5ms) while asserting the code still requested
30_000- Nodecaptures its internal timer at module load, so fake timers cannot intercept
AbortSignal.timeout.Each case was checked against mutants of the fix, so the suite fails for a
wrong-but-plausible fix and not only for a full revert:
AbortSignal.any([options.signal])- timeout leg droppedoptions?.signal ?? ...Verification against a real socket
Against a server that accepts the connection and never responds:
TimeoutErrorat the deadlineTimeoutErrorTimeoutErrorAbortErrorAbortErrorAbortErrorAbortErrorNote (not in this PR)
apps/mcp/src/server/client/index.ts:370(getDocuments) has the identical??pattern and is equally latent - no caller there passesoptionseither.Left out to keep this diff scoped to the issue and to avoid colliding with
#1564, which already touches that file.