Skip to content

🐛 Director-v2: a closing dask client is not a scheduler change - #10308

Merged
mergify[bot] merged 1 commit into
ITISFoundation:masterfrom
sanderegg:fix/director-v2-closing-dask-client-not-scheduler-change
Dec 3, 2026
Merged

mergify[bot] merged 1 commit into
ITISFoundation:masterfrom
sanderegg:fix/director-v2-closing-dask-client-not-scheduler-change

Conversation

@sanderegg

@sanderegg sanderegg commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Goal

Stop director-v2 from failing running computational jobs when it shuts down.

What do these changes do?

distributed.Client._close clears the client's scheduler-identity cache, and director-v2 connects with asynchronous=True, so scheduler_info() returns only that cache. A client that has started closing reports no scheduler id, which check_scheduler_is_still_the_same read as a replaced scheduler. That error is terminal: the computational scheduler marks every processing task FAILED. director-v2 closes its dask clients on shutdown, while a scheduling iteration can still be running, so a rolling update declared a live run lost.

An empty cache now goes through check_scheduler_status first, so a client that is not running raises ComputationalBackendNotConnectedError. The scheduler already treats that error as transient - tasks wait in WAITING_FOR_CLUSTER, bounded by COMPUTATIONAL_BACKEND_MAX_WAITING_FOR_CLUSTER_TIMEOUT, and resume when a replica reconnects - so it needed no change. ComputationalSchedulerChangedError now fires only on a differing scheduler id and stays terminal.

Two tests. Closing the director-v2 dask client against a live SpecCluster must raise the transient error, and a second client still reports the same scheduler id. An unreachable backend must leave tasks in WAITING_FOR_CLUSTER, keep the run unreleased and unscheduled, and return the tasks to STARTED once the backend answers.

Follow-up

Shutting down still does not drain scheduling iterations that are already running, so clients that close later in the lifespan (database, storage) can still be reached mid-iteration. Tracked under #4524.

Related issue/s

  • fixes ITISFoundation/private-issues#710 - a running job was set to FAILED during a director-v2 rolling update, with its outputs uploaded after the run was declared lost
  • relates to Make director-v2 scalable/restartable #4524

How to test

cd services/director-v2
source ../../.venv/bin/activate
pytest tests/unit/test_modules_dask_client.py -k "closed_client or changed_scheduler" -v

The second target needs the core and ops swarm stack for postgres and rabbitmq, so it is slower. It did not run locally; CI's [unit] director-v2 job ran both tests and they passed:

pytest tests/unit/with_dbs/comp_scheduler/test_scheduler_dask.py -k "backend_client_being_closed or scheduler_changes or scheduler_offline" -v

Dev-ops

No changes, no new environment variables.

AI assistance

  • 🤖 This PR was AI generated

Assisted-by: GitHub Copilot VS Code agent (Copilot SDK) [bash] [pytest] [ruff]

@github-actions github-actions Bot added the a:director-v2 issue related with the director-v2 service label Dec 3, 2026
@github-actions github-actions Bot added this to the Run Rudolph run milestone Dec 3, 2026
@sanderegg sanderegg self-assigned this Dec 3, 2026
`check_scheduler_is_still_the_same` reported a `scheduler_info()` without an
`id` as a replaced dask scheduler. That cache is emptied by
`distributed.Client._close`, and director-v2 connects with
`asynchronous=True`, so `scheduler_info()` returns only the cache: a client
that starts closing reports a scheduler change.

That error is terminal in the computational scheduler - it marks every
processing task FAILED. director-v2 closes its dask clients in the
dask-clients-pool lifespan on shutdown, while a scheduling iteration may still
be running, so a rolling update declared a run lost whose dask-scheduler was
alive and untouched.

