Skip to content

fix(workspace): make scheduled deletion purge reliable - #910

Merged
viethung0o0 merged 1 commit into
mainfrom
fix/workspace-purge-reliability
Aug 6, 2026
Merged

fix(workspace): make scheduled deletion purge reliable#910
viethung0o0 merged 1 commit into
mainfrom
fix/workspace-purge-reliability

Conversation

@viethung0o0

Copy link
Copy Markdown
Contributor

Summary

Scheduled workspace deletion was not completing: the hourly purge crashed while deleting a workspace's messages, so no due workspace was ever removed. This makes the purge correct, resilient, and safe to run alongside live traffic.

What changed

  • Purge no longer crashes on message/attachment data. These live in compressed TimescaleDB hypertables that the previous batch-delete could not touch. They are now drained safely by conversation, in small bounded pages, so worker memory stays flat even for very large workspaces.
  • One bad workspace can no longer stall the whole purge. Each workspace is torn down in isolation; a failure is logged and retried on the next run while every other due workspace still gets deleted.
  • Cleaner teardown. Disconnecting channels no longer throws when an integration's credentials are already gone (Messenger/WhatsApp) and for the built-in web chat channel.
  • Deletion timing. The countdown shown to customers is accurate again, and the purge runs on a predictable schedule.
  • Heavier work is throttled so it stays gentle on the shared database and is safe under PgBouncer transaction pooling.

Notable

While verifying against TimescaleDB's documentation, the decompression-limit setting used a parameter name that does not exist in TimescaleDB, which would fail at runtime. It has been corrected and centralized in one shared helper (also removing a duplicated statement), with a test that pins the exact name.

Test plan

  • pnpm --filter @chatbotx.io/business exec vitest run — 730 passing (adds coverage for the per-workspace guard, hypertable draining, and skip-disconnect-when-no-credentials)
  • pnpm --filter @chatbotx.io/database exec vitest run — 378 passing (adds the decompression-parameter-name test)
  • pnpm --filter worker test purge-workspaces
  • Type-check: database, business, worker-config, worker, webchat, builder
  • Lint (Biome) on all changed files
  • Verify on staging against a real compressed hypertable: schedule a workspace with historical messages for deletion and confirm the purge completes cleanly

Notes for reviewers

  • Message sharding (if enabled) is out of scope here — shard-resident messages are cleaned by the existing per-contact path; a follow-up can extend workspace purge to shards.

@github-actions github-actions Bot added the bug Something isn't working as expected label Aug 6, 2026
@viethung0o0
viethung0o0 marked this pull request as ready for review August 6, 2026 09:02
@viethung0o0
viethung0o0 merged commit aec902c into main Aug 6, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants