Skip to content

Feature: Add graph cleanup and pruning command #24

Description

@Pallavikumarimdb

Problem

As repositories evolve, files are deleted, renamed, or refactored. Over several coding sessions:

  1. Components might point to code anchors (code_anchor) that no longer exist on disk.
  2. Claims, flows, or sources can become completely orphaned (disconnected from any active component or flow).
  3. Edges might point to deleted/non-existent subject IDs.

Currently, Greplica has no way to audit the health of the local knowledge graph or prune these stale, dangling, or orphaned entities. Stale data remains in the database and is retrieved during search, which wastes context window tokens and degrades the coding agent's performance.

Proposed Solution

Introduce a new CLI command - greplica graph gc - to safely clean up the repository's local memory database. It should support a --dry-run flag to preview changes before applying them.

Expected Behavior

  • Stale Code Anchors: Check if code_anchor files exist on disk. If a file is missing, flag/prune the component.
  • Orphaned Claims/Flows: Find claims or flows with no incoming or outgoing edges, or claims whose related components/flows have been deleted.
  • Dangling Edges: Identify and prune edges where either the from_id or to_id refers to an entity that no longer exists in the graph.
  • Cascading Deletes: When pruning an entity, ensure its corresponding database memberships (in the graph_memberships table) and associated embeddings are cleanly deleted to avoid database constraints violations.
  • CLI Command routing:
    • greplica graph gc --dry-run: Runs the audit scan and prints the report of stale/orphaned items without modifying the database.
    • greplica graph gc: Permanently prunes the database and outputs a summary of deleted components, claims, flows, and edges.

Activity

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

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions