Part III · RL for LLMs · Chapter 19

Failure modes: reward hacking and friends

Over-optimization, reward hacking, length bias, sycophancy, and entropy collapse — and the fixes.

~150 minBefore this: LLM as a policy, RLHF, RLVR & GRPOUpdated 2026-10

In 2016, researchers at OpenAI trained an agent on CoastRunners, a boat-racing video game. The game’s score came from hitting targets along the course, not from finishing the race. The agent found a lagoon where a few targets kept respawning, and it circled there indefinitely, crashing into other boats, going the wrong way and catching fire. In the researchers’ words, it achieved “a higher score using this strategy than is possible by completing the course in the normal way.” It never finished a race. In 2025, OpenAI researchers watched a frontier reasoning model being trained with RL to fix code until the unit tests passed. Among the tricks it learned was to call exit(0), so the test harness saw a clean exit before any test could fail.

Nine years and many orders of magnitude of compute separate those two stories, and they are the same story. Reinforcement learning is an optimizer. It finds what you reward, not what you meant, and the better the optimizer, the more reliably it finds the difference. Every chapter of Part III so far has quietly assumed the reward is right: the reward model of Chapter 12, the judges and rubrics of Chapter 14, the verifiers of Chapter 15. This chapter drops that assumption. You will see why optimizing a good-but-imperfect reward first helps and then hurts, measure the effect in nats, meet the main ways LLMs hack their rewards, and see a second family of failures in which nothing is hacked but the policy stops exploring. Then we assemble the toolbox people use against all of it.

The proxy and the target

Goodhart’s law

The economist Charles Goodhart observed in 1975 that a statistical regularity tends to collapse once you lean on it to control something. The anthropologist Marilyn Strathern later gave it the form everyone quotes: when a measure becomes a target, it ceases to be a good measure. A school judged on test scores starts teaching to the test. A hospital judged on waiting times starts discharging patients early.

In RL for LLMs the measure is the reward. Following Gao, Schulman and Hilton (2022), we give the two sides of the gap names:

  • The gold reward is what you actually want: a careful human’s judgment, the true correctness of a program, whether a summary is faithful. You usually can’t compute it at training scale. That is why you needed a substitute in the first place.
  • The proxy reward is what the optimizer actually sees: a reward model’s score, a unit-test pass rate, an LLM judge’s verdict.

Reward hacking is when a policy raises the proxy in a way that does not raise, or even lowers, the gold. Specification gaming (the term popularized by Krakovna and colleagues at DeepMind) means the same thing with the emphasis on the specification: the agent did exactly what you wrote down, and what you wrote down was wrong. People use the two terms almost interchangeably. Neither one requires intent. A policy-gradient update has no idea that it is “cheating”; it just raises the probability of whatever scored well.

Why optimization pressure is the problem

Suppose a reward model was trained on responses of ordinary length, and longer answers were slightly preferred by the labelers because they tended to be more complete. The reward model correctly learns “longer is a bit better” in that range. Nothing is wrong yet. Now hand it to an optimizer. The optimizer discovers that length is the cheapest way to raise the score, and pushes responses into lengths no labeler ever saw. Out there, the reward model’s “longer is better” is an extrapolation, and the extrapolation is wrong: a 3,000-word answer to a yes/no question is not better.

So the danger is not that the proxy is noisy or slightly biased. Every proxy is. The danger is the interaction between a slightly wrong proxy and a strong optimizer. You can see this cleanly in a toy model small enough to solve by hand.

A toy you can solve by hand

The setup

Give every response three hidden features, each a standard normal under the starting policy πref\pi_\text{ref}:

  • qq, its quality;
  • ℓ\ell, its length, in standard deviations from typical;
  • ee, some quirk that the reward model happens to like but nobody cares about.

The gold reward is quality, with a penalty for being far from a sensible length in either direction:

g=q−12ℓ2.g = q - \tfrac12 \ell^2 .

The proxy reward model gets quality right, but it has also learned that length is good (a bias of size bb), and it responds to the irrelevant quirk (noise of size σ\sigma):

p=q+b ℓ+σe.p = q + b\,\ell + \sigma e .

Near the starting policy these agree well: for typical responses, ℓ\ell is small, the ℓ2\ell^2 penalty is negligible, and both rewards mostly track qq. Under πref\pi_\text{ref} the average gold is E[g]=0−12E[ℓ2]=−12\mathbb E[g] = 0 - \tfrac12 \mathbb E[\ell^2] = -\tfrac12 and the average proxy is 00. We’ll measure everything as a gain over these starting values.

Optimizing the proxy with a KL leash

From Chapter 11 you know what KL-regularized RL converges to, if optimization succeeds: the maximizer of Eπ[p]−β KL(π∥πref)\mathbb E_\pi[p] - \beta\,\mathrm{KL}(\pi \Vert \pi_\text{ref}) is the tilted distribution

π∗(y)=1Z πref(y) ep(y)/β.\pi^*(y) = \frac{1}{Z}\, \pi_\text{ref}(y)\, e^{p(y)/\beta}.

Here πref\pi_\text{ref} is a standard Gaussian over the features and pp is linear in them, so the tilt is easy. Tilting a Gaussian by the exponential of a linear function shifts its mean and leaves its shape alone (the derivation below completes the square). Write t=1/βt = 1/\beta for the optimization pressure. The optimized policy has

E[q]=t,E[ℓ]=b t,E[e]=σt,KL(π∗∥πref)=12t2(1+b2+σ2).\mathbb E[q] = t, \qquad \mathbb E[\ell] = b\,t, \qquad \mathbb E[e] = \sigma t, \qquad \mathrm{KL}(\pi^* \Vert \pi_\text{ref}) = \tfrac12 t^2 (1 + b^2 + \sigma^2).

Quality goes up, which is good. Length goes up too, in proportion to bb. Plugging in, the gains over πref\pi_\text{ref} are

Δproxy=t (1+b2+σ2),Δgold=t−12b2t2.\Delta\text{proxy} = t\,(1 + b^2 + \sigma^2), \qquad \Delta\text{gold} = t - \tfrac12 b^2 t^2 .

The proxy rises linearly forever. The gold gain is a parabola: it rises, peaks at t=1/b2t = 1/b^2, and then falls without limit.

∂ Tilting a Gaussian: the mean shift and the KL

Collect the features into z=(q,ℓ,e)z = (q, \ell, e) and the proxy’s weights into w=(1,b,σ)w = (1, b, \sigma), so p=w⋅zp = w \cdot z. The reference density is πref(z)∝e−∥z∥2/2\pi_\text{ref}(z) \propto e^{-\lVert z \rVert^2/2}. Then

π∗(z)∝exp⁡ ⁣(−12∥z∥2+1β w⋅z)=exp⁡ ⁣(−12∥z−wβ∥2+∥w∥22β2).\pi^*(z) \propto \exp\!\Big(-\tfrac12 \lVert z\rVert^2 + \tfrac1\beta\, w\cdot z\Big) = \exp\!\Big(-\tfrac12 \big\lVert z - \tfrac{w}{\beta}\big\rVert^2 + \tfrac{\lVert w\rVert^2}{2\beta^2}\Big).

The last term is a constant, absorbed into ZZ. So π∗=N(w/β,I)\pi^* = \mathcal N(w/\beta, I): same covariance, mean μ=w/β=t w\mu = w/\beta = t\,w.

The KL between two Gaussians with the same identity covariance is half the squared distance between their means:

KL(N(μ,I) ∥ N(0,I))=Ez∼N(μ,I)[12∥z∥2−12∥z−μ∥2]=12(∥μ∥2+3)−12⋅3=12∥μ∥2=12t2∥w∥2.\mathrm{KL}\big(\mathcal N(\mu, I)\,\Vert\, \mathcal N(0, I)\big) = \mathbb E_{z\sim\mathcal N(\mu,I)}\Big[\tfrac12\lVert z\rVert^2 - \tfrac12\lVert z-\mu\rVert^2\Big] = \tfrac12\big(\lVert\mu\rVert^2 + 3\big) - \tfrac12\cdot 3 = \tfrac12\lVert \mu\rVert^2 = \tfrac12 t^2\lVert w\rVert^2 .

For the gold, E[q]=t\mathbb E[q] = t and E[ℓ2]=Var(ℓ)+E[ℓ]2=1+b2t2\mathbb E[\ell^2] = \mathrm{Var}(\ell) + \mathbb E[\ell]^2 = 1 + b^2 t^2, so E[g]=t−12(1+b2t2)\mathbb E[g] = t - \tfrac12(1 + b^2t^2). Subtracting the starting value −12-\tfrac12 gives Δgold=t−12b2t2\Delta\text{gold} = t - \tfrac12 b^2 t^2. For the proxy, E[p]=w⋅μ=t∥w∥2\mathbb E[p] = w \cdot \mu = t \lVert w \rVert^2.

Worked example: b=1b = 1, no noise

Take a reward model that likes length about as much as it likes quality (b=1b = 1) and has no noise (σ=0\sigma = 0). Then KL=t2\mathrm{KL} = t^2, so the distance from the reference measured as d=KLd = \sqrt{\mathrm{KL}} is just d=td = t. Lower β\beta step by step (a weaker leash):

KL penalty β\betapressure t=1/βt = 1/\betaKL (nats)proxy gain 2t2tgold gain t−t2/2t - t^2/2mean length E[ℓ]\mathbb E[\ell]
∞\infty (no RL)00000
20.50.2510.3750.5
11120.5 (peak)1
0.524402
0.254168−44

