Repository navigation
Implement the Danger zone section on the Control page - #262
Conversation
|
I have various nitpicky comments, but let's not hang on those. I defer to @danielhollas for review here 🙂 |
|
@yakutovicha I think we need one more option in the danger zone, which is to reset only the .local directory. This will allow the apps to remain but to be incompatible, requiring the user to reinstall each from their manage app page. Without this, scheduling a reset and restarting the container will cause the home to be empty, making it more difficult to reinstall former apps. I'm realizing now that this would require a coordinated change in the docker stack script that executes the resets, which currently only knows of the two options you implemented. |
|
I would like us to step back here and consider only what is really needed (in an MVP sense) for the python 3.12 migration. As Edan pointed out, we just need the users to clean their We can consider this specific PR later after 3.12 is released, but I don't want it to be a blocker.
|
Indeed, that would do. I updated the migration banner PR recently with details in the banner regarding a .local reset, pointing to the danger zone section of the control page. But in principle, I agree that this can just be a button to trigger |
|
@yakutovicha a suggestion from @giovannipizzi is to |
|
@edan-bainglass that sounds very reasonable, let's go with that, thanks! @yakutovicha in terms of priority, it would be great if you could focus on the danger zone first, because that's what is blocking the python 3.12 migration. The other sections are more nice-to-haves and we can ship the new image without them if needed. |
Is this from a fresh container? Or from your development container? |
Oh, interesting, I would have suggested this exact solution, of moving it and then copy back the needed folder. What we can do instead is to hardlink the whole folder into |
|
See comments here 🙏 |
|
btw: I would still advocate for a minimal implementation here, only what we need for the migration --- less code to review and test. See also my earlier comment #262 (comment) |
Replace the DangerZoneWidget placeholder with scheduling of a factory reset that the AiiDAlab container performs on its next restart, via a mode flag written to ~/AIIDALAB_FACTORY_RESET (mode 1: remove ~/apps and ~/.local; mode 2: erase the whole home directory). - The schedule button is enabled only by typing the literal phrase "factory-reset". The written flag is read back to verify it, and the view always reflects what is on disk, so a flag that failed verification shows up with a cancel button. - A scheduled reset replaces the form with an explanatory alert and a cancel button that removes the flag file. - A non-empty AIIDALAB_FACTORY_RESET environment variable overrides the flag file (even "0", which cancels it), so the section warns about it; an empty one is ignored, as by the container script. Tested with the flag file redirected to a temporary path: confirmation gating, the schedule and cancel flows, a failed verification, unknown modes and the environment-variable warning. A final test checks that the real flag file was never created.
The scheduled-reset alert told users to run `aiidalab-launch restart`, a command that does not exist (restarting is `start --restart`). Naming a host-side tool is also wrong on JupyterHub deployments, where the server is stopped and started from the hub. Describe the trigger in deployment-neutral terms instead: the reset happens the next time the AiiDAlab container starts. No test change: no test asserts on this sentence.
Cover the two error branches that had no test: a flag file that exists but cannot be read (the alert says so instead of naming a mode) and a cancel that fails (the error is shown and the scheduled view stays). A directory in place of the flag file triggers both without mocking. Also check that the details line follows the selected reset mode.
The phrase to type was only in the text box's placeholder, which disappears as soon as the user starts typing, so after a typo nothing on the page said what to type. State it in a visible label above the box instead, and drop the placeholder so it is stated in one place. No test change: the existing gating test covers the behaviour, and the label is static text.
e135fe2 to
0efc3ef
Compare
17d969a to
c19b4f4
Compare
|
Please also see my review on aiidalab/aiidalab-docker-stack#605 |
The implementation here is rather minimal, just asking user what kind of reset they want and creating the file. Once the reset is on, I would probably disable the home app telling user "Hey, you need to restart the container to launch the reset, click on this ⏹️ to cancel it"
yes, let's finalise the reset cases and add them to the docker stack. |
aiidalab-docker-stack#605 rewrites the factory-reset script: its only mode is now `local`, which moves ~/.local aside to ~/.local~<date>, and the AIIDALAB_FACTORY_RESET environment variable is gone. Drop the mode choice and the environment-variable warning, schedule `local`, and report any other flag-file content (e.g. the old numeric modes) as an unknown mode that the container ignores. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The default button width cut off "Schedule factory reset" and "Cancel scheduled reset". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Edan Bainglass <45081142+edan-bainglass@users.noreply.github.com>
|
@yakutovicha can you please update the PR description with the up-to-date design, and include relevant screenshots? I'll have a closer look at the code later today (but will not have time to test things) |
done ✅ |
There was a problem hidi 10BC8 ng this comment.
Thanks, this looks great! Some minor comments inline. I've also ran xhigh Claude review, I am posting only points that I think should be fixed ideally. Feel free to merge afterwards, I will not have time for this tomorrow. I'll test things manually once this is part of the image. Some of the fixes are due to the last updates on the aiidalab-docker-stack PR. Thanks for your work on this! 🙏
Probably should be fixed
-
While a reset is scheduled, the home page also hides the Terminal, File Manager and Control links and the admin warning in home_app_warning.md (start_page.py:78). If Cancel fails, the user has no way to reach a terminal to fix it.
-
A garbled flag file crashes the home page (home/package_reset.py:46). scheduled_message() only catches OSError. If ~/AIIDALAB_FACTORY_RESET holds bytes that aren't valid text (e.g. \xff\xfe), it raises UnicodeDecodeError. Rendering the home page then fails and shows a traceback with no apps and no cancel button.
-
The UI's "is a reset scheduled?" check is looser than the container's (package_reset.py:26). is_scheduled() uses Path.exists(), but 05_factory-reset.sh only acts on a regular file that isn't a symlink. With a symlink or a directory there, the page stays locked and the container never clears it, so restarting doesn't help. With a directory, Cancel also always fails. With a FIFO (a named pipe), the kernel hangs when it tries to read it. Separately, schedule() follows a broken symlink and writes to wherever it points.
Maybe worth fixing, but haven't verified
-
The Danger zone has a threading race (control.py:582). _do_refresh creates and edits widgets on the background refresh thread, which breaks the base-class rule. It also runs from button callbacks with no lock. If the user clicks Schedule while a refresh is running, the schedule form can come back even though a reset is scheduled.
-
An empty file or an unknown mode still blocks all apps and says "please restart", even though nothing will be reset (package_reset.py:52).
-
If the _on_cancelled callback raises, the error is never shown. The reset is already cancelled, but the old notice stays on screen (package_reset.py:126).
-
The Danger zone first shows the schedule form no matter what is on disk, and corrects itself only after the async refresh (control.py:558).
-
Each refresh while a reset is scheduled builds a new notice without closing the old one, so widgets leak (control.py:586).
How does one arrive at such a situation? If this requires a user to manipulate the file directly, I don't think that is something for us to guard against.
Again, are these real scenarios? The file is not a user file - it is written by machine code. I suppose it is fine to be cautious, as long as the situations are reasonable. As stated above, if such scenarios are the result of the user messing around with things they shouldn't, I'd reconsider just how much we should guard here.
Same. |
Co-authored-by: Daniel Hollas <danekhollas@gmail.com>
for more information, see https://pre-commit.ci
aiidalab-docker-stack#605 moved it to 05_factory-reset.sh. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Only someone editing the flag file by hand could make it differ from what was just written, so the check guarded against nothing the tools can cause.
Okay, put a link to the terminal, just in case f4ccce5. |
The UI now applies the reset script's own rule: a regular, non-symlink file whose first 64 bytes, without whitespace, are `local`. Anything else (unknown or binary content, a symlink, a directory, a FIFO) is no scheduled reset, so it no longer locks or crashes the home page. The container ignores such files too. Scheduling replaces whatever is at the path instead of writing through a symlink.
|
General comment to Edan's:
The situation is indeed quite hypothetical and rare, but the solution is simple and general enough: we simply ignore the "bad" files: f561422. |
Checking the flag file is instant, so the Danger zone overrides refresh() to run synchronously instead of on the base class's background thread. Nothing races the schedule and cancel buttons any more, and no widget is changed off the main thread. The section also refreshes once when built, so it shows the right view from the start, and the Refresh button still picks up a flag file created or removed by hand. The notice is built once and only shown or hidden, instead of rebuilt on every refresh, so no widgets leak.
There was a problem hiding this comment.
All good on my end. Thanks @yakutovicha 🙏
|
Since there is also good to go from @danielhollas side, I am going to merge the PR. |
Why not keeping the whole top panel? Seems more consistent. I might imagine wanting to go back to the control panel, or file explorer as well.
Yeah, as Sasha says, these should not happen, but given that we're implementing "Danger Zone" it's prudent to be more careful than usual. |
Fixes #257. Related: #53 (not closed: the container no longer supports a full home reset).
Depends on aiidalab/aiidalab-docker-stack#605, which reduces the container's reset to a single
localmode; the image pins the home app, so both ship together.Replaces the
DangerZoneWidgetplaceholder with scheduling a package reset: on its next start, the container moves~/.local(packages installed by apps andpip install --user) aside to~/.local~<date>. Apps, AiiDA data, and profiles are kept. The app only writes or removes~/AIIDALAB_FACTORY_RESET; the container performs the reset.Behaviour
reset-packagesis typed. The section refreshes synchronously (checking the flag is instant), so it always shows what is on disk; Refresh picks up a flag created or removed by hand.aiidalab-launch start --restart -p <profile>, ordocker restart <container>. If cancelling fails, it links to a terminal with thermcommand.local). Anything else counts as no reset, so it never locks the home page; the container ignores it too.home/package_reset.py, without AiiDA imports, to keep the home page's check cheap.Notes for review
localexists.Tests
With the flag file redirected to a temporary path:
package_reset(scheduling, also over a symlink; cancelling; which files count as scheduled; the notice's cancel paths), the Danger zone (initial view and synchronous refresh, confirmation, schedule → cancel, schedule failures), and the home page gate. A session fixture fails the run if the real flag file is created.🤖 Generated with the help of Claude Code
Steps and screenshots
[1] Initial look
[2]

Schedule package resetbutton is pressed[3] The start page is also now requesting a restart

[4] Relaunch using
aiidalab-launch:[5] After the restart, the home page's

.localis moved (you have to trust me on this one), and the start page is restored: