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
7 changes: 6 additions & 1 deletion packages/tools/src/shared/forget-memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ export async function forgetMemoryRequest(
Authorization: `Bearer ${apiKey}`,
},
body: JSON.stringify(params),
signal: options?.signal ?? AbortSignal.timeout(FETCH_TIMEOUT_MS),
// compose the caller's signal with the timeout instead of choosing
// between them: `??` dropped the 30s bound whenever a signal was passed,
// which reopened the unbounded-request hang that #1451 closed.
signal: options?.signal
? AbortSignal.any([options.signal, AbortSignal.timeout(FETCH_TIMEOUT_MS)])
: AbortSignal.timeout(FETCH_TIMEOUT_MS),
})

if (!response.ok) {
Expand Down
12 changes: 10 additions & 2 deletions packages/tools/src/tool-operations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe("memoryForget", () => {
expect(init.signal).toBeInstanceOf(AbortSignal)
})

it("uses a caller-provided signal instead of creating a timeout", async () => {
it("composes the caller signal with the timeout so both still bound the request", async () => {
const fetchMock = stubFetch()
const controller = new AbortController()

Expand All @@ -124,7 +124,15 @@ describe("memoryForget", () => {
)

const [, init] = fetchMock.mock.calls[0] as [string, RequestInit]
expect(init.signal).toBe(controller.signal)
const signal = init.signal as AbortSignal
// #1549: a composed signal, not the raw caller signal. the 30s timeout
// must not be dropped just because a caller passes their own signal.
expect(signal).toBeInstanceOf(AbortSignal)
expect(signal).not.toBe(controller.signal)
expect(signal.aborted).toBe(false)
// the caller's signal still aborts the request through the composite
controller.abort()
expect(signal.aborted).toBe(true)
})

it("throws a descriptive error on non-2xx responses", async () => {
Expand Down
Loading