Skip to content

fix: initialize globalVersion to 1 so skills snapshot refreshes after gateway restart - #55495

Closed
skadauke wants to merge 1 commit into
openclaw:mainfrom
skadauke:fix/skills-snapshot-version-reset
Closed

skadauke wants to merge 1 commit into
openclaw:mainfrom
skadauke:fix/skills-snapshot-version-reset

Conversation

@skadauke

Copy link
Copy Markdown
Contributor

Problem

Long-lived sessions store a skillsSnapshot with version: 0. After a gateway restart, the in-memory globalVersion resets to 0, so the refresh check:

const shouldRefreshSnapshot = snapshotVersion > 0 
    && (nextEntry?.skillsSnapshot?.version ?? 0) < snapshotVersion;

always evaluates to false (0 > 0 is false). The snapshot is never rebuilt, and skills that were added, renamed, or deleted between restarts remain stale in the agent prompt indefinitely.

Fix

Initialize globalVersion to 1 instead of 0 in src/agents/skills/refresh.ts.

This ensures that after any gateway restart, sessions with the default version (0) trigger shouldRefreshSnapshot = true on their first turn, causing a single buildWorkspaceSkillSnapshot() call that picks up the current state of skills on disk.

Verified

Reproduced and fixed on a live system:

Before fix: Main Telegram session showed amazon-shop and walmart-shop (deleted days ago), missing online-shop (the replacement). Multiple gateway restarts did not help. Snapshot version stuck at 0.

After fix: Gateway restart → main session rebuilt snapshot on first turn → all stale entries removed, all current entries present, version bumped to 1.

Side effects

The only change: every session rebuilds its skill snapshot once on the first turn after each gateway restart (stored version 0 < globalVersion 1). This is:

  • Cheap: buildWorkspaceSkillSnapshot reads SKILL.md frontmatter from ~20 files
  • Once per session per restart, not every turn (subsequent turns see version 1 = 1, no refresh)
  • No impact on watcher: bumpVersion still returns Date.now() since Date.now() > 1
  • No race conditions: updateSessionStore uses async lock

Fixes #55489

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Mar 27, 2026
@greptile-apps

greptile-apps Bot commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a stale skills snapshot bug that affected long-lived sessions after a gateway restart. The fix is a single-line change: globalVersion is initialized to 1 instead of 0 in src/agents/skills/refresh.ts.

How the bug occurred: On restart, globalVersion reset to 0. The refresh guard in session-updates.ts is:

const shouldRefreshSnapshot = snapshotVersion > 0 && (nextEntry?.skillsSnapshot?.version ?? 0) < snapshotVersion;

Since snapshotVersion was 0, the condition 0 > 0 was always false, and sessions with a persisted skillsSnapshot.version: 0 were never refreshed — leaving them stuck with stale skill entries indefinitely.

Why 1 is the right sentinel:

  • After the fix, the first turn in any long-lived session evaluates to 1 > 0 && 0 < 1 → true, triggering exactly one snapshot rebuild.
  • Subsequent turns see 1 ≮ 1 → false — no redundant refreshes.
  • bumpVersion(1) correctly returns Date.now() (≫ 1) when the watcher triggers a real change, so the version timeline is unaffected.
  • The isolated-agent path (cron/isolated-agent/skills-snapshot.ts) uses existingSnapshot.version !== snapshotVersion, which also correctly picks up the 0 ≠ 1 mismatch after restart.

Confidence Score: 5/5

Safe to merge — the fix is minimal, correct, and well-explained with no side-effect risks.

The one-line change is the simplest possible correct fix. All downstream consumers of getSkillsSnapshotVersion handle the new initial value of 1 correctly: the session-updates guard triggers exactly one rebuild per session per restart, the isolated-agent path handles it, and bumpVersion is unaffected since Date.now() ≫ 1. No existing tests are broken. The PR description thoroughly documents the before/after behavior and verifies it on a live system.

No files require special attention.

Important Files Changed

Filename Overview
src/agents/skills/refresh.ts Initializes globalVersion to 1 instead of 0, with a thorough explanatory comment. Correctly fixes the stale-snapshot bug without impacting bumpVersion, workspace versioning, or watcher behavior.

Reviews (1): Last reviewed commit: "fix: initialize globalVersion to 1 so sk..." | Re-trigger Greptile

… gateway restart

Long-lived sessions (e.g. the main Telegram session) store a skillsSnapshot
with version: 0. After a gateway restart the in-memory globalVersion resets
to 0, so the refresh check `snapshotVersion > 0 && stored < snapshotVersion`
always evaluates to false. The snapshot is never rebuilt, and skills that were
added, renamed, or deleted between restarts remain stale in the prompt.

Starting globalVersion at 1 ensures that every session with the default
version (0) triggers a single rebuild on its first turn after restart.
Subsequent turns reuse the refreshed snapshot (version 1) until the
watcher bumps the version again on a SKILL.md change.

Fixes openclaw#55489
@skadauke
skadauke force-pushed the fix/skills-snapshot-version-reset branch from 32b79ba to 32ff26b Compare March 29, 2026 16:23
@skadauke

Copy link
Copy Markdown
Contributor Author

Rebased on current main. CI has widespread failures, but none are related to this PR's one-line change (globalVersion initialized to 1 instead of 0 in src/agents/skills/refresh.ts):

  • node-test-*, node-channels-*, windows-node-test-* (14 jobs): All hit the 1-hour CI timeout — infrastructure/flaky issue, not code-related.
  • checks-fast-contracts-protocol: RangeError: Maximum call stack size exceeded in src/plugin-sdk/vllm.ts — circular dependency in the vLLM plugin facade loader. Completely unrelated.
  • checks-fast-extensions: Same vLLM stack overflow.

The passing checks (build-smoke, build-artifacts, check, check-additional, actionlint, no-tabs, security-fast, preflight) all succeed, confirming the build and lint are clean.

This is a one-line fix that prevents stale skill snapshots after gateway restart. Would love to see this included in the next release.

@clawsweeper

clawsweeper Bot commented Apr 26, 2026

Copy link
Copy Markdown
Contributor

Closing this as duplicate or superseded after Codex automated review.

PR #55495 reports a real stale skills-snapshot restart bug, and its linked reproduction in #55489 is useful evidence. Current main still has the bug, but this PR's one-line target is stale after the refresh state moved into src/agents/skills/refresh-state.ts. The remaining work is now superseded by canonical maintainer PR #71497, which is open/draft, labeled maintainer and dedupe:parent, fixes #55489, and applies the fix in the current shared refresh-state layer with regression coverage and a changelog entry.

Best possible solution:

Close #55495 as superseded by canonical maintainer PR #71497, and keep the implementation, regression test, and changelog entry concentrated in the current shared src/agents/skills/refresh-state.ts fix that covers both gateway replies and CLI agent runs.

What I checked:

So I’m closing this here and keeping the remaining discussion on the canonical linked item.

Codex Review notes: model gpt-5.5, reasoning high; reviewed against 06d409dc2738.

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

Labels

agents Agent runtime and tooling size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: skillsSnapshot never refreshes after gateway restart (version counter resets to 0)

1 participant