#1153640 aptitude: "aptitude why" should consider non-autoremoved packages as a fallback

Package:
aptitude
Source:
aptitude
Description:
terminal-based package manager
Submitter:
Vincent Lefevre
Date:
2026-11-10 15:51:02 UTC
Severity:
normal
#1153640#5
Date:
2026-11-10 15:49:27 UTC
From:
To:
The aptitude(8) man page says about "aptitude why":

  If no patterns are present, then aptitude will search for dependency
  chains beginning at manually installed packages. This effectively
  shows the packages that have caused or would cause a given package
  to be installed.

However, it may happen that for some package, there was initially such
a chain, but due to an upgrade, the chain no longer exists while the
package is still not autoremoved because it is still required by a
package in some non-autoremoved list (there seems to be such a list
for aptitude, but this is not documented).

An example:

disset:~> aptitude why linux-modules-7.2.15+deb14-amd64
Automatically installed, current version 7.2.15-1, priority optional
No dependencies require to install linux-modules-7.2.15+deb14-amd64

The message "No dependencies require..." could be improved because
there is actually a dependency (see bug 1153632 I've just reported):

  linux-image-7.2.15+deb14-amd64 → linux-modules-7.2.15+deb14-amd64

found with

disset:~> apt remove -s linux-modules-7.2.15+deb14-amd64
[...]
REMOVING:
  linux-image-7.2.15+deb14-amd64  linux-modules-7.2.15+deb14-amd64
[...]

(note that however, this could not have been found if this had just
been a "Recommends:", while aptitude honors "Recommends:").

Moreover, if no chains from manually installed packages are found,
aptitude could try chains from non-autoremoved packages. Giving
information about such a case would be useful for the user, who
may wonder why some package has not been autoremoved.

More details about this example:

On another machine, where linux-image-amd64 still depends on
linux-image-7.2.15+deb14-amd64 because I haven't upgraded it
yet (linux-image-amd64 is still at version 7.2.15-1):

cventin:~> aptitude why linux-modules-7.2.15+deb14-amd64
i   linux-image-amd64              Depends linux-image-7.2.15+deb14-amd64 (= 7.2.15-1)
i A linux-image-7.2.15+deb14-amd64 Depends linux-modules-7.2.15+deb14-amd64 (= 7.2.15-1)

On disset, linux-image-7.2.15+deb14-amd64 is also automatically
installed; but linux-image-amd64 is now at version 7.3.3-1, so that no
manually installed packages depend on linux-image-7.2.15+deb14-amd64
anymore. But linux-image-7.2.15+deb14-amd64 is not proposed as being
autoremoved by aptitude.

See also bug 902652 (which is not clear to me).

Note: Bug report corrected and improved thanks to AI. There may
be still things that are unclear (I've already spent much time).
For the reference:
https://chat.mistral.ai/work/184ca06c-4f7a-4576-989b-806c34ec62a3