Skip to content

POST /v1/knowledge-graph/rebuild deletes the legacy graph before the rebuild worker runs, with no recovery if the worker dies #11796

Closed

Description

@Git-on-my-level

POST /v1/knowledge-graph/rebuild (backend/routers/knowledge_graph.py) does:

_require_legacy_graph_mutation(uid)
user_name = get_user_name(uid) or ""
kg_db.delete_knowledge_graph(uid)
background_tasks.add_task(_rebuild_graph_task, uid, user_name)
return RebuildResponse(status="rebuilding", ...)

The delete is committed and the 200 is returned before any rebuild work happens. Two consequences:

  1. If the background task never runs to completion — process restart, pod eviction, an LLM error inside rebuild_knowledge_graph — the user is left with no knowledge graph at all and no signal beyond a 200 that said "rebuilding".
  2. _rebuild_graph_task re-evaluates the gate after the delete. An account that becomes assertion-backed between the route's check and the task's check hits the != ALLOWED early return, so the task no-ops and the legacy graph stays deleted. The same is now true for the UNVERIFIED arm added in the mutation-gate hardening PR: a head read that times out in the window between the two checks stops the rebuild after the delete already landed.

This is the pre-5724a10084 contract restored by #11783, not a regression introduced by it — the ordering has been this way since the route existed. Flagging it because there is no test covering "delete succeeded, rebuild failed", and the hardening PR deliberately did not restructure it.

Plausible fixes, none of them free: build into a shadow collection and swap at the end; make the task idempotent and retryable with a persisted "rebuild pending" marker; or drop the eager delete and have rebuild_knowledge_graph overwrite in one transaction.

Evidence: backend/routers/knowledge_graph.py rebuild_graph / _rebuild_graph_task; found in adversarial review of #11783 (rated a nit, not blocking).

Activity

  1. moved this from Someday to In progress in omi TODO / bountieson Aug 18, 2026
  2. added a commit that references this issue on Aug 19, 2026
    71a0543
  3. moved this from In progress to In review in omi TODO / bountieson Aug 19, 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

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions