Skip to content

fix(skills): preserve skillKey in SkillSnapshot for env override resolution - #94221

Closed
Pandah97 wants to merge 1 commit into
openclaw:mainfrom
Pandah97:fix/skills-snapshot-skillkey-94146
Closed

Pandah97 wants to merge 1 commit into
openclaw:mainfrom
Pandah97:fix/skills-snapshot-skillkey-94146

Conversation

@Pandah97

@Pandah97 Pandah97 commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • SkillSnapshot.skills[] only stored name, primaryEnv, and requiredEnv but not skillKey
  • When skills.entries.<skillKey> was configured with a source-specific key (e.g., weather) instead of the skill display name (e.g., Pretty Weather), applySkillEnvOverridesFromSnapshot() looked up config by skill.name, missing the env overrides entirely
  • Fix: persist skillKey in the snapshot and use skill.skillKey ?? skill.name at lookup time for backward compatibility

Fixes #94146

Changes

  1. src/skills/types.ts — Add skillKey?: string to the SkillSnapshot.skills item type
  2. src/skills/loading/workspace.ts — Preserve entry.metadata?.skillKey when building the snapshot
  3. src/skills/runtime/env-overrides.ts — Use skill.skillKey ?? skill.name to resolve config, falling back to name for older snapshots

Real behavior proof

Proof type: Runtime behavior proof that reads the actual TypeScript source from OpenClaw's worktree and demonstrates the skillKey resolution change via tsx.

What the proof demonstrates:

  1. Skill snapshot before fix: resolves config by skill.name → misses env overrides when name differs from skillKey
  2. Skill snapshot after fix: resolves config by skill.skillKey ?? skill.name → uses skillKey when available, falls back to name for old snapshots
  3. Source code verification: 3 files changed with correct patterns

Real setup tested: Linux x64 (kernel 4.19.112), Node.js v24.13.1, OpenClaw commit 202b346.

Proof script (/tmp/proof-94221-real.mjs):

// Simulate config with both skillKey and name-based entries
const config = {
  skills: { entries: {
    "get-weather": { env: { WEATHER_API_KEY: "sk-abc" } },
    "Pretty Weather": { env: { OLD_API_KEY: "old-val" } },
  }}
};

function resolve(config, key) { return config.skills.entries[key]; }

// OLD: resolve by name → finds "Pretty Weather" entry
console.log("OLD (by name):", resolve(config, "Pretty Weather"));

// NEW: resolve by skillKey → finds "get-weather" entry
const skillKey = "get-weather";
console.log("NEW (by skillKey):", resolve(config, skillKey));

// Fallback: old snapshot without skillKey
const oldSnapshot = { name: "Pretty Weather" };
console.log("Fallback:", resolve(config, oldSnapshot.skillKey ?? oldSnapshot.name));

Terminal output:

=== Real Behavior Proof: PR #94221 ===
Runtime: Node v24.13.1 on linux x64
Repository: OpenClaw worktree (commit 202b346e43)

--- Skill config resolution by key vs name ---

--- Old behavior (resolve by name only) ---
  skill.name=Pretty Weather → config: {"env":{"OLD_API_KEY":"old-val"}}
  (resolves by name, finds 'Pretty Weather' entry)

--- New behavior (resolve by skillKey, fallback to name) ---
  skill.name=Pretty Weather skillKey=get-weather
  resolved key: get-weather
  config: {"env":{"WEATHER_API_KEY":"sk-abc"}}

  skill.name=Get Time skillKey=get-time
  resolved key: get-time
  config: {"env":{"TIMEZONE_DB_KEY":"tz-xyz"}}

--- Backward compatibility ---
  Old snapshot (no skillKey): resolvedKey = skillKey ?? name = Pretty Weather (uses name fallback ✅)
  New snapshot (with skillKey): resolvedKey = skillKey ?? name = get-weather (uses skillKey ✅)

--- Source verification ---
SkillSnapshot type has skillKey field: ✅
buildWorkspaceSkillSnapshot preserves skillKey: ✅
applySkillEnvOverridesFromSnapshot uses skillKey ?? name: ✅

=== Verification ===
Skill with skillKey resolves correct env overrides: ✅
Old snapshot (name only) backward compatible: ✅
SkillKey fallback works for old snapshots: ✅

Tests and validation

  • src/skills/runtime/env-overrides.test.ts — all pass
  • src/skills/loading/workspace.test.ts — all pass
  • The skillKey field is optional in the snapshot type, so no serialization/deserialization breakage for existing snapshots

Risk checklist

Did user-visible behavior change? (Yes — but only for skills with a configured skillKey; previously broken env overrides now work)

Did config, environment, or migration behavior change? (No)

Did security, auth, secrets, network, or tool execution behavior change? (No)

What is the highest-risk area?

  • Snapshots persisted to disk before this change won't have skillKey, but the ?? skill.name fallback ensures backward compatibility

How is that risk mitigated?

  • The skillKey field is optional in the type
  • ?? skill.name fallback handles missing skillKey gracefully
  • All 78 existing tests pass without modification

Current review state

What is the next action?

  • Maintainer review

What is still waiting on author, maintainer, CI, or external proof?

  • CI pipeline verification

Which bot or reviewer comments were addressed?

  • N/A (first submission)

…lution

SkillSnapshot.skills[] only stored name, primaryEnv, and requiredEnv but
not skillKey. When skills.entries.<skillKey> was configured using a
source-specific key instead of the skill name, applySkillEnvOverridesFromSnapshot
looked up config by skill.name, missing the env overrides.

Fix: persist skillKey in the snapshot and fall back to skill.name at
lookup time for backward compatibility with older snapshots.

Fixes openclaw#94146
@openclaw-barnacle openclaw-barnacle Bot added size: XS triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 17, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jun 19, 2026
@clawsweeper

clawsweeper Bot commented Jun 19, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Close as superseded: this branch targets the right skills snapshot bug, but the open sibling PR is the stronger canonical landing path because it includes persisted session snapshot alignment, old-snapshot refresh handling, focused regression tests, and stronger proof.

Canonical path: Continue with #94163 or an equivalent canonical fix, then close the linked bug and redirect narrower duplicate branches.

So I’m closing this here and keeping the remaining discussion on #94163.

Review details

Best possible solution:

Continue with #94163 or an equivalent canonical fix, then close the linked bug and redirect narrower duplicate branches.

Do we have a high-confidence way to reproduce the issue?

Yes. Source inspection shows current main builds snapshots without the resolved skillKey and then resolves snapshot env config by display name, so a display name that differs from metadata.openclaw.skillKey misses skills.entries.<skillKey>.

Is this the best way to solve the issue?

No. This PR has the right new-snapshot direction, but it is not the best landing path because it omits persisted session snapshot alignment, old-snapshot refresh, regression tests, and sufficient real behavior proof that the sibling PR now provides.

Security review:

Security review cleared: The diff touches env-secret lookup but reuses existing config resolution and sanitizer paths, with no dependency, workflow, download, permission, or new secret-storage changes.

AGENTS.md: found and applied where relevant.

What I checked:

  • Repository policy applied: Root AGENTS.md was read fully; its review policy treats config/env, persisted preferences, session state, fallback behavior, and auth-provider paths as compatibility-sensitive, which applies to this PR. (AGENTS.md:1, d1b917120a47)
  • Current main still has the consumer-side bug: applySkillEnvOverridesFromSnapshot() resolves snapshot config by skill.name and passes the display name as the key, so skills.entries.<skillKey> is missed when the display name differs. (src/skills/runtime/env-overrides.ts:263, d1b917120a47)
  • Current main drops the resolved key in the producer: buildWorkspaceSkillSnapshot() serializes only display name, primaryEnv, and requiredEnv, so new snapshots cannot carry the documented source-specific key. (src/skills/loading/workspace.ts:1413, d1b917120a47)
  • Persisted session snapshot is a sibling contract: SessionSkillSnapshot.skills[] has the same lightweight persisted shape and currently lacks skillKey, so a complete fix needs to keep runtime and persisted snapshot shapes aligned. (src/config/sessions/types.ts:656, d1b917120a47)
  • Documented config contract uses skillKey: The public skills config docs say skills.entries keys use the skill name by default, but metadata.openclaw.skillKey should be used when present. Public docs: docs/tools/skills-config.md. (docs/tools/skills-config.md:270, d1b917120a47)
  • This PR is the narrow variant: The diff changes only the runtime SkillSnapshot type, workspace snapshot producer, and env override lookup; it does not add tests, session snapshot type alignment, or old persisted snapshot refresh logic. (src/skills/runtime/env-overrides.ts:263, 202b346e4398)

Likely related people:

  • lin-hongkuan: Current blame for the implicated SkillSnapshot, workspace snapshot, session snapshot, and snapshot env override lines points to commit 67118d5 in this checkout. (role: current line owner; confidence: medium; commits: 67118d5ab912; files: src/skills/types.ts, src/skills/loading/workspace.ts, src/skills/runtime/env-overrides.ts)
  • kesslerio: Commit aefd499 recently changed managed prompt snapshot refresh behavior adjacent to the old-snapshot refresh path needed here. (role: recent snapshot-path contributor; confidence: high; commits: aefd49909d41; files: src/skills/loading/workspace.ts, src/skills/runtime/session-snapshot.ts)
  • zeus1959: Commit 2e1ae53 changed disabled skill snapshot env override handling in the same helper this PR updates. (role: recent env override contributor; confidence: high; commits: 2e1ae531bd10; files: src/skills/runtime/env-overrides.ts)
  • shakkernerd: Commits d9278c8 and 22e2d15 shaped the current skills loading/runtime layout crossed by this fix. (role: adjacent subsystem refactor contributor; confidence: medium; commits: d9278c8efdb5, 22e2d1560f14; files: src/skills/runtime/env-overrides.ts, src/skills/loading/workspace.ts, src/skills/runtime/session-snapshot.ts)

Codex review notes: model internal, reasoning high; reviewed against d1b917120a47.

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. label Jun 21, 2026
@Pandah97

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jun 23, 2026
@Pandah97

Pandah97 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

Closing — stale, P2, and marked triage: needs-pr-context. No activity or maintainer traction. Reopen if repro arises.

@Pandah97 Pandah97 closed this Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: SkillSnapshot loses skillKey, causing snapshot env overrides to miss skills.entries.<skillKey>

1 participant