Skip to content

fix(campaign): mid-run event injection actually reaches agents (#29 A1/A2)#37

Open
PRATHAMESH75 wants to merge 1 commit into
mainfrom
fix/29-event-injection-silent-noop
Open

fix(campaign): mid-run event injection actually reaches agents (#29 A1/A2)#37
PRATHAMESH75 wants to merge 1 commit into
mainfrom
fix/29-event-injection-silent-noop

Conversation

@PRATHAMESH75

Copy link
Copy Markdown
Owner

Summary

Part of #29 — fixes the two P0 correctness bugs:

  • A1 — event injection never lands. run_parallel_simulation.py only started servicing IPC interview commands (env_status.jsonalive) after the entire round loop finished. Since the competitive/crisis event is scheduled mid-run (round 7/14 by default), every injection attempt failed with Simulation environment is not running or has closed, cannot perform Interview, and scenarios A/B/C ran on identical inputs. Fixed by starting a command dispatcher and registering each platform's env with ParallelIPCHandler as soon as it's constructed (before the round loop begins), instead of waiting until both platforms finish. A per-platform asyncio.Lock is shared between the round loop and the interview dispatcher so an interview's env.step() can never run concurrently with the round loop's own env.step() on the same OASIS env.
  • A2 — failure reported as success. POST /campaign/<id>/inject always returned success: true regardless of whether the interview actually reached any agents, and the auto/staggered injection path in campaign_manager.py marked scenario_b_injected/scenario_c_injected = True even when the interview call reported failure (only exceptions were checked, not the result's own success flag). Both paths now check result.get("success") before marking anything as injected, and the API route returns success: false (HTTP 502) when the underlying injection failed, instead of silently reporting success on a no-op.

Test plan

  • uv run pytest — 127 passed (backend)
  • New test_parallel_simulation_ipc.py: verifies register_twitter/register_reddit mark the env alive immediately, and that interview-triggered env.step() never overlaps the round loop's own env.step() on the same env (regression guard via a lock-asserting fake env)
  • New test_campaign_injection_success.py: inject_scenario_event and _execute_pending_injections only flip scenario_*_injected on actual success
  • test_sentiment_routes.py: /inject route propagates failure as success: false / HTTP 502 instead of always success: true

🤖 Generated with Claude Code

…A1/A2)

The OASIS runner only serviced IPC interview commands after the full round
loop finished, so a competitive/crisis event scheduled at round 7/14 always
failed with "Simulation environment is not running or has closed" and
scenarios A/B/C ran on identical inputs. Start the IPC dispatcher and
register each platform's env as soon as it's constructed, sharing a
per-platform asyncio.Lock with the round loop so an interview-triggered
env.step() can never race the round loop's own step().

Also stop reporting injection failures as success: inject_scenario_event
and _execute_pending_injections only flip scenario_b/c_injected when the
interview call actually reports success, and the /inject route now
propagates that failure instead of always returning success:true.
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.

1 participant