Skip to content

improvement(cron): run stale execution and file version cleanup off the request path - #8535

Merged
TheodoreSpeaks merged 6 commits into
stagingfrom
debug/cron-fire
Oct 1, 2026
Merged

TheodoreSpeaks merged 6 commits into
stagingfrom
debug/cron-fire

Conversation

@TheodoreSpeaks

@TheodoreSpeaks TheodoreSpeaks commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Stale execution cleanup ran inline in the cron request; once the orphaned Chat run sweep was added, a run could outlast the cron executor's 50s request timeout, so the invocation errored and Lambda re-ran the whole job
  • Moved the cleanup body to a cleanup-stale-executions background task (background/cleanup-stale-executions.ts), unchanged apart from returning its summary instead of a response
  • Cron route now only enqueues the task and returns { triggered, jobId }, same pattern as cleanup-table-row-ttl: job id keyed to the 30-minute schedule window (a retry inside the window dedupes), concurrency 1, maxAttempts: 1 (the next tick is the retry)
  • cleanup-file-versions had the same problem through dispatchCleanupJobs, which pages every active workspace and resolves plans inline before fanning out chunks. Added a generic cleanup-dispatch task (background/cleanup-dispatch.ts, payload { jobType }) that runs the dispatcher in the worker; the route now only enqueues it, keyed to the day
  • Both routes still return 500 when the enqueue itself fails, so the cron error alarm keeps covering dispatch
  • Self-hosted database job backend runs the same functions in-process via the runner

Type of Change

  • Improvement

Testing

  • Existing stale-cleanup tests moved with the logic and call runCleanupStaleExecutions() directly; route tests cover enqueue failure and schedule-window dedupe through the route response
  • bun run lint, bun run check:audits (incl. api-validation) 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)

🤖 Generated with Claude Code

https://claude.ai/code/session_015hKcjxj8i3bzASz9PDTFSX

@vercel

vercel Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Oct 1, 2026 10:15pm UTC

Request Review

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 6 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

Re-trigger cubic

@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[High risk] Moves cleanup work from request handlers to background tasks.

No new blocking finding was established since the previous review.

Summary

The PR moves stale-execution cleanup and file-version dispatch out of cron requests and into background jobs.

  • Cron routes now enqueue window-keyed jobs and report enqueue failures.
  • The latest change adds dispatch retries and a task-level concurrency limit.
  • Existing cleanup tests were moved to exercise the background function directly.

Reviews (6) · Last reviewed commit: "fix(cron): retry and serialize cleanup d..."

Comment thread apps/sim/app/api/cron/cleanup-stale-executions/route.ts
@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@TheodoreSpeaks I have started the AI code review. It will take a few minutes to complete.

Comment thread apps/sim/app/api/cron/cleanup-stale-executions/route.test.ts Outdated

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 7 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

Re-trigger cubic

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@TheodoreSpeaks I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 7 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

Re-trigger cubic

Comment thread apps/sim/app/api/cron/cleanup-stale-executions/route.test.ts
@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@TheodoreSpeaks I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 7 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

Re-trigger cubic

@TheodoreSpeaks TheodoreSpeaks changed the title improvement(cron): run stale execution cleanup as a background task improvement(cron): run stale execution and file version cleanup off the request path Oct 1, 2026
@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@TheodoreSpeaks I have started the AI code review. It will take a few minutes to complete.

Comment thread apps/sim/app/api/cron/cleanup-file-versions/route.ts Outdated
Comment thread apps/sim/background/cleanup-dispatch.ts

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 10 files

You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.
Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

Fix all with cubic | Re-trigger cubic

Comment thread apps/sim/app/api/cron/cleanup-file-versions/route.ts
@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@TheodoreSpeaks I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 10 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.
Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

Re-trigger cubic

@TheodoreSpeaks
TheodoreSpeaks merged commit 320843e into staging Oct 1, 2026
59 of 60 checks passed
@TheodoreSpeaks
TheodoreSpeaks deleted the debug/cron-fire branch October 1, 2026 22:47

This branch was previously deployed

1 inactive deployment
Preview — 078e466f Deployed Oct 1, 2026 by vercel[bot]
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