fix(plugin): prevent sub-agent infinite loop on session lifecycle calls#129
Open
jzambrano12 wants to merge 1 commit intoGentleman-Programming:mainfrom
Open
fix(plugin): prevent sub-agent infinite loop on session lifecycle calls#129jzambrano12 wants to merge 1 commit intoGentleman-Programming:mainfrom
jzambrano12 wants to merge 1 commit intoGentleman-Programming:mainfrom
Conversation
Sub-agents (Explore, etc.) inherit the engram memory protocol and interpret their task completion as a session close, entering an infinite loop of mem_session_summary → mem_context → mem_session_summary calls. With bypassPermissions enabled, sessions hang for up to 1 hour. Add "SUB-AGENT SCOPE" sections to the injected protocol text in session-start.sh, post-compaction.sh, and memory/SKILL.md that explicitly tell sub-agents to skip session lifecycle tools (mem_session_start, mem_session_end, mem_session_summary). Scope SESSION CLOSE and AFTER COMPACTION headers as TOP-LEVEL AGENT ONLY so the mandatory language no longer applies to delegated tasks. Closes Gentleman-Programming#128
MattKotsenas
added a commit
to MattKotsenas/engram
that referenced
this pull request
Mar 27, 2026
Includes PR Gentleman-Programming#129 sub-agent scope guards. Ensures server running, creates session, imports git-synced chunks, injects memory protocol with PROACTIVE SAVE, SEARCH MEMORY, SUB-AGENT SCOPE, and SESSION CLOSE (TOP-LEVEL AGENT ONLY) sections. 5 Pester tests verifying protocol output content.
MattKotsenas
added a commit
to MattKotsenas/engram
that referenced
this pull request
Mar 27, 2026
- post-compaction.ps1: protocol re-injection with PR Gentleman-Programming#129 scope guards - session-stop.ps1: session end REST call - subagent-stop.ps1: passive capture POST - user-prompt-submit.ps1: first-message ToolSearch + save nudge timer 10 Pester tests covering protocol output, exit codes, first-message detection, and second-message empty response.
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.
Closes #128
Summary
session-start.sh,post-compaction.sh, andmemory/SKILL.mdthat tell sub-agents to skip session lifecycle tools (mem_session_start,mem_session_end,mem_session_summary)SESSION CLOSEandAFTER COMPACTIONheaders asTOP-LEVEL AGENT ONLYso the mandatory language no longer applies to delegated tasksmem_save(once) andmem_search/mem_contextas neededChanges
plugin/claude-code/scripts/session-start.shplugin/claude-code/scripts/post-compaction.shplugin/claude-code/skills/memory/SKILL.mdTest plan
go test ./...— 596 tests pass, no regressionsbypassPermissions, trigger an Explore sub-agent, confirm it no longer loops onmem_session_summarymem_session_summaryon session closemem_savefor important discoveriesChecklist
Co-Authored-Bytrailers