fix(forge): resolve abort race condition in agentic loop#4
Open
Mog9 wants to merge 1 commit into
Open
Conversation
The orchestrator's in-memory state overwrites the abort flag set by the API when save_state() is called after tool execution. This made the abort button silently fail — users couldn't cancel expensive runs. Added _sync_abort_flag() that reads the abort flag from disk and merges it into in-memory state before every save_state() call. This ensures the API's abort request is preserved through the orchestrator's state saves. Added 6 tests covering the fix: - _sync_abort_flag preserves/respects abort flag - Abort during tool execution is preserved - Abort after iteration stops loop correctly - Abort flag survives multiple save_state calls All 109 tests pass.
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.
The Problem
The agentic loop's abort mechanism had a race condition that made the abort button silently fail. When a user tried to cancel a running kernel optimization, the orchestrator would overwrite the abort flag, preventing the run from stopping.
Before:
After:
The Fix
Added _sync_abort_flag() function in app/services/forge/agent_runner.py that reads the abort flag from disk and merges it into the in-memory state before every save_state() call. This ensures the API's abort request survives the orchestrator's state saves.
Files Changed