You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: prevent reflection loop with global cross-instance re-entrant guard (#369)
* fix: prevent reflection loop with global cross-instance re-entrant guard
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).
* fix: 仅在 reflection 实际运行后记录 serial cooldown
将 cooldown 时间戳的记录从 finally 无条件执行改为仅当 reflection
通过所有前置条件检查(cfg、session file、conversation)后才记录。
避免因前置条件不满足导致的提前退出误触 cooldown,阻塞后续正常重试。
回应 @rwmjhb 在 #369 的审查反馈。
---------
Co-authored-by: ZengGanghui <zgh@stsctech.com>
api.logger.info(`memory-reflection: skipping serial re-trigger for sessionKey=${sessionKey}; last run ${(Date.now()-lastRun)/1000}s ago (cooldown=${SERIAL_GUARD_COOLDOWN_MS/1000}s)`);
0 commit comments