fix: guard against large output limit causing infinite summarize loop#399
Merged
Merged
Conversation
|
I have seen a similar issue with devstral via external/not selfhosted API, too |
jayair
pushed a commit
that referenced
this pull request
Jun 26, 2025
achembarpu
pushed a commit
to achembarpu/opencode
that referenced
this pull request
Aug 4, 2025
achembarpu
pushed a commit
to achembarpu/opencode
that referenced
this pull request
Aug 4, 2025
andreipromarketing-dev
pushed a commit
to andreipromarketing-dev/opencode
that referenced
this pull request
Apr 7, 2026
…servations (anomalyco#399) * fix(observe): add 5-layer automated session guard to prevent self-loop observations observe.sh currently fires for ALL hook events including automated/programmatic sessions: the ECC observer's own Haiku analysis runs, claude-mem observer sessions, CI pipelines, and any other tool that spawns `claude --print`. This causes an infinite feedback loop where automated sessions generate observations that trigger more automated analysis, burning Haiku tokens with no human activity. Add a 5-layer guard block after the `disabled` check: Layer 1: agent_id payload field — only present in subagent hooks; skip any subagent-scoped session (always automated by definition). Layer 2: CLAUDE_CODE_ENTRYPOINT env var — Claude Code sets this to sdk-ts, sdk-py, sdk-cli, mcp, or remote for programmatic/SDK invocations. Skip if any non-cli entrypoint is detected. This is universal: catches any tool using the Anthropic SDK without requiring tool cooperation. Layer 3: ECC_HOOK_PROFILE=minimal — existing ECC mechanism; respect it here to suppress non-essential hooks in observer contexts. Layer 4: ECC_SKIP_OBSERVE=1 — cooperative env var any external tool can set before spawning automated sessions (explicit opt-out contract). Layer 5: CWD path exclusions — skip sessions whose working directory matches known observer-session path patterns. Configurable via ECC_OBSERVE_SKIP_PATHS (comma-separated substrings, default: "observer-sessions,.claude-mem"). Also fix observer-loop.sh to set ECC_SKIP_OBSERVE=1 and ECC_HOOK_PROFILE=minimal before spawning the Haiku analysis subprocess, making the observer loop self-aware and closing the ECC→ECC self-observation loop without needing external coordination. Fixes: observe.sh fires unconditionally on automated sessions (anomalyco#398) * fix(observe): address review feedback — reorder guards cheapest-first, fix empty pattern bug Two issues flagged by Copilot and CodeRabbit in PR anomalyco#399: 1. Layer ordering: the agent_id check spawns a Python subprocess but ran before the cheap env-var checks (CLAUDE_CODE_ENTRYPOINT, ECC_HOOK_PROFILE, ECC_SKIP_OBSERVE). Reorder to put all env-var checks first (Layers 1-3), then the subprocess-requiring agent_id check (Layer 4). Automated sessions that set env vars — the common case — now exit without spawning Python. 2. Empty pattern bug in Layer 5: if ECC_OBSERVE_SKIP_PATHS contains a trailing comma or spaces after commas (e.g. "path1, path2" or "path1,"), _pattern becomes empty or whitespace-only, and the glob *""* matches every CWD, silently disabling all observations. Fix: trim leading/trailing whitespace from each pattern and skip empty patterns with `continue`. * fix: fail closed for non-cli entrypoints --------- Co-authored-by: Affaan Mustafa <affaan@dcube.ai>
2 tasks
xywsxp
pushed a commit
to xywsxp/opencode
that referenced
this pull request
Apr 24, 2026
xywsxp
pushed a commit
to xywsxp/opencode
that referenced
this pull request
Apr 24, 2026
AIALRA-0
pushed a commit
to AIALRA-0/opencode-turn-engine
that referenced
this pull request
Jun 10, 2026
AIALRA-0
pushed a commit
to AIALRA-0/opencode-turn-engine
that referenced
this pull request
Jun 10, 2026
avion23
pushed a commit
to avion23/opencode
that referenced
this pull request
Jun 10, 2026
avion23
pushed a commit
to avion23/opencode
that referenced
this pull request
Jun 10, 2026
masuda-masuo
reviewed
Jul 2, 2026
masuda-masuo
left a comment
There was a problem hiding this comment.
レビューコメント
概要:
が を上回る(または近い)場合に、 が負の数になり、常に が成立して要約ループが無限に発生するバグの修正。
良い点:
- ✅ 問題の特定と原因説明が的確。特に具体的な再現手順と設定例があるのが良い。
- ✅ 修正は最小限(4行追加)でリスクが低い。 で下限を0にクランプするアプローチはシンプルかつ正しい。
- ✅ の nullable ハンドリングは既にされていた。
気になった点:
- のマジックナンバーは既存コードからの踏襲でこのPRのスコープ外ではあるが、いずれ定数化を検討しても良いかも(例: )。
全体的に問題の特定から修正までクリーンなPRだと思います。LGTM。
masuda-masuo
reviewed
Jul 2, 2026
masuda-masuo
left a comment
There was a problem hiding this comment.
レビューコメント
概要:
model.info.limit.output が model.info.limit.context を上回る(または近い)場合に、context - output が負の数になり、常に tokens > 負の数 が成立して要約ループが無限に発生するバグの修正。
良い点:
- ✅ 問題の特定と原因説明が的確。具体的な再現手順と設定例があり再現性が高い。
- ✅ 修正は最小限(4行追加)でリスクが低い。
Math.max(..., 0)で下限を0にクランプするアプローチはシンプルかつ正しい。 - ✅
model.info.limit.output ?? 0の nullable ハンドリングは既にされており型安全。
気になった点:
0.9のマジックナンバーは既存コードからの踏襲でこのPRのスコープ外ではあるが、いずれ定数化を検討しても良いかも。
全体的に問題の特定から修正までクリーンなPRだと思います。LGTM。
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.
Attempt fixing #262
Problem:
The auto summarize logic goes into infinite loop summarizing the previous conversation if model output limit ends up being larger than the context limit.
Easy way to reproduce this is using a local model with such configuration. However, this could happen for other providers as well if the reported limits are faulty.
{ "$schema": "https://opencode.ai/config.json", "provider": { "lmstudio": { "npm": "@ai-sdk/openai-compatible", "options": { "baseURL": "http://localhost:8080/v1" }, "models": { "qwen/qwen3-30b-a3b": { "limit": { "context": 131072, "output": 1000000 } }, "mistralai/devstral-small-2505": { "limit": { "context": 131072, "output": 1000000 } } } } } }Solution:
Use 0 as minimum value for the limit calculation to avoid any possibility of that calculation resulting in negative number.