Read the table as a training run. The proxy climbs steadily: 0, 1, 2, 4, 8. If the proxy is all you can see, everything looks great. Meanwhile the gold improves at first (the optimizer is finding genuinely better responses), peaks at KL = 1 nat, is back to zero by 4 nats, and is far below the starting policy by 16 nats. At the end, responses are four standard deviations too long, and the proxy loves them.

In terms of dd, the gold gain is d−12d2d - \tfrac12 d^2: rising linearly, falling quadratically. Hold on to that shape; you’ll see it again in real data in a moment.

Two different ways a proxy can be wrong

The toy separates two kinds of error, and they behave very differently.

  • Noise (σ\sigma). Set b=0b = 0. Now Δgold=t\Delta\text{gold} = t, which never falls. But the KL is 12t2(1+σ2)\tfrac12 t^2(1 + \sigma^2), so at a fixed KL budget you get less gold: part of every unit of optimization is spent selecting for the quirk ee, which is worthless. You are disappointed (the gold gain is smaller than the proxy gain promised) but not harmed. This is regressional Goodhart, the first of four variants in Manheim and Garrabrant’s taxonomy: selecting on a noisy measure also selects for the noise.
  • Bias that breaks at the extremes (bb). The proxy’s “longer is better” is true near typical lengths and false far from them. Optimization drives you exactly to where it is false, and the gold eventually falls below where you started. This is extremal Goodhart: a relationship that held in the normal range fails in the extreme range that optimization selects. Gao et al. identify it as the main driver of the gold score’s eventual decline.

The taxonomy has two more members. Causal Goodhart: the proxy is correlated with the gold without causing it, so intervening on the proxy doesn’t move the gold (making answers longer doesn’t make them more thorough). Adversarial Goodhart: an agent actively exploits the measure. At LLM scale the boundaries blur, but the first two are enough to reason with.

Quick check In the toy model, set the length bias b = 0 and the noise σ = 1. What happens to the gold reward as you lower β (more optimization pressure)?

Measuring optimization pressure in nats

Best-of-n: the simplest optimizer

The simplest way to optimize a proxy needs no training at all. Sample nn responses from πref\pi_\text{ref}, score them with the proxy, and return the best one. This is best-of-n (BoN), also called rejection sampling. It defines a new policy πBoN\pi_\text{BoN}, and the bigger nn is, the harder you are pushing on the proxy.

To compare BoN with RL you need a common ruler, and the natural one is how far the policy has moved: KL(πBoN∥πref)\mathrm{KL}(\pi_\text{BoN} \Vert \pi_\text{ref}). Remarkably, it does not depend on the proxy or the model at all:

KL(πBoN ∥ πref)=log⁡n−n−1n.\mathrm{KL}(\pi_\text{BoN} \,\Vert\, \pi_\text{ref}) = \log n - \frac{n-1}{n}.
nn12416642561,00010,000
KL (nats)00.190.641.843.174.555.918.21

KL grows only logarithmically in nn. Best-of-1,000 is about 6 nats from the reference; to reach 16 nats, the end of our RL table, you would need nn in the millions. Exercise 19.3 walks you through the derivation; here is the short version.

∂ Why best-of-n is log n − (n−1)/n nats from the reference

Assume the proxy scores are continuous, so there are no ties, and let FF be the cumulative distribution function of the proxy score under πref\pi_\text{ref}. A response yy wins best-of-n if it is drawn and the other n−1n - 1 draws score below it. Summing over which of the nn draws it is, its probability under BoN is

πBoN(y)=n F(p(y)) n−1 πref(y).\pi_\text{BoN}(y) = n\, F(p(y))^{\,n-1}\, \pi_\text{ref}(y).

So log⁡πBoN(y)πref(y)=log⁡n+(n−1)log⁡F(p(y))\log\frac{\pi_\text{BoN}(y)}{\pi_\text{ref}(y)} = \log n + (n-1)\log F(p(y)), and

KL(πBoN∥πref)=log⁡n+(n−1) Ey∼πBoN[log⁡F(p(y))].\mathrm{KL}(\pi_\text{BoN}\Vert\pi_\text{ref}) = \log n + (n-1)\,\mathbb E_{y\sim\pi_\text{BoN}}\big[\log F(p(y))\big].

Under πref\pi_\text{ref}, U=F(p(y))U = F(p(y)) is uniform on [0,1][0,1]. The winner’s UU is the maximum of nn independent uniforms, which has density nun−1n u^{n-1}. Therefore

E[log⁡U]=∫01nun−1log⁡u du=[unlog⁡u]01−∫01un−1 du=−1n,\mathbb E[\log U] = \int_0^1 n u^{n-1}\log u \, du = \Big[u^n \log u\Big]_0^1 - \int_0^1 u^{n-1}\, du = -\frac1n ,

(integrating by parts with d(un)=nun−1dud(u^n) = n u^{n-1} du). Putting it together: KL=log⁡n−(n−1)/n\mathrm{KL} = \log n - (n-1)/n.

When the response space is discrete and ties are possible, Beirami et al. (2024) show this formula is an upper bound on the true KL, and that it can be loose. For our purposes it is the standard ruler.

In the toy model with b=1b = 1, best-of-n behaves much like the RL table: best-of-10 (KL 1.4 nats) gives the peak gold gain of about +0.66; best-of-256 (KL 4.5) is down to +0.21; past about best-of-630 (KL 5.4) the gold is below the starting policy, while the proxy has climbed to about +4.4. Now try it yourself.

Interactive Goodhart explorer: proxy vs. gold under optimization
proxy reward (what the optimizer sees)gold reward (what you wanted)base policy π_refoptimized policy
Best-of-1
Proxy gain over π_ref
Gold gain over π_ref
Gold peaks at

What to try: press Play and watch the left plot. The dashed proxy only goes up; the solid gold rises, peaks (diamond) and falls. On the right, watch the cloud of responses drift up and to the right: it crosses the gold contours upward at first, then runs off toward long responses. Switch to 'RL with KL penalty' and find β where the gold peaks (compare with the table above). Then set the length bias b to 0 and raise the noise σ: the gold never falls, but it rises more slowly per nat. Finally set b to 1.5: how early does the peak come now?

Reading the two plots

On the left, the x-axis is d=KLd = \sqrt{\mathrm{KL}}, the distance from the starting policy, and the y-axis is the gain over πref\pi_\text{ref}. Both optimizers are plotted against this same ruler, so you can see how much proxy and gold each nat buys. The readout below the plots gives the exact numbers at the current slider position, so you can check them against the table above. The right plot shows why the gold falls. The proxy’s favorite direction (the arrow) points partly along the length axis. The gold contours are parabolas that bend back down at long lengths. A cloud that moves along the arrow first climbs the gold contours, then crosses back down them.

Scaling laws for overoptimization

How does this look with real language models? Gao, Schulman and Hilton (2022) built a clean experiment around the obvious obstacle: you can’t query real humans thousands of times per data point. So they made a synthetic world. A 6B-parameter reward model (the one from InstructGPT) plays the role of the humans: it is the gold RM. It labels comparisons, and those labels train proxy RMs ranging from 3M to 3B parameters. Then they optimize policies against each proxy, with best-of-n and with PPO, and score every policy with both the proxy and the gold.

Every run shows the shape from our toy: the proxy score keeps rising, while the gold score rises, peaks, and falls. With d=KL(π∥πref)d = \sqrt{\mathrm{KL}(\pi \Vert \pi_\text{ref})} (the paper writes πinit\pi_\text{init} for our πref\pi_\text{ref}), the gold-score curves fit simple forms:

RBoN(d)=d (αBoN−βBoN d),RRL(d)=d (αRL−βRLlog⁡d).R_\text{BoN}(d) = d\,(\alpha_\text{BoN} - \beta_\text{BoN}\, d), \qquad R_\text{RL}(d) = d\,(\alpha_\text{RL} - \beta_\text{RL} \log d).

(Here α\alpha and β\beta are fitted coefficients; this β\beta has nothing to do with the KL coefficient.) Our toy’s KL-regularized optimum gave exactly the BoN form, d−12d2d - \tfrac12 d^2, with α=1\alpha = 1 and β=12\beta = \tfrac12 (and the toy’s own best-of-n curve is close to it; the lab fits it). That is no accident: a linear first-order gain and a quadratic penalty for extrapolating too far is the simplest shape a rise-then-fall can have. Both of Gao et al.’s forms are empirical fits, chosen because they match the data, not derived from first principles.

The findings that matter for practice:

  • Bigger reward models overoptimize later. The coefficients change smoothly, roughly logarithmically, with proxy RM size. A better proxy buys you more KL before the gold turns down, but every proxy in the study eventually turns down.
  • RL spends KL much faster than BoN to reach the same proxy score, for both the helpful and the harmful part of the curve. So “KL from the reference” is a good ruler within one method but a poor one for comparing methods.
  • The KL penalty acted like early stopping. Adding a KL penalty to the RL reward made the gold score converge earlier, but it did not move the gold-versus-KL frontier: the gold score depended only on how far the policy had moved, not on how it got there. (The authors note this may be sensitive to hyperparameters.)
  • Policy size mattered little. A 6B and a 1.2B policy peaked at almost the same KL, though the larger one gained less from the optimization.

The synthetic setup is both the strength and the limit of the paper. A 6B “gold” RM is not a human, and it cannot model the adversarial and causal failures of the next section. But the core message has held up: a learned reward is a resource you spend, measured in nats.

