Skip to content

Conversation

Copy link

Copilot AI commented Nov 4, 2025

JSON profile upload automatically triggered analysis without user consent, and clicking X to remove the file re-triggered analysis instead of clearing state.

Changes

Added file deletion detection

  • Detects when uploaded_json transitions from file object to None while profile_loaded_from_json=True
  • Clears all related session state via new _clear_loaded_profile() helper

Decoupled upload from analysis

  • Removed automatic conversation_completed=True assignment on profile load
  • Added explicit "🔍 Analyze Profile" button that only appears after successful upload
  • Analysis now requires user action via button click

State management

# Before: Auto-triggered analysis
if uploaded_json and not profile_loaded_from_json:
    load_profile()
    st.session_state.conversation_completed = True  # ❌ Auto-triggers

# After: User controls trigger
if uploaded_json and not profile_loaded_from_json:
    load_profile()
    st.session_state.profile_loaded_from_json = True  # ✓ Wait for button

if profile_loaded_from_json and not conversation_completed:
    if st.button("🔍 Analyze Profile"):  # ✓ Explicit control
        st.session_state.conversation_completed = True

State Transitions

  • Upload: Sets profile_loaded_from_json=True, shows analyze button
  • Delete (X): Clears profile/portfolio/flags when uploaded_json=None detected
  • Analyze: Button click sets conversation_completed=True, triggers portfolio generation

This separates file management from analysis execution and gives users explicit control over workflow timing.

Original prompt

This section details on the original issue you should resolve

<issue_title>[BUG] JSON Load Blocking Issue and Auto-Analysis on File Deletion</issue_title>
<issue_description>## Description
The JSON file loading is blocked and re-triggers the analysis even when pressing the X button to delete the file. This creates a poor user experience as the user cannot easily cancel the loaded profile without restarting the analysis.

Reproducibility information

  • Steps to reproduce:
    1. Load a JSON profile file
    2. Press the X button to remove/delete the file
    3. Observe that the analysis is re-triggered automatically

Expected behavior

When the user presses the X button to delete the loaded JSON file, the file should be removed from the interface without automatically re-triggering the analysis. The user should have control over when the analysis runs.

Actual behavior

Pressing the X button to delete the JSON file causes the analysis to restart automatically, preventing the user from easily managing loaded profiles.

Further content

Suggested improvement: Add an explicit button to trigger the analysis launch, rather than having it automatically triggered by file operations. This would give users better control over when the analysis runs and provide a clearer separation between file management and analysis execution.</issue_description>

<agent_instructions>Fix this bug using the Streamlit library</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits November 4, 2025 10:02
- Detect when user presses X button to delete uploaded JSON file
- Clear profile and portfolio state when file is deleted
- Add explicit "Analyze Profile" button instead of auto-triggering
- Prevent automatic analysis on file upload for better UX
- Format code with black and isort

Co-authored-by: merendamattia <[email protected]>
- Add _clear_loaded_profile() helper function for reusability
- Add detailed comments explaining condition logic
- Improve code organization and maintainability
- Address code review feedback

Co-authored-by: merendamattia <[email protected]>
Copilot AI changed the title [WIP] Fix JSON load blocking issue and auto-analysis on deletion fix: prevent auto-analysis on JSON profile upload and handle file deletion Nov 4, 2025
Copilot AI requested a review from merendamattia November 4, 2025 10:11
@merendamattia merendamattia marked this pull request as ready for review November 4, 2025 10:26
Copilot AI review requested due to automatic review settings November 4, 2025 10:26
Copy link

Copilot AI left a comment

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 implements a two-step workflow for JSON profile uploads: load first, then explicitly analyze. Previously, uploading a JSON file would immediately trigger portfolio analysis. Now, users upload the file, receive confirmation, and must click an "Analyze Profile" button to start the analysis. Additionally, the PR adds proper cleanup when users remove uploaded files via the X button and refactors some conditional expressions for better readability.

  • Added _clear_loaded_profile() function to handle cleanup when JSON files are removed
  • Implemented detection of file deletion via the X button and triggers profile clearing
  • Added "Analyze Profile" button requiring explicit user action to start analysis after JSON upload
  • Refactored ternary expressions in wealth simulation and portfolio display for better readability

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@merendamattia merendamattia merged commit e6d9f8d into main Nov 4, 2025
12 checks passed
@merendamattia merendamattia deleted the copilot/fix-json-load-blocking-issue branch November 4, 2025 10:30
@merendamattia
Copy link
Owner

🎉 This PR is included in version 1.3.3 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] JSON Load Blocking Issue and Auto-Analysis on File Deletion

2 participants