From 6d7fad0f524237ddc2ed2b43ffa56173faca0ece Mon Sep 17 00:00:00 2001 From: Josui Date: Wed, 18 Nov 2026 02:48:00 +0000 Subject: [PATCH] fix: skills-sync reports stale, not current, when the fetch failed A checkout whose every fetch fails (dolza's josui gets a 401 from the gateway) compared HEAD with a local origin/main no fetch had refreshed and wrote state=current with fetched=0 for weeks (a268). When this pass's clone or fetch failed, HEAD equal to origin now writes state=stale, aged from drift_since, so check_skills_sync.sh warns after 1h and goes critical after 6h with no change on the nagios side. A read-only checkout, which never fetches, is unchanged. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01R7Y1jgQzPHsAyyjYY7kKir --- CHANGELOG.md | 7 +++++ rootfs/usr/local/bin/developer-skills-sync | 15 ++++++---- tests/test_skills_sync.py | 35 +++++++++++++++++++++- 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6190e0..2ce0b54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,13 @@ All notable changes to this project are documented here. The format follows is more than one line stops the start with a message naming the variable, never the value (#77). +### Fixed +- `developer-skills-sync` no longer reports `state=current` when this pass's + fetch failed. A checkout whose fetches always fail (a 401 from GitHub) kept + comparing HEAD with a stale `origin/main` and read current with `fetched=0`. + It now writes `state=stale`, aged from `drift_since`, so `check_skills_sync.sh` + warns after an hour and goes critical after six. + ## [1.15.0] - 2026-11-18 ### Added diff --git a/rootfs/usr/local/bin/developer-skills-sync b/rootfs/usr/local/bin/developer-skills-sync index 5413110..ebede0a 100755 --- a/rootfs/usr/local/bin/developer-skills-sync +++ b/rootfs/usr/local/bin/developer-skills-sync @@ -25,10 +25,11 @@ # # SKILLSSYNC written= state= head= origin= drift_since= fetched= # -# state is current, behind, diverged or off-branch. drift_since is when -# HEAD was first seen differing from origin/, 0 while it does -# not. fetched is the last fetch that worked: a checkout that can no -# longer reach GitHub reads as a stale fetched, never as "current". +# state is current, stale, behind, diverged or off-branch. stale is HEAD +# equal to an origin/ that this pass could not refresh: the fetch +# failed, so "equal" proves nothing. drift_since is when HEAD was first +# seen differing from, or unverifiable against, origin/, 0 while +# it is not. fetched is the last fetch that worked. # # A failed step is reported on stderr and the pass goes on; the exit status # is 0 unless the arguments are wrong. The next pass tries again. @@ -52,12 +53,14 @@ repo=$1 url=${JOSUI_SKILLS_URL:-https://github.com/crunchtools/josui-skills} now=$(date +%s) fetched= +fetch_failed= if ! [ -e "$repo/.git" ] && [ -z "$(ls -A "$repo" 2>/dev/null)" ]; then if git clone --quiet "$url" "$repo"; then fetched=$now else log "skills clone of $url into $repo failed; no skills until a pass succeeds" + fetch_failed=1 fi elif [ -d "$repo/.git" ] && [ -w "$repo/.git" ]; then # origin/HEAD is recorded at clone time; ask the remote what it is now. @@ -66,6 +69,7 @@ elif [ -d "$repo/.git" ] && [ -w "$repo/.git" ]; then fetched=$now else log "fetch failed in $repo, using the checkout as it is" + fetch_failed=1 fi fi @@ -128,7 +132,8 @@ origin=$(git -C "$repo" rev-parse --verify --quiet "origin/$default" 2>/dev/null if [ "$(git -C "$repo" branch --show-current)" != "$default" ]; then state=off-branch elif [ "$head" = "$origin" ]; then - state=current + # The local origin ref is only as fresh as the last fetch that worked. + if [ -n "$fetch_failed" ]; then state=stale; else state=current; fi elif [ "$origin" != none ] && git -C "$repo" merge-base --is-ancestor "$head" "$origin" 2>/dev/null; then state=behind else diff --git a/tests/test_skills_sync.py b/tests/test_skills_sync.py index c959025..eae5f05 100644 --- a/tests/test_skills_sync.py +++ b/tests/test_skills_sync.py @@ -129,7 +129,40 @@ def test_a_failed_fetch_keeps_the_last_good_fetch_time(self) -> None: self.assertEqual(result.returncode, 0) self.assertIn("fetch failed", result.stderr) self.assertEqual(status_of(self.repo)["fetched"], fetched) - self.assertEqual(status_of(self.repo)["state"], "current") + + def test_a_failed_fetch_is_stale_not_current_and_dated(self) -> None: + self.sync() + good = status_of(self.repo) + self.assertEqual(good["state"], "current") + self.assertEqual(good["drift_since"], "0") + self.git(self.repo, "remote", "set-url", "origin", str(self.root / "gone")) + + # The stale origin/main still equals HEAD; that must not read as current. + self.sync() + first = status_of(self.repo) + self.sync() + second = status_of(self.repo) + + self.assertEqual(first["head"], first["origin"]) + self.assertEqual(first["state"], "stale") + self.assertGreater(int(first["drift_since"]), 0) + self.assertEqual(second["state"], "stale") + self.assertEqual(second["drift_since"], first["drift_since"]) + self.assertEqual(second["fetched"], good["fetched"]) + + def test_a_fetch_that_works_again_is_current_and_clears_the_drift(self) -> None: + self.sync() + self.git(self.repo, "remote", "set-url", "origin", str(self.root / "gone")) + self.sync() + self.assertEqual(status_of(self.repo)["state"], "stale") + self.git(self.repo, "remote", "set-url", "origin", str(self.upstream)) + + self.sync() + + after = status_of(self.repo) + self.assertEqual(after["state"], "current") + self.assertEqual(after["drift_since"], "0") + self.assertGreater(int(after["fetched"]), 0) def test_an_empty_directory_is_cloned(self) -> None: shutil.rmtree(self.repo)