Skip to content

simpleclient: Preserve the "#auto" install marker through local depen… - #19

Open
AlexB7 wants to merge 1 commit into
linuxmint:masterfrom
AlexB7:autoremove-kernel-fix
Open

simpleclient: Preserve the "#auto" install marker through local depen…#19
AlexB7 wants to merge 1 commit into
linuxmint:masterfrom
AlexB7:autoremove-kernel-fix

Conversation

@AlexB7

@AlexB7 AlexB7 commented Aug 13, 2026

Copy link
Copy Markdown

Related: linuxmint/mintupdate#938 and linuxmint/mintupdate#1078

Summary

Companion fix to a mintupdate change (https://github.com/linuxmint/mintupdate, branch: autoremove-kernel-fix) that fixes apt autoremove never cleaning up old kernels installed via mintupdate. PR linuxmint/mintupdate#1081

Root cause

aptworker._mark_packages_for_installation() already supports an opt-in convention for callers: a package name suffixed with #auto (e.g. "linux-image-6.17.0-41-generic#auto") is installed with from_user=False, i.e. recorded as automatically installed rather than manually installed. This is what lets a caller install a specific package by name while still leaving it eligible for apt autoremove later, matching how apt would treat it if it had been pulled in as a dependency instead.

SimpleAPTClient.install_packages() undermines this. Before handing the package list to the worker over D-Bus, it does a local apt.Cache() dependency resolution pass to discover any additional packages a request will pull in (e.g. a kernel image pulled in by a meta package upgrade), and appends their bare names to the same packages list:

for pkg in changes:
    if pkg.marked_install and pkg.name not in packages:
        packages.append(pkg.name)

None of these names carry the #auto suffix, so every package in the flattened list — both the ones the caller explicitly asked for and the ones only pulled in as a dependency — ends up marked manually installed by the worker. This defeats the purpose of the #auto convention entirely: even a caller that tags its own request with #auto gets nothing, since the local resolver strips out whatever wasn't an exact literal package name in the original list in the first place, and anything it discovers is re-added without the tag.

History

The flattening step was introduced in 18d255f ("simpleclient: Use python-apt resolver when installing pkgs", 2024-09-11), days before mintupdate 7.0.0 switched its installs from synaptic to aptkit. The combination is what regressed kernel autoremoval for mintupdate users: under synaptic (and under aptkit without the flattening), dependency packages were marked automatically installed by the resolver, so superseded kernels remained autoremovable. The "#auto" convention itself predates the fork - it was inherited from aptdaemon in the initial aptkit import (April 2022) and validated at the D-Bus boundary all along, but no client ever used it.

Fix

  • Compute requested_names by stripping any #auto suffix before doing the local apt.Cache() lookups (apt itself doesn't know about the suffix convention), so callers can pass pre-tagged names through install_packages() without breaking the resolution step.
  • Newly-discovered dependency packages (present in cache.get_changes() but not in the caller's original request) are now tagged #auto themselves before being appended, since by definition they were resolved rather than explicitly requested — matching what a normal apt install/apt upgrade would leave them as.

Behavior change for all SimpleAPTClient consumers

Note that the second part affects every caller of SimpleAPTClient.install_packages() (mintinstall, driver manager, ...), not just mintupdate: dependency packages pulled in alongside a requested package are now recorded as automatically installed, where previously the flattening step left them manually installed. This moves aptkit toward standard apt semantics — after a plain apt install foo, foo's dependencies are marked auto and become autoremovable once nothing needs them — so e.g. libraries installed alongside an application can now be reclaimed by apt autoremove after the application is removed, instead of lingering forever. Callers that genuinely want a dependency pinned as manual can still request it explicitly by name.

Testing

Manually tested as part of the mintupdate branch above: with this change plus the mintupdate-side tagging, apt-mark showauto shows newly-installed kernel packages as automatic (previously all showed as manual), and apt-get autoremove --dry-run / apt autoremove correctly identify and reclaim superseded kernel packages while leaving the running kernel untouched.

No test suite exists in this repo to extend.

Claude Fable 5 was used to fix these issues.

…dency resolution.

SimpleAPTClient.install_packages() locally resolves dependencies with
python-apt to discover which extra packages a request will pull in
(e.g. a kernel image pulled in by a meta package), then flattens
those names into the same list sent to the worker. Since none of
those names carried the "#auto" suffix that
aptworker._mark_packages_for_installation() looks for (and that
_check_package_names() already validates at the D-Bus boundary),
every package in the flattened list ended up marked as manually
installed regardless of whether it was actually requested by the
caller or merely a resolved dependency - defeating the purpose of
the "#auto" convention and leaving "apt autoremove" unable to
reclaim packages like superseded kernels
(linuxmint/mintupdate#938).

Now, package names already tagged "#auto" by the caller are honored
(the tag is stripped only for the local apt.Cache() lookups, which
would otherwise fail), and newly-discovered dependency packages that
weren't explicitly requested are tagged "#auto" themselves before
being handed to the worker.

Note this affects every SimpleAPTClient.install_packages() consumer:
dependency packages are now recorded as automatically installed,
matching standard apt semantics, where previously the flattening
step left them permanently manual. Callers that want a dependency
pinned as manual can still request it explicitly by name.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Comment thread aptkit/simpleclient.py
# (e.g. a kernel image pulled in by a meta package): flag it
# as automatic so it stays eligible for autoremoval, same as
# a normal "apt install"/"apt upgrade" would leave it.
packages.append(pkg.name + "#auto")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, exact duplicate of

Yes but with some more logic and it's needed for linuxmint/mintupdate#1081.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants