fix: make agent_end auto-capture hook non-blocking (fire-and-forget)#278
Merged
rwmjhb merged 2 commits intoCortexReach:masterfrom Mar 20, 2026
Merged
Conversation
added 2 commits
March 20, 2026 01:21
The agent_end hook for auto-capture was async and awaited multiple slow operations (embedding, LLM extraction, vector search). When OpenClaw's hook system awaits the returned promise, it holds the session lock for the entire duration of these API calls (potentially 30+ seconds). This causes downstream channel deliveries (particularly Telegram) to be silently dropped when subsequent messages hit session store lock timeouts. The fix wraps the async work in a void IIFE so the hook handler returns immediately. The capture work continues in the background without blocking the session. Symptoms before fix: - First message in a session gets a response - All subsequent messages are received and processed (tools.profile loads, memory plugin runs) but sendMessage never fires - No errors logged anywhere — completely silent failure Fixes CortexReach#260
The before_agent_start hook for auto-recall awaits the full retrieval chain (embedding → rerank → lifecycle maintenance) without any timeout. When the embedding or rerank API is slow or unresponsive, this holds the session lock indefinitely, stalling agent startup and causing downstream channel deliveries (e.g. Telegram) to silently drop messages. The fix wraps the recall pipeline in a Promise.race with a 3-second timeout. If the retrieval chain does not complete in time, the hook returns undefined (skipping memory injection) and logs a warning. The agent proceeds normally without injected memories rather than hanging. This is the before_agent_start counterpart to the agent_end fix in the previous commit; together they ensure neither hook can block the session. Fixes CortexReach#253
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
The
agent_endhook for auto-capture (index.ts:2191) isasyncandawaits multiple slow operations:smartExtractor.filterNoiseByEmbedding()— embedding API callsmartExtractor.extractAndPersist()— LLM call (6-category extraction + dedup)embedder.embedPassage()— embedding for regex fallbackstore.vectorSearch()— vector similarity search for dedupWhen OpenClaw's hook system awaits the returned promise, it holds the session lock for the entire duration of these API calls (potentially 30+ seconds with default LLM timeout). This causes downstream channel deliveries (particularly Telegram) to be silently dropped when subsequent messages hit session store lock timeouts.
Symptoms
sendMessagenever firesautoCaptureandsmartExtractionimmediately resolves the issueFix
Wrap the async capture work inside the
agent_endhandler in avoidIIFE so the hook returns immediately. The capture work continues in the background without blocking the session.Change: 8 lines added, 1 line modified. The early-return guard (
!event.success) stays synchronous for efficiency.Testing
Verified on OpenClaw v2026.3.13 with Telegram channel (long-polling,
streaming: "partial"):Related