Skip to content

feat(server): cleanup embedding after workspace deleted - #15851

Merged
darkskygit merged 2 commits into
canaryfrom
darksky/workspace-deletion-cleanup
Nov 12, 2026
Merged

darkskygit merged 2 commits into
canaryfrom
darksky/workspace-deletion-cleanup

Conversation

@darkskygit

@darkskygit darkskygit commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes
    • Workspace deletion now more reliably removes associated documents, search data, embeddings, and other workspace records, including when cleanup is retried or object deletion encounters errors.
    • Cleanup waits for in-progress embedding updates and prevents deleted workspace data from reappearing. Reconciliation also removes orphaned search documents and blocks while preserving data for live workspaces.
    • Banning an account now removes its workspace, access policies, and associated data.

@github-actions github-actions Bot added docs Improvements or additions to documentation mod:i18n Related to i18n app:server test Related to test cases rust app:core mod:server-native labels Nov 12, 2026
@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Workspace cleanup now discovers and removes orphan rows across additional runtime tables, with embedding-table availability passed through deletion and reconciliation. Native and server tests cover cleanup during workspace deletion, including remote search projections and account bans.

Changes: Workspace-scoped storage cleanup

Layer / File(s) Summary
Discover and delete orphan storage rows
packages/backend/native/src/runtime/storage_runtime/workspace_cleanup_checkpoint.rs, packages/backend/native/src/runtime/storage_runtime/workspace_cleanup.rs, packages/backend/native/src/runtime/storage_runtime/mod.rs
Orphan-row discovery and deletion now cover expanded workspace-storage tables and configured checkpoint kinds. Cleanup paths pass embedding-table availability through targeted deletion and reconciliation. The runtime module updates related exports and imports.
Validate native cleanup and embedding commit fencing
packages/backend/native/src/runtime/storage_runtime/workspace_cleanup.rs, packages/backend/native/src/runtime/backend_runtime/embedding/store.rs
Database-backed tests cover live-workspace preservation, orphan cleanup, repeat deletion, and reconciliation. The embedding test coordinates a commit with workspace deletion and checks that later commits cannot restore deleted rows.
Validate server workspace deletion cleanup
packages/backend/server/src/__tests__/e2e/indexer/remote-provider.spec.ts, packages/backend/server/src/__tests__/e2e/user/account.spec.ts, packages/backend/server/e2e/remote-provider/README.md
The remote-provider test checks that deletion and reconciliation remove workspace rows from OpenSearch. The account-ban test checks removal of workspace-scoped records. The README updates setup instructions and suite coverage.

Entitlement test precision

Layer / File(s) Summary
Set expiration at millisecond precision
packages/backend/native/src/runtime/backend_runtime/entitlement/tests.rs
The entitlement test truncates the statement timestamp to milliseconds when setting the subscription expiration time.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Possibly related PRs

  • toeverything/AFFiNE#15822: This PR changes delete_orphan_storage_rows and workspace-deletion cleanup behavior in the same checkpoint module.
Merge Risk: Moderate · up to 65418

