Skip to content

DaemonClient: add wait option to increase/decrease workers - #7502

Merged
khsrali merged 2 commits into
aiidateam:mainfrom
khsrali:allow_for_wait_in_increment_methods_of_DaemonClient
Jul 31, 2026
Merged

DaemonClient: add wait option to increase/decrease workers#7502
khsrali merged 2 commits into
aiidateam:mainfrom
khsrali:allow_for_wait_in_increment_methods_of_DaemonClient

Conversation

@khsrali

@khsrali khsrali commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

The increase_workers and decrease_workers methods sent the circus
incr/decr command without the waiting property. Without it, the
daemon replies as soon as it acknowledged the command, which is before
the workers have actually been spawned or stopped, and the response does
not even contain the resulting numprocesses.

Add a wait keyword to both methods that is forwarded as the waiting
property. When set, the call returns only once the daemon acted on the
command and the response contains the resulting number of workers. It
defaults to False to keep the current behavior for existing callers.

Closes #7500

The `increase_workers` and `decrease_workers` methods sent the circus
`incr`/`decr` command without the `waiting` property. Without it, the
daemon replies as soon as it acknowledged the command, which is before
the workers have actually been spawned or stopped, and the response does
not even contain the resulting `numprocesses`.

Add a `wait` keyword to both methods that is forwarded as the `waiting`
property. When set, the call returns only once the daemon acted on the
command and the response contains the resulting number of workers. It
defaults to `False` to keep the current behavior for existing callers.
@khsrali
khsrali requested a review from agoscinski July 30, 2026 13:10
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 10eec259-54a5-42ad-ba1f-72cc37ea2cfd

📥 Commits

Reviewing files that changed from the base of the PR and between 92167d4 and a76a801.

📒 Files selected for processing (1)
  • tests/engine/daemon/test_client.py

📝 Walkthrough

Walkthrough

DaemonClient worker scaling methods now accept wait=True, forward the waiting flag to the daemon, and return completed worker counts or raise timeout exceptions. Tests cover asynchronous acknowledgements and synchronous completion behavior.

Changes

Daemon worker operations

Layer / File(s) Summary
Worker command waiting semantics
src/aiida/engine/daemon/client.py
increase_workers and decrease_workers accept wait and send it as the daemon command’s waiting property.
Worker operation behavior tests
tests/engine/daemon/test_client.py
Tests cover default acknowledgements, completed results with wait=True, and DaemonTimeoutException handling for both operations.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: agoscinski, edan-bainglass, bud-macaulay

Sequence Diagram(s)

sequenceDiagram
  participant DaemonClient
  participant Daemon
  participant Workers
  DaemonClient->>Daemon: Request worker increase or decrease
  Daemon->>Workers: Apply worker count change
  Workers-->>Daemon: Report updated count
  Daemon-->>DaemonClient: Return acknowledgement or completed count
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: adding a wait option to worker increase/decrease methods.
Description check ✅ Passed The description matches the code change by explaining the wait flag, waiting behavior, and default false.
Linked Issues check ✅ Passed The PR fulfills #7500 by making worker increase/decrease calls wait via the waiting flag instead of polling.
Out of Scope Changes check ✅ Passed Changes stay within the daemon worker wait feature and its tests/docstrings, with no obvious unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.68%. Comparing base (b2f05de) to head (a76a801).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7502      +/-   ##
==========================================
+ Coverage   80.67%   80.68%   +0.02%     
==========================================
  Files         581      581              
  Lines       47002    47002              
==========================================
+ Hits        37913    37918       +5     
+ Misses       9089     9084       -5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/engine/daemon/test_client.py`:
- Around line 399-405: Update tests/engine/daemon/test_client.py lines 399-405
in test_change_workers_without_wait and its nested await_workers helper by
annotating started_daemon_client and target and adding matching Sphinx :param:
fields; update lines 425-426 to annotate started_daemon_client and document it
with :param:; update lines 439-441 to annotate stopped_daemon_client and method
and add both :param: fields. Keep types in annotations and use Sphinx-style
docstrings consistently.
- Line 451: Update the pytest.raises match assertion in the daemon timeout test
to escape the literal period in “Connection to the daemon timed out.”, using a
raw regex literal so the message match remains exact.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d0405d7e-61d5-4b3b-9c75-96efdd194ada

📥 Commits

Reviewing files that changed from the base of the PR and between b2f05de and 92167d4.

📒 Files selected for processing (2)
  • src/aiida/engine/daemon/client.py
  • tests/engine/daemon/test_client.py

Comment thread tests/engine/daemon/test_client.py
Comment thread tests/engine/daemon/test_client.py Outdated

@edan-bainglass edan-bainglass left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Easy. LGTM! Thanks @khsrali

@Bud-Macaulay Bud-Macaulay left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@agoscinski agoscinski left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure circus is doing something with the waiting parameter in the case of incr and decr? I could not find the same logic for these two commands as for start/stop/restart where it definitely uses this parameter. It seems to me that circus ignores the waiting parameter in the case of incr and decr. I admit its strange, since the keyword is mentioned in the docstring (see class IncrProc). Really don't want to add this functionality into circus, since we are about to remove it in the next release.

@khsrali

khsrali commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator Author

@agoscinski
circus is certainly not ignoring that, as it's demonstrated in the tests.

Yes! agreed to drop circus, but whatever you replace it with, you gotta provide that public api. And wait seems like something that our gui developers are legitimately requesting.
So it's harmless to already provide the functionality as of now.

@agoscinski

Copy link
Copy Markdown
Collaborator

well you dont test wait=False

@agoscinski

agoscinski commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

We can still add it. As u say its an API change we can support later. I just wanted to make u aware (or verify) that wait=False seems to have the same functionality as wait=True and I would at least make the user aware that this does not work as expected

@edan-bainglass

Copy link
Copy Markdown
Member

We can still add it. As u say its an API change we can support later. I just wanted to make u aware (or verify) that wait=False seems to have the same functionality as wait=True and I would at least make the user aware that this does not work as expected

Thanks @agoscinski. @khsrali can you confirm this? Is wait=True actually causing a wait for response? Otherwise, we cannot switch to this.

@khsrali

khsrali commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator Author

well you dont test wait=False

We actually do, that's test_change_workers_without_wait does exactly that. False is the default value.

We can still add it. As u say its an API change we can support later. I just wanted to make u aware (or verify) that wait=False seems to have the same functionality as wait=True and I would at least make the user aware that this does not work as expected

Thanks @agoscinski. @khsrali can you confirm this? Is wait=True actually causing a wait for response? Otherwise, we cannot switch to this.

Yes, as demonstrated by the tests.

@agoscinski

agoscinski commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

You are right. I see now that you assert 'numprocesses' not in response which means the result response is not there. @khsrali also checked in circus the logic which is in the Controler class. start/stop/restart only had some additional logic considering the waiting argument in Command that is not needed IncrProc. PR is good to go. Sorry for making a mess but when I did not find any logic in circus I was a bit worried that the parameter is silently ignored.

@khsrali

khsrali commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator Author

Cheers @agoscinski
It's always nice to be careful with these things
Also a pleasure to investigate & learn more about circus 😃👍🏽

@khsrali
khsrali merged commit df7fdcd into aiidateam:main Jul 31, 2026
19 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in aiida-core v2.9.0 Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Asyncronous daemon ops

4 participants