fix: preserve skill command cache on scan failure in scan_skill_commands()#18720
Open
henrytran1803 wants to merge 1 commit into
Open
fix: preserve skill command cache on scan failure in scan_skill_commands()#18720henrytran1803 wants to merge 1 commit into
henrytran1803 wants to merge 1 commit into
Conversation
…nds() scan_skill_commands() unconditionally cleared the module-level _skill_commands dict before entering the try block. When scanning failed (e.g. unreadable directory, import error), the exception was silently swallowed and all 90+ skill slash commands were lost with zero user-facing error. Build the new dict in a local variable and assign to the global only on success. On failure, log a warning and keep the previous cache intact. Closes NousResearch#18659
Collaborator
Closed
9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #18659
scan_skill_commands()unconditionally cleared the module-level_skill_commandsdict to{}before entering thetryblock. When scanning failed (e.g. unreadable directory, broken import chain), the exception was silently swallowed byexcept Exception: pass, leaving the global empty — all 90+ skill slash commands were lost with zero user-facing error.Changes
agent/skill_commands.py—scan_skill_commands():new_commands) instead of writing directly to the global_skill_commandsonly on success (viaelseclause on thetry/except)logger.warning("skill scan failed; preserving previous command cache", exc_info=True)) instead of silently discarding the errortests/agent/test_skill_commands.py—TestScanPreservesCacheOnFailure:test_outer_exception_preserves_existing_commands— verifies previously-cached commands survive a failed scantest_outer_exception_logs_warning— verifies the warning is logged (no more silent failure)test_empty_scan_replaces_cache— verifies successful empty scans still correctly replace the cache (no false preservation)test_reload_skills_preserves_commands_on_scan_failure— verifiesreload_skills()diff does not report skills as "removed" when the scan failsTesting
All 45 existing + 4 new tests pass:
Zero regressions.
Design rationale
The fix follows the pattern suggested in the issue: build locally, assign on success. This is the same atomicity pattern used by
reload_skills()(which snapshotsbeforestate and diffs against it). Theelseclause ensures the global is only touched when the scan completes without raising — if any outer exception occurs, the previous cache is preserved intact.