Skip to content

feat(cron): deduplicate and protect scheduled executions#601

Open
JAVA-LW wants to merge 1 commit into
iOfficeAI:mainfrom
JAVA-LW:codex/cron-execution-dedup
Open

feat(cron): deduplicate and protect scheduled executions#601
JAVA-LW wants to merge 1 commit into
iOfficeAI:mainfrom
JAVA-LW:codex/cron-execution-dedup

Conversation

@JAVA-LW

@JAVA-LW JAVA-LW commented Jul 10, 2026

Copy link
Copy Markdown

Summary

  • add task-level queue protection for scheduled cron executions
  • deduplicate scheduled occurrences with a database-backed (job_id, scheduled_at) claim
  • add renewable run leases, heartbeat renewal, retry preservation, and restart recovery
  • claim occurrences before conversation preparation/creation
  • keep schedule calculation on the theoretical occurrence grid

Closes #600

Why

Conversation busy state alone cannot prevent duplicate callbacks from creating two independent conversations. The occurrence claim must happen at the task/database level before any conversation is materialized.

Implementation

  • add queue_enabled to cron jobs
  • add cron_job_runs with a unique occurrence key and active-run index
  • use BEGIN IMMEDIATE for atomic cross-process claims
  • record duplicate, running, retrying, skipped, success, and error outcomes
  • use owner IDs and expiring leases for crash recovery
  • preserve scheduled_at through retries and scheduler callbacks
  • fence stale owners from updating job state after losing their lease

Testing

  • RUSTUP_TOOLCHAIN=stable cargo fmt --all -- --check
  • RUSTUP_TOOLCHAIN=stable cargo check -p aionui-cron -p aionui-db -p aionui-app
  • RUSTUP_TOOLCHAIN=stable cargo test -p aionui-cron -p aionui-db -p aionui-api-types
  • RUSTUP_TOOLCHAIN=stable cargo test -p aionui-app --test cron_e2e

All checks pass on the latest upstream main.

Related UI

The corresponding queue-protection UI and visual schedule builder are in iOfficeAI/AionUi#3552.

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.

Prevent duplicate and overlapping scheduled task executions

1 participant