Skip to content

fix(memory): prevent vector store corruption hangs - #1962

Merged
yyhhyyyyyy merged 9 commits into
devfrom
fix/memory-vector-store-corruption-hang
Jul 14, 2026
Merged

fix(memory): prevent vector store corruption hangs#1962
yyhhyyyyyy merged 9 commits into
devfrom
fix/memory-vector-store-corruption-hang

Conversation

@yyhhyyyyyy

@yyhhyyyyyy yyhhyyyyyy commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Prevent corrupted, wedged, or slow DuckDB vector stores from blocking message delivery, memory injection, cleanup, or application shutdown. Vector failures now degrade safely to FTS while preserving data unless corruption is confirmed.

  • Add bounded vector-store operations covering admission, locks, identity transitions, store opening, queries, and mutations.
  • Introduce suspect, grace, recovery, and terminal quarantine handling without treating ordinary slow queries as corruption.
  • Prevent late native operations from resuming quarantined stores or continuing batch and embedding work.
  • Preserve FTS fallback time within the memory injection deadline and cancel abandoned retrieval pipelines.
  • Record typed memory degradation causes while suppressing expected cold-store noise.
  • Add pre-stream watchdogs for asynchronous preparation steps and slow logging for synchronous tape and message operations.
  • Exclude provider rate-limit waiting from pre-stream stuck detection.
  • Preserve mandatory tool-output cleanup when a resume operation is aborted.
  • Expand regression coverage for timeout recovery, shutdown, identity transitions, injection fallback, and pre-stream observability.

Summary by CodeRabbit

  • New Features

    • Memory retrieval now reports degraded states, including vector-store timeouts, while continuing with available results where possible.
    • Memory injection accepts cancellation and has a four-second deadline, allowing responses to continue without delayed memory context.
    • Added visibility into recall health and pre-stream preparation progress.
  • Bug Fixes

    • Improved handling of stalled or corrupted vector-store operations, preventing unsafe recovery attempts.
    • Prevented late or abandoned retrieval work from affecting completed responses.
    • Improved shutdown behavior for in-flight memory operations.
  • Tests

    • Expanded coverage for timeouts, degradation reporting, watchdogs, cancellation, and lifecycle scenarios.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1ede67cb-7f23-4e4b-b9c7-f38db9015768

📥 Commits

Reviewing files that changed from the base of the PR and between c6bf2f2 and e4b8931.

📒 Files selected for processing (25)
  • docs/issues/memory-vector-store-corruption-hang/spec.md
  • src/main/agent/deepchat/loop/contextCoordinator.ts
  • src/main/agent/deepchat/memory/memoryRuntimeCoordinator.ts
  • src/main/presenter/agentRuntimePresenter/index.ts
  • src/main/presenter/memoryPresenter/core/asyncDeadline.ts
  • src/main/presenter/memoryPresenter/core/injectionPort.ts
  • src/main/presenter/memoryPresenter/domain/types.ts
  • src/main/presenter/memoryPresenter/index.ts
  • src/main/presenter/memoryPresenter/infra/embeddingPipeline.ts
  • src/main/presenter/memoryPresenter/infra/vectorStoreManager.ts
  • src/main/presenter/memoryPresenter/injection.ts
  • src/main/presenter/memoryPresenter/ports.ts
  • src/main/presenter/memoryPresenter/runtimeConstants.ts
  • src/main/presenter/memoryPresenter/services/retrievalService.ts
  • src/shared/types/agent-memory.ts
  • test/main/agent/deepchat/loop/contextCoordinator.test.ts
  • test/main/agent/deepchat/memory/memoryRuntimeCoordinator.test.ts
  • test/main/presenter/agentRuntimePresenter/agentRuntimePresenter.test.ts
  • test/main/presenter/memory/embeddingPipeline.test.ts
  • test/main/presenter/memory/lifecycleRegression.test.ts
  • test/main/presenter/memory/retrievalDiagnostics.test.ts
  • test/main/presenter/memory/serviceTestSupport.ts
  • test/main/presenter/memory/vectorStoreManager.test.ts
  • test/main/presenter/memory/workingMemoryService.test.ts
  • test/main/presenter/memoryInjectionPort.test.ts

