Fixed stop graph deactivation cascade.#34
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts graph shutdown ordering so property-backed inputs can still be resolved while the StopGraph deactivation cascade is running (before the processor reference is cleared).
Changes:
- Delay clearing
GraphContext.Processoruntil afterEntryNode.StopGraph(...)to keep property resolution working during deactivation. - Add a lifecycle test that asserts a property-backed input can be resolved via an
OnDeactivatepath duringStopGraph().
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| Forge/Statescript/GraphProcessor.cs | Reorders shutdown steps in StopGraph() to keep the processor available during the disable cascade. |
| Forge.Tests/Statescript/GraphProcessorTests.cs | Adds a regression test ensuring property-backed inputs resolve during StopGraph() deactivation. |
Comments suppressed due to low confidence (1)
Forge/Statescript/GraphProcessor.cs:121
- StopGraph is no longer re-entrancy safe: during the disable cascade, nodes like ExitNode can call graphContext.Processor?.StopGraph() while Processor is still set, causing a nested StopGraph that clears Processor/contexts mid-cascade and may invoke OnGraphCompleted multiple times. Add a guard (e.g., HasStarted) so any re-entrant StopGraph during the cascade becomes a no-op, while still keeping Processor set for property resolution.
public void StopGraph()
{
if (GraphContext.Processor != this)
{
return;
}
// Clear HasStarted first so the disable cascade is re-entrancy safe (e.g. an ExitNode triggering StopGraph, or a
// state node reaching FinalizeGraph) without nulling Processor yet. Keeping Processor set throughout the cascade
// lets action nodes on OnDeactivate paths still resolve property-backed inputs.
GraphContext.HasStarted = false;
Graph.EntryNode.StopGraph(GraphContext);
GraphContext.Processor = null;
GraphContext.ActiveStateNodes.Clear();
GraphContext.InternalNodeActivationStatus.Clear();
GraphContext.RemoveAllNodeContext();
OnGraphCompleted?.Invoke();
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Fixed