Skip to content

orphans: soft-deleted pages still counted in orphan scan, inflating orphan count #1021

Description

@Simona-digital-ops

Bug Report

gbrain version: 0.33.1.0
Engine: PGLite

Problem

gbrain orphans counts soft-deleted pages in its orphan scan. When you soft-delete a page with gbrain delete <slug>, the row remains in the pages table (recoverable for 72h), and the orphan query:

SELECT p.slug, ...
FROM pages p
WHERE NOT EXISTS (
  SELECT 1 FROM links l WHERE l.to_page_id = p.id
)

...does not filter out soft-deleted rows (p.deleted_at IS NULL missing). This means:

  1. Soft-deleted orphan pages still inflate the orphan count.
  2. Soft-deleting pages that linked to other pages can cause previously non-orphaned pages to appear orphaned (their inbound links disappear).

Reproduction

# Create a page and link it to another
gbrain put test-page < <(echo '# Test')
gbrain link test-page some-other-page

# Orphan count — some-other-page should not be orphaned (has inbound link)
gbrain orphans --count  # e.g., 100

# Soft-delete test-page
gbrain delete test-page

# Orphan count — some-other-page is now orphaned (inbound link gone)
# AND deleted test-page is still counted as orphan
gbrain orphans --count  # e.g., 101 or higher

Expected Behavior

gbrain orphans should filter out soft-deleted pages:

WHERE p.deleted_at IS NULL
AND NOT EXISTS (SELECT 1 FROM links l WHERE l.to_page_id = p.id)

Impact

In multi-source setups where the same page slugs exist in both default and another source (e.g., after gbrain sync --repo imports into default while the same files are also managed by a named source), soft-deleting the duplicates to clean up does not reduce the orphan count until the 72h hard-purge window expires. The doctor's sources purge-orphan-clones command (tracked for v0.32.0) would help here.

Workaround

Wait 72h for the autopilot hard-purge phase to remove soft-deleted rows. No immediate fix available.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions