Skip to content

✨ Auto-start daemon in verdi presto#7351

Merged
GeigerJ2 merged 5 commits into
aiidateam:mainfrom
agoscinski:feat/presto-daemon-autostart
May 6, 2026
Merged

✨ Auto-start daemon in verdi presto#7351
GeigerJ2 merged 5 commits into
aiidateam:mainfrom
agoscinski:feat/presto-daemon-autostart

Conversation

@agoscinski
Copy link
Copy Markdown
Collaborator

@agoscinski agoscinski commented Apr 29, 2026

I would have preferred to not add an option --no-daemon-autostart but the docker image needs to be flexible for different environments and automatically detect and initialize the aiida profile according to them which would have resulted in copying the auto-configuration from verdi presto into the CI.


When a broker is configured, verdi presto now automatically starts the daemon after profile setup. If the daemon fails to start, a warning is shown without failing the command.

Add --no-daemon-autostart flag to skip the daemon auto-start. This is needed in the Docker container where s6-overlay manages the daemon lifecycle separately (the editable install in run-before-daemon-start must complete before the daemon starts).

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.29%. Comparing base (6adc2b0) to head (7e61b20).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7351      +/-   ##
==========================================
+ Coverage   80.27%   80.29%   +0.03%     
==========================================
  Files         577      577              
  Lines       45530    45543      +13     
==========================================
+ Hits        36544    36564      +20     
+ Misses       8986     8979       -7     

☔ View full report in Codecov by Sentry.
📢 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.

agoscinski added a commit to agoscinski/aiida-core that referenced this pull request Apr 29, 2026
When a broker is configured, `verdi presto` now automatically
starts the daemon after profile setup. If the daemon fails to
start, a warning is shown without failing the command.
@agoscinski agoscinski force-pushed the feat/presto-daemon-autostart branch from 9a7f318 to 58cf75a Compare April 29, 2026 20:15
agoscinski added a commit to agoscinski/aiida-core that referenced this pull request Apr 29, 2026
When a broker is configured, `verdi presto` now automatically
starts the daemon after profile setup. If the daemon fails to
start, a warning is shown without failing the command.
@agoscinski agoscinski force-pushed the feat/presto-daemon-autostart branch from 58cf75a to 478b194 Compare April 29, 2026 20:16
agoscinski added a commit to agoscinski/aiida-core that referenced this pull request Apr 30, 2026
When a broker is configured, `verdi presto` now automatically
starts the daemon after profile setup. If the daemon fails to
start, a warning is shown without failing the command.
@agoscinski agoscinski force-pushed the feat/presto-daemon-autostart branch from 478b194 to 5ebbda0 Compare April 30, 2026 13:49
agoscinski added a commit to agoscinski/aiida-core that referenced this pull request Apr 30, 2026
When a broker is configured, `verdi presto` now automatically
starts the daemon after profile setup. If the daemon fails to
start, a warning is shown without failing the command.

Replace `verdi presto` with `verdi profile setup core.psql_dos`
in the Docker container's `aiida-prepare.sh` because `verdi presto`
auto-starting the daemon conflicts with the s6-overlay startup
sequence (the editable install in `run-before-daemon-start` must
complete before the daemon starts).
@agoscinski agoscinski force-pushed the feat/presto-daemon-autostart branch from 5ebbda0 to d252d46 Compare April 30, 2026 15:18
agoscinski added a commit to agoscinski/aiida-core that referenced this pull request Apr 30, 2026
When a broker is configured, `verdi presto` now automatically
starts the daemon after profile setup. If the daemon fails to
start, a warning is shown without failing the command.

Add `--no-daemon-autostart` flag to skip the daemon auto-start.
This is needed in the Docker container where s6-overlay manages
the daemon lifecycle separately (the editable install in
`run-before-daemon-start` must complete before the daemon starts).
@agoscinski agoscinski force-pushed the feat/presto-daemon-autostart branch from d252d46 to 5ed5cdd Compare April 30, 2026 15:42
@mbercx
Copy link
Copy Markdown
Member

mbercx commented Apr 30, 2026

One alternative: instead of an option, which is user facing and pollutes the API, can we read an env variable instead? So inside a Docker container one could run:

NO_DAEMON_AUTOSTART=1 verdi presto

agoscinski added a commit to agoscinski/aiida-core that referenced this pull request Apr 30, 2026
When a broker is configured, `verdi presto` now automatically
starts the daemon after profile setup. If the daemon fails to
start, a warning is shown without failing the command.

Add `--no-daemon-autostart` flag to skip the daemon auto-start.
This is needed in the Docker container where s6-overlay manages
the daemon lifecycle separately (the editable install in
`run-before-daemon-start` must complete before the daemon starts).
@agoscinski agoscinski force-pushed the feat/presto-daemon-autostart branch from 5ed5cdd to 04a3890 Compare April 30, 2026 20:08
@agoscinski agoscinski marked this pull request as ready for review April 30, 2026 20:30
agoscinski added a commit to agoscinski/aiida-core that referenced this pull request Apr 30, 2026
When a broker is configured, `verdi presto` now automatically
starts the daemon after profile setup. If the daemon fails to
start, a warning is shown without failing the command.

Add `--no-daemon-autostart` flag to skip the daemon auto-start.
This is needed in the Docker container where s6-overlay manages
the daemon lifecycle separately (the editable install in
`run-before-daemon-start` must complete before the daemon starts).
@agoscinski agoscinski force-pushed the feat/presto-daemon-autostart branch from 04a3890 to 61455d2 Compare April 30, 2026 20:30
@agoscinski
Copy link
Copy Markdown
Collaborator Author

