Skip to content

Fix inconsistencies left by a failed module evaluation - #751

Merged
xdelaruelle merged 5 commits into
envmodules:mainfrom
xdelaruelle:rollback-consistency
Nov 28, 2026
Merged

xdelaruelle merged 5 commits into
envmodules:mainfrom
xdelaruelle:rollback-consistency

Conversation

@xdelaruelle

Copy link
Copy Markdown
Collaborator

Follow-up of #750: other in-memory structures were not restored when a module evaluation fails and gets rolled back, leading to inconsistent results for the modules evaluated afterward by the same command.

  • Extra tags, enabled modulepaths (module use) and sourced shell scripts (source-sh) of loaded modules are now saved along with the other settings pushed before an evaluation. Previously, when a module load failed then the same module was successfully loaded, __MODULES_LMEXTRATAG, __MODULES_LMUSE and __MODULES_LMSOURCESH mixed the properties of the failed attempt with those of the successful one.
  • The caches of the test checking that a loaded or loading module comes from a given modulepath are also saved. A requirement loaded from one modulepath by a failed load attempt, then loaded from another modulepath, was wrongly satisfying a prereq --modulepath targeting the first modulepath.
  • The module modulefile command now withdraws the states it sets (sub-command name, modulefile read mode, requirement record inhibition) even if the sub-command it runs raises an error. These states were kept for the modulefiles evaluated afterward: for instance a module loaded with module load --not-req was kept loaded when the module that has loaded it got unloaded.

A last commit fixes an issue found while testing the above, which is not related to failed evaluations: an internal error (list must have an even number of elements) was raised when loading a modulefile that defines several requirements restricted to the same modulepath with prereq --modulepath, or that defines the same requirement several times with different modulepath restrictions. These restrictions were recorded element by element instead of pair by pair. When a requirement is defined several times, the modulepaths common to its definitions are now retained. This issue exists since the record of these restrictions was introduced in 5.5.0.

Each fix comes with tests, added to 377-rollback.exp and to the new 642-modulepath-multi.exp testsuite file.

Extra tags, enabled modulepaths and sourced shell scripts of loaded
modules are recorded in memory structures that were not part of the
settings pushed before an evaluation. When a module load fails, its
evaluation is rolled back but these records are kept. If the same
module is then successfully loaded, the properties saved for it in the
loaded environment mix those of the failed attempt with those of the
successful one.

Save these structures along with the other settings, so a rollback
restores them to their state prior the failed evaluation.

Assisted-by: Claude:claude-fable-5-2
Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
Result of the test checking that a loaded or loading module comes from
a given modulepath is cached and this cache is only dropped when a
module is unloaded. When the load of a module fails, the requirements
it has loaded are withdrawn by a rollback and their cache entry is kept.
If such requirement is then loaded from another modulepath, the outdated
entry makes it satisfy a requirement targeting the first modulepath.

Save these caches along with the other settings pushed before an
evaluation, so a rollback restores them to their state prior the failed
evaluation.

Assisted-by: Claude:claude-fable-5-2
Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
The module modulefile command sets states describing the sub-command it
runs: its name, the way modulefiles should be read and, when the
--not-req option is set, the inhibition of requirement recording. These
states were only withdrawn when the sub-command ended without error.
When it raised an error, like for a module to load that cannot be found,
the modulefile evaluation is aborted but these states stayed set for
the modulefiles evaluated afterward. Among other effects, a module
loaded with "module load --not-req" was kept loaded when the module
that has loaded it got unloaded.

Run the sub-command from a dedicated procedure, so the calling module
procedure withdraws the states whatever the result obtained.

Assisted-by: Claude:claude-fable-5-2
Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
Modulepath restrictions set with the --modulepath option of prereq are
recorded per module as a list of requirement and modulepath list pairs.
New pairs were added to this list element by element, skipping those
already found in it. A second requirement restricted to the same
modulepath, or the same requirement defined again with another
restriction, thus led to an unbalanced list and to an internal error
when the dependencies of the loading module were computed.

Record these restrictions pair by pair. When a requirement is defined
several times, the modulepaths common to its definitions are retained,
as a loaded module has to comply with all of them. Definitions without
any modulepath in common can never be fulfilled and make the load fail.
Latest definition is recorded in this case, so the requirement is
reported unmet if load is forced.

Assisted-by: Claude:claude-fable-5-2
Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
When conflict_unload option is enabled, a requirement loaded from
another modulepath than the one expected is unloaded and replaced
instead of making the load fail.

Assisted-by: Claude:claude-fable-5-2
Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
@xdelaruelle
xdelaruelle merged commit bd915a6 into envmodules:main Nov 28, 2026
22 checks passed
@xdelaruelle
xdelaruelle deleted the rollback-consistency branch November 28, 2026 14:03
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.

1 participant