Fix project delete platform cleanup ordering#12179
Conversation
Greptile SummaryThis PR fixes an orphaned-resource bug in Confidence Score: 5/5Safe to merge — ordering fix is correct and the added error isolation is a reasonable improvement for a cleanup worker. No P0 or P1 issues found. The reordering correctly ensures platform-scoped resources (especially the globally-unique _console_rules.domain) are cleaned before the project DB teardown can fail and leave them orphaned. The move outside the outer try block is safe because those cleanup calls only use $dbForPlatform, which is available from the start of the function. The shift from fail-fast to log-and-continue semantics is a deliberate and appropriate trade-off for a background cleanup worker. No files require special attention. Important Files Changed
Reviews (2): Last reviewed commit: "Continue project cleanup after resource ..." | Re-trigger Greptile |
✨ Benchmark resultsComparing 1.9.x (before) to fix/project-delete-platform-cleanup (after). Before
After
Delta
Top API waits
|
🔄 PHP-Retry SummaryFlaky tests detected across commits: Commit
|
| Test | Retries | Total Time | Details |
|---|---|---|---|
UsageTest::testFunctionsStats |
1 | 10.19s | Logs |
UsageTest::testPrepareSitesStats |
1 | 7ms | Logs |
UsageTest::testEmbeddingsTextUsageDoesNotBreakProjectUsage |
1 | 5ms | Logs |
FunctionsClientTest::testCreateExecution |
1 | 3.44s | Logs |
FunctionsClientTest::testGetExecution |
1 | 13ms | Logs |
FunctionsServerTest::testCreateExecution |
1 | 39ms | Logs |
DatabaseServerTest::testBulkCreate |
1 | 240.74s | Logs |
What does this PR do?
Moves project-level platform cleanup earlier in the deletes worker, before project database cleanup begins.
When a project is deleted, the project document is removed first and the deletes worker later cleans related resources. Previously, platform-scoped cleanup for
platforms,rules,keys,webhooks,installations,repositories,vcsComments, andscheduleshappened after the worker opened and cleaned the project database. If project database cleanup failed before that point, those platform rows could be left behind.This is especially visible for proxy rules because
_console_rules.domainis globally unique. An orphaned rule keeps the domain reserved and causes users to seedomain is already usedwhen adding the domain to a site in another project.This PR does not add new cleanup behavior. It moves the existing cleanup blocks earlier so they run before the project DB cleanup failure point.
Test Plan
Result:
_console_rulesrow, then invoking the realDeletes::deleteProject()path with a simulated project DB cleanup failure before the old platform cleanup section.Old ordering result:
This confirms the rule was orphaned when project DB cleanup failed first.
Fixed rule cleanup result:
This confirms the rule is removed before the project DB cleanup failure point.
Deletes::deleteProject()path with the same simulated project DB cleanup failure.Fixed platform cleanup result:
Related PRs and Issues
Checklist