From b1ab05b15b9f4900f26c25f3b2deed2318c3978c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 6 Apr 2026 06:44:17 +0000 Subject: [PATCH 1/4] fix(fetch): only skip save on exact cache key match, not restore-key match MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a cache is found via a restore key (prefix match) instead of the exact primary key, CACHE_STATE should NOT be set to "hit". Previously, any hit — including a partial/restore-key match — set the state, causing save.js to skip saving the updated ccache content after a build. Now CACHE_STATE is only set to "hit" when cacheFetchingResult === keyString (exact primary-key match), so ccache is correctly saved after every build even when a previous cache was restored via the fallback restore key. Agent-Logs-Url: https://github.com/HiGarfield/cachewrtbuild/sessions/d095a004-01ae-47c6-94fd-826723eff894 Co-authored-by: HiGarfield <32226909+HiGarfield@users.noreply.github.com> --- fetch.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fetch.js b/fetch.js index 23cbac7f..fdc8e32c 100644 --- a/fetch.js +++ b/fetch.js @@ -29,7 +29,9 @@ try { if (cacheFetchingResult) { core.info(`${cacheFetchingResult} cache fetched!`); core.setOutput("hit", "1"); - core.saveState("CACHE_STATE", "hit"); + if (cacheFetchingResult === keyString) { + core.saveState("CACHE_STATE", "hit"); + } if (cacheToolchain && skipBuildingToolchain) { execSync("sed -i 's/ $(tool.*\\/stamp-compile)//;' Makefile"); From 8f1777786a58ac97c6bdaa81298a013bac1ceefb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 6 Apr 2026 06:44:28 +0000 Subject: [PATCH 2/4] fix(save): check cacheId !== -1 instead of truthy to detect save success @actions/cache.saveCache() returns -1 (not undefined/0) when the save fails (e.g. ReserveCacheError because the key already exists). Because -1 is truthy in JavaScript, the previous `if (cacheId)` guard incorrectly logged "Cache saved with key: ... (id: -1)" on every such failure. Use `cacheId !== -1` to correctly distinguish a successful save (positive integer ID) from a failed one (-1). Agent-Logs-Url: https://github.com/HiGarfield/cachewrtbuild/sessions/d095a004-01ae-47c6-94fd-826723eff894 Co-authored-by: HiGarfield <32226909+HiGarfield@users.noreply.github.com> --- save.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/save.js b/save.js index 0c3a1fb6..1db614e3 100644 --- a/save.js +++ b/save.js @@ -25,7 +25,7 @@ try { core.debug(`Cache paths: ${paths.join(", ")}`); const cacheId = await cache.saveCache(paths, keyString); - if (cacheId) { + if (cacheId !== -1) { core.info(`Cache saved with key: ${keyString} (id: ${cacheId})`); } } else { From 9def66611ff4ce5cfaaac744bfd6e403e4b78f22 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 6 Apr 2026 06:45:19 +0000 Subject: [PATCH 3/4] fix(save): use cacheId > -1 for more defensive success check Prefer > -1 over !== -1 to guard against any negative return value, not just exactly -1. Agent-Logs-Url: https://github.com/HiGarfield/cachewrtbuild/sessions/d095a004-01ae-47c6-94fd-826723eff894 Co-authored-by: HiGarfield <32226909+HiGarfield@users.noreply.github.com> --- save.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/save.js b/save.js index 1db614e3..57cd7571 100644 --- a/save.js +++ b/save.js @@ -25,7 +25,7 @@ try { core.debug(`Cache paths: ${paths.join(", ")}`); const cacheId = await cache.saveCache(paths, keyString); - if (cacheId !== -1) { + if (cacheId > -1) { core.info(`Cache saved with key: ${keyString} (id: ${cacheId})`); } } else { From 2c462489b3e964576f84e90b5c8bf181b9786ac2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 6 Apr 2026 06:48:58 +0000 Subject: [PATCH 4/4] fix: safely handle non-Error thrown values in catch blocks error.message is undefined when the thrown value is not an Error object (e.g. a plain string or number). Use the pattern error instanceof Error ? error.message : String(error) in both fetch.js (core.setFailed) and save.js (core.warning) so that any thrown value produces a meaningful failure/warning message. Agent-Logs-Url: https://github.com/HiGarfield/cachewrtbuild/sessions/130dfcbb-449a-4a4b-903c-aa57ffc5280d Co-authored-by: HiGarfield <32226909+HiGarfield@users.noreply.github.com> --- fetch.js | 2 +- save.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fetch.js b/fetch.js index fdc8e32c..ff0d75fc 100644 --- a/fetch.js +++ b/fetch.js @@ -44,5 +44,5 @@ try { } } } catch (error) { - core.setFailed(error.message); + core.setFailed(error instanceof Error ? error.message : String(error)); } \ No newline at end of file diff --git a/save.js b/save.js index 57cd7571..c2bc1348 100644 --- a/save.js +++ b/save.js @@ -33,5 +33,5 @@ try { } } } catch (error) { - core.warning(error.message); + core.warning(error instanceof Error ? error.message : String(error)); }