One alternative: instead of an option, which is user facing and pollutes the API, can we read an env variable instead? So inside a Docker container one could run:

Yes true could work. It's mainly for setting up aiida in CI environments where setting env vars is not annoying. Maybe AIIDA_NO_DAEMON_AUTOSTART so all our env variables start with the same prefix.

@GeigerJ2 GeigerJ2 self-requested a review May 4, 2026 17:42
@GeigerJ2
Copy link
Copy Markdown
Collaborator

GeigerJ2 commented May 4, 2026

One alternative: instead of an option, which is user facing and pollutes the API, can we read an env variable instead? So inside a Docker container one could run:

NO_DAEMON_AUTOSTART=1 verdi presto

Agree with this! Adding a commit rn.

agoscinski and others added 3 commits May 4, 2026 20:54
When a broker is configured, `verdi presto` now automatically
starts the daemon after profile setup. If the daemon fails to
start, a warning is shown without failing the command.

Add `--no-daemon-autostart` flag to skip the daemon auto-start.
This is needed in the Docker container where s6-overlay manages
the daemon lifecycle separately (the editable install in
`run-before-daemon-start` must complete before the daemon starts).
The daemon auto-start in `verdi presto` previously caught the
broad `Exception`, which would silently swallow unrelated
programmer errors (`AttributeError`, `TypeError`, etc.) under
a friendly "Failed to start daemon" warning and hide
regressions in nearby code paths.

Catch only `DaemonException` (the documented failure mode of
`DaemonClient.start_daemon`) and `ConfigurationError` (raised
by `get_daemon_client` for an unknown profile). Anything else
now propagates as a real traceback.

Tests:

- Rewrite `test_presto_daemon_start_failure` to inject a
  `DaemonException` through the shared `mock_daemon_client`
  fixture instead of redefining its own monkeypatch and
  raising a `RuntimeError` (which only worked under the broad
  except). Also assert the "verdi daemon start" follow-up
  hint is shown.
- Tighten `test_presto_starts_daemon` from
  `assert_called_once()` to `assert_called_once_with()` so any
  future change to the call signature is caught.
- Add `test_presto_no_broker_skips_daemon` covering the
  `--no-broker` branch of the skip guard.
- Move `mock_daemon_client` into `@pytest.mark.usefixtures`
  for tests that only need the side effect, and drop an
  unused `pytestconfig` parameter from
  `test_presto_without_rmq`.
Replace `--no-daemon-autostart` with the environment variable
`AIIDA_NO_DAEMON_AUTOSTART`. The flag exists to serve scripted
container/CI setups, not interactive users; an env var keeps that
contract out of the user-facing CLI surface and matches the existing
`AIIDA_*` prefix convention (`AIIDA_PATH`, `AIIDA_BROKER_*`,
`AIIDA_TEST_PROFILE`, etc.). Suggested by @mbercx and refined by
@agoscinski in PR review.

Update `aiida-prepare.sh` accordingly: prepend
`AIIDA_NO_DAEMON_AUTOSTART=1` to the `verdi presto` invocation instead
of passing the flag.

Tests: replace `test_presto_no_daemon_autostart` with
`test_presto_no_daemon_autostart_env`, exercising the env var via
`monkeypatch.setenv`.
@GeigerJ2 GeigerJ2 force-pushed the feat/presto-daemon-autostart branch from d608c59 to a9bc5f5 Compare May 4, 2026 18:54
Copy link
Copy Markdown
Collaborator

@GeigerJ2 GeigerJ2 left a comment

Choose a reason for hiding this comment

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

LGTM!

GeigerJ2 added 2 commits May 6, 2026 13:32
The previous implementation treated any non-empty value of
`AIIDA_NO_DAEMON_AUTOSTART` as "skip daemon". That made
`AIIDA_NO_DAEMON_AUTOSTART=0` and `=false` silently skip the
daemon, contrary to what those values read as.

The env var is an internal escape hatch for the Docker init
script (and similar CI setups), not a public API surface. Keep
the recognized form narrow: only the literal string `1` skips
the daemon. Any other value (`0`, `true`, `false`, empty, typos)
falls through to "start the daemon", which is the safe default.

Drop the env var from user-facing reference: `--help` and
`command_line.rst` no longer mention it. Documenting it in the
CLI reference would turn an internal hatch into public API and
require a deprecation cycle to remove. The Docker init script
already comments why it sets the var; that's the right place
for consumer-side docs. A short comment near the call site
in `cmd_presto.py` keeps it discoverable for future maintainers
via `grep`.

Tests: parametrize over representative non-`1` values (`0`,
`true`, `false`, empty, `banana`) to lock in that none of them
skip the daemon.
@GeigerJ2 GeigerJ2 enabled auto-merge (squash) May 6, 2026 11:58
@GeigerJ2 GeigerJ2 merged commit 6a6f66a into aiidateam:main May 6, 2026
19 checks passed
@GeigerJ2
Copy link
Copy Markdown
Collaborator

GeigerJ2 commented May 6, 2026

Added myself as co-author, bc I iterated a bit on the PR, and @mbercx, as he brought up the env var idea; and having ideas is the actual real work nowadays, not the prompting to get the code :)

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.

3 participants