-
Notifications
You must be signed in to change notification settings - Fork 726
feat: cleanup orphan script (CM-904) #3808
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
services/apps/script_executor_worker/src/workflows/cleanup/segments-agg.ts
Show resolved
Hide resolved
services/apps/script_executor_worker/src/activities/cleanup/segments-agg.ts
Outdated
Show resolved
Hide resolved
services/apps/script_executor_worker/src/activities/cleanup/segments-agg.ts
Show resolved
Hide resolved
|
|
||
| export async function cleanupMemberSegmentsAgg(args: IScriptBatchTestArgs): Promise<void> { | ||
| const BATCH_SIZE = args.batchSize ?? 100 | ||
| const TABLE_NAME = 'memberSegmentsAgg' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
humm, probably not a good idea to pass the table name like this - we usually use an interface and reference it where needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok here maybe the name can be confusing, this will not query a different table, it will just add the table name in a field of the orphans table so that we know it came from memberAggs or orgAggs or any other table in future, i will probably change the field name
5bb85b9 to
a6993b7
Compare
| orphansFound: totalOrphansFound, | ||
| orphansDeleted: totalOrphansDeleted, | ||
| }) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cumulative counts reset on each continueAsNew iteration
Medium Severity
The totalOrphansFound, totalOrphansDeleted, and startTime variables are initialized to zero at the start of each workflow function, which resets them after every continueAsNew call. Since updateOrphanCleanupRun uses direct assignment rather than increment, each batch overwrites the previous counts with only the current batch's values. The final orphanCleanupRuns record will only reflect the last batch's statistics, not cumulative totals across all batches. Similarly, executionTimeMs on completion only measures the final empty-results query, not total execution time.
Additional Locations (1)
services/apps/script_executor_worker/src/workflows/cleanup/segments-agg.ts
Show resolved
Hide resolved
a6993b7 to
31a9ea7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cursor Bugbot has reviewed your changes and found 1 potential issue.


Add Temporal Scripts for Orphaned Segment Aggregates Cleanup
Summary
Added automated cleanup scripts to remove orphaned segment aggregates that reference deleted members and organizations.
Changes
cleanupMemberSegmentsAggandcleanupOrganizationSegmentAggworkflows to identify and delete orphaned records inmemberSegmentAggsandorganizationSegmentAggstablesTechnical Details
BUFFER_ONEoverlap policy to prevent concurrent executionsscript-executortask queueNote
Medium Risk
Automates recurring deletions in production tables and adds new scheduled Temporal workflows; risk is mainly around query correctness/performance and unintended data removal if orphan detection is wrong.
Overview
Adds two new Temporal cleanup workflows to delete orphan rows in
memberSegmentsAggandorganizationSegmentsAgg(records whose referenced member/org no longer exists), processing in batches with chunked deletes andcontinueAsNewuntil drained.Introduces DAL helpers to query/delete these orphans plus an
orphanCleanupRunstracking table API, and wires new activities/exports and Temporal schedules (daily at midnight) so the worker automatically runs and records progress/status.Written by Cursor Bugbot for commit 374cb58. This will update automatically on new commits. Configure here.