Skip to content

fix(cleanup): compare live-paused statuses with IN, not ANY over a row constructor - #6004

Merged
TheodoreSpeaks merged 1 commit into
stagingfrom
fix/large-value-cleanup-status-array
Jul 28, 2026
Merged

fix(cleanup): compare live-paused statuses with IN, not ANY over a row constructor#6004
TheodoreSpeaks merged 1 commit into
stagingfrom
fix/large-value-cleanup-status-array

Conversation

@TheodoreSpeaks

@TheodoreSpeaks TheodoreSpeaks commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • unreferencedLargeValuePredicate() and the legacy/prune queries wrote pe.status = ANY(${LIVE_PAUSED_REFERENCE_STATUSES}::text[]). Drizzle expands a JS array to ($1, $2, $3) — correct for IN, but as ANY((...)::text[]) Postgres rejects it outright: cannot cast type record to text[]
  • Switched all 9 sites to pe.status IN ${LIVE_PAUSED_REFERENCE_STATUSES}, which uses drizzle's native expansion as intended — no cast, no helper
  • Broken since fix(large-refs): cleanup based on table read #4716 (2026-05-22), so cleanup-logs failed on every run since. The throw landed at step 2 of 6, which also silently disabled legacy large-value cleanup, large-value metadata pruning, job_execution_logs retention, and orphaned-snapshot cleanup

Type of Change

  • Bug fix

Testing

  • New live-paused-statuses-sql.test.ts renders the real unreferencedLargeValuePredicate() against the real drizzle dialect and schema (the global drizzle/schema mocks hide rendering bugs). Verified it fails on both the original ANY() form and on a status = IN (...) typo, and passes only on the correct form
  • Executed the actual rendered predicate against staging Postgres: it runs and matches 52,203 unreferenced large values (the old form errors)
  • 85 tests across lib/execution/payloads, background/cleanup-*, lib/cleanup pass; tsc --noEmit clean; bun run lint and the full audit suite pass

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Jul 28, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jul 28, 2026 4:41pm

Request Review

@cursor

cursor Bot commented Jul 28, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches retention/deletion eligibility for execution large values and metadata; wrong SQL would either fail jobs (old bug) or delete data that still references live paused runs.

Overview
Fixes broken cleanup-logs and large-value cleanup SQL by changing how LIVE_PAUSED_REFERENCE_STATUSES is compared in raw Drizzle sql fragments.

All nine predicates that gated deletion/pruning on “live” paused executions used status = ANY(${LIVE_PAUSED_REFERENCE_STATUSES}::text[]). Drizzle expands the JS array as a row constructor ($1, $2, $3), so Postgres rejected the statements (cannot cast type record to text[]) and the cleanup job failed early on every run.

Those sites now use status IN ${LIVE_PAUSED_REFERENCE_STATUSES}, which renders as a valid IN ($1, $2, $3) list. Updates span cleanup-logs.ts (legacy large-value file eligibility) and large-value-metadata.ts (stale reference prune + unreferencedLargeValuePredicate()).

Adds live-paused-statuses-sql.test.ts, which renders unreferencedLargeValuePredicate() with the real PgDialect (unmocked drizzle/schema) and asserts IN binding, no ANY(($… form, and no = IN typo.

Reviewed by Cursor Bugbot for commit f8df6e7. Bugbot is set up for automated code reviews on this repo. Configure here.

@greptile-apps

greptile-apps Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Fixes Postgres binding of live-paused statuses used in cleanup/prune SQL.

  • Adds shared livePausedStatusArray that renders ARRAY[$n,...]::text[] via drizzle sql.join instead of a row constructor from a raw JS array.
  • Replaces all nine = ANY(...) sites in cleanup-logs and large-value metadata helpers; leaves notInArray(..., LIVE_PAUSED_REFERENCE_STATUSES) unchanged.
  • Adds dialect-level render tests and mocks livePausedStatusArray in cleanup-logs tests.

Confidence Score: 5/5

Safe to merge; the SQL array-binding fix matches the failure mode and all prior broken ANY() sites are covered.

Shared fragment produces ARRAY[...]::text[] with one bind per status; remaining LIVE_PAUSED_REFERENCE_STATUSES use is notInArray, which expects a JS array; tests pin the render shape against the real dialect.

Important Files Changed

Filename Overview
apps/sim/lib/execution/payloads/large-value-metadata.ts Introduces correctly rendered text[] fragment and updates all ANY() guards that previously cast a row constructor.
apps/sim/background/cleanup-logs.ts Switches four ANY() predicates to livePausedStatusArray; notInArray still uses the JS status list appropriately.
apps/sim/lib/execution/payloads/live-paused-status-array.test.ts Unmocks drizzle and asserts ARRAY rendering, param count, and rejection of the broken row-constructor form.
apps/sim/background/cleanup-logs.test.ts Mocks the new livePausedStatusArray export so cleanup-logs unit tests keep loading.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[LIVE_PAUSED_REFERENCE_STATUSES JS array] --> B[livePausedStatusArray sql fragment]
  B --> C["ANY(ARRAY[$1,$2,$3]::text[])"]
  C --> D[cleanup-logs legacy large values]
  C --> E[unreferencedLargeValuePredicate]
  C --> F[pruneStaleReferences]
Loading

Reviews (1): Last reviewed commit: "fix(cleanup): bind live-paused statuses ..." | Re-trigger Greptile

@TheodoreSpeaks
TheodoreSpeaks force-pushed the fix/large-value-cleanup-status-array branch from dfeac7b to f8df6e7 Compare July 28, 2026 16:41
@TheodoreSpeaks TheodoreSpeaks changed the title fix(cleanup): bind live-paused statuses as a Postgres array, not a row constructor fix(cleanup): compare live-paused statuses with IN, not ANY over a row constructor Jul 28, 2026
@TheodoreSpeaks
TheodoreSpeaks merged commit bf376dd into staging Jul 28, 2026
20 checks passed
@TheodoreSpeaks
TheodoreSpeaks deleted the fix/large-value-cleanup-status-array branch July 28, 2026 17:23
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.

1 participant