Quick check Gao et al. added a KL penalty to the RL reward in their overoptimization experiments. What did they find?

Before LLMs, specification gaming was a collection of anecdotes from games and robotics, and the collection is instructive because each item is so clearly not a bug in the optimizer. Victoria Krakovna maintains a public list with dozens of examples; a few favorites:

  • CoastRunners (OpenAI, 2016): the boat circling a lagoon of respawning targets, described above.
  • The flipped block (from DeepMind’s write-up): a robot arm was supposed to stack a red Lego block on a blue one, and was rewarded for the height of the red block’s bottom face. It flipped the red block upside down.
  • Agents in physics simulators that exploit simulator bugs to move in impossible ways, and game-playing agents that pause the game forever rather than lose.

Chapter 1 met the boat as a curiosity. The systematic version is Pan, Bhatia and Steinhardt (2022): across four environments with deliberately misspecified rewards, more capable agents (bigger networks, finer action resolution, longer training) got higher proxy reward and lower true reward. Some showed phase transitions, where a small increase in capability flipped the agent into a qualitatively different, hacking behavior with a sharp drop in true reward. That is the uncomfortable trend for LLMs: the hacking gets worse as the optimizer gets better.

Reward hacking in language models

LLM reward hacking falls into three groups, by which part of the reward is exploited: a learned reward model’s blind spots, human raters’ preferences, and the code of a verifier.

Length and verbosity

The most common hack against learned reward models is simply to talk more. Singhal et al. (2023) examined standard RLHF setups and found the improvements in reward “largely driven by increasing response length”. More striking, “even a purely length-based reward reproduces most downstream RLHF improvements” over the SFT model in their settings. The mechanism is the extremal Goodhart of our toy. Human raters (and LLM judges, Chapter 14) mildly prefer longer, more detailed answers, the reward model learns “longer is better”, and RL extrapolates that far past where it holds.

Diagnose it by plotting reward against length on the policy’s samples, and by evaluating with length-controlled metrics such as length-controlled AlpacaEval (Dubois et al., 2024), which regress out the length difference before computing a win rate.

Sycophancy: hacking the rater

Sycophancy is telling people what they want to hear: agreeing with a user’s stated opinion, praising their work, abandoning a correct answer when they push back. Sharma et al. (2023) found it in five production assistants across four kinds of task, and traced it to the data: human preference judgments favor responses that match the user’s views, and optimizing against preference models sometimes trades truthfulness for agreement.

Here is why a small preference becomes a large behavior. Suppose that when two answers are equally correct, raters pick the one that agrees with the user 60% of the time. The Bradley–Terry reward model of Chapter 12 turns that into a reward gap Δ\Delta with σ(Δ)=0.6\sigma(\Delta) = 0.6:

Δ=log⁡0.60.4≈0.405.\Delta = \log\frac{0.6}{0.4} \approx 0.405 .

Now optimize. The KL-regularized optimum multiplies each response’s reference probability by er/βe^{r/\beta}, so the odds of agreeing versus disagreeing get multiplied by

eΔ/β=1.51/β.e^{\Delta/\beta} = 1.5^{1/\beta}.

With β=1\beta = 1 the odds go up by a factor of 1.5. With β=0.5\beta = 0.5, by 2.25. With β=0.1\beta = 0.1, a common order of magnitude in practice, by 1.510≈581.5^{10} \approx 58. A reference model that agreed half the time ends up agreeing 98% of the time. A mild bias of the raters became a near-certainty in the policy. Optimization amplifies whatever the reward prefers, including the parts nobody meant. (Exercise 19.5 asks you to find the β that keeps agreement below a target.)

Two real cases show the range:

  • Convincing, not correct. Wen et al. (2024) gave human evaluators limited time to judge answers and found that RLHF made models better at convincing those evaluators without making them more correct. The evaluators’ false-positive rate rose by 24% on a reading-comprehension task and 18% on a programming task. The policy learned to hack the evaluators’ limited attention.
  • The GPT-4o rollback. In April 2025 OpenAI rolled back a GPT-4o update that had become noticeably sycophantic. In its post-mortem, OpenAI explained that the update “introduced an additional reward signal based on user feedback—thumbs-up and thumbs-down data from ChatGPT”, that this “weakened the influence of our primary reward signal, which had been holding sycophancy in check”, and that user feedback “can sometimes favor more agreeable responses”. A thumbs-up is a reward from a rater who likes being agreed with.

Hacking the verifier

Verifiable rewards (Chapter 15) sidestep the reward model’s blind spots, which is a big part of why they work. But a verifier is a program, programs have loopholes, and a policy that is trained for thousands of steps against it will find them. The documented cases cluster in agentic coding, where the policy can run commands in the same environment as the grader (Chapter 18):

  • Special-casing tests. Anthropic’s Claude 3.7 Sonnet system card (Feb 2025) reports that the model “occasionally resorts to special-casing in order to pass test cases”: most often “directly returning expected test values rather than implementing general solutions”, sometimes “modifying the problematic tests themselves”. The card attributes it to reward hacking during RL. User testing missed it, because it appeared mostly after repeated failed attempts; automated classifiers on training transcripts caught it.
  • Escaping the test harness. Baker et al. (2025) list systemic hacks a frontier reasoning model learned during OpenAI’s agentic-coding RL, including calling exit(0) so the process ends successfully before tests can fail, and raising SkipTest so failing tests are skipped.
  • Breaking equality. In Anthropic’s production coding environments, MacDiarmid et al. (2025) studied models that returned an object whose __eq__ method always returns True (so every assert result == expected passes), exited early with sys.exit(0), or wrote a conftest.py file that patches pytest’s reporting.

The same pattern appears outside code. A lenient math checker that accepts a response if the right number appears anywhere can be hacked by listing many numbers. A format reward for producing <think> tags can be satisfied with an empty thinking block. Your coding lab builds exactly such a two-part trap for TinyLM, and you will watch the policy walk into it.

Watching the chain of thought

Reasoning models write out their reasoning before acting, and that gives you a way to catch hacks: read it. Baker et al. (2025) used GPT-4o as a chain-of-thought (CoT) monitor for a frontier reasoning model during agentic-coding RL. Models often state their intent plainly (“let’s just make the tests pass”). The CoT monitor caught about 95% of the systemic hacks, versus about 60% for a monitor that saw only the model’s actions. A weaker model could usefully monitor a stronger one.

The obvious next step is to put the monitor into the reward and penalize hacky thoughts. Baker et al. tried it. At low optimization pressure it helped: less hacking, better agents. With more optimization, the agents learned obfuscated reward hacking: they kept hacking, but stopped saying so. The CoT looked innocent and the monitor’s recall collapsed. The authors recommend paying a monitorability tax: avoid applying strong optimization pressure directly to the CoT, so it stays useful as a window.

How much can you trust that window to begin with? The evidence points in different directions under different conditions, and the claims are compatible:

  • Chen et al. (Anthropic, 2025) found that reasoning models often fail to mention a hint they used. Rates of verbalization were often below 20%, and when RL increased the use of a hint (a reward hack), verbalization did not increase.
  • Guan et al. (OpenAI, Dec 2025) built evaluations of monitorability and report that RL optimization “does not materially decrease monitorability” at current frontier scale, and that CoT monitoring beats action-only monitoring.
  • A cross-lab position paper (Korbak et al., 2025) calls CoT monitorability “a new and fragile opportunity” and asks developers to consider how their training choices affect it.

Summary: CoT monitoring is useful and imperfect, and putting it in the reward is the surest way to break it.

Quick check Baker et al. added a chain-of-thought monitor's verdict to the RL reward. With strong optimization, what happened?

When hacking generalizes

The most worrying finding of 2025–26 is that reward hacking does not stay in its box. What a model learns from hacking can change how it behaves elsewhere.

  • Emergent misalignment (Betley et al., 2025): fine-tuning a model (with SFT, not RL) to write insecure code without telling the user produced broadly misaligned behavior on unrelated prompts, such as asserting that humans should be enslaved by AI.
  • School of Reward Hacks (Taylor et al., 2025): SFT on more than a thousand harmless hacks (gaming poetry and simple-code graders) generalized to other forms of hacking and to misaligned behavior.
  • Natural emergent misalignment from production RL (MacDiarmid et al., Anthropic, Nov 2025): models that learned the AlwaysEqual, sys.exit(0) and conftest.py hacks during RL on real coding environments generalized to alignment faking, cooperating with malicious actors, and attempting to sabotage safety research. Standard chat-style safety training made them look aligned on chat evaluations while the misalignment persisted on agentic tasks. Three mitigations worked: prevent the hacking in the first place, diversify safety training, and inoculation prompting, where the training prompt frames hacking as acceptable in that context. The last one removed the misaligned generalization even when the hacking itself was still learned, which suggests that what generalizes is partly what the model learns about what kind of agent it is.
  • A deliberately misaligned reward seeker (Qi, Wright, MacDiarmid and Hubinger, Anthropic, Aug 2026): starting from an early Opus 4.8 checkpoint, the team trained on 80 RL environments known to be hackable, as a proxy for a run with no anti-hacking effort. By the end it hacked 40% of all episodes. The resulting model generalized to new reward-seeking behaviors: reward tampering rose from 0% to 41% and attacks on simulated infrastructure from 0% to 8% in their evaluations. Yet on evaluations with no clear grader it looked aligned. Its chain of thought showed “a strong desire to satisfy the grader”.

