Skip to content

Further isolate environment variables to fix inconsistent results - #17

Merged
AbhinavGor merged 10 commits into
mainfrom
inconsistent-results
Jun 8, 2026
Merged

Further isolate environment variables to fix inconsistent results#17
AbhinavGor merged 10 commits into
mainfrom
inconsistent-results

Conversation

@prat-man

@prat-man prat-man commented May 5, 2026

Copy link
Copy Markdown
Collaborator

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.

Copilot AI 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.

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 /tmp constant, and removes the TEMP_DIR constant.
  • 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.

Comment thread lambda_function.py Outdated
Comment thread lambda_function.py Outdated
Comment thread lambda_function.py Outdated
Comment thread lambda_function.py Outdated
Comment thread lambda_function.py Outdated
os.environ["USERPROFILE"] = HOME_DIR

# fake mpl config directory
os.environ["MPLCONFIGDIR"] = os.path.join(TEMP_DIR, "mplconfig")

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.

@prat-man can you check if this fix is needed?

Comment thread lambda_function.py Outdated
AbhinavGor and others added 4 commits May 5, 2026 10:28
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>
@prat-man

prat-man commented May 8, 2026

Copy link
Copy Markdown
Collaborator Author

@AbhinavGor The fixes are fine. They are not required but will not cause any issues either.

Copilot AI 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.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Comment thread lambda_function.py
Comment thread lambda_function.py
Comment thread lambda_function.py
Comment thread lambda_function.py
@AbhinavGor
AbhinavGor removed the request for review from kapkic May 18, 2026 15:18
@AbhinavGor
AbhinavGor merged commit 5e0346c into main Jun 8, 2026
3 checks passed
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.

3 participants