fix: prevent reflection loop with global cross-instance re-entrant guard#369
Open
ggzeng wants to merge 1 commit intoCortexReach:masterfrom
Open
fix: prevent reflection loop with global cross-instance re-entrant guard#369ggzeng wants to merge 1 commit intoCortexReach:masterfrom
ggzeng wants to merge 1 commit intoCortexReach:masterfrom
Conversation
Previously each plugin instance maintained its own re-entrant guard Map. When the runtime re-loaded the plugin during embedded agent turns (e.g. command:new inside a reflection), a new instance would bypass the guard, causing infinite reflection loops. This change introduces two global guards using Symbol.for + globalThis so ALL plugin instances share the same state: 1. **Global re-entrant lock** — prevents concurrent reflection calls for the same sessionKey across all plugin instances. 2. **Serial loop guard** — imposes a 2-minute cooldown per sessionKey between consecutive reflection runs, preventing gateway-level re-triggering chains (session_end → new session → command:new).
This was referenced Mar 27, 2026
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.
Problem
Each plugin instance maintained its own re-entrant guard
Map. When the runtime re-loaded the plugin during embedded agent turns (e.g.command:newinside a reflection), a new instance would bypass the guard, causing infinite reflection loops.Solution
Introduce two global guards using
Symbol.for+globalThisso all plugin instances share the same state:sessionKeyacross all plugin instances.sessionKeybetween consecutive reflection runs, preventing gateway-level re-triggering chains (session_end→ new session →command:new).Changes
index.tsmodified — no dependency changes.Symbol.forkeys, safe for multiple loads.SERIAL_GUARD_COOLDOWN_MSconstant (currently 120s).