Skip to content

feat(task-queue): Procrastinate worker for the three Track 1 scheduled jobs - #588

Closed
aivong-openhands wants to merge 1 commit into
mainfrom
task-queue/03-worker
Closed

aivong-openhands wants to merge 1 commit into
mainfrom
task-queue/03-worker

Conversation

@aivong-openhands

@aivong-openhands aivong-openhands commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Stack 3/7: OHE-3417 Track 1. Based on #587. Implements T1.5, T1.5.1 and T1.6: the task registry and python -m server.task_queue.worker. The watchdog (#4 in the stack) and ops recovery (#5) come next.

Change

server/task_queue/ runs clean_app_conversation_start_tasks, clean_proactive_convo_table and enrich_user_interaction_data as Procrastinate periodic tasks. Each calls the job's existing main() unchanged, imported lazily so a disabled job needs none of its configuration.

Decision Why
Execution lock per job, no queueing_lock anywhere retry_job_v2 sets todo and keeps queueing_lock. The index is unique over todo, so a retry would collide with the next queued occurrence. lock reproduces concurrencyPolicy: Forbid
TASK_QUEUE_ROLE=business|ops scopes periodic registration _periodic_deferrer reads the whole registry regardless of consumed queues. Without this, ops workers would schedule business jobs (#17)
TASK_QUEUE_SCHEDULING_ENABLED, separate from role Rollback must stop scheduling while workers keep draining
max_delay 26 h app-wide; startup refuses a schedule whose gap the window does not cover max_delay drops an occurrence before any task body runs, so nothing downstream can recover it
Per-occurrence outcome logged as executed / skipped_stale / failed Skipped is not success; the overdue-run alert keys on executed only (T1.11)
Cleanup occurrences superseded by a newer one are skipped and recorded; enrichment runs late T1.5.1 staleness table
Retry cap 3, shutdown_graceful_timeout unset Setting it marks unfinished jobs aborted, and recovery never picks those up
Worker exits non-zero whenever it stops without a signal (DB loss) Otherwise the container stays up but idle
Refuses GCP_DB_INSTANCE PRE-3: the psycopg pool cannot use the Cloud SQL connector creator. OHE (DB_HOST) is unaffected
Per-job enable, schedule and budget env: TASK_QUEUE_<JOB>_{ENABLED,SCHEDULE,BUDGET_SECONDS} server/constants.py convention

Tests (real Postgres, real worker)

Covers acceptance criteria #1, #2, #8, #9, #10, #17, #23 and #25:

  • Occurrence uniqueness is asserted at the DB level, including with one replica's clock 2 s fast.
  • Ops workers do not schedule business jobs.
  • A running A plus a queued B retries cleanly.
  • The poison-job cap holds.
  • The worker exits on an unreachable DB.
  • max_delay window behaviour.
  • Cron is UTC.
  • An end-to-end entrypoint test: SIGTERM, then exit 0.

This PR was created by an AI agent (OpenHands) on behalf of the user.

@aivong-openhands can click here to continue refining the PR


Enterprise server image for this PR:

ghcr.io/openhands/enterprise-server:sha-0f0e532

@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  server/task_queue
  app.py
  config.py 52, 70
  jobs.py
  tasks.py
  worker.py 29-32, 61-63, 87-91, 95-96, 100
Project Total  

This report was generated by python-coverage-comment-action

@aivong-openhands
aivong-openhands force-pushed the task-queue/02-procrastinate-schema branch from c591712 to c27fe11 Compare September 30, 2026 06:14
@aivong-openhands
aivong-openhands force-pushed the task-queue/02-procrastinate-schema branch from c27fe11 to f8db211 Compare September 30, 2026 15:18
@aivong-openhands
aivong-openhands force-pushed the task-queue/03-worker branch 2 times, most recently from 0f7e86c to 387acd8 Compare September 30, 2026 20:55
Base automatically changed from task-queue/02-procrastinate-schema to main September 30, 2026 21:18
…d jobs

server/task_queue runs clean-app-conversation-start-tasks,
clean-proactive-convo-table and enrich-user-interaction as Procrastinate
periodic tasks. Each calls the job's existing main().

- Execution lock per job and no queueing_lock anywhere: Procrastinate
  keeps queueing_lock across a retry, which would collide with the next
  queued occurrence.
- TASK_QUEUE_ROLE (business|ops) scopes periodic registration, because
  the deferrer reads the whole registry regardless of consumed queues.
- TASK_QUEUE_SCHEDULING_ENABLED stops scheduling without changing what
  the worker consumes, so rollback can drain.
- max_delay 26h app-wide; startup refuses a schedule whose gap the
  window does not cover, since a dropped occurrence is unrecoverable.
- Cleanup occurrences superseded by a newer one are skipped and
  recorded; every occurrence logs executed/skipped_stale/failed.
- Worker exits non-zero whenever it stops without a signal (database
  unreachable), shutdown_graceful_timeout left unset.
- Refuses the Cloud SQL connector path (PRE-3) rather than bypass it.

OHE-3417 (Track 1, T1.5, T1.6)

Co-authored-by: openhands <openhands@all-hands.dev>
@aivong-openhands

Copy link
Copy Markdown
Contributor Author

Closing: superseded by the revised CronJob migration plan for OHE-3417 (rev 16). That plan runs the scheduled jobs on the shared worker App from #601 instead of a separate business/ops App. It also uses a per-job queueing lock with no execution lock, and drops Procrastinate retries and the 26 h max_delay. The branch is kept for reference. Worth reusing in the new work: calling each job's existing main() lazily, the TASK_QUEUE__* env convention, outcome logging, and the real-Postgres / real-worker test harness.


This comment was posted by an AI agent (OpenHands) on behalf of @aivong-openhands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: feat A new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants