Skip to content

fix(graph): a workspace's ontology counts only its live documents - #535

Merged
jwvanderstam merged 1 commit into
mainfrom
fix/ontology-live-documents
Nov 11, 2026
Merged

jwvanderstam merged 1 commit into
mainfrom
fix/ontology-live-documents

Conversation

@jwvanderstam

Copy link
Copy Markdown
Owner

What

A follow-up from the separate security review of #527 (Low, within one workspace).

EntitiesRepository.workspace_ontology joined each entity_relations row to its document but never checked deleted_at. A retired document's entities, and those of chunks a re-ingest had retired, therefore kept counting in the workspace's ontology.

Change

Both ontology queries now join documents ... AND d.deleted_at IS NULL and document_chunks ... AND c.deleted_at IS NULL. This is the same rule #527 applies to the expansion lookup.

Tests

  • tests/integration/test_ontology_reads_live_documents.py sets up one live document, one retired document and one re-ingested (chunk-retired) document. Only LIVE remains among the types. It fails on the old code against Postgres.
  • test_db_entities_memories passes: 31 passed in total. ruff is clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KkWPqAcWbxfqz1aCP6Qsdx

workspace_ontology joined each relation to its document without asking
whether the document, or the chunk the relation came from, was retired, so a
retired document's entities, and those of chunks a re-ingest had replaced,
kept shaping the ontology. Both queries now require a live document and a
live chunk. Within one workspace only; found by the separate review of #527.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KkWPqAcWbxfqz1aCP6Qsdx
Copilot AI balanced review requested due to automatic review settings November 8, 2026 21:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@sonarqubecloud

sonarqubecloud Bot commented Nov 8, 2026

Copy link
Copy Markdown

@jwvanderstam
jwvanderstam merged commit 2c05045 into main Nov 11, 2026
17 checks passed
@jwvanderstam
jwvanderstam deleted the fix/ontology-live-documents branch November 11, 2026 00:04
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.

2 participants