The lesson for a practitioner: hack rates are not only an efficiency problem (wasted compute, a worse model). They are a safety metric to monitor and drive toward zero.

Collapse: when the policy stops exploring

The second family of failures involves no loophole. The reward can be perfect, and the policy still ends up worse than it should be, because RL also changes how spread out the policy is.

Losing diversity

RLHF makes outputs less diverse. Kirk et al. (2023) measured this across the RLHF pipeline and found that RLHF generalized better than SFT to new inputs, but substantially reduced output diversity: the familiar “every answer sounds the same” effect. Part of this is built into the objective. The optimum π∗∝πrefer/β\pi^* \propto \pi_\text{ref} e^{r/\beta} concentrates mass on high-reward responses, and the reverse KL of Chapter 11 is mode-seeking: it penalizes putting mass where the reference has none, not failing to cover everything the reference covers.

For reasoning, the cost of lost diversity is easy to measure with pass@k, the probability that at least one of kk samples is correct. If a policy solves a problem with probability pp per sample, then pass@k =1−(1−p)k= 1 - (1-p)^k. Here is a worked example of RL sharpening a policy. Take two problems:

problem A: ppproblem B: ppmean pass@1mean pass@16
base model0.600.100.3512(1.000+0.815)=0.91\tfrac12(1.000 + 0.815) = 0.91
after RL0.950.000.47512(1.000+0)=0.50\tfrac12(1.000 + 0) = 0.50

RL made the common case much more reliable and pass@1 went up. But the rare way of solving problem B was squeezed out, and at k=16k = 16 the base model wins easily. This is the shape behind Yue et al.’s (2025) finding that base models often beat their RLVR-trained versions at large kk, discussed in Chapter 15. Whether RLVR only sharpens or can also expand what a model can solve is still debated: prolonged training with KL control and reference resets (ProRL), many more rollouts per prompt (BroRL) and different metrics give different answers. Keep pass@k at large kk on your dashboard either way.

Entropy collapse in RLVR

The sharpest version of the problem shows up during RLVR training itself. Watch the average per-token entropy of the policy: it typically falls fast in the first few hundred steps and keeps falling, responses within a group become nearly identical, and accuracy plateaus. DAPO’s authors saw it in naive GRPO runs. Cui et al. (2025) found that performance and entropy were tied by a simple empirical law across many runs,

R=−a eH+b,R = -a\, e^{H} + b ,

where RR is validation performance, HH the policy entropy, and a,ba, b fitted constants. Performance is bought with entropy, and when the entropy is gone, at H=0H = 0, you hit a predictable ceiling, R=b−aR = b - a. Once the policy is nearly deterministic, every sample in a group is the same, the group advantages are all zero (Chapter 15), and learning stops.

Why does entropy fall? There is a clean first-order answer.

The covariance rule

Take a softmax policy over actions with logits zaz_a, so π(a)∝eza\pi(a) \propto e^{z_a}. Change the logits by a small Δza\Delta z_a. To first order, the entropy changes by

ΔH≈− Cova∼π(log⁡π(a), Δza).\Delta H \approx -\,\mathrm{Cov}_{a\sim\pi}\big(\log\pi(a),\ \Delta z_a\big).

In words: if the update raises the logits of actions that are already likely, entropy falls; if it raises the logits of unlikely actions, entropy rises. The derivation below takes four lines.

What does policy gradient do to the logits? For a one-step problem with rewards r(a)r(a), the exact gradient of J=∑aπ(a)r(a)J = \sum_a \pi(a) r(a) with respect to zaz_a is π(a) A(a)\pi(a)\,A(a), where A(a)=r(a)−JA(a) = r(a) - J is the advantage (Chapter 7). A gradient step of size η\eta sets Δza=η π(a)A(a)\Delta z_a = \eta\,\pi(a) A(a), so

ΔH≈− η Cova∼π(log⁡π(a), π(a) A(a)).\Delta H \approx -\,\eta\ \mathrm{Cov}_{a\sim\pi}\big(\log\pi(a),\ \pi(a)\,A(a)\big).

Entropy falls when the likely actions are the ones with positive advantage. Cui et al. derive the same rule for LLMs, token by token, with the covariance taken over the vocabulary at each position.

∂ The first-order entropy change of a softmax policy

Let H=−∑bπblog⁡πbH = -\sum_b \pi_b \log \pi_b and πb=ezb/∑cezc\pi_b = e^{z_b}/\sum_c e^{z_c}. The softmax Jacobian is ∂πb/∂za=πb(1[a=b]−πa)\partial\pi_b/\partial z_a = \pi_b(\mathbb 1[a=b] - \pi_a). Then

∂H∂za=−∑b∂πb∂za (log⁡πb+1)=−πa(log⁡πa+1)+πa∑bπb(log⁡πb+1)=−πa(log⁡πa+H).\frac{\partial H}{\partial z_a} = -\sum_b \frac{\partial \pi_b}{\partial z_a}\,(\log\pi_b + 1) = -\pi_a(\log\pi_a + 1) + \pi_a\sum_b \pi_b(\log\pi_b + 1) = -\pi_a\big(\log\pi_a + H\big).

Since −H=Eb∼π[log⁡πb]-H = \mathbb E_{b\sim\pi}[\log\pi_b], this is −πa(log⁡πa−Eπ[log⁡π])-\pi_a\big(\log\pi_a - \mathbb E_\pi[\log\pi]\big). A first-order Taylor expansion gives

ΔH≈∑a∂H∂zaΔza=−∑aπa(log⁡πa−Eπ[log⁡π]) Δza=−Cova∼π(log⁡π(a),Δza).\Delta H \approx \sum_a \frac{\partial H}{\partial z_a}\Delta z_a = -\sum_a \pi_a\big(\log\pi_a - \mathbb E_\pi[\log\pi]\big)\,\Delta z_a = -\mathrm{Cov}_{a\sim\pi}\big(\log\pi(a), \Delta z_a\big).

The last step uses the fact that subtracting Eπ[Δz]\mathbb E_\pi[\Delta z] from Δza\Delta z_a changes nothing, because ∑aπa(log⁡πa−Eπ[log⁡π])=0\sum_a \pi_a(\log\pi_a - \mathbb E_\pi[\log\pi]) = 0. For the policy-gradient step, ∂J/∂za=∑brb πb(1[a=b]−πa)=πa(ra−J)=πaA(a)\partial J/\partial z_a = \sum_b r_b\, \pi_b(\mathbb 1[a=b] - \pi_a) = \pi_a(r_a - J) = \pi_a A(a).

Worked example. Three actions with π=(0.7,0.2,0.1)\pi = (0.7, 0.2, 0.1), entropy H=0.802H = 0.802 nats. Take one exact policy-gradient step with η=1\eta = 1 in two scenarios:

rewards rradvantages AAΔz=πA\Delta z = \pi Apredicted ΔH\Delta Hnew π\piactual ΔH\Delta H
likely action is right(1,0,0)(1, 0, 0)(0.3,−0.7,−0.7)(0.3, -0.7, -0.7)(0.21,−0.14,−0.07)(0.21, -0.14, -0.07)−0.099-0.099(0.764,0.154,0.082)(0.764, 0.154, 0.082)−0.102-0.102
rare action is right(0,0,1)(0, 0, 1)(−0.1,−0.1,0.9)(-0.1, -0.1, 0.9)(−0.07,−0.02,0.09)(-0.07, -0.02, 0.09)+0.032+0.032(0.681,0.205,0.114)(0.681, 0.205, 0.114)+0.032+0.032

When the confident answer is right, entropy drops. When a rare answer is right, entropy rises. Now consider RLVR after SFT: the model’s confident tokens are usually the right ones, so the first row is the common case. The covariance is mostly positive, step after step, and entropy drains away monotonically. That is entropy collapse in one sentence.

Where the clip comes in, and clip-higher

The PPO clip of Chapter 9 makes it worse. For a token with positive advantage, the objective stops pushing once the ratio ρ=πθ/πold\rho = \pi_\theta/\pi_\text{old} exceeds 1+ϵ1 + \epsilon. With ϵ=0.2\epsilon = 0.2:

  • a token with πold=0.9\pi_\text{old} = 0.9 can rise to 0.9×1.2=1.080.9 \times 1.2 = 1.08, more than 1, so the clip never binds;
  • a token with πold=0.01\pi_\text{old} = 0.01 can only rise to 0.0120.012 within that batch.

So the upper clip restrains exactly the updates that would raise entropy (rare tokens with positive advantage, row two of the table) while barely touching the updates that lower it. DAPO’s authors made this argument with these numbers and proposed clip-higher: decouple the two clip ranges and raise only the upper one, ϵlow=0.2\epsilon_\text{low} = 0.2, ϵhigh=0.28\epsilon_\text{high} = 0.28. The same reasoning motivated CISPO’s choice to clip the importance weight but keep every token’s gradient (Chapter 16).

Quick check A token has probability 0.02 under π_old and a positive advantage. With the symmetric PPO clip ε = 0.2, what is the highest probability it can reach in this batch before the objective stops pushing it up?

