8000 Implement app reinstall feature by edan-bainglass · Pull Request #537 · aiidalab/aiidalab · GitHub
[go: up one dir, main page]

Skip to content

Implement app reinstall feature - #537

Merged
edan-bainglass merged 4 commits into
mainfrom
app-reinstall
Oct 2, 2026
Merged

edan-bainglass merged 4 commits into
mainfrom
app-reinstall

Conversation

@edan-bainglass
Copy link
Copy Markdown
Member

This PR provides support for the corresponding button requested in aiidalab/aiidalab-home#245.

@codecov
codecov Bot commented Sep 26, 2026 •
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.65217% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 75.95%. Comparing base (1a2f10c) to head (9ae0a09).

Files with missing lines Patch % Lines
aiidalab/app.py 95.65% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #537      +/-   ##
==========================================
+ Coverage   74.39%   75.95%   +1.55%     
==========================================
  Files          18       18              
  Lines        1738     1759      +21     
==========================================
+ Hits         1293     1336      +43     
+ Misses        445      423      -22     
Flag Coverage Δ
py-3.12 75.95% <95.65%> (+1.55%) ⬆️
py-3.9 75.89% <95.65%> (+1.49%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

@cpignedoli
cpignedoli commented Sep 26, 2026 •
Copy link
Copy Markdown
Member

@edan-bainglass I have seen this working and the normal path looks good. A closer review of 2b396274da5ac725c2b3de616719d32e679e0095, with Codex assistance, found one issue I would address before approval and a smaller robustness improvement:

Support scope clarified: our work targets aiida-core>=2.9.2 and the current AiiDAlab release or later (aiidalab>=26.9.0, based on the current v26.09.0 release, verified on 2026-09-26). These two PRs will be used together with the backend implementation here. Older runtime compatibility and fallback code are outside our scope. The core-dependency concern below is about protecting this modern environment against an incompatible app requirement downgrading it, not supporting old AiiDA/AiiDAlab versions.

  1. Preserve the core-dependency protection when reinstalling. At the dependency-install call, the new method goes straight to pip without checking the local app's requirements against the protected core packages. A focused probe with a local requirements.txt containing ipywidgets<8 and installed ipywidgets 8.1.8 confirmed that _strict_dependencies_met() returns false, but reinstall_app() still reaches run_pip_install() for that requirements file. The probe intercepted the call before running pip. This could downgrade shared packages and break other apps, particularly when reinstalling older apps after an environment migration. Could we check the local requirements against the protected core packages before invoking pip? This should still allow missing ordinary dependencies to be repaired; rejecting every app with compatible=False would defeat that use case. The companion button in Implement app reinstall button aiidalab-home#250 currently permits reinstall for any installed app, so it does not supply this guard either.

  2. Refresh dependency state after a failed post-install hook. At the post-install/cleanup sequence, a successful dependency installation followed by a failing post_install skips cache clearing and refresh(). A probe simulating a dependency change from 1.0 to 2.0 followed by CalledProcessError confirmed that the package cache still reports 1.0 and refresh is never called. It would be useful to perform this cleanup on failure too, while preserving the original error. The existing install path has a similar pattern, so this is also a broader robustness improvement.

Validation on Python 3.12: 17 tests passed across tests/test_appclass.py and tests/test_appdataclass.py, including the new test. test_prereleases failed identically on the PR and its exact base (c8a3c35a7aec5dbeb5120333c46903baf3e5179f): the local environment has AiiDA installed, which filters out a fixture release that the test expects to remain available. This is unrelated to the change. Additional probes passed for missing-app rejection, pip-error propagation, hook skipping after pip failure, successful cache clearing/refresh, and busy-state cleanup. All GitHub checks are green. Installation calls were intercepted during the probes; no installed apps or packages were changed.

@cpignedoli
Copy link
Copy Markdown
Member

@edan-bainglass could you sanity-check my review above and the related comment on aiidalab/aiidalab-home#250? I may have expanded the scope beyond what these PRs need.

Our intended environment is aiida-core>=2.9.2 and the current AiiDAlab release or later, with these two changes deployed together. We are not asking for compatibility with older runtimes.

Are the core-dependency guard and refresh-after-failure suggestions appropriate here, or do they concern existing installation behavior that should be handled separately? In particular, is protection against an app changing core packages already enforced elsewhere?

A possible approach discussed with Codex was to constrain the installed versions of protected packages during app installation, including indirect dependencies, and handle platform upgrades separately. Does that fit AiiDAlab's intended policy, or would it be too restrictive?

Please treat my earlier “before approval” wording as a point for discussion pending your assessment, rather than a demand to add that broader policy to this PR. The normal reinstall path worked in the checks.

@danielhollas
Copy link
Copy Markdown
Contributor

Are the core-dependency guard and refresh-after-failure suggestions appropriate here, or do they concern existing installation behavior that should be handled separately? In particular, is protection against an app changing core packages already enforced elsewhere?

Yeah, we should definitely check agains core dependencies before allowing re-install. If the core deps are incompatible, the re-install button must be disabled. This is especially important for the use-case we're targetting, where a user changes their underlying image so the app can suddenly become incompatible.

@edan-bainglass
Copy link
Copy Markdown
Member Author

@cpignedoli please re-review 🙏

@danielhollas danielhollas 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.

Thanks! Couple quick comments.

Comment thread aiidalab/app.py Resolved
Comment thread aiidalab/app.py Resolved
Comment thread aiidalab/app.py Resolved
Comment thread tests/test_appclass.py Outdated

def test_reinstall_app_rejects_core_dependency_conflict(generate_app, monkeypatch):
app = generate_app()
monkeypatch.setattr(app._app, "core_dependencies_met", lambda: False)
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.

Instead of monkeypatching, let's have an app that has a dependencies that actually do not meet out mocked out environment, e.g. have it depend on aiida-core 1.x. Have a look in conftest.py

@edan-bainglass edan-bainglass Sep 27, 2026 •
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm not fully convinced the second iteration over this test achieved what you had in mind. Happy to iterate once more if needed 🙂

@cpignedoli cpignedoli 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.

Thanks, Edan! I re-reviewed 748bdcc with Codex assistance. Both earlier concerns are addressed: reinstall checks local core requirements while allowing missing ordinary dependencies to be repaired, and failure cleanup clears the cache and refreshes state without masking the original error. The companion button behavior in aiidalab/aiidalab-home#250 also checked out.

Validation on Python 3.12: 19 repository tests passed, plus all 20 additional failure-path and widget probes. The one local test_prereleases failure reproduces identically on the exact base and is unrelated. Installation, daemon and hook subprocess calls were intercepted; no installed packages were changed. GitHub checks are green.

I agree that broader installation-policy hardening can be handled separately. Looks good to me!

@edan-bainglass
Copy link
Copy Markdown
Member Author

@danielhollas can you kindly address the recent changes and confirm/object w.r.t your earlier request for changes? 🙏

@danielhollas
Copy link
Copy Markdown
Contributor

Yes, but not on a Sunday ;-)

