From patchwork Thu Dec 3 15:58:29 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Kanavin X-Patchwork-Id: 107218 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) by mx.groups.io with SMTP id smtpd.msgproc01-g2.17063.1796313527011006180 for ; Thu, 03 Dec 2026 07:58:47 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20260707 header.b=ME1OGbQ3; spf=pass (domain: gmail.com, ip: 209.85.221.46, mailfrom: alex.kanavin@gmail.com) Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-491971ac844so2183f8f.2 for ; Thu, 03 Dec 2026 07:58:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796313525; x=1796918325; darn=lists.yoctoproject.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=PNxF/1BbQ4e40vwaf3MkjGjj83DI0PgVwqdAbkaJrnY=; b=ME1OGbQ35qSyXICV082Tf21dvR5lvW4JQQoy/Y9gPAzzwYabDUKc2MbqgN9TxtxiRl a+Fmz2c7yb7Y3S9NGq8wVmScR8UG33gUEGcWqRL0fSrCcfGaBJbRP1lf6ZAUC1682MHp bLp/8s3RXRolo+ObvZmn73dpxs55sK346y2E9ZcMRtGfgzclZwFyo6ROFGLWLWfVmsOt Y6OzW2meVF9vt+wPPqW5PqjmFxYUAWnB+ndW/xf/s2N9nS1Piru51fo71R2iaiyaqOLz bhSKg2y0q7Z1zGejBLmK4t3xOSKfo76kwv2DJb3/XaSKjfBCsctd1CUnsSSYX1FY2T7t 0mTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796313525; x=1796918325; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=PNxF/1BbQ4e40vwaf3MkjGjj83DI0PgVwqdAbkaJrnY=; b=LEIBr2Yz/L0jo6Rp2e0b5eQJjztn79gEbNQgM2EZsZ6GxtYHMSxLpr8DucKKTc2+ZW rk7PZgjBH2Eor//VTuunCL1NSEum7KWqCJGjrGaXJIdWKcepns2Qq+JX5MdYBQIu+Xxb ts1feNar2UAOwHX95x9CRTRR17SbEUjiVfVUtWZbRE2h/xFHeEYBWGMF9wuiP2zXiLK+ yuOfDYbF7xWCbNIHxgE/q43LYT2hOTToH3E4Quxp6ju+XAQ7qEbJf/tFNL4lAHqwsKwd ziJp9Mkm15wRYZEd/2ryhYW450wyzokbhFG7tSaooooc10qxtEVNvCV0CW7e0ksFpqkk zN8w== X-Gm-Message-State: APuU4Z/T0UVgC1m+B8g6ULjilYgHMXIw5kZxq6w0u8WzTV/h1XgDpqW2 4tMwM3uCKPPgg5cxVdorY5jeJwSJ2TNPi+piDnVRtNORwTkhelXXPtfijMapbA== X-Gm-Gg: AZFdTZcyiIvLg7ZQjwuYUMhTy+Zdu+8zCQypIN0OR4OEoMqNhK3BINSxLbb6D7onUSU Nyr6jh6H4xLnvy2FTiv4Wq9ANjePo2N0LBLE7vl/65/wVcJDjYMXel+0Qgjqjvyop/bCcHLAduz 4uJX0kMOGm39MtbSDgwQgZodzbpIe7E6dDGpWB7OZ+Bqw5iyirQkUOott4pWR+wCQrLmF/HjSam vnFYhw7NgNY/FS1OKX3CMfflcyxTjDVaNLJwW9MILeFBFnwTFzZDbWIcS2+tNTjFTvQp8PsrGyV ZJ53U8kBhOMX0YObaIFKtmUzVFsndejz4O9AZzj7sm1/medwmIqGbllf10UAcMd2mC7uiQ2G81l BT+yo9bT2AI4o4QuEjAylcrwiBAi2qYnkNF6BG8+2/AvRSwHNqo/ekPdSW8oE0/rpJ0TkghRKI9 QUwxFxAKbdeIWrGXk5WM+nqAUnvHk/El02WjcT0l1icGkXSJwRoTPisKRp9/FG6VJbS1YEzCXtg ottw5/ElOZ1qwJJqH8ufLeXZj6OblFxWeybDbUIgAnFsExCQnNjjX+t5LFbI3sVhTmq63JCwi9a ADxcdf5CWQts5CpRPeQPVDAy+1ERU+sWRuz6jyyfNswOJChFXN6nfdqKRpq2vzhAjDq0mCObECY uigsUdCMgWoo= X-Received: by 2002:a05:6000:2507:b0:4b7:66fb:b092 with SMTP id ffacd0b85a97d-4b766fbb479mr66860195f8f.48.1796313525037; Thu, 03 Dec 2026 07:58:45 -0800 (PST) Return-Path: Received: from Zen2.lab.linutronix.de. (drugstore.linutronix.de. [80.153.143.164]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6ae2dd55sm82333075f8f.30.2026.12.03.07.58.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 07:58:44 -0800 (PST) From: Alexander Kanavin X-Google-Original-From: Alexander Kanavin To: yocto-patches@lists.yoctoproject.org Cc: daniel.turull@ericsson.com, Alexander Kanavin Subject: [auh][PATCH 1/2] modules/state: rework state to include both original and updated version Date: Thu, 3 Dec 2026 16:58:29 +0100 Message-ID: <20261203155830.3136352-1-alex@linutronix.de> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by lin-tor-korg-lkml-alma10-1 with HTTPS for ; Thu, 03 Dec 2026 15:58:56 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/yocto-patches/message/5661 The state information in incremental mode did not keep the original versions that recipse were updated from, only the new versions. This is problematic when upstreams release new versions in quick succession: if a layer updates a recipe to an intermediate version after AUH produced an update from the original version to latest version, AUH will not re-roll the update from an intermediate to latest because it doesn't track the original versions, and the update will only be retried after a retry period (typically 30 days) expires. Additionally, it would be useful to know when the original version, or the latest version was first seen by AUH; if either period grows too much, that means the AUH upgrade attempts are being ignored, the recipe isn't being updated, and the situation needs to be looked at. The patch reworks the state format from being a dict of recipes containing a dict of (latest) versions to a flat dict of recipes that contains the original version, the new version, when either was first seen, and when an AUH did the update. The rest of the code is adapted to that; it's difficult to test all the corner cases, but I confirmed that at least the update and the skipping after work as they should. Note that AUH will not try to migrate the v1 state to v2 state. It will simply detect that the state is not usable, and re-run the full update cycle to repopulate state. Signed-off-by: Alexander Kanavin --- modules/state.py | 81 +++++++++++++++++++++++------------------------ upgrade-helper.py | 9 +++--- 2 files changed, 45 insertions(+), 45 deletions(-) diff --git a/modules/state.py b/modules/state.py index d70972b..1a99760 100644 --- a/modules/state.py +++ b/modules/state.py @@ -32,7 +32,7 @@ RESULT_SUCCESS = "success" RESULT_FAILURE = "failure" STATE_FILENAME = "auh-state.json" -STATE_VERSION = 1 +STATE_VERSION = 2 SECONDS_PER_DAY = 86400 DEFAULT_RETRY_SAME_VERSION_DAYS = 30 @@ -41,7 +41,7 @@ DEFAULT_SUCCESS_MAX_AGE_DAYS = 30 class State: - """Tracks upgrade attempts as {recipe: {version: {timestamp, result}}}.""" + """Tracks upgrade attempts as {recipe: {old_version, new_version, timestamp, result}}.""" def __init__(self, state_dir, retry_same_version_days=DEFAULT_RETRY_SAME_VERSION_DAYS, @@ -53,10 +53,8 @@ class State: self.success_max_age = success_max_age_days * SECONDS_PER_DAY self.retry_any_version = retry_any_version_days * SECONDS_PER_DAY self.any_version_recipes = set(retry_any_version_recipes or []) - self.data = self._load() - self._prune() - def _load(self): + def _load_state_file(self): if os.path.exists(self.path): try: with open(self.path) as f: @@ -71,43 +69,60 @@ class State: return raw.get("recipes", {}) return {} + def load_state(self, pkggroups): + """ Loads existing state, and trims it to contain only the packages in need of update (passed in via pkggroups argument). """ + self.data = {} + existing_state = self._load_state_file() + for g in pkggroups: + for p in g['pkgs']: + pn = p['PN'] + if pn in existing_state: + self.data[pn] = existing_state[pn] + 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 this recipe/version should not be attempted.""" - return self.check(pn, version)['skip'] - - def skip_reason(self, pn, version): - """Return a human-readable string explaining why pn/version is being skipped.""" - return self.check(pn, version)['reason'] - - def check(self, pn, version): + def record(self, pn, old_version, new_version, result): + current_time = time.time() + oldversion_firstseen = current_time + newversion_firstseen = current_time + + if pn in self.data: + if self.data[pn]['oldversion'] == old_version: + oldversion_firstseen = self.data[pn]['oldversion_firstseen'] + if self.data[pn]['newversion'] == new_version: + newversion_firstseen = self.data[pn]['newversion_firstseen'] + + self.data[pn] = {"timestamp": current_time, + "result": result, + "oldversion": old_version, + "oldversion_firstseen": oldversion_firstseen, + "newversion": new_version, + "newversion_firstseen": newversion_firstseen, + } + + def check(self, pn, old_version, new_version): """Return {'skip': bool, 'reason': str} for a recipe/version pair. For any_version_recipes, any recent attempt (any version) causes a skip. For normal recipes, only a matching version entry causes a skip. """ + + entry = self.data.get(pn, {}) + + if not entry: + return {'skip': False, 'reason': ''} + if pn in self.any_version_recipes: - entry = self._newest_entry(pn) max_age = self.retry_any_version else: - entry = self.data.get(pn, {}).get(version) - if entry is None: - return {'skip': False, 'reason': ''} max_age = self.success_max_age \ if entry.get("result") == RESULT_SUCCESS \ else self.retry_same_version - if not entry: + if pn not in self.any_version_recipes and (entry['oldversion'] != old_version or entry['newversion'] != new_version): return {'skip': False, 'reason': ''} ts = entry.get("timestamp", 0) @@ -122,19 +137,3 @@ class State: return {'skip': True, 'reason': "%slast attempt %s result=%s; will retry in %d day(s)" % (prefix, when, result, retry_in)} - - def _newest_entry(self, pn): - """Return the most recent entry for a recipe across all versions.""" - versions = self.data.get(pn, {}) - return max(versions.values(), key=lambda e: e.get("timestamp", 0), - default={}) - - def _prune(self): - """Remove entries that check() would no longer skip.""" - for pn in list(self.data): - versions = self.data[pn] - for ver in list(versions): - if not self.check(pn, ver)['skip']: - del versions[ver] - if not versions: - del self.data[pn] diff --git a/upgrade-helper.py b/upgrade-helper.py index 56b1f02..4e9249e 100755 --- a/upgrade-helper.py +++ b/upgrade-helper.py @@ -496,12 +496,13 @@ 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: + self.state.load_state(pkggroups_ctx) kept = [] for g in pkggroups_ctx: - pn, npv = g['pkgs'][0]['PN'], g['pkgs'][0]['NPV'] - r = self.state.check(pn, npv) + pn, opv, npv = g['pkgs'][0]['PN'], g['pkgs'][0]['PV'], g['pkgs'][0]['NPV'] + r = self.state.check(pn, opv, npv) if r['skip']: - I(" %s %s: skipping (%s)" % (pn, npv, r['reason'])) + I(" %s %s -> %s: skipping (%s)" % (pn, opv, npv, r['reason'])) self.statistics.skip(g, r['reason']) else: kept.append(g) @@ -579,7 +580,7 @@ class Updater(object): # 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) + self.state.record(pkg_ctx['PN'], pkg_ctx['PV'], pkg_ctx['NPV'], result) if self.state: self.state.save()