Skip to content

fix(agent): add per-platform skill_commands cache to prevent cross-platform leakage (#14536)#15375

Closed
Tranquil-Flow wants to merge 1 commit into
NousResearch:mainfrom
Tranquil-Flow:fix/skill-commands-platform-cache
Closed

fix(agent): add per-platform skill_commands cache to prevent cross-platform leakage (#14536)#15375
Tranquil-Flow wants to merge 1 commit into
NousResearch:mainfrom
Tranquil-Flow:fix/skill-commands-platform-cache

Conversation

@Tranquil-Flow
Copy link
Copy Markdown
Contributor

Summary

Fixes #14536.

skill_commands.py uses a module-level _skill_commands dict as a process-global cache. When the gateway serves multiple platforms (Telegram, Discord, Slack), get_skill_commands() returns the same dict to all. If a skill is disabled for one platform and that platform's handler removes it from the cache, the removal leaks to all other platforms sharing the same process.

Changes

  • agent/skill_commands.py:
    • Add _skill_commands_by_platform: Dict[str, Dict] for per-platform cache isolation
    • Add platform parameter to get_skill_commands() (defaults to "" for backward compatibility)
    • Per-platform views are shallow copies of the global cache, so mutations in one platform don't affect others

Validation

Targeted test: tests/agent/test_skill_commands_platform_cache.py — 4 tests:

  1. get_skill_commands accepts platform parameter
  2. _skill_commands_by_platform dict exists
  3. Removing a skill from telegram's cache does not affect discord's cache
  4. Calling without platform returns the global cache

Tested on macOS (Python 3.14).

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent loop, run_agent.py, prompt builder tool/skills Skills system (list, view, manage) labels Apr 24, 2026
@alt-glitch
Copy link
Copy Markdown
Collaborator

Likely duplicate of #14594 — Same fix for #14536: per-platform skill_commands cache to prevent cross-platform leakage. Superseded by #14594.

@teknium1
Copy link
Copy Markdown
Contributor

teknium1 commented May 2, 2026

Thanks for the contribution. Closing in favor of #18739 which salvages #14570 — a parallel PR that actually filters per platform.

The bug is that scan_skill_commands() applies the skills.platform_disabled filter at scan time (via _get_disabled_skill_names() which resolves the current platform from the environment). This PR caches per-platform copies of the one-and-only global scan result, so every per-platform view is whichever platform scanned first. Verified against the issue's repro: both telegram and discord still return ['/beta'].

To actually fix this, the scan itself needs to rerun when the active platform changes (or the filter needs to be applied at read time). #18739 takes the rescan approach. Appreciate the thorough tests here — they'd be a good addition to that PR if you want to rebase them on top.

@Tranquil-Flow
Copy link
Copy Markdown
Contributor Author

Thanks @teknium1 — agreed our per-platform-cache tests were tied to the wrong fix and don't translate.

I opened #19042 with three fresh regression tests on top of #18739, targeting code paths the existing rescan test doesn't exercise:

  1. Gateway session context (HERMES_SESSION_PLATFORM via ContextVar) — uses set_session_vars / clear_session_vars so the rescan is proven against the actual ContextVar signal, not just the legacy os.environ fallback in get_session_env.
  2. Returning to no-platform-scope (CLI / cron / RL after a gateway session) — unfiltered scan must repopulate.
  3. Same-platform cache hit — consecutive calls under the same scope must not rescan (gateway serving many telegram requests in a row should pay the scan cost once).

Test-only, +131 lines, no source changes.

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

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists tool/skills Skills system (list, view, manage) type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

skill_commands cache can leak one platform's disabled-skill view into another

3 participants