The original post is a real Debian-user thread from Nov 14, 2026, on apt 3.0.4. There's a follow-up from Greg Wooledge; let me read it.
The list site uses a proof-of-work challenge for curl, but the web fetch tool works. Let me get the "Next by thread" link from the original post.
Real data now. Let me read the rest of the thread.
The key data is in: booted kernel is the newest, 5 kernels installed, apt-get -s autoremove removes nothing. Let me read the rest of the thread to see how it resolves.
Excellent, this thread has the decisive data: all 5 kernels on Charles's machine are auto-installed (only the meta is manual), yet apt-get -s autoremove removes nothing. That contradicts the theory that this is just manual-install status. Since he runs apt 3.0.4, let me check whether the trixie version differs from main here.
The function is identical across 3.0.1/3.0.4/main, so the keep-selection isn't the difference. The kernels are auto-installed yet not garbage, so something is marking them as required. Let me diff the autoremove marking logic (MarkRequired/MarkPackage) between main and 3.0.4.
The marking code differences between main and 3.0.4 are unrelated to kernels. Rather than keep speculating, let me try to reproduce this directly with apt's own integration-test framework: 5 auto-installed kernels, booted = newest, KernelCount=3, then check what autoremove removes.
We're actually running on Debian trixie, the same distro, with the system apt available. I can reproduce the exact scenario with the system apt using a sandboxed root dir. Let me check the tools first.
The real apt binary is preserved at /opt/sandbox/image/usr/bin/apt-get. Let me try running it directly.
dpkg/apt are blocked here, so I can't reproduce live. But the new evidence (kernels are auto-installed, yet nothing is garbage) means something marks the old kernels as required. Let me read the full MarkPackage providers logic in apt 3.0.4.
I need to see which dependency pulls in all kernel versions as providers. Let me inspect the actual trixie kernel package control files.
The pool listing shows bpftool and hyperv-daemons built per kernel version. Let me grab the trixie Packages index and find what depends on or provides $kernel.
$kernel is synthesized by apt, not in the archive. Let me look at the actual control stanzas: the meta's Depends and the versioned kernel image's Depends/Provides.
Key subtlety spotted in that output: apt show lists alphabetically, so the single "yes" is linux-image-6.12.111+deb13-amd64 (the oldest kernel), not the meta. Let me read the remaining messages of the thread to see if the discussion caught this.
Found it! msg00286 is the smoking gun: removing the setting makes the 3 old kernels appear as "no longer required" again. So setting the option is what keeps all 5. I have a strong hypothesis: APT::NeverAutoRemove is also a regex list (matched by MatchAgainstConfig), and adding a leaf KernelCount = "3" under it injects the string "3" as a regex. Let me verify against apt's MatchAgainstConfig implementation.
MatchAgainstConfig("APT::NeverAutoRemove") builds its regex list via FindVector("APT::NeverAutoRemove"). Let me confirm FindVector collects the values of all leaves under the subtree.
Bug confirmed.FindVector("APT::NeverAutoRemove") returns the values of every child under that node. Let me check whether this is already known upstream, then wrap up.
Yes, there's a genuine bug, and Vincent's suspicion in the thread was right. But it's not in the loop you pasted, it's in a configuration namespace collision: APT::NeverAutoRemove is simultaneously a scalar option scope (holding KernelCount) and a list of regexes that protects packages from autoremove. Setting KernelCount "3" injects the string 3 into that regex list.
The mechanism
apt autoremove's root set includes every package matching the APT::NeverAutoRemove regexes. That matcher is built in MatchAgainstConfig("APT::NeverAutoRemove"), which calls Configuration::FindVector("APT::NeverAutoRemove") — and FindVector returns the value of every child node under that scope:
When you write APT::NeverAutoRemove::KernelCount "3";, the config tree under APT::NeverAutoRemove gains a child KernelCount whose value is "3". FindVector therefore returns {"^firmware-linux.*", "^linux-firmware$", "3"}, and MatchAgainstConfig happily compiles "3" as a regex (unanchored, so it matches any package name containing the character '3').
On Debian 13 every kernel package name contains +deb13, so all kernels match, are placed in the root set, marked as required, and can never be autoremove garbage. The same collateral applies to any other package with a '3' in its name, which is why Charles's apt-get -s upgrade showed no "no longer required" hints at all while the setting was active.
The thread data confirms it
With KernelCount "3" set: apt-get -s --purge autoremove → nothing to remove, no garbage hints.
Same machine, setting removed: the 3 oldest kernels immediately show up as "automatically installed and are no longer required" (and the kernels really are auto-installed: the APT-Manual-Installed check shows only the linux-image-amd64 meta as manual).
Also consistent: Greg (who never sets the option) always gets the normal 2-kernel behavior.
So the keep-selection loop in algorithms.cc is behaving exactly as designed (booted + newest up to the count); the packages are simply never reaching the removal stage because the polluted APT::NeverAutoRemove list protects them first. This affects the feature commit a6e30cc ("Configure the amount of kernels to keep", first shipped in apt 2.7.12, commit) and the code is still unchanged in current main and in trixie's 3.0.4, so there is no fix released. I found no existing Debian bug report for it.
You can confirm it in one line on an affected machine:
The debug output will show the old kernels marked "Blacklisted [APT::NeverAutoRemove]" — before the Kernel protection regex is even consulted.
Recommendations
Report it: this is worth filing against apt in the Debian BTS. The upstream fix would be either moving the option out of the list scope (e.g. APT::KernelCount), or having FindVector/MatchAgainstConfig skip children that were set as named scalar options rather than list items. This also explains why any value (2, 3, 4…) misbehaves, and the mailing-list suggestion to test N=0…6 will show the same pattern.
Workaround until fixed: there is no clean config-only way to set KernelCount without polluting the list. If you want more than 2 kernels, mark the extra ones apt-mark manual (or hold) instead; or patch 01autoremove to also add the wanted kernel unames as explicit APT::NeverAutoRemove regexes.
This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.