Skip to content

Bug: syncRagDocumentScopes can fail silently, leaving corpus scope stamps stale #2990

Closed

Description

@Israeltheminer

Problem

convex/documents/internal_actions.ts → syncRagDocumentScopes re-stamps a corpus row's team_ids / project_id when a document's scope changes. It is scheduled fire-and-forget, and its failure path is a warning and nothing else:

} catch (error) {
  console.warn(
    `[syncRagDocumentScopes] corpus update failed for org ${orgSlug}:`,
    error instanceof Error ? error.message : error,
  );
}

No retry, no reconciliation, no signal. If the knowledge database is briefly unreachable, the Convex row says "project X" while the corpus row still says NULL/NULL/NULL, indefinitely.

Not a leak — but not harmless

Correctness survives, because retrieval re-checks every document hit against live Convex truth (filterRetrievableRagFileIds) rather than trusting the SQL projection. The unstamped row is filtered out after the fact.

The cost is silent degradation instead:

  • an unstamped row reads as a hub row in the SQL pre-filter (team_ids IS NULL AND team_id IS NULL AND project_id IS NULL), so it is returned to every caller and rejected afterwards
  • the pre-filter stops pre-filtering, so searches scan and post-filter more than they should
  • nothing anywhere reports the drift, so it accumulates

The fail-open-then-catch design is deliberate and documented — unstamped rows keep org-wide visibility so pre-scoping rows stay retrievable. That is defensible. Having no way to notice the divergence is the gap.

Suggested

Verifying on a deployment

select file_id, coalesce(project_id,'—') project,
       coalesce(array_to_string(team_ids,','),'—') teams
from private_knowledge.documents;

compared against each document's projectId / teamTags in Convex. Any mismatch is a silent sync failure.

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

    bugpriority: lowservice: platform

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions