Skip to content

Add request timeouts to Supermemory MCP client calls#1146

Open
Dhravya wants to merge 2 commits into
mainfrom
cursor/polylane-autofix-add-request-timeouts-to-supermemory-mcp-client-calls-c1ad
Open

Add request timeouts to Supermemory MCP client calls#1146
Dhravya wants to merge 2 commits into
mainfrom
cursor/polylane-autofix-add-request-timeouts-to-supermemory-mcp-client-calls-c1ad

Conversation

@Dhravya

@Dhravya Dhravya commented Jun 20, 2026

Copy link
Copy Markdown
Member

Summary

Fixes recurring supermemory-mcp Durable Object latency spikes caused by outbound fetch calls to https://api.supermemory.ai (and downstream services like Turbopuffer and Gemini) stalling indefinitely, which in turn blocked parent supermemory Worker jsrpc spans for tens of seconds to minutes.

Changes (apps/mcp/src/client.ts only)

SDK client timeout

Added timeout: 30_000 (30 s) to the Supermemory constructor. The SDK's ClientOptions.timeout field applies to every request made through the client (add, memories.forget, search.memories, profile), so a single change covers all SDK method calls.

Manual fetch helpers

Added signal: AbortSignal.timeout(30_000) to the two manual fetch calls in getProjects and getDocuments. These helpers bypass the SDK and hit /v3/projects / /v3/documents/documents directly, so they need their own timeout signal.

AbortError handling

Extended the existing handleError method to intercept AbortError and TimeoutError (the DOMException name used by AbortSignal.timeout) and convert them to a clean user-facing message instead of letting the raw exception propagate into the Durable Object.

Assumptions & notes

  • SDK retries: The Supermemory SDK retries failed requests twice by default. A timed-out request will therefore retry up to 2 additional times before the AbortError surfaces, meaning total worst-case wait per SDK call is ~90 s. This is still dramatically better than the unbounded stall seen in production and avoids unnecessarily degrading reliability for transient network hiccups. Retries can be disabled (maxRetries: 0) if stricter latency bounds are required.
  • No new dependencies introduced; AbortSignal.timeout is available in the Cloudflare Workers runtime (same as Node ≥ 17).
  • Pre-existing TypeScript errors in server.ts (MCP SDK version mismatch) and mcp-app.ts (DOM lib) are unrelated to this change and were present before.
Open in Web Open in Cursor 

cursoragent and others added 2 commits June 20, 2026 21:37
- Set timeout: 30_000 on the Supermemory SDK constructor so all SDK
  method calls (add, memories.forget, search.memories, profile) time
  out after 30 s instead of hanging indefinitely.
- Add signal: AbortSignal.timeout(30_000) to the two manual fetch
  helpers getProjects and getDocuments.
- Handle AbortError / TimeoutError in handleError so a timed-out
  request surfaces a clear message instead of propagating an unhandled
  exception into the Durable Object.

Co-authored-by: Dhravya Shah <dhravya@supermemory.com>
Co-authored-by: Dhravya Shah <dhravya@supermemory.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 20, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
supermemory-mcp c33c904 Jun 20 2026, 09:39 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 20, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
supermemory-app c33c904 Commit Preview URL

Branch Preview URL
Jun 20 2026, 09:40 PM

@MaheshtheDev MaheshtheDev marked this pull request as ready for review June 23, 2026 05:18
@MaheshtheDev MaheshtheDev requested a review from ved015 June 23, 2026 05:18
@claude

claude Bot commented Jun 23, 2026

Copy link
Copy Markdown

Claude finished @MaheshtheDev's task in 1m 27s —— View job


Reviewing PR #1146: Add request timeouts to Supermemory MCP client calls

  • Analyzing PR context and changes
  • Reading the full diff
  • Examining surrounding code for edge cases
  • Checking for existing review comments
  • Submitting review

Summary

Reviewed the timeout implementation in apps/mcp/src/client.ts. The changes are clean and correct:

  • SDK timeout: timeout: 30_000 on the constructor covers all SDK methods
  • Manual fetch timeouts: AbortSignal.timeout(30_000) correctly applied to both getProjects and getDocuments
  • Error handling: Properly catches AbortError and TimeoutError with user-friendly messages

No bugs, security issues, or logic errors found. Score: 10/10 — ready to ship.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview: Adds 30-second request timeouts to all Supermemory MCP client calls (SDK constructor + manual fetch helpers) with proper error handling.

Issues found: None — this looks good to ship.

The implementation is clean and correct:

  • timeout: 30_000 on the SDK constructor covers all SDK method calls (add, memories.forget, search.memories, profile)
  • AbortSignal.timeout(30_000) on the two manual fetch calls (getProjects, getDocuments) is the correct pattern for Cloudflare Workers
  • Error handling properly intercepts both AbortError and TimeoutError (the DOMException name used by AbortSignal.timeout) and converts them to user-friendly messages
  • The error handler is correctly placed at the start of handleError so timeout errors are caught before other checks

The PR description accurately notes that SDK retries (2 by default) could extend worst-case latency to ~90s, which is documented and acceptable given the tradeoff against reliability.

Score: 10/10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants