Skip to content

fix: auto-detect platform to prevent silent data loss in Twitter-only simulations#168

Open
JasonOA888 wants to merge 2 commits into666ghj:mainfrom
JasonOA888:fix/platform-auto-detect
Open

fix: auto-detect platform to prevent silent data loss in Twitter-only simulations#168
JasonOA888 wants to merge 2 commits into666ghj:mainfrom
JasonOA888:fix/platform-auto-detect

Conversation

@JasonOA888
Copy link

Fixes #150

Problem

When a simulation is created with Twitter-only configuration (enable_reddit=false), all data retrieval APIs silently return empty results because they default to looking up Reddit data.

Root Cause

  • Platform parameter hardcoded to 'reddit' in 3+ API locations
  • Twitter-only simulations never create reddit_simulation.db
  • APIs look for Reddit data → empty results → user sees no data

Solution

  1. Added detect_platform_from_simulation() - checks which db files exist
  2. Added get_platform_with_fallback() - intelligent fallback
  3. Updated 3 API endpoints to use auto-detection

Affected Endpoints

  • GET /<simulation_id>/profiles
  • GET /<simulation_id>/profiles/realtime
  • GET /<simulation_id>/posts

Logic

  • Check for actual db files: reddit_simulation.db and twitter_simulation.db
  • Return platform that actually has data
  • Fallback to reddit for backward compatibility

Testing

  • Twitter-only simulation returns Twitter data (not empty)
  • Reddit-only simulation still works
  • Both-platform simulation defaults to Reddit

Impact

Eliminates silent data loss for Twitter-only simulations

- Added VITE_API_TIMEOUT environment variable support
- Default remains 300000ms (5 minutes)
- Users can increase timeout for slow local models like Ollama
- Example: VITE_API_TIMEOUT=600000 for 10 minutes

Fixes 666ghj#58
… simulations

Fixes 666ghj#150

## Problem
When a simulation is created with Twitter-only configuration (enable_reddit=false), all data retrieval APIs silently return empty results because they default to looking up Reddit data. No error is raised — the user sees an empty UI with no indication of what went wrong.

## Root Cause
- Platform parameter hardcoded to 'reddit' in 3+ API locations
- When Twitter-only simulation runs, reddit_simulation.db is never created
- APIs still look for Reddit data by default → empty results → user confusion

## Solution
1. Added  - checks which db files actually exist
2. Added  - intelligent fallback logic
3. Updated all 3 API endpoints to use auto-detection

## Changes
- backend/app/api/simulation.py:
  - Line 994: get_simulation_profiles()
  - Line 1108: get_simulation_profiles_realtime()
  - Line 2053: get_simulation_posts()

## Logic

## Testing
- [x] Twitter-only simulation returns Twitter data (not empty)
- [x] Reddit-only simulation still works
- [x] Both-platform simulation defaults to Reddit (backward compatible)

## Impact
Eliminates silent data loss for Twitter-only simulations
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Hardcoded 'reddit' platform default causes silent data loss for Twitter-only simulations

1 participant