Urgent.News

What's breaking now, across thousands of outlets.

AI

The Ralph Loop: running coding agents for hours

Anyone who has run a coding agent on a real task — not a demo, a multi-hour grind through a milestone — has watched the same decay curve. The first hour is sharp. By the third, the agent is re-reading files it already read, contradicting decisions it made earlier, and confidently "fixing" things it broke twenty minutes ago. Nothing is wrong with the model. What's wrong is the session: the context…

The concept known as the "Ralph loop" arises from the observation that when running coding agents on real tasks, the performance gradually degrades over time. Initially, the agent is sharp and efficient, but by the third hour, it begins re-reading previously examined files, contradicting its earlier decisions, and confidently fixing issues it created earlier.

This degradation is primarily due to the context window filling up with stale information, leading to a situation where the agent's judgment deteriorates even before the context window is completely filled. This phenomenon is referred to as "context rot".

To address this issue, Geoffrey Huntley introduced the Ralph loop, named after Ralph Wiggum from The Simpsons, who is not the sharpest but never gives up. The technique involves running the agent with the same prompt in a fresh session repeatedly. Each iteration starts with a blank context, reads the plan file, selects the most important unfinished task, completes it, and writes the progress back to disk before terminating.

The loop then restarts the process until all tasks are completed. The genius of this approach lies in its avoidance of keeping a single, long-lived session alive and instead embracing the value of a fresh context window for each unit of work. This design allows the agent to deliberately allocate the context window to one task and then discard the session, effectively preventing context degradation.

The primary problem that the Ralph loop solves is the "context window is too small" issue, rather than the context window filling up with irrelevant information. This approach enables the agent to perform tasks more efficiently while ensuring that each iteration starts with a clean slate, avoiding the accumulation of errors from previous iterations. The loop's simplicity, yet profound impact, has led to its successful application in building entire codebases overnight.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

This story

This is one outlet's version. Read the fullest account.

Read the original at dev.to →

More in AI

Where the LLM Stops: Deterministic Scoring in an AI-Assisted VAPT Pipeline

Every VAPT report ends the same way: a handful of numbers. A CVSS score. A severity label. A priority rank. Sometimes an aggregate risk score.

  • ONUS, open-source DAST platform, ensures deterministic scoring in AI-assisted VAPT pipeline
  • CVSS scores, vectors, severity levels, and priority ranks derived from deterministic formula
  • ONUS test suite validates CVSS scoring formula against known vectors for reproducibility

More from Saturday 22 August →