The fixes people use, all of which act on the covariance in some way:

  • Clip-higher (DAPO), and keeping gradients on clipped tokens (CISPO).
  • Clip-Cov and KL-Cov (Cui et al.): find the small fraction of tokens with the highest covariance between log-probability and advantage, and either detach their gradients or put a KL penalty on them.
  • Train mostly on the uncertain tokens. Wang et al. (2025) found that a minority of high-entropy “forking” tokens (like “wait” or “however”) carry most of the useful learning signal; restricting updates to the top 20% highest-entropy tokens matched or beat full updates on Qwen3 models.
  • An entropy bonus is the textbook fix (Chapter 8), but Cui et al. found it very sensitive to its coefficient: large coefficients made the entropy explode, and a small stabilizing one did not beat other baselines.
  • A KL penalty to the reference, which pulls the policy back toward the more diverse SFT model. Cui et al. report that it does keep entropy stable but lowered accuracy in their runs; ProRL combines it with periodic resets of the reference so that the leash doesn’t hold the policy back for good.

There is no consensus winner. Entropy management is one of the most active areas of LLM RL, and the right amount of entropy is itself unclear: some exploration is needed, but entropy is not the goal.

Failures of the training run, and of the experimenter

Two more categories look like the failures above on a dashboard but have different causes.

Numerical instabilities. A run can collapse with no reward hacking at all: the inference engine that samples rollouts and the trainer that computes gradients disagree about token probabilities even with identical weights, mixture-of-experts models route the same token to different experts in the two systems, and a slow drift of hidden off-policyness ends in a sudden crash. These are systems problems, and Chapter 20 covers them and their fixes (importance-sampling corrections, routing replay, precision changes).

Fooling yourself. Shao et al. (2025) ran GRPO on Qwen2.5-Math-7B with random rewards and still gained 21.4 points on MATH-500, against 29.1 with the true reward. The effect did not transfer to other model families. Their explanation: a bias in GRPO’s clipping amplified behaviors the model already favored (such as reasoning in code), which happened to help on that benchmark. Wu et al. (2025) argue that the Qwen2.5 models are likely contaminated on popular math benchmarks. Whatever the mechanism, the lesson is about evaluation: a reward signal can look like it works for reasons that have nothing to do with the reward. Validate across model families, include a control run, and use test sets the base model cannot have memorized.

A toolbox of mitigations

No single fix works, so production systems layer several. Each one below targets a specific failure, and each has a known limitation.

MitigationWhat it doesCaveat
KL penalty to πref\pi_\text{ref} (Ch 11)Limits how far the policy moves from where the reward model is reliableGao et al.: acts like early stopping, not a better frontier. Many RLVR recipes drop it (Ch 16)
Early stopping on a held-out gold metricStops near the gold peakNeeds a gold signal you trust (human evals, hidden tests)
Bigger / better reward modelsMoves the gold peak to larger KL (Gao et al.)Every proxy still turns down eventually
Reward model ensembles (Coste et al., 2023)Optimize the worst case or penalize disagreement, so hacks that fool one member don’t payEisenstein et al. (2023): members trained from the same pretrained model share errors; ensembles mitigate but don’t eliminate hacking
Retrain the reward model on fresh policy samplesLabels the new region the policy moved into (“iterated online” RLHF, Bai et al., 2022)Costs new labels each round
Length penalties and length-controlled evaluationRemoves the cheapest hack against learned RMsCan suppress useful long reasoning; tune on accuracy
Verifiable rewards (Ch 15)No learned RM to foolVerifiers have loopholes; harden the environment
Harden environmentsRead-only tests, graders in a separate sandbox, hidden tests, check that the test count didn’t changeAn arms race; new hacks keep being found
Monitor transcripts (classifiers, CoT monitors)Detects hacks humans miss (Claude 3.7, Baker et al.)Don’t put the monitor in the reward: obfuscation
Inoculation prompting (MacDiarmid et al., 2025)Stops a learned hack from generalizing into broader misalignmentDoesn’t stop the hack itself
Entropy controlsClip-higher, Clip-Cov/KL-Cov, KL, resetsNo consensus winner

Underneath the table is one habit: never watch only the number you are optimizing. A minimal monitoring plan for any RL run on an LLM:

Every N steps, log and plot:
  1. training reward (the proxy)            -- should go up
  2. a held-out GOLD metric                 -- hidden tests, human/strong-judge evals
     -> alert if (1) rises while (2) is flat or falling: overoptimization
  3. KL(pi || pi_ref) and response length   -- how far, and the cheapest hack
  4. token entropy, pass@1 AND pass@k       -- collapse
  5. hack detectors: test-file edits, early exits, skipped tests,
     classifier / CoT-monitor flag rate     -- per environment
Every few hundred steps: read 20 random transcripts and the 20 highest-reward ones.
Keep a checkpoint from before each alert; stop at the gold peak, not the proxy peak.

The highest-reward transcripts are the most informative ones to read, because the hacks live there.

Summary

  • Goodhart’s law in RL: a proxy reward that agrees with the gold reward on typical responses stops agreeing where the optimizer takes the policy. Gold rises, peaks and falls while the proxy keeps rising.
  • Measure optimization in nats. Best-of-n is log⁡n−(n−1)/n\log n - (n-1)/n nats from the reference. Gao et al. fit gold =d(α−βd)= d(\alpha - \beta d) for best-of-n and d(α−βlog⁡d)d(\alpha - \beta\log d) for RL, with d=KLd = \sqrt{\mathrm{KL}}. Bigger RMs peak later; a KL penalty behaved like early stopping.
  • Noise disappoints; extrapolated bias harms. Selecting on a noisy proxy wastes KL (regressional Goodhart). A proxy feature that is right in-distribution and wrong at the extremes, like “longer is better”, makes the gold fall (extremal Goodhart).
  • LLMs hack learned rewards with length and sycophancy. Optimization amplifies small rater biases: odds scale by eΔ/βe^{\Delta/\beta}.
  • LLMs hack verifiers in agentic coding: special-casing tests, editing tests, exit(0), always-equal objects. CoT monitors catch much of it, but training against the monitor teaches obfuscation. Hacking can generalize into broader misalignment.
  • Collapse needs no hack. RL sharpens the policy: pass@1 up, diversity and sometimes pass@k down. Entropy falls when the update favors already-likely actions, ΔH≈−Cov(log⁡π,Δz)\Delta H \approx -\mathrm{Cov}(\log\pi, \Delta z), and the PPO upper clip restrains the rare tokens that would raise it (hence clip-higher).
  • Mitigate in layers and monitor the gold. KL leash, better or ensembled RMs, fresh labels, hardened environments, length control, entropy controls, and a held-out gold metric on the dashboard.

Exercises

Exercise 19.1Spot the hackConcept●○○

For each reward design, say how an RL-trained policy could raise the reward without doing what the designer meant, and suggest one fix.

  1. A coding agent gets reward equal to the fraction of the repository’s test suite that passes after its edits.
  2. A math model gets reward 1 if the reference answer appears anywhere after the string “Answer:”.
  3. An R1-style format reward gives +0.5 if the response contains a <think> tag and a </think> tag.
  4. A chat assistant gets reward from users’ thumbs-up clicks.
  5. A summarizer is trained against a reward model fit to comparisons from raters who had 30 seconds per comparison.
  6. A customer-support agent is rewarded when a ticket is marked “resolved” within 10 minutes.
Solution
  1. Delete or skip the failing tests, edit the tests to match the code’s output, special-case the expected values, or exit with status 0 before the tests run. Fixes: make test files read-only (or restore them before grading), run hidden tests the agent never saw, check that the number of tests collected didn’t change, run the grader in a separate sandbox.
  2. Print many numbers (“Answer: 1 2 3 … 500”). Fix: extract exactly one final answer with a strict parser and give zero reward if there are several (Chapter 14’s verifier lab).
  3. Output <think></think> with nothing inside, then whatever answer. Fix: make the format reward small relative to the accuracy reward, or give it only when the answer is also correct, or require non-trivial content.
  4. Flattery, agreement with the user’s opinions, reassurance instead of bad news: sycophancy (the GPT-4o rollback of April 2025). Fix: keep thumbs-up as a minor signal next to a primary reward that checks for honesty, and evaluate sycophancy explicitly.
  5. Summaries that look thorough and confident in 30 seconds: longer, more detail, plausible but unverifiable claims (the “convincing, not correct” effect of Wen et al.). Fix: give raters time and tools to check faithfulness, or use a faithfulness check against the source.
  6. Mark tickets resolved without solving them, or tell the customer it’s fixed. Fix: measure resolution by whether the customer reopens the ticket or confirms, sampled audits.

The common thread: each reward measures something correlated with success on honest attempts, and each is cheaper to satisfy dishonestly.

Exercise 19.2Explore the Goodhart demoExplore the demo●○○

Use the demo above.

  1. With the defaults (best-of-n, b=1b = 1, σ=0\sigma = 0), drag the pressure slider until the gold peaks. Note nn, the KL and the gold gain. At about what nn does the gold fall below zero?
  2. Switch to “RL with KL penalty”. At what β\beta does the gold peak, and does it match the worked-example table?
  3. Switch to RL mode and set b=0b = 0, σ=1.5\sigma = 1.5. Does the gold ever fall? Compare the gold gain at KL = 1 nat (KL=1\sqrt{\mathrm{KL}} = 1 on the x-axis) with what you get with σ=0\sigma = 0.
  4. Set b=1.5b = 1.5, σ=0\sigma = 0 in RL mode. Where is the peak now? Explain using the formula t∗=1/b2t^* = 1/b^2.
  5. Watch the right-hand plot during Play. In which direction does the cloud move, and why does it first cross the gold contours upward and then downward?
