Skip to content

armgit / ECC

Public Imported from GitHub
0

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

fix(observer): auto-scale max_turns by analysis batch size (#2062)

zucchinia3d8d8ab925c
diff --git a/skills/continuous-learning-v2/agents/observer-loop.sh b/skills/continuous-learning-v2/agents/observer-loop.sh
index a899124a1..9bab37c5b 100755
--- a/skills/continuous-learning-v2/agents/observer-loop.sh
+++ b/skills/continuous-learning-v2/agents/observer-loop.sh
@@ -205,9 +205,22 @@ PROMPT
fi
timeout_seconds="${ECC_OBSERVER_TIMEOUT_SECONDS:-120}"
- max_turns="${ECC_OBSERVER_MAX_TURNS:-20}"
+ # Auto-scale max_turns proportional to analysis batch size when not explicitly set.
+ # The old hardcoded default of 20 is insufficient for the 500-line MAX_ANALYSIS_LINES
+ # default: Claude hits --max-turns before it can write all discovered instinct files.
+ # Formula: 1 turn per 10 analysis lines, floor 20, cap 100. (#2035)
+ if [ -n "${ECC_OBSERVER_MAX_TURNS:-}" ]; then
+ max_turns="${ECC_OBSERVER_MAX_TURNS}"
+ else
+ max_turns=$(( analysis_count / 10 ))
+ if [ "$max_turns" -lt 20 ]; then max_turns=20; fi
+ if [ "$max_turns" -gt 100 ]; then max_turns=100; fi
+ fi
exit_code=0
+ # Sanitize max_turns. The auto-scaled path above always yields a valid value >=20,
+ # but an explicit ECC_OBSERVER_MAX_TURNS override may be non-numeric, empty, or too
+ # small, so guard here and fall back to the safe default of 20.
case "$max_turns" in
''|*[!0-9]*)
max_turns=20
diff --git a/tests/hooks/hooks.test.js b/tests/hooks/hooks.test.js
index 7ed884223..af0d0d246 100644
--- a/tests/hooks/hooks.test.js
+++ b/tests/hooks/hooks.test.js
@@ -3137,7 +3137,9 @@ async function runTests() {
const observerLoopSource = fs.readFileSync(path.join(__dirname, '..', '..', 'skills', 'continuous-learning-v2', 'agents', 'observer-loop.sh'), 'utf8');
assert.ok(observerLoopSource.includes('ECC_OBSERVER_MAX_TURNS'), 'observer-loop should allow max-turn overrides');
- assert.ok(observerLoopSource.includes('max_turns="${ECC_OBSERVER_MAX_TURNS:-20}"'), 'observer-loop should default to 20 turns');
+ assert.ok(observerLoopSource.includes('max_turns=$(( analysis_count / 10 ))'), 'observer-loop should auto-scale max_turns from the analysis batch size when no override is set');
+ assert.ok(observerLoopSource.includes('if [ "$max_turns" -lt 20 ]; then max_turns=20; fi'), 'observer-loop should clamp the auto-scaled budget to a floor of 20 turns');
+ assert.ok(observerLoopSource.includes('if [ "$max_turns" -gt 100 ]; then max_turns=100; fi'), 'observer-loop should clamp the auto-scaled budget to a cap of 100 turns');
assert.ok(!observerLoopSource.includes('--max-turns 3'), 'observer-loop should not hardcode a 3-turn limit');
assert.ok(observerLoopSource.includes('ECC_SKIP_OBSERVE=1'), 'observer-loop should suppress observe.sh for automated sessions');
assert.ok(observerLoopSource.includes('ECC_HOOK_PROFILE=minimal'), 'observer-loop should run automated analysis with the minimal hook profile');