fix: guard against episode storm stalling foreground sessions#1844
Open
de1tydev wants to merge 1 commit into
Open
fix: guard against episode storm stalling foreground sessions#1844de1tydev wants to merge 1 commit into
de1tydev wants to merge 1 commit into
Conversation
Author
|
Linked to #1755 — detailed root-cause analysis is in the issue comments. |
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
Large merged episodes trigger a cascade of expensive post-processing (capture → reward → L2 induction → L3 abstraction → skill crystallization) that can stall OpenClaw and Hermes Agent foreground sessions. This is especially common in long development workflows where
relation.classifyconsistently returnsrevision/follow_up, allowing a single episode to accumulate dozens or hundreds of turns.Fixes #1755
Root Causes
before_prompt_build—relation.classify()is an LLM call that blocks foreground prompt construction with no timeoutChanges
Fix 1: Episode turn hard limit (
maxTurnsPerEpisode)algorithm.session.maxTurnsPerEpisode(default 30, range 5–200)Fix 2: Relation classify timeout (
classifyTimeoutMs)algorithm.session.classifyTimeoutMs(default 5000ms, range 1000–30000)relation.classify()calls are wrapped withPromise.raceagainst the timeoutnew_task(safe conservative boundary)Fix 3: Background LLM concurrency semaphore (
bgLlmConcurrency)algorithm.session.bgLlmConcurrency(default 2, range 1–8)llmConcurrency(per-step α scoring) is unaffected — the semaphore only applies to the shared LLM client used by post-capture processingNew Files
core/util/semaphore.ts— lightweight async semaphorecore/util/rate-limited-llm.ts— transparent LLM client wrapper that acquires a semaphore permit per callFiles Modified
core/config/schema.ts— 3 new config fields with JSDoccore/config/defaults.ts— defaults: maxTurns=30, classifyTimeout=5s, bgConcurrency=2core/pipeline/types.ts— SessionRoutingConfig extendedcore/pipeline/deps.ts— config extraction + semaphore wiringcore/pipeline/orchestrator.ts— turn-limit guard + classify timeout wrapperTesting
tsc --noEmitpasses (no type errors)