fix(ralph-loop): keep LLM in smart zone with fresh context per iteration#1901
Open
edxeth wants to merge 7 commits intocode-yeongyu:devfrom
Open
fix(ralph-loop): keep LLM in smart zone with fresh context per iteration#1901edxeth wants to merge 7 commits intocode-yeongyu:devfrom
edxeth wants to merge 7 commits intocode-yeongyu:devfrom
Conversation
… context per iteration - Add ContextStrategySchema with 'reset' and 'continue' options - 'reset' (default): creates new session with fresh context each iteration - 'continue': keeps same session, accumulates context - Implement TUI session switch via raw API call to /tui/select-session - Update tests and documentation This addresses context overflow in long-running Ralph loops by starting each iteration with a clean context window (smart zone).
- Rename context_strategy to default_strategy in config schema - Add --strategy=reset|continue flag to /ralph-loop and /ulw-loop commands - Store strategy in loop state for per-loop override - Parse --strategy from command arguments in index.ts - Skip todo-continuation-enforcer when ralph-loop is active - Update tests for new naming and behavior
…t_strategy config
…ation 1
- Always write strategy field to state file with fallback to DEFAULT_STRATEGY
- Reset strategy now sends full command template (not continuation prompt)
- Preserve raw user task with flags instead of parsed prompt
- Skip startLoop re-initialization when loop already active (prevents infinite loop)
- Rename initial session to 'Ralph Loop - Iteration 1' using session.update API
- Only replace {{PROMISE}} placeholder for continue strategy
Fixes reset strategy creating endless iteration code-yeongyu#2 sessions and ensures
each iteration receives the exact same message format as iteration 1.
Remove hardcoded session rename to 'Ralph Loop - Iteration 1' for the first iteration. Iteration 2+ already use dynamic naming via ralph-loop/index.ts, so this was redundant. Let OpenCode generate session names naturally for iteration 1.
There was a problem hiding this comment.
No issues found across 20 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Auto-approved: PR only adds new feature for context strategy with thorough tests and no regressions detected.
4 tasks
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.
The Problem: Context Window Overflow
The original ralph-loop implementation kept all iterations in a single session, causing the context window to fill up over time. This is exactly the problem described in "Why the Anthropic Ralph plugin sucks":
Every LLM has a smart zone (first ~40% of context) and a dumb zone (remaining ~60%). The original implementation guaranteed you'd enter the dumb zone after just a few iterations:
The Solution: Fresh Context Per Iteration
This PR adds a
default_strategyconfig option with "reset" as the new default:resetcontinueWith
reset, each iteration starts with a fresh context window. The LLM always operates in the smart zone:This matches how the original bash-loop Ralph works:
Each invocation = fresh context.
Changes
Core Feature
default_strategyconfig withreset(default) andcontinueoptions--strategyflag for per-loop override:/ralph-loop "task" --strategy=continueBug Fixes
todo-continuation-enforcerwhen ralph-loop is active - prevents hook conflictsresetallows keyword detection (new session needs mode injections),continueskips it (mode already applied)Implementation
/tui/select-sessionchat.messageandPreToolUsehandlersUsage
Config (default for all loops):
{ "ralph_loop": { "enabled": true, "default_strategy": "reset" } }Command (per-loop override):
/ralph-loop "Build feature X" --strategy=continue --max-iterations=10Testing
References
Reopen Note
This PR is a direct reopen of #1348 from a dedicated feature branch (
edxeth:pr-1348-reopen) because the previous PR useddevas both head and base branch name context.dev)