📝 Walkthrough

Walkthrough

The PR bounds memory injection and vector-store operations, adds health-aware lease and quarantine handling, propagates retrieval degradation causes, and introduces watchdogs for pre-stream steps and provider-boundary transitions. Tests and the issue specification are updated for the new timeout, cancellation, teardown, and observability behavior.

Changes

Memory reliability and streaming control

Layer / File(s) Summary
Shared contracts and deadline primitives
src/main/presenter/memoryPresenter/core/*, src/main/presenter/memoryPresenter/domain/types.ts, src/main/presenter/memoryPresenter/ports.ts, src/shared/types/agent-memory.ts
Adds typed vector-store timeout errors, recall health states, injection options, degradation metadata, timing constants, and a reusable soft-deadline helper.
Vector-store lease deadlines and health state
src/main/presenter/memoryPresenter/infra/vectorStoreManager.ts
Adds bounded lease/query execution, suspect observation with grace handling, health-aware admission, quarantine, generation checks, and teardown behavior.
Retrieval cancellation and degradation propagation
src/main/presenter/memoryPresenter/services/retrievalService.ts, src/main/presenter/memoryPresenter/infra/embeddingPipeline.ts, src/main/agent/deepchat/memory/memoryRuntimeCoordinator.ts
Threads cancellation through retrieval and injection, maps timeout and health failures to degradation causes, bounds memory injection at 4 seconds, and gates embedding work on recall health and generation validity.
Pre-stream watchdog and provider boundary
src/main/presenter/agentRuntimePresenter/index.ts, src/main/agent/deepchat/loop/contextCoordinator.ts
Wraps preparation steps with stuck-step watchdogs and marks the provider boundary before rate admission and provider streaming.
Regression tests and specification updates
test/main/presenter/memory/*, test/main/presenter/agentRuntimePresenter/*, test/main/agent/deepchat/*, docs/issues/memory-vector-store-corruption-hang/spec.md
Adds coverage for timeout settlement, abort propagation, degradation manifests, quarantine and disposal, watchdog timing, ordering, and revised implementation status.
Estimated code review effort: 5 (Critical) ~90 minutes

Sequence Diagram(s)

sequenceDiagram
  participant AgentRuntimePresenter
  participant MemoryRuntimeCoordinator
  participant RetrievalService
  participant VectorStoreManager
  participant VectorStore
  participant Provider

  AgentRuntimePresenter->>MemoryRuntimeCoordinator: build bounded memory injection
  MemoryRuntimeCoordinator->>RetrievalService: retrieve with signal and degradation collector
  RetrievalService->>VectorStoreManager: query vector store
  VectorStoreManager->>VectorStore: execute query under deadline
  VectorStoreManager-->>RetrievalService: results or typed timeout
  RetrievalService-->>MemoryRuntimeCoordinator: injection and degradation metadata
  MemoryRuntimeCoordinator-->>AgentRuntimePresenter: prompt or timeout fallback
  AgentRuntimePresenter->>Provider: cross pre-stream boundary
  Provider-->>AgentRuntimePresenter: begin streaming
Loading

Possibly related PRs

Suggested reviewers: zhangmo8, zerob13

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: preventing memory vector-store corruption and hang issues.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/memory-vector-store-corruption-hang

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@yyhhyyyyyy
yyhhyyyyyy merged commit d60b876 into dev Jul 14, 2026
4 checks passed
@yyhhyyyyyy
yyhhyyyyyy deleted the fix/memory-vector-store-corruption-hang branch July 14, 2026 01:12
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.

1 participant