Want to review aiidalab-home changes as well and do some testing. Thanks for all your work on this!

@edan-bainglass
Copy link
Copy Markdown
Member Author

Yes, but not on a Sunday ;-)

Want to review aiidalab-home changes as well and do some testing. Thanks for all your work on this!

It's Monday 🙂

@danielhollas danielhollas 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.

Thanks!

I am a little confused about the error handling, see comments inline. I also think there's a bit too much mocking in the tests and we can do a bit better.

By the way, have you tested manually what happens in the UI during various error conditions, e.g. when a pip install or post_install fails?

Comment thread aiidalab/app.py Resolved
Comment thread aiidalab/app.py Resolved
Comment thread tests/test_appclass.py Resolved
Comment thread tests/test_appclass.py
Comment on lines +55 to +59
monkeypatch.setattr(
app._app,
"_post_install_triggers",
lambda: calls.append(("post_install",)),
)
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.

Let's not mock this, you can instead create an actual post_install bash script, e.g.

#/bin/bash
echo "Hello from post_install script"

You can then capture a log output to verify that the _post_install_triggers function was called.

Comment thread tests/test_appclass.py
Comment on lines +50 to +54
monkeypatch.setattr(
app._app,
"_install_dependencies",
lambda python_bin, stdout: calls.append(("install", python_bin, stdout)),
)
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.

I think this mocking is too high-level and makes the test super weak. We can instead run the actual _install_dependencies function and mock only the run_pip_install.

Comment thread tests/test_appclass.py Outdated
Comment on lines +92 to +93
def fail_post_install():
raise CalledProcessError(1, "post_install")
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.

Here again we can have a better test fidelity by actually creating a failing post_install script

#!/bin/bash
echo "Hello from failing post_install script"
exit 1

@edan-bainglass
Copy link
Copy Markdown
Member Author

Thanks!

I am a little confused about the error handling, see comments inline. I also think there's a bit too much mocking in the tests and we can do a bit better.

Thanks @danielhollas. I'll address your comments.

By the way, have you tested manually what happens in the UI during various error conditions, e.g. when a pip install or post_install fails?

Not via the UI. I'll see what I can do.

@danielhollas danielhollas 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.

Thanks @edan-bainglass!

I'd still like to understand the exact purpose and semantics of .aiidalab but that is independent of this PR.

@edan-bainglass
edan-bainglass merged commit 9226088 into main Oct 2, 2026
9 checks passed
@edan-bainglass
edan-bainglass deleted the app-reinstall branch October 2, 2026 10:14
@edan-bainglass
Copy link
Copy Markdown
Member Author

@danielhollas FYI, I accidently clicked merged halfway through editing the commit message. If crucial, I can do surgery. Otherwise, I can also add the missing part to the stacked PR (#542), but maybe that's more confusing than helpful.

One note regarding stacked PRs, they are a bit confusing and can cause a mess. As I found out elsewhere, merging the head will merge the entire stack, without allowing you to provide any form of commit messages along the way. Not great 😵‍💫

@danielhollas
Copy link
Copy Markdown
Contributor

No worries, thanks for letting us know. "App reinstall feature" is clear enough, and the commit is linked to this PR for more context.

As I found out elsewhere, merging the head will merge the entire stack, without allowing you to provide any form of commit messages along the way. Not great

Yeah, I noticed that as well, very annoying.

@danielhollas danielhollas added the enhancement New feature or request label Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0