Maintenance: reload settings when the file changes so audits reflect current cache paths#179
Merged
Brandon-Haney merged 1 commit intoJun 5, 2026
Conversation
… cache paths The MaintenanceService singleton memoized settings and the derived cache/array paths for the life of the web process. When path mappings were edited after startup, the audit kept scanning the previous cache path, reported '0 on cache', and flagged every tracked exclude/timestamp entry as stale until a container restart. _load_settings() now reloads when the file's mtime changes and clears the derived path cache, so audits reflect the current configuration without a restart. Refs StudioNirin#176
StudioNirin
approved these changes
Jun 5, 2026
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.
Fixes #176.
Problem
The Maintenance/audit layer (
MaintenanceService) is a process-lifetime singleton that memoized settings and the derived cache/array directory paths on first use, with no invalidation. If path mappings were edited after the web process started (e.g. a mapping gained itscache_path), the audit kept scanning the previous path.When that cached path resolved to an empty or old directory, the cache scan returned 0 files, so the audit marked every tracked exclude and timestamp entry as "stale — no longer on cache." The dashboard then showed a large warning count (e.g.
140 warnings = 70 stale exclude + 70 stale timestamp) and Maintenance showedProtected: N of 0 on cache. Cleaning removed the tracking entries (the physical files were untouched), and the next run re-created them, so the warnings returned every run. A container restart cleared the stale snapshot and the warnings stayed gone — confirming the cause.The actual caching run was always correct: it resolves each file via
mapping.cache_pathand found all cached files. Only the long-lived audit singleton was out of date.Fix
_load_settings()now tracks the settings filemtimeand reloads when it changes, clearing the derivedcache_dirs/array_dirsso they are recomputed from the current configuration._get_paths()consults_load_settings()before its cache short-circuit so the reload is honored. When settings are unchanged, behavior is identical to before (no extra file reads beyond a cheapstat).Testing
Automated coverage added in
tests/test_maintenance_service.py(TestSettingsReloadOnChange): paths refresh after a settings change, stay cached when unchanged, and the cache scan recovers once a mapping is corrected.