Skip to content

fix(memory): circuit breaker for Upstash Vector search failures#478

Merged
xlabtg merged 4 commits intoxlabtg:mainfrom
konard:issue-477-92dc3d8d2d09
May 5, 2026
Merged

fix(memory): circuit breaker for Upstash Vector search failures#478
xlabtg merged 4 commits intoxlabtg:mainfrom
konard:issue-477-92dc3d8d2d09

Conversation

@konard
Copy link
Copy Markdown

@konard konard commented May 5, 2026

Summary

Fixes #477

When Upstash Vector backend is temporarily unavailable, the agent was logging a WARN on every semantic search attempt (which runs on every incoming message), flooding the logs with:

WARN: [Memory] Semantic Memory: Fallback Mode (Upstash Vector search failed)
    err: { "type": "UpstashError", "message": "The vector store backend is currently unavailable..." }

Root Cause

HybridSearch.semanticVectorSearchKnowledge() catches every error from UpstashSemanticVectorStore.searchKnowledge() and logs a WARN. Without any cooldown, this fires on every message when Upstash is down.

Fix

Added a 60-second circuit breaker to UpstashSemanticVectorStore.searchKnowledge():

  • On the first failure, the circuit opens and the error is re-thrown (so HybridSearch logs the warning once and falls back to local keyword search).
  • While the circuit is open, subsequent calls return [] immediately — no network call, no repeated log entry.
  • After 60 seconds the circuit closes and the next call retries Upstash normally.
  • On success, the circuit resets.
  • configure() also resets the circuit breaker so reconfiguring the store starts fresh.

How to Reproduce / Verify

  1. Configure UPSTASH_VECTOR_REST_URL and UPSTASH_VECTOR_REST_TOKEN with valid credentials.
  2. Make the Upstash endpoint unreachable (e.g. wrong URL or network block).
  3. Send multiple messages to the agent.
  4. Before fix: A WARN is logged for every message.
  5. After fix: The WARN fires once, then is suppressed for 60 seconds while local memory continues to work.

Tests

Added two new test cases to src/memory/__tests__/vector-store-timeout.test.ts:

  • circuit breaker skips Upstash calls after a failure without re-throwing — verifies the second call within the cooldown returns [] silently without contacting Upstash.
  • circuit breaker resets after the cooldown period — verifies that after 60 seconds the circuit closes and Upstash is contacted again.

All 360 memory-module tests pass.

konard added 2 commits May 5, 2026 16:30
Adding .gitkeep for PR creation (default mode).
This file will be removed when the task is complete.

Issue: xlabtg#477
Adding .gitkeep for PR creation (default mode).
This file will be removed when the task is complete.

Issue: xlabtg#477
@konard
Copy link
Copy Markdown
Author

konard commented May 5, 2026

🤖 AI Work Session Started

Starting automated work session at 2026-05-05T17:07:44.531Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait for the session to finish, and provide your feedback.

…press log spam on repeated failures

When Upstash Vector is temporarily unavailable, each semantic search attempt
would throw and be caught by HybridSearch, logging a WARN on every request.
This adds a 60-second circuit breaker: after the first failure, subsequent
searchKnowledge calls return [] silently without hitting the network or flooding
logs. The circuit resets automatically after the cooldown and on reconfigure().

Fixes xlabtg#477
@konard konard changed the title [WIP] Upstash Vector search failed fix(memory): circuit breaker for Upstash Vector search failures May 5, 2026
@konard konard marked this pull request as ready for review May 5, 2026 17:14
@konard
Copy link
Copy Markdown
Author

konard commented May 5, 2026

Working session summary

Done. Here's a summary of what was done:

Root cause: When Upstash Vector backend is unavailable, HybridSearch.semanticVectorSearchKnowledge() catches errors from the store's searchKnowledge() and logs a WARN on every semantic search — which runs on every incoming message. This floods the logs with the same error repeatedly.

Fix: Added a 60-second circuit breaker to UpstashSemanticVectorStore.searchKnowledge() (src/memory/vector-store.ts):

  • First failure → circuit opens, error re-thrown (warning logged once by HybridSearch, falls back to local keyword search)
  • While circuit is open → returns [] silently, no network call, no log spam
  • After 60s → circuit resets, next call retries Upstash
  • Success → circuit resets immediately
  • configure() also resets the circuit

Two new tests verify the circuit opens on failure and resets after the cooldown. All 360 memory-module tests pass.

PR: #478


This summary was automatically extracted from the AI working session output.

@konard
Copy link
Copy Markdown
Author

konard commented May 5, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost: $1.125849

📊 Context and tokens usage:

  • 75.0K / 1M (7%) input tokens, 12.0K / 64K (19%) output tokens

Total: (44 new + 75.3K cache writes + 2.2M cache reads) input tokens, 12.0K output tokens, $1.125849 cost

🤖 Models used:

  • Tool: Anthropic Claude Code
  • Requested: sonnet
  • Model: Claude Sonnet 4.6 (claude-sonnet-4-6)

📎 Log file uploaded as Gist (1341KB)


Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Copy Markdown
Author

konard commented May 5, 2026

✅ Ready to merge

This pull request is now ready to be merged:

  • All CI checks have passed
  • No merge conflicts
  • No pending changes

Monitored by hive-mind with --auto-restart-until-mergeable flag

@xlabtg xlabtg merged commit 4b959a4 into xlabtg:main May 5, 2026
18 checks passed
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.

Upstash Vector search failed

2 participants