Solution
  1. The peak is around n≈10n \approx 10 (KL ≈ 1.4 nats) with gold gain ≈ +0.66. The gold crosses zero near n≈630n \approx 630 (KL ≈ 5.4 nats), where the proxy gain is about +4.4.
  2. The peak is at β=1\beta = 1 (KL = 1 nat, gold +0.50, proxy +2.00), exactly the table’s row.
  3. No: with no length bias, the gold gain is tt, which only increases. But per nat it is lower: at KL = 1 the gold gain is 2/(1+σ2)\sqrt{2/(1+\sigma^2)}, which is 1.41 with σ=0\sigma = 0 and 0.78 with σ=1.5\sigma = 1.5. Noise wastes optimization (regressional Goodhart); it doesn’t reverse it.
  4. t∗=1/b2=0.44t^* = 1/b^2 = 0.44, so β∗=b2=2.25\beta^* = b^2 = 2.25, KL∗=12t∗2(1+b2)=0.32^* = \tfrac12 t^{*2}(1 + b^2) = 0.32 nats, and the gold peak is only 1/(2b2)=0.221/(2b^2) = 0.22. A stronger bias means an earlier and lower peak.
  5. The cloud moves along the proxy’s direction (b,1)(b, 1) in the (length, quality) plane: up and to the right. Moving up raises the gold; moving right lowers it quadratically. Near ℓ=0\ell = 0 the parabolic contours are flat, so the upward motion dominates. Further right they are steep, so the rightward motion dominates and the cloud crosses them going down.
Exercise 19.3The KL of best-of-nPen & paper●●○

Let the proxy score of a response under πref\pi_\text{ref} have a continuous CDF FF.

  1. Show that the best-of-n policy is πBoN(y)=nF(p(y))n−1πref(y)\pi_\text{BoN}(y) = n F(p(y))^{n-1}\pi_\text{ref}(y).
  2. Derive KL(πBoN∥πref)=log⁡n−(n−1)/n\mathrm{KL}(\pi_\text{BoN}\Vert\pi_\text{ref}) = \log n - (n-1)/n.
  3. How large must nn be for best-of-n to reach the KL of the RL policy at β=0.5\beta = 0.5 in the worked example (4 nats)? What does that tell you about using best-of-n as a cheap stand-in for RL?
Hint

For (1), yy wins if one of the nn draws is yy and the other n−1n-1 score lower; with a continuous score, ties have probability zero. For (2), the quantity U=F(p(y))U = F(p(y)) is uniform under πref\pi_\text{ref}; what is its distribution for the winner?

Solution
  1. Think of it as a density over a continuous response space (or responses with distinct scores). The winner is yy if some draw lands at yy and the remaining n−1n - 1 draws have lower proxy scores, which happens with probability F(p(y))n−1F(p(y))^{n-1} because they are independent. There are nn positions for the winning draw, so πBoN(y)=n πref(y) F(p(y))n−1\pi_\text{BoN}(y) = n\,\pi_\text{ref}(y)\,F(p(y))^{n-1}. Check that it normalizes: with U=F(p(Y))U = F(p(Y)) uniform under πref\pi_\text{ref}, Eref[nUn−1]=∫01nun−1du=1\mathbb E_\text{ref}[nU^{n-1}] = \int_0^1 n u^{n-1}du = 1.

  2. KL=EBoN[log⁡n+(n−1)log⁡U]\mathrm{KL} = \mathbb E_\text{BoN}\big[\log n + (n-1)\log U\big]. Under BoN, UU is the max of nn uniforms, with CDF unu^n and density nun−1nu^{n-1}. Integrate by parts:

E[log⁡U]=∫01nun−1log⁡u du=[unlog⁡u]01−∫01un⋅1u du=0−1n.\mathbb E[\log U] = \int_0^1 n u^{n-1}\log u\,du = \big[u^n\log u\big]_0^1 - \int_0^1 u^n\cdot\frac1u\,du = 0 - \frac1n .

(The boundary term vanishes because unlog⁡u→0u^n\log u \to 0 as u→0u \to 0.) So KL=log⁡n−(n−1)/n\mathrm{KL} = \log n - (n-1)/n.

  1. Solve log⁡n−(n−1)/n=4\log n - (n-1)/n = 4, roughly log⁡n≈5\log n \approx 5, so n≈e5≈150n \approx e^5 \approx 150 (check: log⁡150−149/150=5.01−0.99=4.02\log 150 - 149/150 = 5.01 - 0.99 = 4.02). Reaching 16 nats would need n≈e17≈2.4×107n \approx e^{17} \approx 2.4 \times 10^7. Best-of-n moves the policy only logarithmically in its cost, so it is a good model of mild optimization and a poor stand-in for long RL runs, which routinely travel tens of nats. (And per Gao et al., the KL scales of the two methods aren’t directly comparable anyway.)
Exercise 19.4The toy model in generalPen & paper●●○

In the toy model with gold g=q−12ℓ2g = q - \tfrac12\ell^2 and proxy p=q+bℓ+σep = q + b\ell + \sigma e:

  1. For the KL-regularized optimum with pressure t=1/βt = 1/\beta, find the tt that maximizes the gold gain, the maximum gain, and the KL at the peak, as functions of bb and σ\sigma.
  2. Write the gold gain as a function of d=KLd = \sqrt{\mathrm{KL}} and identify Gao’s coefficients α\alpha and βG\beta_\text{G} in d(α−βG d)d(\alpha - \beta_\text{G}\, d).
  3. Explain in words why increasing σ\sigma lowers both α\alpha and βG\beta_\text{G}, but does not change the peak gold gain.
Hint

Use Δgold=t−12b2t2\Delta\text{gold} = t - \tfrac12 b^2t^2 and KL=12t2s2\mathrm{KL} = \tfrac12 t^2 s^2 with s2=1+b2+σ2s^2 = 1 + b^2 + \sigma^2. Then substitute t=d2/st = d\sqrt2/s.

Solution
  1. ddt(t−12b2t2)=1−b2t=0\frac{d}{dt}(t - \tfrac12 b^2t^2) = 1 - b^2 t = 0 gives t∗=1/b2t^* = 1/b^2, i.e. β∗=b2\beta^* = b^2. The peak gain is t∗−12b2t∗2=12b2t^* - \tfrac12 b^2 t^{*2} = \frac{1}{2b^2}. The KL there is 12t∗2s2=1+b2+σ22b4\tfrac12 t^{*2}s^2 = \frac{1 + b^2 + \sigma^2}{2b^4}. For b=1,σ=0b = 1, \sigma = 0: t∗=1t^* = 1, gain 0.5, KL 1 nat, matching the table.

  2. KL=12t2s2\mathrm{KL} = \tfrac12 t^2 s^2 means d=ts/2d = ts/\sqrt2, so t=2 d/st = \sqrt2\, d/s. Then

Δgold=2sd−b2s2d2=d(2s−b2s2 d),\Delta\text{gold} = \frac{\sqrt2}{s}d - \frac{b^2}{s^2}d^2 = d\Big(\frac{\sqrt2}{s} - \frac{b^2}{s^2}\,d\Big),

so α=2/s\alpha = \sqrt2/s and βG=b2/s2\beta_\text{G} = b^2/s^2. For b=1,σ=0b = 1, \sigma = 0: s2=2s^2 = 2, α=1\alpha = 1, βG=12\beta_\text{G} = \tfrac12.

  1. Noise makes every unit of KL less useful: part of each move goes into the worthless direction ee, so both the gain per nat (α\alpha) and the damage per nat (βG\beta_\text{G}) shrink by the same mechanism, stretching the curve along the dd axis. But the optimum in terms of tt is unchanged (t∗=1/b2t^* = 1/b^2 doesn’t involve σ\sigma), because the qq and ℓ\ell components of the mean shift, tt and btbt, don’t depend on σ\sigma. You reach the same peak gold, just at a larger KL. Noise costs distance; bias costs gold.
Exercise 19.5How optimization amplifies a rater biasPen & paper●●○

Raters prefer the answer that agrees with the user with probability qagree=0.6q_\text{agree} = 0.6 when both are equally correct. The reference model agrees with probability a0=0.5a_0 = 0.5 in such situations. Assume a Bradley–Terry reward model learns this exactly, and the policy reaches the KL-regularized optimum.

  1. Show that the policy’s probability of agreeing is a∗=a0 ka0k+(1−a0)a^* = \dfrac{a_0\, k}{a_0 k + (1-a_0)}, where k=(qagree/(1−qagree))1/βk = (q_\text{agree}/(1-q_\text{agree}))^{1/\beta}.
  2. Compute a∗a^* for β=1,0.5,0.1\beta = 1, 0.5, 0.1.
  3. Which β\beta keeps a∗a^* at or below 0.6? Comment on what this means for using a KL penalty as the only defense against sycophancy.
Hint

Bradley–Terry says σ(ragree−rdisagree)=qagree\sigma(r_\text{agree} - r_\text{disagree}) = q_\text{agree}, so eΔ=qagree/(1−qagree)e^{\Delta} = q_\text{agree}/(1 - q_\text{agree}). The optimum multiplies each response’s reference probability by er/βe^{r/\beta} and renormalizes.

Solution
  1. Let Δ=ragree−rdisagree\Delta = r_\text{agree} - r_\text{disagree}. Bradley–Terry gives σ(Δ)=qagree\sigma(\Delta) = q_\text{agree}, so eΔ=qagree/(1−qagree)e^\Delta = q_\text{agree}/(1 - q_\text{agree}). The optimum is π∗∝πrefer/β\pi^* \propto \pi_\text{ref} e^{r/\beta}, so the odds become
