Windows 11 25H2 gets slower every day you run coding agents

All articles

The machine was fine last week. Now every command takes a beat to start, the fans run, and Task Manager shows the processors busy without any one program to blame. You restart, it is quick again, and a day or two later it is slow again.

If that machine runs Windows 11 version 25H2 and spends its days running coding agents, there is a good chance it is a known Windows bug, and there is a one-setting fix. We found it on our own machine in November.

What is leaking

Every program Windows starts gets a security token, a small piece of kernel memory that says who the program runs as. When the program exits, the token should be freed. Version 25H2 (build 26200) has a bug: when it checks whether a newly started console program may bring its window to the front, it keeps a reference to that program's token and never lets go.

A person starting a few programs an hour never notices. A fleet of agents starts dozens a minute, because every command an agent runs, and every hook around it, is a new process. On our machine, after 19 days of agent work, Windows held 7.9 million leaked tokens and 37 GB of kernel memory, and every program launch took about 2.4 seconds. After a fresh restart without the fix, the same machine reached 11 GB in 28 hours.

It is not specific to one coding agent or one tool. Other tools that start many console programs have reported it too, for example git-for-windows issues 6471 and 6499.

Check whether you have it

Two numbers tell you: the build, and how much kernel paged pool memory is in use. In PowerShell:

[System.Environment]::OSVersion.Version          # Build 26200 = version 25H2
"{0:N1} GB kernel paged pool" -f ((Get-Counter '\Memory\Pool Paged Bytes').CounterSamples[0].CookedValue / 1GB)

A healthy machine sits well under 1 GB of paged pool. Several gigabytes that keep growing, on a machine that has been up a day or two, is the leak.

The fix is one setting

The setting is the foreground lock timeout: how long Windows waits before it lets a program take focus away from the window you are using. Set it to 0 and Windows skips the step that holds on to the token. On our machine the leak went from 43 to 182 tokens every two minutes down to almost none. It changes no files and installs nothing. Three things about it catch people out:

  • The registry value is not enough. You can set ForegroundLockTimeout to 0 in the registry and the live setting Windows uses stays at its maximum. The live value has to be set through a Windows call, and read back to prove it took.
  • It has to run in a visible window. Windows only accepts the change from a program that is allowed to come to the front. Run from inside an agent's terminal, a background service or a hidden window, it fails. A coding agent can still do it, by opening a normal visible PowerShell window for the script.
  • Windows resets it at every sign-in. So the script runs again at each logon, from a scheduled task. That task can still fail on a given sign-in if another window holds the front at that moment, which is why checking the live value after a restart is part of the fix, not an extra.

The script, the logon task and the check are written out step by step on the docs page linked below, in a form a person or a coding agent can follow.

Restart, do not shut down

The fix stops new leaks. It does not give back memory that has already leaked. Only a restart does that, and it has to be Restart: with Fast Startup on, which is the Windows default, Shut down keeps the kernel memory, leaks included. If the paged pool is already several gigabytes, apply the fix now and restart when it suits you.

What it costs

With the timeout at 0, a program can now and then bring its window to the front while you are typing somewhere else. That is the whole cost. On a machine that mostly runs agents it is rarely noticed, and undoing it is deleting the task and restarting.

The full procedure, including the script, the logon task, how to read the live value and how to undo it, is on Run DevThrottle on Windows. The Mac equivalent, for a machine nobody sits at, is Run DevThrottle on a Mac unattended.

Talk to usBook a 20-minute call