An empty cache now goes through `check_scheduler_status`, so a client that is
not running raises `ComputationalBackendNotConnectedError`, which the scheduler
already treats as transient: tasks wait in WAITING_FOR_CLUSTER and resume when
a replica reconnects. `ComputationalSchedulerChangedError` now requires
evidence of a different scheduler id.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sanderegg
sanderegg force-pushed the fix/director-v2-closing-dask-client-not-scheduler-change branch from 336ee62 to 945e961 Compare December 3, 2026 11:33
@sanderegg
sanderegg requested a balanced review from Copilot December 3, 2026 11:33
@sonarqubecloud

sonarqubecloud Bot commented Dec 3, 2026

Copy link
Copy Markdown

Copilot AI 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.

🟢 Approval recommended

No active review issues were identified for the change distinguishing Dask client shutdown from scheduler replacement.

No open issues 🎉

What changed in this PR

Prevents director-v2 shutdown from incorrectly failing running computational jobs by distinguishing a closing Dask client from a replaced scheduler.

Changes:

  • Checks client status before treating a missing scheduler ID as a scheduler change.
  • Adds regression tests for closed-client error handling and task recovery without resubmission or resource release.
File Description
services/​director-v2/​src/​simcore_service_director_v2/​utils/​dask.py Treats non-running clients with missing scheduler IDs as transient disconnects.
services/​director-v2/​tests/​unit/​test_modules_dask_client.py Tests closed-client handling while the scheduler remains alive.
services/​director-v2/​tests/​unit/​with_dbs/​comp_scheduler/​test_scheduler_dask.py Tests waiting and recovery without resubmitting tasks or releasing resources.

Review effort: Balanced

@sanderegg
sanderegg marked this pull request as ready for review December 3, 2026 13:07
@mergify mergify Bot added the queued label Dec 3, 2026
@mergify

mergify Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

✅ Merged into master as 1286ca6 at 14:46 UTC

Less than a minute in the queue, with no time running CI.

So far

  • ✅ Entered the queue Thu 3 Dec, 14:46 · rule default · triggered by rule queue every pull request that is not a draft anymore
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged 14:46 · 1286ca6
15 merge conditions met
  • #approved-reviews-by>=2
  • #changes-requested-reviews-by=0
  • #review-threads-unresolved=0
  • -conflict
  • -draft
  • base=master
  • github-review-approved · required by GitHub repository ruleset rule master-branch-reviews
  • label!=🤖-do-not-merge
  • any of · required by GitHub repository ruleset rule master branch:
    • check-skipped = @github-actions/deploy to dockerhub
    • check-neutral = @github-actions/deploy to dockerhub
    • check-success = @github-actions/deploy to dockerhub
  • any of · required by GitHub repository ruleset rule master branch:
    • check-success = @github-actions/unit-tests
    • check-neutral = @github-actions/unit-tests
    • check-skipped = @github-actions/unit-tests
  • any of · required by GitHub repository ruleset rule master branch:
    • check-success = @github-actions/integration-tests
    • check-neutral = @github-actions/integration-tests
    • check-skipped = @github-actions/integration-tests
  • any of · required by GitHub repository ruleset rule master branch:
    • check-success = @github-actions/system-tests
    • check-neutral = @github-actions/system-tests
    • check-skipped = @github-actions/system-tests
  • any of · required by GitHub repository ruleset rule master branch:
    • check-success = @github-actions/check OAS' are up to date
    • check-neutral = @github-actions/check OAS' are up to date
    • check-skipped = @github-actions/check OAS' are up to date
  • any of · required by GitHub repository ruleset rule master branch:
    • check-success = @github-actions/api-server openai compatibility
    • check-neutral = @github-actions/api-server openai compatibility
    • check-skipped = @github-actions/api-server openai compatibility
  • any of · required by GitHub repository ruleset rule master branch:
    • check-success = @sonarqubecloud/SonarCloud Code Analysis
    • check-neutral = @sonarqubecloud/SonarCloud Code Analysis
    • check-skipped = @sonarqubecloud/SonarCloud Code Analysis

Times in UTC · dashboard · how the merge queue works

@mergify
mergify Bot merged commit 1286ca6 into ITISFoundation:master Dec 3, 2026
71 checks passed
@mergify mergify Bot removed the queued label Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a:director-v2 issue related with the director-v2 service

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants