fix(simulation): stop discarding an existing run when Step 3 remounts - #758
Open
mrbeandev wants to merge 1 commit into
Open
fix(simulation): stop discarding an existing run when Step 3 remounts#758mrbeandev wants to merge 1 commit into
mrbeandev wants to merge 1 commit into
Conversation
Step3Simulation mounted with a simulation id and immediately called doStartSimulation() with force: true. Because the id lives in the route path (/simulation/:simulationId/start), a browser refresh remounted the component and re-sent that request, so the backend stopped the running subprocess and cleaned the run directory: run_state.json, the twitter and reddit actions.jsonl action logs, and both *_simulation.db files. The timeline, posts and comments views read those files directly, so the data was unrecoverable. Probe the run status before deciding what to do. A simulation that has never run (runner_status "idle" with no recorded actions) still starts exactly as before. Anything else is adopted instead of restarted: live runs resume polling, finished runs load their existing timeline read-only. If the status probe itself fails we now do nothing rather than risk overwriting a run we could not verify. force is also no longer hardcoded to true. The remaining call site only runs when there is nothing to lose, and the flag should never be an implicit default.
CyrusAuyeung
added a commit
to CyrusAuyeung/MiroFish
that referenced
this pull request
Aug 6, 2026
|
Thanks for isolating this data-loss path. To keep both branches independently mergeable, I removed only the overlapping Step 3 remount/existing-run recovery hunk from #718 in bd4babb. #718 remains intended for merge for its independent provider, IPC, state, initial-post, and action-integrity fixes. Its remaining |
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.
Fixes #757.
Problem
Step3Simulation.vuestarts a simulation on every mount withforce: true. The simulation id is a route path param, so a browser refresh remounts the component and re-sends that request — the backend kills the subprocess and deletesrun_state.json, bothactions.jsonlaction logs and both*_simulation.dbfiles. Those files are the only copy of the timeline, posts and comments, so a refresh permanently discards the run. Full analysis in the issue.Change
onMountednow callsresumeOrStartSimulation(), which readsGET /simulation/<id>/run-statusbefore deciding:idleand no recorded actionsstarting/running/paused/stoppingstopped/completed/failedphase = 2so Generate Report is reachable — no restartforceis no longer hardcoded totrue. The one remaining call site only runs when there is nothing to lose, and the flag should never be an implicit default.Three log strings added to
locales/en.jsonandlocales/zh.json.Why this is a separate PR
The fix already exists inside two open PRs, and I would rather say so up front than look like I am duplicating work:
psutil). Open since 2026-07-07, rebased three times.Both are worth merging on their own merits and this is not meant to pre-empt either. But the data-loss fix itself is ~60 lines, and while it waits behind a larger review every refreshed tab costs someone a multi-hour run. This PR does only that one thing so it can be reviewed and merged on its own schedule. If #718 or #693 lands first, close this one — no complaints.
The code here was written from the issue analysis rather than taken from either branch, so there is nothing to untangle if you merge one of them instead.
Trade-off, stated plainly
Re-entering Step 3 for a simulation that already ran now adopts it instead of restarting it. Step 2's Next button reuses the same simulation id (
SimulationView.vue:164-167), so "go back to Step 2, then forward again" no longer re-runs the simulation.That is deliberate — silently deleting a finished run is worse than declining to restart it — and it is not a new gap. The only explicit restart control,
<button class="retry-btn" @click="doStartSimulation">, was removed ind768fd1(2025-12-12), which is howforce: trueended up reachable only from mount in the first place. Related leftover:startErroris still assigned but never rendered anywhere, because it belonged to that same removed retry UI.If you would like an explicit "Restart run" control (with a confirmation) restored as part of this, say the word and I will add it. I left it out to avoid folding a UI decision into a bug-fix PR.
Validation
npm run buildpasses; the remaining warnings are the pre-existing chunk-size and dynamic-import notices onmainen.jsonandzh.jsonparse, and key parity checked in both directionsrunner_status,current_round,twitter_current_round,reddit_current_round,total_actions_count) verified againstSimulationRunState.to_dict()package-lock.jsonchurn