8000 Implement the Daemon section on the Control page by yakutovicha · Pull Request #259 · aiidalab/aiidalab-home · GitHub
[go: up one dir, main page]

Skip to content

Implement the Daemon section on the Control page - #259

Open
yakutovicha wants to merge 20 commits into
mainfrom
feature/daemon-tab
Open

yakutovicha wants to merge 20 commits into
mainfrom
feature/daemon-tab

Conversation

@yakutovicha
@yakutovicha yakutovicha commented Sep 28, 2026 •
Copy link
Copy Markdown
Member

Fixes #254

Replaces the DaemonControlWidget placeholder with:

  • A status line (running with N workers / not running / error), with a warning when workers exceed the available CPUs.
  • A per-worker table: worker id, PID, CPU, memory, RSS, uptime.
  • Start / Stop / Restart. Start, and Restart's fallback when the daemon is stopped, start the configured daemon.default_workers, as verdi daemon start does.
  • Add / Remove worker; removing the last worker is refused after re-checking the live count.
  • A collapsed accordion with the last 50 lines of the daemon log, loaded when opened and following status updates while open.

Actions run on a background thread with feedback. All buttons are disabled meanwhile and re-enabled before the status is re-probed; refresh() is a no-op during an action, so revisiting the tab can't re-enable them early.

Notes for review:

  • get_worker_info() is only called once is_daemon_running holds, since it blocks for the client timeout otherwise. Only DaemonNotRunningException counts as "not running"; other daemon errors (e.g. a stale PID file) show as an error with AiiDA's message, which says how to fix it.
  • circus refuses a command that clashes with one still in progress (e.g. removing a worker while a previously removed one is still shutting down) in its reply, {"status": "error", "reason": ...}, instead of raising. Such refusals are shown as failures rather than reported as success.
  • circus reports a message string instead of stats for a worker that has just stopped; the table shows "?" for it.
  • Restart uses DaemonClient.restart_daemon() (restarts the workers). Note that verdi daemon restart in AiiDA 2.9 does a full stop + start instead.

Tests

Unit tests for the probe, age humanizer, log tail reader, worker table rendering and button-state sync, plus, against a fake daemon client, the start/stop/restart/add/remove flows, the configured worker count, refused commands and a failing re-probe after an action; and a refresh with the test profile's real client.

🤖 Generated with Claude Code

@edan-bainglass
Copy link
Copy Markdown
Member

Comments:

  • What should reload log do? Unclear.
  • Should we also have a clear log button?
  • I don't think remove worker is working as it should (see below)

After adding a few workers...

image

Then removing one...

image

Still showing 4. I then hit refresh...

image

I expected 4 to be removed, not 1.

👃🐟

@yakutovicha
yakutovicha removed this pull request from stack #263 October 23, 2026 10:30
@yakutovicha
yakutovicha changed the base branch from feature/storage-tab to main October 23, 2026 10:42
Replace the DaemonControlWidget placeholder with daemon management:
a status line with the worker count (warning when workers exceed the
CPUs), a per-worker stats table, start/stop/restart, add/remove
worker, and a collapsible tail of the daemon log.

- Actions run on a background thread with feedback. All buttons are
  disabled meanwhile and re-enabled before the status is re-probed,
  so a failing probe cannot leave the page locked; refresh() is a
  no-op during an action, so revisiting the tab cannot re-enable
  them early.
- get_worker_info() is only called once is_daemon_running holds (it
  blocks for the client timeout otherwise). A daemon that stopped in
  between shows as not running, an unreachable one as an error.
- Restart falls back to start when the daemon is stopped. Removing
  the last worker is refused after re-checking the live count.
- The log tail (last 50 lines, reading at most 64 KiB) loads when
  the accordion opens and follows status updates while open.

