Skip to content

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

Open
alex-rawlings-yyc wants to merge 3 commits into
mainfrom
cleanup-orphaned-project-records
Open

Sweep project records orphaned by failed index rollback (#141)#154
alex-rawlings-yyc wants to merge 3 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.

Devin: https://app.devin.ai/review/sillsdev/interlinearizer-extension/pull/154


This change is Reviewable

@alex-rawlings-yyc alex-rawlings-yyc self-assigned this Jul 8, 2026
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@alex-rawlings-yyc, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 8 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8951f95a-422c-45aa-bfa1-27e34583ef18

📥 Commits

Reviewing files that changed from the base of the PR and between 7ba086d and d83f2c5.

📒 Files selected for processing (4)
  • src/__tests__/main.test.ts
  • src/__tests__/services/projectStorage.test.ts
  • src/main.ts
  • src/services/projectStorage.ts
✨ 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
@alex-rawlings-yyc
alex-rawlings-yyc force-pushed the cleanup-orphaned-project-records branch 2 times, most recently from 7a532c4 to 4a6a40c Compare July 15, 2026 18:14
alex-rawlings-yyc and others added 2 commits July 15, 2026 16:07
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>
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.
@alex-rawlings-yyc
alex-rawlings-yyc force-pushed the cleanup-orphaned-project-records branch from 4a6a40c to 1383522 Compare July 15, 2026 22:07
@alex-rawlings-yyc
alex-rawlings-yyc marked this pull request as ready for review July 15, 2026 22:16
A corrupt pendingCleanup value was recovered as empty but the sweep's
empty-set early return skipped the rewrite, so the bad value survived
and
re-warned on every launch. Report corruption from readPendingCleanup and
overwrite the key with [] when nothing is left to sweep.
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