Fix subagent announce + add promptMode for token efficiency#944
Closed
tyler6204 wants to merge 13 commits intoopenclaw:mainfrom
Closed
Fix subagent announce + add promptMode for token efficiency#944tyler6204 wants to merge 13 commits intoopenclaw:mainfrom
tyler6204 wants to merge 13 commits intoopenclaw:mainfrom
Conversation
0aed539 to
0dd3d20
Compare
Contributor
Always do a codex review. You'll be surprised what it finds. |
Member
Author
|
Thanks appreciate the feedback, I'll update and check with codex. I also found another issue where subagents appear to be serialized instead of running in parallel. tested by spawning a 30 second wait subagent, then 5 seconds later spawning one that should reply instantly. the instant one didnt start until the slow one finished, confirmed by timestamps. the second subagent showed 0 tokens and empty session while the first was running, then executed right after. will include this fix as well |
- Fix session entry merging bug where entries with same canonical key would overwrite each other, losing lastChannel/lastTo routing info - Track lastChannel, lastTo, lastAccountId in session entries for announce target resolution - Use compact format for external channels (telegram, whatsapp) with clean result text only; verbose Stats format for internal/dashboard - Inject announce into main session context via enqueueSystemEvent so main agent sees subagent completion - Skip Skills, Memory, Heartbeats, Silent Replies, Messaging sections in system prompt for subagents to reduce token usage - Update tests for compact format on external channels Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replace the announce LLM step with a simpler report_back tool that subagents can use to send results directly to the main session. Key changes: - Add report_back tool: subagents call this to send findings to main agent - Add chat.inject gateway method: injects messages into session + broadcasts to webchat - Remove announce LLM step: subagents now report explicitly, main agent summarizes - Update subagent system prompt to explain report_back usage - Registry now only does cleanup (label patch + optional delete), not announce Benefits: - Simpler flow: subagent uses report_back when done, no extra LLM call - Main agent summarizes in its own voice (using SOUL.md) - Silent subtasks work naturally (just don't call report_back) - Results show in gateway dashboard via chat.inject broadcast - System events still inject into main session context Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…cript - Only register report_back tool for subagent sessions (not main agent) - Fix chat.inject to write to transcript file (was only broadcasting) - Use role: "assistant" instead of "system" so webchat displays the message - Add stopReason and usage fields for proper Pi AI format Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Flow:
1. Subagent calls report_back("findings")
2. chat.inject writes to main session transcript (shows in webchat)
3. Triggers main agent via agent gateway call
4. Main agent sees subagent report in transcript, responds to user
5. Response delivered to external channel (Telegram, etc.)
Main agent summarizes in its own voice - no extra user message needed.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Remove extra announce LLM step (runAgentStep) - Send instructional message to main agent instead of direct send - Main agent summarizes in its own voice (uses SOUL.md, identity) - Include stats (runtime, tokens, cost) in trigger message - Remove report_back tool entirely - Update subagent system prompt to remove report_back references - Add promptMode support for subagents (minimal system prompt) - Main agent can respond with NO_REPLY if silent Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
When multiple subagents spawn simultaneously, concurrent calls to saveSessionStore would overwrite each other's changes. Fixed by re-reading the store inside the lock and merging before writing. Before: ~33% success rate (1-2 of 3-5 subagents persisted) After: 100% success rate (all subagents persist correctly) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Parallel subagent spawns were losing session entries due to read-modify-write race conditions. The fix modifies saveSessionStore to re-read and merge inside the lock, and updates deletion patterns to use undefined instead of delete operator so merges can detect and honor deletions. Files changed: - store.ts: Re-read and merge inside lock in saveSessionStore - agent-runner-execution.ts: Use undefined for deletion signaling - session.ts: Use undefined for legacy key migration deletion - sessions.ts: Use undefined for RPC session deletion
- Fix delete semantics: use store[key] = undefined for merge-safe deletes in session store (legacy alias migrations now work with concurrent writes) - Add chat.inject bridge handler for bridge client accessibility - Add tests for merge-delete semantics in session store - Add tests for chat.inject append/broadcast path - Fix subagent parallelism: increase default lane concurrency from 1 to 5 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
9b0901b to
7d7e30e
Compare
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Users can still cap via agents.defaults.subagents.maxConcurrent if needed. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Member
Author
Addressed all review feedbackFixed:
Additional changes:
All 3261 tests pass, build clean, lint clean. Ready for re-review! |
Contributor
1 similar comment
Contributor
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.
Summary
Fix subagent announce flow (was completely broken) and address all review feedback.
Original Changes
chat.injectgateway method to inject messages into session transcriptspromptModeto reduce subagent token usage (~25% reduction)Review Feedback Fixes
delete store[key]withstore[key] = undefinedfor merge-safe writes in all 6 flagged locations (legacy alias migrations now work correctly with concurrent writes)chat.injectagents.defaults.subagents.maxConcurrentSession Store Race Condition Fix
When multiple subagents spawn simultaneously, concurrent calls to
saveSessionStorewould overwrite each other's changes (classic read-modify-write race). Fixed by re-reading the store inside the lock and merging before writing:Subagent Parallelism Fix
Changed default
maxConcurrentfrom 1 to unlimited (Infinity) in:server-lanes.ts(initial apply)server-reload-handlers.ts(hot reload)Users can still cap via
agents.defaults.subagents.maxConcurrentconfig if needed.Test Plan
🤖 Generated with Claude Code