Add unit tests for the probe, age humanizer, log tail reader, worker
table rendering (including circus' message for a stopped worker), the
button-state sync and the actions against a fake daemon client.
circus refuses a command that clashes with one still in progress, for
example removing a worker while a previously removed one is still
shutting down, and reports it as {"status": "error", "reason": ...}
in its reply instead of raising. The Daemon section ignored the reply
and announced success, e.g. "A worker has been removed.", although
nothing happened.

Check the reply in _run_action and show circus's reason as the
failure; the restart and remove-worker helpers now return it.

Add a test with a fake daemon that refuses to remove a worker.
The Start button, and the start fallback of Restart, called
start_daemon() with its default of one worker. `verdi daemon start`,
which the container uses at startup, starts daemon.default_workers
instead, so a user who configured more workers got only one after
stopping and starting the daemon from the Control page.

Pass the profile's daemon.default_workers, as verdi does.

The fake daemon now requires the number of workers; the start and
restart-fallback tests check that the configured number is used.
After a daemon action, _run_action re-enables the buttons before it
re-probes the status, and reports a probe failure after the action's
own message. So a failing probe can neither leave the page with all
buttons disabled nor hide the action's result. Nothing tested this.

Add a test whose status probe raises after a successful stop.
Flatten _probe_daemon_workers into a single try with two excepts; the
behaviour is unchanged, since is_daemon_running only reads the PID
file and cannot raise DaemonNotRunningException.

List the daemon's action buttons once and build the button row from
that list, instead of repeating the five buttons.

No behaviour change; the existing probe and action tests cover both.
yakutovicha and others added 2 commits November 3, 2026 16:28
It was hidden in #275 while the section was a placeholder; it is now
implemented.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
circus replied before the worker had started or stopped, so the
status shown after removing a worker still listed it. Pass wait=True
with a timeout above circus' 30 s graceful shutdown, and show a
timeout as a warning, since circus still completes the change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@yakutovicha
Copy link
Copy Markdown
Member Author

Then removing one...

image Still showing 4

Okay, this has been fixed in df0de83. The problem was that the UI didn't wait for the process to finish, so it was still showing 4 workers, while 1 was shutting down.

circus stops the oldest worker, which surprised the reviewer. While
it shuts down, mark its row as stopping and name its PID.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@yakutovicha
Copy link
Copy Markdown
Member Author
image I expected 4 to be removed, not 1.

This is how circus' code works: it stops the oldest worker; naturally, the smallest ID gets removed. In this commit, it is made explicit: d44db6c

@yakutovicha
Copy link
Copy Markdown
Member Author
  • What should reload log do? Unclear.

I removed the button. The log is anyway getting reloaded after one presses "Refresh"

@yakutovicha
Copy link
Copy Markdown
Member Author
  • Should we also have a clear log button?

Probably not; it is already cut to 50 lines. Hard to imagine what the use case would be.

8000

yakutovicha and others added 7 commits November 3, 2026 17:02
An action started during a refresh, e.g. right after opening the
tab, ran alongside it: the refresh then cleared the action's message
and re-enabled the buttons. Show a warning instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A timeout means circus did not answer within 40 s, usually because a
worker is still stopping, but possibly because circus is stuck. Say
so instead of asserting that the worker is still starting or
stopping.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keep the log tail size and the worker change timeout together at the
top of the daemon code, instead of spread over the module and the
class.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The worker table and the choice of the worker shown as stopping each
sorted the workers by age their own way. Share one helper, so the
top row and the stopping worker are the same by construction.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cover the not-running warnings of stop/add/remove, a plain restart,
timeouts of start/stop/restart (errors, unlike add/remove), removing a
worker when none reports an age, and an unreadable daemon log.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The six tests differed only in the daemon's state and the expected
result. Every row now compares the whole result, and a stopped daemon
must not be asked for its workers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
yakutovicha and others added 4 commits November 3, 2026 17:49
Show side by side that a timeout fails start, stop and restart, but
only warns for adding or removing a worker, and check that the
buttons come back in every case. The restart failure test went
through the same path as the restart timeout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The stopped, one-worker and two-worker states of the Add/Remove
worker buttons were spread over three tests. The status and table
checks dropped from them are covered by the stop/start and
add/remove tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Start on a running daemon and stop/add/remove on a stopped one only
show a warning. Test them together, also checking the warning
color.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Check formatting, oldest-first order and the hidden circus ids on one
table whose workers are not listed in order, as circus may report
them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

Control page: implement the Daemon section

2 participants

0