Skip to content

Sweep project records orphaned by failed index rollback (#141)#154

Draft
alex-rawlings-yyc wants to merge 2 commits into
mainfrom
cleanup-orphaned-project-records
Draft

Sweep project records orphaned by failed index rollback (#141)#154
alex-rawlings-yyc wants to merge 2 commits into
mainfrom
cleanup-orphaned-project-records

Conversation

@alex-rawlings-yyc

@alex-rawlings-yyc alex-rawlings-yyc commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

createProject writes project:{id} before adding it to the projectIds index, and rolls the record back if the index write fails. If that rollback delete also fails, the record was orphaned forever — never listed, never deleted, pure storage bloat.

The PAPI storage API exposes only read/write/delete with no key enumeration, so reconciling live keys against the index isn't possible. Instead, record the orphaned id in a persistent pendingCleanup set on rollback failure, and retry the deletion opportunistically on the next activation via a fire-and-forget sweep.

  • Add pendingCleanup storage key with its own serialization queue so recording an orphan and sweeping can't clobber each other's writes.
  • recordPendingCleanup: idempotently add an orphan id; a failure to record is logged and swallowed so it never masks the original index error the caller must see.
  • sweepPendingCleanup: retry each recorded delete (ENOENT = already gone = success), clear cleaned ids, retain ids that fail again.
  • Run the sweep at activation, fire-and-forget: a cleanup failure never blocks activation and it retries on the next run.

This change is Reviewable

createProject writes project:{id} before adding it to the projectIds
index, and rolls the record back if the index write fails. If that
rollback delete also fails, the record was orphaned forever — never
listed, never deleted, pure storage bloat.

The PAPI storage API exposes only read/write/delete with no key
enumeration, so reconciling live keys against the index isn't possible.
Instead, record the orphaned id in a persistent pendingCleanup set on
rollback failure, and retry the deletion opportunistically on the next
activation via a fire-and-forget sweep.

- Add pendingCleanup storage key with its own serialization queue so
  recording an orphan and sweeping can't clobber each other's writes.
- recordPendingCleanup: idempotently add an orphan id; a failure to
  record is logged and swallowed so it never masks the original index
  error the caller must see.
- sweepPendingCleanup: retry each recorded delete (ENOENT = already
  gone = success), clear cleaned ids, retain ids that fail again.
- Run the sweep at activation, fire-and-forget: a cleanup failure never
  blocks activation and it retries on the next run.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@alex-rawlings-yyc alex-rawlings-yyc self-assigned this Jul 8, 2026
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9a84e28d-8cb0-4b5c-8270-39e153d52969

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cleanup-orphaned-project-records

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@alex-rawlings-yyc alex-rawlings-yyc linked an issue Jul 8, 2026 that may be closed by this pull request
Skip (and drop) pending-cleanup ids still in the index so a
misrecorded live project's record is never deleted, and tolerate a
corrupt pendingCleanup value instead of wedging the sweep on every
activation. Dedup the queue/read helpers.
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.

Clean up orphaned project records when index rollback fails

1 participant