upgrade-helper: add state module and --incremental mode
PATCH v2 1/2 upgrade-helper: add state module and --incremental mode
From: Daniel Turull <[email protected]>
Without this, every AUH run retries all candidates regardless of previous outcomes, wasting time on recipes that consistently fail or were already upgraded recently.
Add modules/state.py which persists upgrade results to a JSON state file (auh-state.json in the upgrade-helper work directory, typically $BUILDDIR/upgrade-helper/). The new --incremental flag activates this tracking and skips package groups where all packages were recently attempted.
Behavior:
- Failed attempts are retried after retry_interval days (default 30).
- Successful/already-current upgrades are suppressed for success_max_age days (default 30).
Tested with master (2026-06-01):
command: ../auto-upgrade-helper/upgrade-helper.py all --incremental -s
- Run 1 (2026-06-01 07:38): 122 attempted, 98 succeeded, 24 failed, 0 skipped
- Run 2 (2026-06-01 11:17): 1 attempted, 0 succeeded, 1 failed, 26 skipped
- Run 3 (2026-06-01 11:20): 0 attempted, 0 succeeded, 0 failed, 27 skipped
2nd test on master (2026-06-02)
Now in the second run we get the skipping message
INFO: piglit 1.0-new-commits-available: skipping (last attempt 2026-06-02 13:38:01 result=failure; will retry in 30 day(s))
INFO: libinput 1.31.2: skipping (last attempt 2026-06-02 13:40:03 result=failure; will retry in 30 day(s))
INFO: alsa-ucm-conf 1.2.16: skipping (last attempt 2026-06-02 13:43:57 result=failure; will retry in 30 day(s))
INFO: webkitgtk 2.52.4: skipping (last attempt 2026-06-02 13:46:52 result=failure; will retry in 30 day(s))
INFO: boost 1.91.0: skipping (last attempt 2026-06-02 13:50:11 result=failure; will retry in 30 day(s))
INFO: libical 4.0.2: skipping (last attempt 2026-06-02 13:52:44 result=failure; will retry in 30 day(s))
INFO: vte 0.84.0: skipping (last attempt 2026-06-02 13:53:31 result=failure; will retry in 30 day(s))
INFO: 28/28 package groups skipped (incremental mode)
And extract of auh-state.json
"cargo": {
"1.96.0": {
"timestamp": 1780405831.0888734,
"result": "failure"
}
},
"sbom-cve-check-update-cvelist-native": {
"2026-06-02": {
"timestamp": 1780406109.500104,
"result": "success"
}
},---
Changes in v2:
- should_skip() simplified to a presence check; _prune() owns all time logic
- log skip reason (previous timestamp, result, days until retry) per group
- log recorded result per package after each attempt
- drop upgrade_err capture; use g['error'] directly after commit_changes()
- drop dead isinstance(upgrade_err, UpgradeNotNeededError) check
--- modules/state.py | 109 ++++++++++++++++++++++++++++++++++++++++++++ upgrade-helper.conf | 10 +++- upgrade-helper.py | 37 +++++++++++++++ 3 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 modules/state.py
modules/state.py new file +109 -0
@@ -0,0 +1,109 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# vim: set ts=4 sw=4 et: +# +# Copyright (c) 2026 Ericsson AB +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# AUTHORS +# Daniel Turull <[email protected]> +# + +import datetime +import json +import os +import time + +from logging import warning as W + +RESULT_SUCCESS = "success" +RESULT_FAILURE = "failure" + +STATE_FILENAME = "auh-state.json" +STATE_VERSION = 1 + +SECONDS_PER_DAY = 86400 +DEFAULT_COOLDOWN_DAYS = 30 +DEFAULT_SUCCESS_MAX_AGE_DAYS = 30 + + +class State: + """Tracks upgrade attempts as {recipe: {version: {timestamp, result}}}.""" + + def __init__(self, state_dir, cooldown_days=DEFAULT_COOLDOWN_DAYS, + success_max_age_days=DEFAULT_SUCCESS_MAX_AGE_DAYS): + self.path = os.path.join(state_dir, STATE_FILENAME) + self.cooldown = cooldown_days * SECONDS_PER_DAY + self.success_max_age = success_max_age_days * SECONDS_PER_DAY + self.data = self._load() + self._prune() + + def _load(self): + if os.path.exists(self.path): + try: + with open(self.path) as f: + raw = json.load(f) + except (json.JSONDecodeError, OSError) as e: + W(" %s is corrupt (%s), starting fresh" % (self.path, e)) + return {} + if not isinstance(raw, dict) or raw.get("version") != STATE_VERSION: + W(" %s: unsupported or missing version, starting fresh" + % self.path) + return {} + return raw.get("recipes", {}) + return {} + + def save(self): + with open(self.path, "w") as f: + json.dump({"version": STATE_VERSION, "recipes": self.data}, + f, indent=2) + + def record(self, pn, version, result): + entry = {"timestamp": time.time(), "result": result} + if pn not in self.data: + self.data[pn] = {} + self.data[pn][version] = entry + + def should_skip(self, pn, version): + """Return True if a recent state entry exists (stale entries are pruned at load).""" + return self.data.get(pn, {}).get(version) is not None + + def skip_reason(self, pn, version): + """Return a human-readable string explaining why pn/version is being skipped.""" + entry = self.data.get(pn, {}).get(version, {}) + ts = entry.get("timestamp", 0) + when = datetime.datetime.fromtimestamp(ts).strftime("%Y-%m-%d %H:%M:%S") + result = entry.get("result", "unknown") + max_age = self.success_max_age if result == RESULT_SUCCESS else self.cooldown + retry_in = int((ts + max_age - time.time()) / SECONDS_PER_DAY) + 1 + return ("last attempt %s result=%s; will retry in %d day(s)" + % (when, result, retry_in)) + + def _prune(self): + """Remove stale entries older than their respective max-age.""" + now = time.time() + for pn in list(self.data): + versions = self.data[pn] + for ver in list(versions): + entry = versions[ver] + age = now - entry.get("timestamp", 0) + if entry.get("result") == RESULT_SUCCESS: + if age > self.success_max_age: + del versions[ver] + else: + if age > self.cooldown: + del versions[ver] + if not versions: + del self.data[pn]
upgrade-helper.conf +9 -1
@@ -50,7 +50,15 @@ # passed; does not apply when layer_mode is enabled). #blacklist=python glibc gcc -# specify the directory where work (patches) will be saved +# When running with --incremental, how many days to wait before retrying +# a failed upgrade attempt for the same recipe version. Default is 30 days. +#retry_interval=30 + +# When running with --incremental, how many days to skip a successfully +# upgraded recipe version before attempting it again. Default is 30 days. +#success_max_age=30 + +# specify the directory where work (patches) will be saved # (optional; default is BUILDDIR/upgrade-helper/) #workdir=
upgrade-helper.py +37 -0
@@ -59,6 +59,8 @@ from utils.emailhandler import Email from statistics import Statistics from steps import upgrade_steps from testimage import TestImage +from state import (State, RESULT_SUCCESS, RESULT_FAILURE, + DEFAULT_COOLDOWN_DAYS, DEFAULT_SUCCESS_MAX_AGE_DAYS) if not os.getenv('BUILDDIR', False): E(" You must source oe-init-build-env before running this script!\n")
@@ -104,6 +106,8 @@ def parse_cmdline(): help="do not compile, just change the checksums, remove PR, and commit") parser.add_argument("-c", "--config-file", default=None, help="Path to the configuration file. Default is $BUILDDIR/upgrade-helper/upgrade-helper.conf") + parser.add_argument("--incremental", action="store_true", + help="skip recipes already attempted (uses JSON state file)") parser.add_argument("--layer-names", nargs='*', action="store", default='', help="layers to include in the upgrade research") parser.add_argument("--layer-dir", action="store", default='',
@@ -169,6 +173,16 @@ class Updater(object): self.email_handler = Email(settings) self.statistics = Statistics() + if self.args.incremental: + cooldown = int(settings.get('retry_interval', DEFAULT_COOLDOWN_DAYS)) + success_max_age = int(settings.get('success_max_age', + DEFAULT_SUCCESS_MAX_AGE_DAYS)) + self.state = State(self.uh_dir, + cooldown_days=cooldown, + success_max_age_days=success_max_age) + else: + self.state = None + def _set_options(self): self.opts = {} self.opts['layer_mode'] = settings.get('layer_mode', '')
@@ -468,6 +482,18 @@ class Updater(object): pkggroups_ctx.append({"name":",".join([pkg_ctx['PN'] for pkg_ctx in pkgs_ctx]),"pkgs":pkgs_ctx,"error":None, 'base_dir':self.uh_recipes_all_dir}) I(" ############################################################") + if self.state: + kept = [] + for g in pkggroups_ctx: + pn, npv = g['pkgs'][0]['PN'], g['pkgs'][0]['NPV'] + if self.state.should_skip(pn, npv): + I(" %s %s: skipping (%s)" % (pn, npv, self.state.skip_reason(pn, npv))) + else: + kept.append(g) + I(" %d/%d package groups skipped (incremental mode)" + % (len(pkggroups_ctx) - len(kept), len(pkggroups_ctx))) + pkggroups_ctx = kept + total_pkggroups = len(pkggroups_ctx) if pkggroups_ctx and not self.args.skip_compilation: I(" Building gcc runtimes ...") for machine in self.opts['machines']:
@@ -534,6 +560,17 @@ class Updater(object): succeeded_pkggroups_ctx.remove(g) failed_pkggroups_ctx.append(g) + if self.state: + result = RESULT_FAILURE if g.get('error') else RESULT_SUCCESS + # All packages in a group share the same result because AUH + # upgrades them atomically; individual outcomes are not tracked. + for pkg_ctx in g['pkgs']: + I(" %s %s: recording result=%s" % (pkg_ctx['PN'], pkg_ctx['NPV'], result)) + self.state.record(pkg_ctx['PN'], pkg_ctx['NPV'], result) + + if self.state: + self.state.save() + if self.opts['testimage']: ctxs = {} ctxs['succeeded'] = succeeded_pkggroups_ctx
Signature · 1 line
2.51.0
PATCH v2 2/2 upgrade-helper: remove unused UpgradeNotNeededError
From: Daniel Turull <[email protected]>
UpgradeNotNeededError is never raised anywhere in the codebase. Remove the class definition and all references to it.
--- modules/errors.py | 7 ------- modules/statistics.py | 4 +--- upgrade-helper.py | 6 ++---- 3 files changed, 3 insertions(+), 14 deletions(-)
modules/errors.py +0 -7
@@ -89,13 +89,6 @@ class UnsupportedProtocolError(Error): def __str__(self): return "Failed(Unsupported protocol)" -class UpgradeNotNeededError(Error): - def __init__(self): - super(UpgradeNotNeededError, self).__init__("Recipe already up to date") - - def __str__(self): - return "Failed(up to date)" - class EmptyEnvError(Error): def __init__(self, stdout): super(EmptyEnvError, self).__init__("Empty environment returned", stdout)
modules/statistics.py +1 -3
@@ -34,9 +34,7 @@ class Statistics(object): self.total_attempted = 0 def _update(self, pn, new_ver, maintainer, error): - if type(error).__name__ == "UpgradeNotNeededError": - return - elif error is None: + if error is None: status = "Succeeded" else: status = str(error)
upgrade-helper.py +2 -4
@@ -49,7 +49,7 @@ import shutil sys.path.insert(1, os.path.join(os.path.abspath( os.path.dirname(__file__)), 'modules')) -from errors import Error, EmptyEnvError, UpgradeNotNeededError, UnsupportedProtocolError +from errors import Error, EmptyEnvError, UnsupportedProtocolError from utils.git import Git from utils.devtool import Devtool
@@ -527,9 +527,7 @@ class Updater(object): I(" %s: Upgrade SUCCESSFUL! Please test!" % pkggroup_name) except Exception as e: - if isinstance(e, UpgradeNotNeededError): - I(" %s: %s" % (pkggroup_name, e.message)) - elif isinstance(e, UnsupportedProtocolError): + if isinstance(e, UnsupportedProtocolError): I(" %s: %s" % (pkggroup_name, e.message)) else: if not isinstance(e, Error):
Signature · 1 line
2.51.0
Quoted 4 lines · On Wed, 3 Jun 2026 at 17:50, <[email protected]> wrote:
Behavior:
- Failed attempts are retried afterretry_intervaldays (default 30).
- Successful/already-current upgrades are suppressed forsuccess_max_agedays (default 30).
I have realized that we also need to handle recipes with rapid-fire releases, that would otherwise flood the mailing list with daily updates (if AUH is run once a day, which is the goal). This typically happens when:
- there are no release tags, the recipe just takes the latest commit, and upstream adds commits frequently (for example, vulkan-samples)
- upstream does have release tags, but they're added often, e.g. sbom-cve-check-* items add them once a day, and some python items are also rather quite 'liberal' with tags
So I'd suggest:
retry_interval is renamed to retry_same_version_interval retry_any_version_interval setting is introduced retry_any_version_recipes setting is introduced, and is a list of recipes _prune() is adjusted to first check if a recipe is in that list, and if so, it's checked against retry_any_version_interval, and not any other intervals, so that it's guaranteed to be skipped until that interval elapses (and skip_reason() should consider that similarly)
Otherwise, I think this is more or less ready!
Alex
Quoted 11 lines · Alexander Kanavin via lists.yoctoproject.org
So I'd suggest:
retry_intervalis renamed toretry_same_version_intervalretry_any_version_intervalsetting is introducedretry_any_version_recipessetting is introduced, and is a list of recipes_prune()is adjusted to first check if a recipe is in that list, and if so, it's checked againstretry_any_version_interval, and not any other intervals, so that it's guaranteed to be skipped until that interval elapses (andskip_reason()should consider that similarly)Otherwise, I think this is more or less ready!
Actually not quite. I'd really like to avoid duplicating timestamp logic in skip_reason and prune(), and only implement it once, so perhaps the way to do it is to have a helper function that returns a dict:
{'verdict': True, 'reason' : "explanation here"}
Then function callers can pick and use the entries they need.
Alex
Quoted 25 lines
-----Original Message-----
From: Alexander Kanavin <[email protected]>
Sent: Friday, 5 June 2026 12:23
To: [email protected]
Cc: Daniel Turull <[email protected]>
Subject: Re: [yocto-patches] [AUH] [PATCH v2 1/2] upgrade-helper: add state module and --incremental modeQuoted 11 lines · Alexander Kanavin via lists.yoctoproject.org
So I'd suggest:
retry_intervalis renamed toretry_same_version_intervalretry_any_version_intervalsetting is introducedretry_any_version_recipessetting is introduced, and is a list of recipes_prune()is adjusted to first check if a recipe is in that list, and if so, it's checked againstretry_any_version_interval, and not any other intervals, so that it's guaranteed to be skipped until that interval elapses (andskip_reason()should consider that similarly)Otherwise, I think this is more or less ready!
Quoted 9 lines
Actually not quite. I'd really like to avoid duplicating timestamp logic in
skip_reasonandprune(), and only implement it once, so perhaps the way to do it is to have a helper function that returns a dict:{'verdict': True, 'reason' : "explanation here"}
Then function callers can pick and use the entries they need.
Ok. I'll made both changes in v3.
Quoted 1 line
Alex
Quoted 25 lines
-----Original Message-----
From: Alexander Kanavin <[email protected]>
Sent: Friday, 5 June 2026 12:23
To: [email protected]
Cc: Daniel Turull <[email protected]>
Subject: Re: [yocto-patches] [AUH] [PATCH v2 1/2] upgrade-helper: add state module and --incremental modeQuoted 11 lines · Alexander Kanavin via lists.yoctoproject.org
So I'd suggest:
retry_intervalis renamed toretry_same_version_intervalretry_any_version_intervalsetting is introducedretry_any_version_recipessetting is introduced, and is a list of recipes_prune()is adjusted to first check if a recipe is in that list, and if so, it's checked againstretry_any_version_interval, and not any other intervals, so that it's guaranteed to be skipped until that interval elapses (andskip_reason()should consider that similarly)Otherwise, I think this is more or less ready!
Quoted 8 lines
Actually not quite. I'd really like to avoid duplicating timestamp logic in
skip_reasonandprune(), and only implement it once, so perhaps the way to do it is to have a helper function that returns a dict:{'verdict': True, 'reason' : "explanation here"}
Then function callers can pick and use the entries they need.
In v3, the log is:
INFO: sbom-cve-check-update-nvd-native 2026.06.05-000006: skipping (rapid-fire; last attempt 2026-06-05 12:21:22 result=success; will retry in 7 day(s))
Quoted 2 lines
Alex