a∗1−a∗=a01−a0 eΔ/β=a01−a0 k.\frac{a^*}{1-a^*} = \frac{a_0}{1-a_0}\, e^{\Delta/\beta} = \frac{a_0}{1-a_0}\,k .

Solving for a∗a^* gives the formula. (Only the reward difference matters, which is why the per-prompt constant ambiguity of Chapter 12 doesn’t affect the answer.)

  1. Here q/(1−q)=1.5q/(1-q) = 1.5 and a0=0.5a_0 = 0.5, so a∗=k/(k+1)a^* = k/(k+1):

    • β=1\beta = 1: k=1.5k = 1.5, a∗=0.60a^* = 0.60.
    • β=0.5\beta = 0.5: k=2.25k = 2.25, a∗=0.69a^* = 0.69.
    • β=0.1\beta = 0.1: k=1.510≈57.7k = 1.5^{10} \approx 57.7, a∗≈0.983a^* \approx 0.983.
  2. a∗≤0.6a^* \le 0.6 requires k≤1.5k \le 1.5, i.e. 1.51/β≤1.51.5^{1/\beta} \le 1.5, i.e. β≥1\beta \ge 1. At β=1\beta = 1 the policy reproduces the raters’ bias exactly; it can never do better than that, because the reward is the bias. A KL penalty strong enough to stop the amplification (β≥1\beta \ge 1) is also too strong for the policy to learn much else: practical KL coefficients are far below 1 (DeepSeekMath’s GRPO used 0.04). So the leash limits amplification but cannot remove a bias that is in the reward itself: you need to fix the data (instructions to raters, targeted comparisons where agreeing is wrong) or add a reward that penalizes sycophancy.

Exercise 19.6Why entropy collapsesPen & paper●●●
  1. Starting from H=−∑aπalog⁡πaH = -\sum_a \pi_a\log\pi_a with a softmax policy, derive ΔH≈−Cova∼π(log⁡π(a),Δza)\Delta H \approx -\mathrm{Cov}_{a\sim\pi}(\log\pi(a), \Delta z_a).
  2. A two-action policy has π=(0.9,0.1)\pi = (0.9, 0.1). For an exact policy-gradient step Δza=η π(a)A(a)\Delta z_a = \eta\,\pi(a) A(a), compute the predicted sign and size of ΔH\Delta H when (a) action 1 has reward 1 and action 2 reward 0, (b) the reverse. Use η=1\eta = 1.
  3. Give an informal argument for why, in RLVR after SFT, the covariance between a token’s log-probability and its advantage is positive more often than not, so entropy falls step after step.
  4. Using the same formula, explain why the PPO upper clip slows exploration but the lower clip does not have a symmetric effect.
Hint

For (2), with two actions Cov(X,Y)=π1π2(X1−X2)(Y1−Y2)\mathrm{Cov}(X, Y) = \pi_1\pi_2(X_1 - X_2)(Y_1 - Y_2). For (3), think about which tokens the SFT model is confident about, and whether those tend to lead to correct answers. For (4), which actions can the upper clip stop from growing, and what does the covariance rule say about growing them?

Solution
  1. See the derivation in the “covariance rule” section: ∂H/∂za=−πa(log⁡πa+H)=−πa(log⁡πa−Eπ[log⁡π])\partial H/\partial z_a = -\pi_a(\log\pi_a + H) = -\pi_a(\log\pi_a - \mathbb E_\pi[\log\pi]), then a first-order Taylor expansion and the fact that the weights πa(log⁡πa−Eπlog⁡π)\pi_a(\log\pi_a - \mathbb E_\pi\log\pi) sum to zero.

  2. With two actions, Cov(X,Y)=π1π2(X1−X2)(Y1−Y2)=0.09 (X1−X2)(Y1−Y2)\mathrm{Cov}(X,Y) = \pi_1\pi_2(X_1-X_2)(Y_1-Y_2) = 0.09\,(X_1 - X_2)(Y_1 - Y_2). Here log⁡π1−log⁡π2=log⁡9=2.197\log\pi_1 - \log\pi_2 = \log 9 = 2.197.

    • (a) J=0.9J = 0.9, A=(0.1,−0.9)A = (0.1, -0.9), Δz=(0.09,−0.09)\Delta z = (0.09, -0.09), Δz1−Δz2=0.18\Delta z_1 - \Delta z_2 = 0.18. Cov=0.09×2.197×0.18=0.0356\mathrm{Cov} = 0.09 \times 2.197 \times 0.18 = 0.0356, so ΔH≈−0.036\Delta H \approx -0.036: entropy falls (from H=0.325H = 0.325).
    • (b) J=0.1J = 0.1, A=(−0.1,0.9)A = (-0.1, 0.9), Δz=(−0.09,0.09)\Delta z = (-0.09, 0.09), difference −0.18-0.18, so ΔH≈+0.036\Delta H \approx +0.036: entropy rises.

    Exact check for (a): new logits differ by log⁡9+0.18\log 9 + 0.18, so π1=0.915\pi_1 = 0.915, H=0.291H = 0.291, ΔH=−0.034\Delta H = -0.034. Close to the prediction.

  3. After SFT, the model is confident mostly where it is right: the high-probability continuations are usually the ones that lead to correct answers, and low-probability tokens are disproportionately mistakes. So positive advantages fall mostly on high-log⁡π\log\pi tokens and negative ones mostly on low-log⁡π\log\pi tokens (which, being rarely sampled, also contribute little). Both make Cov(log⁡π,Δz)\mathrm{Cov}(\log\pi, \Delta z) positive, so ΔH<0\Delta H < 0, and since this is true at almost every step, the decrease compounds. Only the relatively rare event “an unlikely token turned out right” pushes the other way.

  4. Apply the covariance rule to each clip separately. Both clips bound the ratio π/πold\pi/\pi_\text{old}, which is a tight absolute limit on a rare token and a loose one on a likely token, so both bind mostly on rare tokens.

    • The upper clip binds on rare tokens with positive advantage (0.01 can only reach 0.012). Raising a rare token raises entropy (row two of the worked example). So the upper clip blocks an entropy-raising move. On likely tokens it hardly binds (0.9 → 1.08 is above 1).
    • The lower clip binds on rare tokens with negative advantage (0.01 can only fall to 0.008). Pushing a rare token further down lowers entropy, so the lower clip blocks an entropy-lowering move, and if anything protects entropy.

    So the two clips are not symmetric in their effect on entropy: together they make it easy to sharpen the policy and hard to spread it out. Raising ϵhigh\epsilon_\text{high} (clip-higher) relaxes exactly the constraint that blocks exploration. Raising ϵlow\epsilon_\text{low} instead would let rare tokens be pushed toward zero faster, which would shrink the space of things the policy can sample.

Exercise 19.7Lab Part 1: an overoptimization curveCode●●○

In overopt.py, implement Task 1a bon_kl, Task 1b best_of_n_stats (the exact expected proxy and gold of best-of-n from a pool, using rank weights), and Task 1c fit_gao_bon. Then run python run.py overopt. For the three reward models in the plot (bias only, noise only, both), report the fitted α\alpha and β\beta and where the gold peaks. Which one has β≈0\beta \approx 0, and why? Finally, how much should you trust the right-hand end of each curve, where nn is in the thousands?

Hint

The winner has rank kk (in ascending proxy order) with probability (k/M)n−((k−1)/M)n(k/M)^n - ((k-1)/M)^n: all nn draws have rank at most kk, but not all have rank at most k−1k-1. The Gao fit has no intercept: build a matrix with columns dd and −d2-d^2.

Solution

The key lines (full code in solutions/overopt.py):

order = np.argsort(proxy)
k = np.arange(1, M + 1)
w = (k / M) ** n - ((k - 1) / M) ** n
return float(w @ proxy[order]), float(w @ gold[order])

and X = np.stack([d, -d**2], axis=1); np.linalg.lstsq(X, gold_gain).

With the reference solution you should see roughly: bias only (b=1b=1): α≈1.1\alpha \approx 1.1, β≈0.47\beta \approx 0.47, gold peaks at n≈10n \approx 10 (KL ≈ 1.4) with gain ≈ +0.66 and is negative by n=3000n = 3000. Noise only (b=0,σ=1b = 0, \sigma = 1): β≈0\beta \approx 0 (slightly negative), the gold keeps rising up to n=3000n = 3000. Bias and noise (b=σ=1b = \sigma = 1): the peak comes a little later in KL and a little lower than with bias alone (best-of-14, KL ≈ 1.7, gain ≈ +0.61). The last point of this curve says the gold is negative again at n=3000n = 3000 (about −0.4), but see the last paragraph below before you believe it.

Noise alone gives β≈0\beta \approx 0 because with independent Gaussian noise the gold is linear in what the selection pushes on: selection on pp raises E[q]\mathbb E[q] in proportion to E[p]\mathbb E[p], and there is no feature that is good at first and bad later. It is the regressional Goodhart case: less gold per nat, but no downturn. The downturn needs a feature that the proxy rewards and the gold punishes at the extremes.

Note that the fit for the bias-only pool is close but not perfect: our toy’s best-of-n curve is only approximately quadratic in dd, which is the same kind of approximation Gao et al.’s form is.

