Skip to content

feat(task-queue): rollback reconcile and verify gate - #592

Closed
aivong-openhands wants to merge 1 commit into
task-queue/06-watermarksfrom
task-queue/07-rollback
Closed

aivong-openhands wants to merge 1 commit into
task-queue/06-watermarksfrom
task-queue/07-rollback

Conversation

@aivong-openhands

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

Copy link
Copy Markdown
Contributor

Stack 7/7: OHE-3417 Track 1. Based on #591. Implements T1.10.2 steps 4 and 5. The chart counterpart is OpenHands/OpenHands-Cloud#1320 (T1.9).

Why

Queue tables keep work that runs the moment a worker returns, so switching workers off is not enough to roll back. Reconciliation must come after shutdown. procrastinate_retry_job_v2 matches status IN ('doing','failed'), so a retry from a still-running job or from a recovery pass can re-queue work the sweep already cleared.

Change

python -m server.task_queue.rollback:

  • reconcile cancels every todo job of the scheduled task names, including retries waiting on scheduled_at, and fails every residual doing one, so no execution lock stays held. It uses Procrastinate's own cancel_job_v1 (without abort) and finish_job_v1, all in one transaction under FOR UPDATE. Other tasks are untouched.
  • It refuses while any worker heartbeat is fresh. The tool cannot see pods, but it can see live workers, which makes the unsafe ordering hard to hit by accident.
  • verify is the zero-rows gate: it exits non-zero unless no todo or doing row remains.

Full rollback procedure (T1.10.2)

  1. Set taskQueue.schedulingEnabled: false. Workers keep draining.
  2. Allow a bounded drain of doing, D = 5 min.
  3. Scale the business and ops Deployments to 0 and confirm no pod remains.
  4. rollback reconcile.
  5. rollback verify, which must exit 0.
  6. Set startingDeadlineSeconds on the CronJobs, un-suspend them, and confirm the first occurrence fires.

Tests

  • Support pagination for branch search queries #22: cancelled todo jobs do not replay when a worker returns.
  • #22a: sweeping before shutdown leaves replayable work, shown by bypassing the guard and then retrying. The specified ordering does not, and the gate passes.
  • Refusal while a worker is alive; unrelated tasks untouched; CLI exit codes.

Not in this stack

  • T1.11 alert definitions: Datadog monitors on the task_queue.outcome log (outcome=executed), plus queue-age, failed and doing-age queries.
  • The T1-6 staging soak and the T1-7 cutover.
  • CronJob template deletion and post_ migrations (T1-8), after the rollback window closes.
  • Open items that gate cutover: PRE-1 (helm get values per env), PRE-3 (Cloud SQL, SaaS only), PRE-4 (pooler topology decides LISTEN/NOTIFY vs polling), PRE-5, and the per-job budgets / G from measured runtimes.

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-a902980

@github-actions github-actions Bot added the type: feat A new feature label Sep 30, 2026
@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
  rollback.py 127
Project Total  

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

@aivong-openhands
aivong-openhands force-pushed the task-queue/07-rollback branch 2 times, most recently from 57c8ea1 to 62f95a7 Compare September 30, 2026 19:00
python -m server.task_queue.rollback reconcile cancels every todo job of
the scheduled tasks and fails every residual doing one, so no execution
lock stays held; verify exits non-zero unless none remain (T1.10.2 steps
4 and 5).

reconcile refuses while any worker heartbeat is fresh. retry_job_v2
accepts doing and failed jobs, so a sweep while a job or recovery pass
can still retry re-queues work the sweep already cleared; the tests show
that ordering leaving replayable work and the specified one not.

OHE-3417 (Track 1, T1.10.2)

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). The branch is kept for reference. reconcile (cancel_job_v1 / finish_job_v1 in one transaction under FOR UPDATE) and verify (the zero-rows gate) carry into the new rollback runbook with two changes. First, the 'refuse while any worker heartbeat is fresh' guard is replaced by 'worker permit closed and closed-set gate passed', because worker pods keep running sandbox lifecycle during rollback. Second, the task set becomes the full inventory, including the repair tasks.


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