Fix startup instability and remove CWD dependency in MUIO v5#20
Open
parthdagia05 wants to merge 1 commit intoOSeMOSYS:masterfrom
Open
Fix startup instability and remove CWD dependency in MUIO v5#20parthdagia05 wants to merge 1 commit intoOSeMOSYS:masterfrom
parthdagia05 wants to merge 1 commit intoOSeMOSYS:masterfrom
Conversation
- Derive all paths in Config.py from __file__ to eliminate CWD dependency - Auto-create DataStorage directory on startup - Guard os.chmod to prevent Windows/import-time crash - Fix Flask template resolution using absolute Config.WebAPP_PATH - Add guard in createCase() to skip unknown parameter groups Resolves server startup crashes and model creation failures when running from different directories.
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.
Bug Fix: Backend Path Hardening and Case Initialization Stability 🛡️
Closes: #2
Summary
This PR resolves startup instability and model creation failures in MUIO v5. It eliminates Current Working Directory (CWD) dependencies, guards import-time filesystem operations, and hardens the case initialization logic.
Prior to these changes, fresh installations often failed to configure new models due to path fragility and template resolution errors. This PR ensures a "plug-and-play" experience across different execution environments.
Root Causes Identified
The following blockers were identified during the investigation:
Config.pyrelied on relative paths (e.g.,Path("WebAPP", ...)), causing failures if the server was started outside theAPI/directory.os.chmod(DATA_STORAGE)was executed at import time. This crashed if the directory didn't exist or if running on Windows.os.path.abspath('WebAPP'), which resolved incorrectly relative to the CWD, leading toTemplateNotFound: index.html.createCase()utilized unprotected lookups inConfig.DEFAULT_F, causing silent failures when encountering unknown groups.Changes Implemented
1. Absolute Path Resolution
All paths in
Config.pyare now dynamically derived from__file__. This ensures consistent directory resolution regardless of whether the app is started from the repository root, theAPI/folder, or an external orchestrator.2. Robust Filesystem Initialization
DataStorage/directory is now automatically created at startup if it is missing.os.chmodoperations are now skipped on Windows and wrapped in atry/exceptblock to prevent startup crashes.3. Flask & Case Logic Hardening
Config.WebAPP_PATHfor both template and static assets.createCase()to skip unknown parameter groups instead of raising aKeyError, allowing for more resilient model initialization.Manual Verification
The following scenarios were verified in a fresh environment:
API/directory.WebAPP/DataStorage/no longer causes a crash; the system regenerates it on launch.index.html) load correctly on the first request./AddCaseendpoint.Scope & Impact