Skip to content

Maintenance: reload settings when the file changes so audits reflect current cache paths#179

Merged
Brandon-Haney merged 1 commit into
StudioNirin:mainfrom
Brandon-Haney:fix/issue-176-maintenance-stale-settings
Jun 5, 2026
Merged

Maintenance: reload settings when the file changes so audits reflect current cache paths#179
Brandon-Haney merged 1 commit into
StudioNirin:mainfrom
Brandon-Haney:fix/issue-176-maintenance-stale-settings

Conversation

@Brandon-Haney

Copy link
Copy Markdown
Collaborator

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 its cache_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 showed Protected: 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_path and found all cached files. Only the long-lived audit singleton was out of date.

Fix

_load_settings() now tracks the settings file mtime and reloads when it changes, clearing the derived cache_dirs/array_dirs so 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 cheap stat).

Testing

  1. Start the Web UI and run a cache operation so files are tracked and the dashboard shows them as cached.
  2. Edit a path mapping in Settings (or complete setup so a mapping gains its cache path) without restarting.
  3. Open Maintenance / Dashboard and confirm the audit reflects the updated mapping — cached files are counted and no false "stale" warnings appear.
  4. Confirm that with mappings unchanged, repeated runs keep a stable tracking count and an empty warning list.

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.

… 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
@Brandon-Haney Brandon-Haney merged commit def6779 into StudioNirin:main Jun 5, 2026
2 checks passed
@Brandon-Haney Brandon-Haney deleted the fix/issue-176-maintenance-stale-settings branch June 7, 2026 04:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

After running "Maintenance" actions to clear warnings, the next run brings them back.

2 participants