The new workspace-deletion cleanup could delete the global root-inspection cursor, which may stop inspection from reaching workspaces beyond the first batch. Several earlier concerns about root-source error reporting and sync state also remain open. Resolve or explicitly accept these before merging.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "feat(server): cleanup embedding after workspace deleted" matches the main change. The raw summary shows that workspace deletion now also removes embedding-table rows (checked by embedding_t…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "feat(server): cleanup embedding after workspace deleted" matches the main change. The raw summary shows that workspace deletion now also removes embedding-table rows (checked by embedding_tables_exist and passed into orphan-row cleanup), and the tests verify that all workspace rows, including embedding rows, are removed after deletion. The title is specific and describes the primary behavior. The title does not mention the test, reconciliation, or lock-ordering changes, but those are supporting details and not the main point.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 63c9eb0a-8593-460b-8a67-397d87ccf99c
Commits

Reviewing files that changed from the base of the PR and between 04846ca and 65418e5.

Files selected for processing: 1

  • packages/backend/native/src/runtime/backend_runtime/entitlement/tests.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Deploying blocksuite-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 65418e5
Status: ✅  Deploy successful!
Preview URL: https://76306058.blocksuite-docs.pages.dev
Branch Preview URL: https://darksky-workspace-deletion-c.blocksuite-docs.pages.dev

View logs

@codecov

codecov Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 55.27%. Comparing base (e2767cb) to head (65418e5).

Additional details and impacted files
@@            Coverage Diff             @@
##           canary   #15851      +/-   ##
==========================================
- Coverage   55.32%   55.27%   -0.05%     
==========================================
  Files        4032     4032              
  Lines      193839   193839              
  Branches    31504    31486      -18     
==========================================
- Hits       107237   107146      -91     
- Misses      82324    82399      +75     
- Partials     4278     4294      +16     
Flag Coverage Δ
server-test 78.87% <ø> (-0.13%) ⬇️
unittest 34.58% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 12

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9d00a3b2-3cc7-482f-a10e-dfd64cbe468c
Commits

Reviewing files that changed from the base of the PR and between e2767cb and 97cf2b1.

Files ignored due to path filters: 1

  • Cargo.lock is excluded by !**/*.lock
Files selected for processing: 80

  • Cargo.toml
  • packages/backend/native/Cargo.toml
  • packages/backend/native/index.d.ts
  • packages/backend/native/src/blocking.rs
  • packages/backend/native/src/doc/mod.rs
  • packages/backend/native/src/lib.rs
  • packages/backend/native/src/runtime/backend_runtime/blob_access/cache.rs
  • packages/backend/native/src/runtime/backend_runtime/blob_access/mod.rs
  • packages/backend/native/src/runtime/backend_runtime/doc_compactor.rs
  • packages/backend/native/src/runtime/backend_runtime/doc_storage.rs
  • packages/backend/native/src/runtime/backend_runtime/doc_writer.rs
  • packages/backend/native/src/runtime/backend_runtime/domain_command/execute.rs
  • packages/backend/native/src/runtime/backend_runtime/domain_command/history.rs
  • packages/backend/native/src/runtime/backend_runtime/domain_command/lifecycle.rs
  • packages/backend/native/src/runtime/backend_runtime/domain_command/mod.rs
  • packages/backend/native/src/runtime/backend_runtime/embedding/mod.rs
  • packages/backend/native/src/runtime/backend_runtime/embedding/source.rs
  • packages/backend/native/src/runtime/backend_runtime/embedding/store.rs
  • packages/backend/native/src/runtime/backend_runtime/mod.rs
  • packages/backend/native/src/runtime/backend_runtime/root_inspection/mod.rs
  • packages/backend/native/src/runtime/backend_runtime/root_inspection/report.rs
  • packages/backend/native/src/runtime/backend_runtime/root_inspection/source.rs
  • packages/backend/native/src/runtime/backend_runtime/root_inspection/worker.rs
  • packages/backend/native/src/runtime/backend_runtime/scope_compiler.rs
  • packages/backend/native/src/runtime/backend_runtime/search/mod.rs
  • packages/backend/native/src/runtime/backend_runtime/search/projection.rs
  • packages/backend/native/src/runtime/backend_runtime/search/worker/mod.rs
  • packages/backend/native/src/runtime/backend_runtime/search/worker/root.rs
  • packages/backend/native/src/runtime/backend_runtime/search/worker/workspace.rs
  • packages/backend/native/src/runtime/mod.rs
  • packages/backend/native/src/runtime/root_doc.rs
  • packages/backend/native/src/runtime/storage_lifecycle.rs
  • packages/backend/native/src/runtime/storage_runtime/current_doc.rs
  • packages/backend/native/src/runtime/storage_runtime/document_cleanup_execution.rs
  • packages/backend/native/src/runtime/storage_runtime/mod.rs
  • packages/backend/native/src/runtime/storage_runtime/workspace_cleanup.rs
  • packages/backend/native/src/runtime/storage_runtime/workspace_cleanup_checkpoint.rs
  • packages/backend/server/e2e/remote-provider/README.md
  • packages/backend/server/src/__tests__/doc/history.spec.ts
  • packages/backend/server/src/__tests__/doc/userspace.spec.ts
  • packages/backend/server/src/__tests__/doc/workspace.spec.ts
  • packages/backend/server/src/__tests__/e2e/indexer/remote-provider.spec.ts
  • packages/backend/server/src/__tests__/e2e/user/account.spec.ts
  • packages/backend/server/src/__tests__/models/doc.spec.ts
  • packages/backend/server/src/__tests__/sync/gateway.spec.ts
  • packages/backend/server/src/base/error/def.ts
  • packages/backend/server/src/base/error/errors.gen.ts
  • packages/backend/server/src/cli.ts
  • packages/backend/server/src/core/auth/dev.ts
  • packages/backend/server/src/core/auth/service.ts
  • packages/backend/server/src/core/backend-runtime/operations.ts
  • packages/backend/server/src/core/backend-runtime/provider.ts
  • packages/backend/server/src/core/backend-runtime/search-operations.ts
  • packages/backend/server/src/core/doc-jobs/job.ts
  • packages/backend/server/src/core/doc/adapters/userspace.ts
  • packages/backend/server/src/core/doc/adapters/workspace.ts
  • packages/backend/server/src/core/doc/merge-updates.ts
  • packages/backend/server/src/core/doc/options.ts
  • packages/backend/server/src/core/doc/storage/doc.ts
  • packages/backend/server/src/core/sync/gateway.ts
  • packages/backend/server/src/core/workspaces/resolvers/workspace.ts
  • packages/backend/server/src/data/app.ts
  • packages/backend/server/src/data/commands/root-source.ts
  • packages/backend/server/src/models/doc.ts
  • packages/backend/server/src/schema.gql
  • packages/common/graphql/src/schema.ts
  • packages/common/nbstore/src/__tests__/sync.spec.ts
  • packages/common/nbstore/src/frontend/doc.ts
  • packages/common/nbstore/src/impls/cloud/doc.ts
  • packages/common/nbstore/src/impls/idb/doc.ts
  • packages/common/nbstore/src/storage/doc.ts
  • packages/common/nbstore/src/sync/doc/index.ts
  • packages/common/nbstore/src/sync/doc/peer.ts
  • packages/frontend/core/src/components/affine/page-history-modal/data.spec.ts
  • packages/frontend/core/src/components/affine/page-history-modal/data.ts
  • packages/frontend/core/src/components/workspace-selector/workspace-card/index.spec.tsx
  • packages/frontend/core/src/components/workspace-selector/workspace-card/index.tsx
  • packages/frontend/i18n/src/i18n-completenesses.json
  • packages/frontend/i18n/src/i18n.gen.ts
  • packages/frontend/i18n/src/resources/en.json

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@darkskygit
darkskygit force-pushed the darksky/workspace-deletion-cleanup branch from 97cf2b1 to 04846ca Compare November 12, 2026 09:43
@darkskygit darkskygit changed the title feat(server): improve workspace root sync feat(server): cleanup embedding after workspace deleted Nov 12, 2026
@darkskygit
darkskygit merged commit 9c61550 into canary Nov 12, 2026
65 of 66 checks passed
@darkskygit
darkskygit deleted the darksky/workspace-deletion-cleanup branch November 12, 2026 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app:core app:server docs Improvements or additions to documentation mod:i18n Related to i18n mod:server-native rust test Related to test cases

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant