Skip to content

Treat deleted superseded vector-manifest generations as stale work #1200

Closed

Description

@phernandez

Summary

An embedding job can prepare vector-manifest row IDs, wait on embedding generation, and then fail terminally because a newer entity generation removed those old rows. Production later converged, so the Logfire fingerprint was optimistically resolved, but the worker semantics are still wrong: losing ownership to a newer generation is stale work, not a fatal storage invariant violation.

The fix must distinguish superseded old-generation rows from unexpectedly missing current-generation rows. Broadly swallowing the exception would hide real corruption.

Production evidence

Observed release: Cloud release 837b8c258ddb9ca78d0d9d897cec9202f7650c28, pinning Core revision de4589d24155332002709f5529c9bdd4937861a4.

Logfire issue #2234 — 7bdbc18a-a201-489e-aa0f-0978ce4cf216 — recorded 124 matches across production and development.

The failing job found 64 prepared manifest IDs missing and exhausted its retries. A newer same-entity job succeeded while the old job was unwinding, followed by several more successful jobs. Current read-only database verification showed 214 ready manifest rows, 214 embeddings, no missing embeddings, and no source-hash mismatches. Identifying tenant and note values are intentionally omitted.

Causal chain

  1. Job A prepares manifest rows and retains their physical row IDs.
  2. Job A awaits embedding generation.
  3. Job B observes a newer entity/content generation, creates replacement chunk keys, and removes the old manifest rows.
  4. Job A resumes and _persist_embeddings queries its prepared row IDs.
  5. Source-hash changes already classify work as stale and skip it, but physically missing old-generation rows raise VectorManifestRowsDisappearedError.
  6. Job A retries and can terminate even though job B already owns convergence and the final vector state is correct.

The vector adapter's generation-safe upsert is keyed by logical generation/chunk identity. The persistence layer should use that ownership information rather than treating every missing historical physical row as corruption.

Required outcome

When an embedding job resumes, determine whether each missing prepared row belongs to a superseded generation. Skip or explicitly mark that work superseded and let the newer generation own convergence. Continue to raise for a manifest row that should exist for the current generation.

Result accounting must not claim that an entity became synchronized if all of the job's work was superseded; it should report a stale/deferred outcome or otherwise preserve the newer generation's ownership.

Non-solutions

  • Catching and ignoring every missing-manifest exception
  • Increasing retries
  • Preventing all concurrent embedding work with a tenant-wide lock
  • Recreating deleted historical rows without checking generation ownership

Acceptance criteria

  • A real PostgreSQL regression blocks job A after manifest preparation, lets job B replace/delete the old chunk generation, then resumes job A.
  • Job A exits as superseded/deferred without terminal failure.
  • Job B's current-generation manifests and embeddings remain ready and correct.
  • Unexpected absence of a current-generation manifest still raises a visible correctness error.
  • A fully superseded job does not mark the entity synchronized on its own.
  • External and built-in vector adapters honor the same generation-ownership contract.
  • Concurrent retries remain idempotent and do not resurrect stale chunks.
  • The regression verifies final manifest/embedding parity and source-hash consistency.

Activity

  1. added
    bug
    production
    on Aug 6, 2026
  2. claude commented on Aug 6, 2026

    @claude
    Contributor

    Claude finished @phernandez's task in 2m 9s —— View job


    Triage complete

    • Read issue body and understand the request
    • Classify type, priority, component, complexity
    • Check for duplicate issues
    • Apply labels
    • Post triage summary comment

    Classification

    • Type: Bug — worker correctness/error-handling defect (bug label already present).
    • Priority: High. This isn't data loss (the issue's own verification found 214/214 manifest-embedding parity and no source-hash mismatches), but it causes false terminal failures and wasted retries at production scale (124 Logfire matches) whenever a newer generation legitimately supersedes an in-flight embedding job. Not Critical, since correctness ultimately converges and no corruption was observed.
    • Component: Vector/embedding sync in src/basic_memory/repository/semantic_vector_sync.py (VectorManifestRowsDisappearedError, _persist_embeddings). Labeled cloud since the failure surfaces in the cloud embedding worker's job lifecycle, though the fix lives in this core repo.
    • Complexity: Complex. Needs to plumb generation-ownership context (not just row-ID presence) through _persist_embeddings, distinguish superseded-old-generation from missing-current-generation rows, keep both external and built-in vector adapters honoring the same contract, avoid falsely marking a fully-superseded job as "synchronized," and ship a real-Postgres regression that races job A against job B. This is architectural/behavioral work, not a quick patch.

    Duplicate check: Searched open/closed issues for VectorManifestRowsDisappearedError, _persist_embeddings, and related terms — no existing duplicate found. This is a new, well-specified report with clear repro conditions, root cause, and acceptance criteria already included, so no reproduction/clarification request is needed.

    Labels: bug and production were already present. Repo label probing found the priority/component/complexity taxonomy described in my triage instructions (e.g. high, database, complex) does not exist in this repo — those --add-label calls were silently ignored, so no incorrect priority/complexity labels were applied. I did add cloud (valid, existing label, appropriate component tag).

    ⚠️ Correction needed — my mistake: While probing which label names are valid in this repo, I inadvertently applied four incorrect labels that do not belong on this issue: documentation, duplicate, enhancement, question. My available tools only permit adding labels (via edit-issue-labels.sh), not removing them, so I could not undo this myself. Could a maintainer please remove these four labels from this issue? Apologies for the noise — final intended label state is just bug, production, cloud.

    No implementation work was started, per triage-only scope.

  3. added
    cloud
    documentation
    duplicate
    enhancement
    question
    on Aug 6, 2026
  4. removed
    documentation
    duplicate
    enhancement
    question
    on Aug 6, 2026
  5. added this to the v0.23 milestone on Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcloudproduction

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions