Repository navigation
fix(reload): instantiate reloaded command classes and drop removed triggers - #205
Merged
Merged
Conversation
…iggers CommandHandler imported BaseCommand/VoiceTrigger/Say by name, so after reload(Commands) Setup() still walked the pre-reload class objects and re-instantiated old code. Resolve the classes through the Commands module at Setup() time and keep BaseCommand as a typing-only import so nothing pins the old classes. TriggerManager.Load() now builds voice_triggers into a fresh dict and swaps it in at the end, so triggers removed from triggers.json disappear and a failed load keeps the previous triggers. Sounds.Path is re-read on every load. OnReload no longer re-reads config.json (Torchlight.Reload already did, and still raises ConfigError before any callback runs) and now also refreshes the advertiser config. Closes #189 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
15 of 16 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.
Stale command classes after
!reloadWhy:
CommandHandlerimportedBaseCommand,SayandVoiceTriggerby name.Reload()re-executestorchlight.Commands, butSetup()then walked__subclasses__()on the old class objects, which those names kept alive. Every!reloadre-instantiated the pre-reload classes, so code changes inCommands.pywere never picked up.Fix:
Setup()resolves the classes through the module object (Commands.BaseCommand.__subclasses__(),Commands.VoiceTrigger...,Commands.Say...). Discovery semantics are unchanged (direct subclasses ofBaseCommandplus subclasses ofVoiceTriggerandSay, sorted byorderdesc).BaseCommandis now a typing-only import, so nothing at module level pins the first generation of classes. After a reload the old classes and old command instances are garbage-collectable.Removed voice triggers survived
!reloadWhy:
TriggerManager.Load()wrote into the existingself.voice_triggersand never cleared it, so triggers removed fromtriggers.jsonstayed active.sound_pathwas only read in__init__.Fix:
Load()buildstriggers_dict,voice_triggersand the sound path into locals and swaps them in at the end. Removed triggers disappear, a malformedtriggers.json(ConfigError) leaves the previous triggers intact, andSounds.Pathis re-read on every load.Advertiser config not refreshed / config loaded twice
Why:
OnReloadrefreshedanti_spam.configbut notadvertiser.config. It also re-readconfig.json, whichTorchlight.Reload()had just done.Fix:
OnReloadalso refreshesaudio_manager.advertiser.configand no longer callsconfig.load().Torchlight.Reload()stays the only placeconfig.jsonis re-read on reload, so a malformedconfig.jsonstill raisesConfigErrorto the!reloadcaller before anyOnReloadstate is swapped.Persistent caches still live outside
Commands.py(GeoIP.pyis untouched).Test plan
I ran a throwaway script (not committed) against a temp copy of
config/, with the realConfig,Torchlight,AudioManager,AccessManager,TriggerManager,SourcemodConfigandCommandHandler. It ran the fullTorchlight.Reload()→OnReloadpath onorigin/masterand on this branch:type(cmd) is Commands.<Name>for every command after reloadconfig.load()calls per reloadtriggers.jsongone fromvoice_triggersandVoiceTrigger.triggersSounds.Pathchange picked upadvertiser.configrefreshedgc.collect()triggers.json→ConfigError, previous triggers keptconfig.json→ConfigErrorpropagates fromTorchlight.Reload()ruff check .,ruff format --check .,mypy: no new errors. The only errors left are the known baseline ones (UP041 inFFmpegAudioPlayer.py,FlareSolverr.py:29), which CI: Python Linting is red on master since the Python 3.12 bump (ruff UP041, mypy arg-type) #178 fixes.No VERSION bump (batch policy, see #177).
Closes #189
Part of #177
🤖 Generated with Claude Code