Reset the TP2 environment between mod installations - #372
Open
4Luke4 wants to merge 9 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
READLNstate, inlined files, and the BCS IDS cache between mod contexts.Var.var_clear_push/Var.var_pop.Problem
WeiDU can install, temporarily uninstall, and reinstall multiple mods within one process.
During an automatic uninstallation/reinstallation chain, a subsequent TP2 context could inherit variables and other interpreter definitions created by the preceding mod. This allowed state from one mod installation to affect another mod that happened to be reinstalled by the same WeiDU process.
The reproduction attached to issue #342 demonstrates the problem using three test mods:
A7-Mod1.A7-Mod2.A7-Mod3.A7-Mod1.Reinstalling the first mod causes WeiDU to temporarily uninstall and subsequently restore the later mods. Before this change, the restored mods inherited the first mod's variable values.
Implementation
The fix centralizes TP2 environment initialization in
Tpstate.Before entering a top-level TP2 context, WeiDU now restores copies of an initial environment snapshot containing:
The snapshot is captured lazily before TP2-specific metadata such as
TP2_AUTHOR,TP2_FILE_NAME,TP2_BASE_NAME, andMOD_FOLDERis assigned.This preserves legitimate process-level values, including architecture, game, and command-line state, without hardcoding their names.
The reset also clears mod-owned state that must not cross TP2 boundaries:
READLNvalues;Temporary metadata evaluation performed inside an existing variable or array stack is intentionally excluded from the reset.
This preserves the existing
Var.var_clear_push/Var.var_popbehavior used while formatting log entries and prevents those lookups from disturbing an active installation environment.State remains available across components belonging to the same TP2. Cleanup occurs only when WeiDU enters another top-level TP2 context.
Scope
The production change is confined to:
src/tpstate.mlValidation
A temporary GitHub Actions workflow was used to perform a controlled baseline-versus-fix reproduction with the original
testmods.zipattachment from issue #342.The workflow independently:
devel;A7-Mod1,A7-Mod2, andA7-Mod3;A7-Mod1, triggering temporary removal and restoration of the later mods;The temporary validation workflow was removed after the evidence was collected, leaving only the production change in the final branch diff.
Baseline: unmodified
develThe original code reproduced both variable leaks:
The reinstall operation failed:
This branch
With this change, each restored mod observed its own variable value:
No
Leaked variable detectedwarning was emitted, and the complete installation/reinstallation chain succeeded:CI result
develThe baseline job failed because the supplied fixture detected the original leaked-variable behavior. The fixed-branch job passed.
View the temporary baseline-versus-fix validation run
Additional validation performed:
handle_tpinitialization path;src/tpstate.ml;Fixes #342