fix(campaign): mid-run event injection actually reaches agents (#29 A1/A2)#37
Open
PRATHAMESH75 wants to merge 1 commit into
Open
fix(campaign): mid-run event injection actually reaches agents (#29 A1/A2)#37PRATHAMESH75 wants to merge 1 commit into
PRATHAMESH75 wants to merge 1 commit into
Conversation
…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.
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.
Summary
Part of #29 — fixes the two P0 correctness bugs:
run_parallel_simulation.pyonly started servicing IPC interview commands (env_status.json→alive) after the entire round loop finished. Since the competitive/crisis event is scheduled mid-run (round 7/14 by default), every injection attempt failed withSimulation 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 withParallelIPCHandleras soon as it's constructed (before the round loop begins), instead of waiting until both platforms finish. A per-platformasyncio.Lockis shared between the round loop and the interview dispatcher so an interview'senv.step()can never run concurrently with the round loop's ownenv.step()on the same OASIS env.POST /campaign/<id>/injectalways returnedsuccess: trueregardless of whether the interview actually reached any agents, and the auto/staggered injection path incampaign_manager.pymarkedscenario_b_injected/scenario_c_injected=Trueeven when the interview call reported failure (only exceptions were checked, not the result's ownsuccessflag). Both paths now checkresult.get("success")before marking anything as injected, and the API route returnssuccess: 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)test_parallel_simulation_ipc.py: verifiesregister_twitter/register_redditmark the env alive immediately, and that interview-triggeredenv.step()never overlaps the round loop's ownenv.step()on the same env (regression guard via a lock-asserting fake env)test_campaign_injection_success.py:inject_scenario_eventand_execute_pending_injectionsonly flipscenario_*_injectedon actual successtest_sentiment_routes.py:/injectroute propagates failure assuccess: false/ HTTP 502 instead of alwayssuccess: true🤖 Generated with Claude Code