Skip to content

Add automatic rule file reloading with selective serve_once tracking#9

Merged
maclarel merged 5 commits intomainfrom
copilot/add-rules-file-reload-functionality
Jan 28, 2026
Merged

Add automatic rule file reloading with selective serve_once tracking#9
maclarel merged 5 commits intomainfrom
copilot/add-rules-file-reload-functionality

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 28, 2026

Rules files are now monitored for changes and reloaded automatically without server restart. This eliminates the need to restart the server when updating access control rules.

Implementation

  • Background monitoring: Daemon thread polls rules directory using file modification timestamps (default: 3s interval, configurable via watch_interval)
  • Thread safety: Locks protect shared state (rules, served_once_rules) across monitoring and request handler threads
  • Selective serve_once tracking: Only rules from changed files have tracking reset; unchanged rules preserve their served state
  • Zero-downtime reloads: Old rules remain active during reload; failed reloads retain existing rules
  • Configuration: watch_rules boolean to disable monitoring if needed

Key Changes

class RuleFileMonitor:
    def reload_rules(self):
        changed_files = self.get_changed_rule_files()  # Track which files changed
        new_rules = load_rules(self.rules_dir)
        
        with self.rules_lock:
            self.rules = new_rules
            self.file_mtimes = self.get_rule_files()
        
        # Only reset serve_once for changed rules
        if self.reload_callback:
            self.reload_callback(new_rules.copy(), changed_files)

Configuration

config:
  watch_rules: true        # Enable/disable monitoring (default: true)
  watch_interval: 3.0      # Poll interval in seconds (default: 3.0)

Behavior

  • Adding/modifying/deleting rule files triggers reload within poll interval
  • Rules with serve_once: true maintain state unless their file changed
  • Errors during reload preserve existing rules and log the issue
Original prompt

We need to add functionality that will detect changes to rules files and reload them when the change is detected. Ideally this should be done very quickly, either through a thread polling the rules files to identify changes, or some other mechanism that will have the same outcome but be more lightweight. This should not be intense polling - once every few seconds is sufficient.

If a rule change is detected, the server should reload with the newly defined rule(s). It will be important to ensure that rules are still enforced during startup and shutdown of the server to prevent accidental leaks of files being served.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits January 28, 2026 15:05
Co-authored-by: maclarel <21298298+maclarel@users.noreply.github.com>
Co-authored-by: maclarel <21298298+maclarel@users.noreply.github.com>
…ndling

Co-authored-by: maclarel <21298298+maclarel@users.noreply.github.com>
Co-authored-by: maclarel <21298298+maclarel@users.noreply.github.com>
Copilot AI changed the title [WIP] Add functionality to detect and reload rules files Add automatic rule file reloading with selective serve_once tracking Jan 28, 2026
Copilot AI requested a review from maclarel January 28, 2026 15:15
@maclarel maclarel marked this pull request as ready for review January 28, 2026 15:19
@maclarel maclarel merged commit 2381ab9 into main Jan 28, 2026
3 checks passed
@maclarel maclarel deleted the copilot/add-rules-file-reload-functionality branch January 28, 2026 15:22
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.

2 participants