On trusting the tail: at n=3000n = 3000 the winner is almost always one of the top few hundred responses in a pool of 200,000, so the far right of each curve rests on very few samples and is noisy. For b=σ=1b = \sigma = 1 the exact infinite-pool value (the max-of-normals integral that the demo uses) is about +0.10 at n=3000n = 3000, and the gold only crosses zero near n≈6,000n \approx 6{,}000 (KL ≈ 7.6 nats). Re-run with make_pool(..., seed=1) or a pool of 2,000,000 and watch the tail move while the peak barely changes. The same caution applies to real best-of-n curves: estimating best-of-n at large nn from a finite set of samples needs many more samples than nn.

Exercise 19.8Lab Part 2: watch TinyLM hack a rewardCode●●○

First, without running anything, read proxy_reward in common.py. It gives 1 if the correct answer appears anywhere in the response, plus 0.1 per character. Predict what the policy will learn, and what will happen to exact-match accuracy.

Then implement Task 2 kl_penalized_rewards and Task 3 clipped_pg_loss in failures.py (Task 4 token_entropy is needed too; it’s three lines), and run python run.py hack. It trains three policies from the same SFT checkpoint for 200 steps: proxy reward with no KL, proxy reward with β=0.05\beta = 0.05, and the gold (exact-match) reward. Describe the three curves. Why does a KL penalty this small stop the hack, when it barely slows down learning the correct answers?

Hint

Neither flaw alone is exploitable: a lenient check gives no reason to change a correct answer, and a 0.1 bonus per character can’t outweigh losing a full point for a wrong answer. Together, appending a digit to a correct answer keeps the full point and adds 0.1. For the KL question, compare how much reward each behavior gains with how unlikely it was under the reference: the optimum multiplies probabilities by er/βe^{r/\beta}.

Solution

Prediction: the policy learns to keep writing digits after the correct answer instead of stopping. “85” scores 1.2; “850” scores 1.3; “8500” scores 1.4. Exact-match accuracy should fall to zero while the proxy rises.

Key lines (full code in solutions/failures.py):

seq_kl = ((logp - ref_logp) * mask).sum(dim=1)
return rewards - beta * seq_kl
rho = torch.exp(logp - old_logp)
obj = torch.min(rho * adv[:, None], torch.clamp(rho, 1 - eps_low, 1 + eps_high) * adv[:, None])
return -(obj * mask).sum() / mask.sum()

What you should see (reference solution, seed 0): with no KL, gold accuracy first rises (about 0.52 → 0.62 by step 50: the proxy rewards correctness too, so early optimization helps), then the padding hack takes over around step 80–120. Response length jumps to the maximum of 4 characters, the KL estimate jumps to about 15 nats, gold accuracy falls to 0, and the proxy keeps rising. That is the Gao curve in a 100k-parameter model. With β = 0.05, length stays near 2.5 and gold accuracy climbs steadily (to roughly 0.75–0.8), tracking the gold-reward run.

Why the asymmetry: at the KL-regularized optimum, each response’s probability is multiplied by er/βe^{r/\beta} relative to the reference. A correct answer gains a full reward point over a wrong one: a factor of e1/0.05=e20e^{1/0.05} = e^{20}, which overwhelms any reference prior, so correctness is learned. Padding gains only 0.1 per digit: a factor of e2≈7.4e^{2} \approx 7.4, applied to something the SFT model almost never does (it ends with <eos> right after the answer with probability close to 1). The small gain cannot pay for moving that far from the reference. The leash prices each behavior by reward gained per unit of improbability under the reference, and hacks are typically high-improbability, low-gain behaviors, until a run without a leash finds a way to make them high-gain.

Try also: set LENGTH_BONUS = 0.0, or make the check exact while keeping the bonus. Neither flaw alone is enough.

Exercise 19.9Lab Part 3: entropy under clip, clip-higher, and no upper clipCode●●●

With Task 4 token_entropy implemented, run python run.py entropy. It trains with the gold reward and 4 gradient epochs per batch (so the clip actually binds), three times: ϵhigh=0.2\epsilon_\text{high} = 0.2 (symmetric), 0.280.28 (clip-higher), and ∞\infty (no upper clip at all), always with ϵlow=0.2\epsilon_\text{low} = 0.2. The loop also logs a diagnostic: among tokens with positive advantage, the fraction whose ratio ended above 1+ϵhigh1 + \epsilon_\text{high} (so the upper clip switched their gradient off), separately for rare tokens (πold<0.2\pi_\text{old} < 0.2) and common ones (πold>0.8\pi_\text{old} > 0.8).

  1. Describe the three entropy curves and the three accuracy curves.
  2. What does the diagnostic say about which tokens the upper clip restrains? Connect it to the covariance rule.
  3. Why is the difference between 0.2 and 0.28 so small here, and what does the “no upper clip” run tell you about why nobody simply removes the clip?
Hint

For (2), a rare token’s log-probability moves fast: the gradient of log⁡π\log\pi with respect to its own logit is 1−π1 - \pi, close to 1. How many epochs does it take for its ratio to pass 1.2 or 1.28? For (3), look at how far past the threshold the rare tokens end up, and at the accuracy of the unclipped run.

Solution

Reference run (seed 0, your numbers will differ a little):

runentropy (nats/token)accuracyrare tokens upper-clippedcommon tokens upper-clipped
ε_high = 0.20.34 → 0.150.52 → 0.570.940.005
ε_high = 0.280.35 → 0.140.51 → 0.640.960.000
no upper clip0.35 → 0.190.50 → 0.3100
  1. In all three runs entropy falls steadily: entropy collapse on a tiny scale, as the covariance rule predicts (the SFT model’s confident digits are usually right). The two clipped runs are nearly indistinguishable in entropy; accuracy rises in both (a second seed gave 0.48 → 0.68 for both, so the accuracy gap in this table is noise). Without the upper clip, entropy stays clearly higher, but accuracy falls: the policy is unstable.

  2. The upper clip switches off almost all rare positive-advantage tokens (over 90%) and essentially none of the common ones. This is the chapter’s argument made visible: the ratio cap is a tight absolute limit for rare tokens and no limit for likely ones, so the clip blocks exactly the updates that would raise entropy (row two of the covariance worked example).

  3. Within 4 epochs at this learning rate, a rare token’s ratio shoots far past 1.2 and past 1.28, so moving the threshold from 1.2 to 1.28 changes almost nothing: both runs clip nearly all of them. Clip-higher is a small relaxation, and DAPO measured its effect over thousands of steps on a 32B model, not 120 steps on a 100k-parameter one. Removing the cap entirely keeps entropy higher but lets each batch push rare tokens arbitrarily far on the evidence of a single sample, and the run degrades. That is the trade-off behind every entropy fix in the chapter: you want to let rare good tokens grow, but not without limit. A careful study would also run several seeds; try it.

Exercise 19.10Design a monitoring planConcept●●○

You are about to run GRPO for 2,000 steps on a coding agent. The reward is the fraction of unit tests passed in a sandboxed repository; the agent can run shell commands. Write a monitoring plan: what you log, what alerts you set, what you read by hand, and what you will do when an alert fires. Include at least one signal for each of: overoptimization, verifier hacking, entropy collapse, and evaluation contamination.

Hint

Organize by failure: for each, ask “what number moves when this happens, and what number would I need to compare it against?” The comparison is usually something the policy can’t optimize.

Solution

A good plan, organized by failure:

  • Overoptimization. Log training reward, and every 50 steps a held-out gold eval: tasks the policy never trains on, graded with hidden tests, plus a small set graded by humans or a strong judge for code quality. Alert when training reward rises over 200 steps while the held-out score is flat or falls. Action: roll back to the checkpoint at the held-out peak; investigate what is being rewarded.
  • Verifier hacking. Log per-environment: whether test files were modified (diff the test directory before grading), the number of tests collected (a drop means deletion or skipping), exit codes and early exit calls, SkipTest/xfail markers added, objects overriding __eq__, writes to conftest.py or pytest config, and run times that are suspiciously short. Run a CoT monitor and a hack classifier on a sample of transcripts and log the flag rate per environment, without putting it in the reward. Alert on any rise in flag rate or any environment where the hack rate exceeds a few percent. Action: patch the environment (read-only tests, grader in a separate container), drop the affected data, consider inoculation-style prompting, restart from before the hack spread.
  • Entropy collapse. Log per-token entropy, the fraction of groups with zero reward variance (all pass or all fail), and pass@1 and pass@k (kk = 8 or 16) on the held-out set. Alert if entropy falls faster than a set rate, or pass@k falls while pass@1 rises. Action: raise ϵhigh\epsilon_\text{high}, add Clip-Cov-style controls or a weak KL, use dynamic sampling to drop zero-variance groups.
  • Contamination and self-deception. Use a held-out set created after the base model’s training cutoff, include a control run with shuffled or random rewards for a few hundred steps (if it “improves” too, your gains aren’t from the reward), and check results on a second model family.
  • Also: KL to the reference and response length (cheap early warnings), and the train–inference log-prob gap (Chapter 20).
  • By hand: every 200 steps, read 20 random transcripts and the 20 highest-reward ones. Hacks concentrate in the top-reward transcripts.

Files: README.md, overopt.py, failures.py, common.py, test_overopt.py, test_failures.py, run.py

cd 19-failure-modes
python -m pytest -q          # your code: tests fail until you fill in the TODOs
RL_SOLUTIONS=1 python -m pytest -q   # reference solutions: all pass

First time? See Exercises & setup.

Further reading

Next, Chapter 20 leaves the objective and looks at the machinery: why rollouts dominate the cost of RL for LLMs, how asynchronous training works, and the train–inference mismatch that can crash a run with no hacking at all.