Further isolate environment variables to fix inconsistent results - #17
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses inconsistent causal analysis results in AWS Lambda warm starts by isolating filesystem/environment state per invocation, reducing the chance of stale intermediate files being reused across runs.
Changes:
- Introduces per-invocation environment setup in
lambda_function.handler()(TMPDIR/TEMP/TMP, HOME/USERPROFILE, MPLCONFIGDIR). - Switches report outputs to use
tempfile.gettempdir()instead of a shared/tmpconstant, and removes theTEMP_DIRconstant. - Minor logging fix to print the downloaded filepath.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
lambda_function.py |
Adds configure_env() and calls it per invocation to isolate temp/home/MPL config paths. |
helper_services/report_helper.py |
Writes YAML/PDF/XLSX outputs to the active temp directory (tempfile.gettempdir()). |
helper_services/download_helper.py |
Adjusts download logging to print the full downloaded filepath. |
helper_services/causal_analysis_helper.py |
Removes TEMP_DIR/MPLCONFIGDIR initialization tied to the shared temp constant. |
common/yaml_to_csv.py |
Removes TEMP_DIR/MPLCONFIGDIR initialization tied to the shared temp constant. |
common/common_constants.py |
Removes the TEMP_DIR constant. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| os.environ["USERPROFILE"] = HOME_DIR | ||
|
|
||
| # fake mpl config directory | ||
| os.environ["MPLCONFIGDIR"] = os.path.join(TEMP_DIR, "mplconfig") |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Collaborator
Author
|
@AbhinavGor The fixes are fine. They are not required but will not cause any issues either. |
…xplanation into inconsistent-results
AbhinavGor
approved these changes
May 18, 2026
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.
When a causal analysis was performed multiple times, the number of experiments considered were different. I found that the issue was due to AWS Lambda instances being reused, which led to some old intermediate files not being deleted, causing erroneous results. I have implemented isolation of executions so each execution will write to a separate directory, thus avoiding any overlaps.