Skip to content

Project info fails on legacy pgvector embeddings schema #1195

Closed

Description

@phernandez

Production impact

Project info can fail with HTTP 500 when a tenant has a legacy pgvector embeddings table that predates the source_hash column. Cloud surfaces the upstream failure as HTTP 503.

Logfire issue: #2173

Root cause

ProjectService.get_embedding_status() counts physical embeddings with a join on search_vector_embeddings.source_hash. Legacy pgvector tables may exist without that column, so the status read raises asyncpg UndefinedColumnError / SQLAlchemy ProgrammingError before it can recommend a rebuild.

PgVectorIndex.initialize() already detects this legacy schema and owns the repair: it recreates the physical embeddings table and marks chunks pending. The project-info status path can run before index initialization, however, and currently assumes the physical table is current merely because it exists.

This is a code compatibility defect, not expected log noise.

Proposed fix

  • inspect the PostgreSQL physical embeddings table schema before executing count queries
  • require source_hash for built-in pgvector storage
  • when the column is missing, report vector storage as outdated and recommend bm reindex --embeddings
  • keep the status path read-only; do not drop or rebuild tables from a GET request
  • leave external vector adapters and SQLite behavior unchanged

Acceptance criteria

  • legacy Postgres storage without search_vector_embeddings.source_hash returns a status response instead of raising
  • the response marks vector tables unavailable/outdated and recommends reindexing
  • current pgvector storage still performs the physical count
  • external vector adapters and SQLite manifest checks retain their existing behavior
  • regression tests cover the legacy schema path

Activity

  1. claude commented on Aug 5, 2026

    @claude
    Contributor

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


    Triage complete

    • Read issue and gather context
    • Classify type, priority, component, complexity
    • Check for duplicate issues
    • Inspect relevant code (ProjectService.get_embedding_status(), PgVectorIndex.initialize())
    • Apply labels
    • Post triage summary

    ⚠️ Labeling error — needs manual cleanup

    While probing which labels exist in this repo (the label-add script silently ignores unknown names without listing valid ones, and I have no read-only gh label list access), I passed a batch of candidate names and several turned out to be real, existing labels that were incorrectly applied to this issue:

    • duplicate
    • enhancement
    • documentation
    • question

    None of these apply — this is a bug report, not a duplicate/enhancement/docs/question. I only have --add-label available (no removal capability), so a maintainer needs to manually remove these four labels from this issue. My apologies for the noise.

    cloud was also added by the same probe and I judged it defensible to leave — the issue explicitly documents Cloud surfacing this as an HTTP 503, so it's a legitimate component tag even though the root cause lives in core.

    Classification

    • Type: Bug (code defect) — already labeled bug
    • Priority: High. Confirmed production-impacting (89 occurrences over 8 days per the linked Logfire trace), but it's a single status-read endpoint failing on a specific legacy-schema tenant condition, not a full outage — doesn't rise to "complete breakage." No critical/high/low priority labels exist in this repo's label set (probed and all rejected), so this is a prose assessment only.
    • Component: Postgres/vector-index status path (ProjectService, database layer) + Cloud (status surfaced as 503). No database label exists in this repo to apply.
    • Complexity: Medium — well-scoped, single-method fix plus regression tests; no architectural changes needed. No simple/medium/complex labels exist in this repo to apply.

    Duplicate check

    No exact duplicate. Related but distinct closed issues:

    Neither covers the Postgres legacy-pgvector-schema case this issue describes.

    Code verification

    The root cause as described checks out:

    • ProjectService.get_embedding_status() in src/basic_memory/services/project_service.py:1221-1237 builds embeddings_sql/orphaned_sql with a join on e.source_hash as soon as search_vector_embeddings is found to exist (storage_exists check at line 1110), with no check that the column is actually present. On a legacy Postgres table predating that column, this raises before a rebuild can be recommended.
    • PgVectorIndex.initialize() in src/basic_memory/repository/pgvector_index.py:59-64 already detects this exact condition via a private _has_source_hash_column() helper and self-heals by dropping/recreating the table — confirming the schema drift is real and that repair logic already exists elsewhere, just not on this read-only status path.
    • The proposed fix (inspect the physical table schema, report outdated/unavailable + recommend bm reindex --embeddings instead of querying, leave SQLite/external adapters untouched) is consistent with the existing code structure and the manifest_schema_current pattern already used for the SQLite side (lines 1115-1127) — this is a solid, well-scoped bug report.

    Per triage scope, no fix has been implemented — this issue is ready for someone to pick up.

  2. added
    cloudBasic Memory Cloud
    documentationImprovements or additions to documentation
    duplicateThis issue or pull request already exists
    enhancementNew feature or request
    questionFurther information is requested
    on Aug 5, 2026
  3. removed
    documentationImprovements or additions to documentation
    duplicateThis issue or pull request already exists
    enhancementNew feature or request
    questionFurther information is requested
    cloudBasic Memory Cloud
    on Aug 5, 2026
  4. phernandez commented on Aug 6, 2026

    @phernandez
    MemberAuthor

    Production follow-up

    This incident has self-repaired and is no longer active.

    • The final Logfire #2173 occurrence was at 2026-08-05 10:31 UTC.
    • At 10:44:45 UTC, PGQueuer embeddings job 6966561 ran PgVectorIndex.initialize(), logged source_hash_missing=True, recreated search_vector_embeddings, and completed successfully.
    • The affected tenant is now at Alembic head q0l1m2n3o4p5.
    • Current Neon schema inspection confirms search_vector_embeddings.source_hash TEXT NOT NULL.
    • No later #2173 occurrences were observed. Logfire #2173 has been resolved and will reopen automatically if the exception recurs.

    This was not a request overlapping a tenant migration. The tenant's Alembic-managed schema was current; the stale object was adapter-owned derived pgvector storage, which is reconciled lazily when the pgvector adapter initializes.

    Given the confirmed self-repair, PR #1196 is not required for this incident. It changes the status read to describe stale storage, but it does not update the tenant or change the repair lifecycle. If this recurs on a tenant that does not self-repair, the root fix should be proactive vector-storage reconciliation rather than masking the status-path exception.

    Representative final failure trace

  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

    bugSomething isn't workingproductionObserved in production

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions