Преглед изворни кода

seperate deployment for reconcile

Johan Le Baut пре 2 недеља
родитељ
комит
96043e4689

+ 7 - 7
AGENTS.md

@@ -11,10 +11,10 @@ The current target is Debian GNU/Linux 13 on AArch64 with a Behringer UMC404HD 1
 - `config/desired-state.yaml` is the central YAML description of the intended components, four mono sources, looper channel assignments, mix, the guitar NAM/cabinet chain, planned/forbidden connections, and the exact PipeWire links currently tracked for observation.
 - `config/pipewire/filter-chain.conf.d/rigforge-direct-mix.conf` is a PipeWire filter-chain fragment with four mono mixer inputs, one mono output, and initial gain `0.2` per input. It defines the processing graph and ports, but does not create links to hardware or implement the looper graph.
 - `scripts/validate_desired_state.py` checks the YAML's four-source/physical-input model, single four-channel looper, source-to-channel assignments, mix declaration, and prohibition on routing looper returns back to looper inputs.
-- `scripts/observe_pipewire.py` validates the state and managed endpoint declarations, reads `pw-link -l`, and compares observed links against explicitly managed ports and links. Observation is the default; one-shot reconciliation and the opt-in timer create only declared missing links and remove only declared stale links.
+- `scripts/observe_pipewire.py` validates the state and managed endpoint declarations, reads `pw-link -l`, and compares observed links against explicitly managed ports and links. Without `--reconcile-once`, it is read-only; one-shot reconciliation and the separately deployed timer create only declared missing links and remove only declared stale links.
 - `scripts/configure_mod_host.py` loads the YAML-declared NAM and LSP IR instances and guitar links for the user service `config/systemd/user/rigforge-mod-host.service.in`.
-- `config/systemd/user/rigforge-pipewire-reconcile.service.in` and `.timer.in` define periodic link reconciliation after mod-host is installed.
-- `scripts/deploy.sh` dispatches scoped user-level install/uninstall/reload actions for YAML-declared PipeWire, LV2 bundles, and the mod-host service/timer through `scripts/deploy.py`. `mod-host` is an explicit target, not part of `all`.
+- `config/systemd/user/rigforge-pipewire-reconcile.service.in` and `.timer.in` define periodic reconciliation for the whole YAML-managed graph.
+- `scripts/deploy.sh` dispatches scoped user-level install/uninstall/reload actions for YAML-declared PipeWire, LV2 bundles, the mod-host service, and the separate graph-reconcile timer through `scripts/deploy.py`. `mod-host` and `reconcile` are explicit targets, not part of `all`.
 - `tests/` contains Python `unittest` tests for state validation, observation/reconciliation, mixer configuration, mod-host startup configuration, and simulated deployment operations. These validate repository-level invariants, not live audio behavior.
 - `config/sooperlooper/fcb1010.slb` is supplied controller configuration, pending target verification. No SooperLooper build definition or artifact is present.
 
@@ -39,7 +39,7 @@ python3 scripts/observe_pipewire.py
 python3 scripts/observe_pipewire.py --state path/to/desired-state.yaml
 ```
 
-The observer invokes `pw-link -l` itself. It never creates or removes links. A clean test run does not verify physical port mappings, sustained performance, clipping headroom, or hardware operation; those require target checks described in `README.md`.
+The observer invokes `pw-link -l` itself. Its default mode never creates or removes links. A clean test run does not verify physical port mappings, sustained performance, clipping headroom, or hardware operation; those require target checks described in `README.md`.
 
 ## State and safety invariants
 
@@ -49,7 +49,7 @@ The observer invokes `pw-link -l` itself. It never creates or removes links. A c
 - A managed link's endpoints must both be declared in `routing.managed_ports`, and names must match the observer's approved endpoint pattern. Use concrete observed PipeWire ports rather than logical aliases. The current effect allowlist is limited to the declared `effect_0` NAM and `effect_1` IR ports.
 - Link status values used by the observer are `planned` and `observed`; both are compared against the current graph. Only declare real target observations as `observed`.
 - Deployment declarations belong in `config/desired-state.yaml`. The deploy helper must remain scoped to declared user paths, preserve and restore prior files, refuse destructive actions after local modifications, and never restart the main PipeWire or WirePlumber service as a generic update.
-- Keep observation as the default. Explicit `--reconcile-once` and the opt-in mod-host user timer may create declared missing links and remove only exact links listed in `routing.managed_unlinks`; they must defer removals until all desired managed links are present, must not alter other connections, and must not restart PipeWire/WirePlumber. Retain tests for simulated repair, safe removal, deferral, and post-check behavior.
+- Keep observation as the default. Explicit `--reconcile-once` and the separately installed user timer may create declared missing links and remove only exact links listed in `routing.managed_unlinks`; they must defer removals until all desired managed links are present, must not alter other connections, and must not restart PipeWire/WirePlumber. Retain tests for simulated repair, safe removal, deferral, and post-check behavior.
 - Mixer gain `0.2` is an initial conservative value, not a calibrated level or clipping guarantee. Test summed sources and loop returns on hardware before live use.
 
 ## Working conventions and gotchas
@@ -59,8 +59,8 @@ The observer invokes `pw-link -l` itself. It never creates or removes links. A c
 - Scripts resolve their default state file relative to their own location, so the documented commands work from any current directory, though repository-root execution is the clearest convention.
 - PipeWire's `filter-chain.conf.d` fragment is loaded by the separate filter-chain process (`pipewire -c filter-chain.conf` on the current target), not automatically by the main PipeWire daemon. It defines nodes/ports, not connections. Target service installation and restart steps are specific to the README's current test and should not be treated as an established deployment recipe.
 - The current port mapping, sample rate/quantum, and physical output details have differing verification levels recorded in YAML and README. Preserve those distinctions; do not infer a complete deployment procedure from the exploratory test notes.
-- Deployment is manual; no CI/CD or auto-pull is configured. The mod-host user service, dependent-service restart propagation, and 15-second reconciliation timer are implemented in the repository but the latest changes and recovery behavior still require target verification. Keep unverified changes away from live audio use and follow the README's rollback procedure for target experiments.
-- `install mod-host` activates audio routing and is intentionally excluded from `install all`. The current mod-host build listens on `0.0.0.0:5555` without authentication by owner request; do not change that policy silently, and retain the security warning in documentation.
+- Deployment is manual; no CI/CD or auto-pull is configured. The mod-host user service, dependent-service restart propagation, and separately deployed 15-second reconciliation timer are implemented in the repository but the latest changes and recovery behavior still require target verification. Keep unverified changes away from live audio use and follow the README's rollback procedure for target experiments.
+- `install mod-host` activates guitar audio routing and is intentionally excluded from `install all`. `install reconcile` separately enables graph-wide periodic link repair and is also opt-in. The current mod-host build listens on `0.0.0.0:5555` without authentication by owner request; do not change that policy silently, and retain the security warning in documentation.
 
 # Environnement local — rigforge
 

+ 18 - 8
README.md

@@ -110,12 +110,13 @@ After a manual `git pull --ff-only`, run the deploy helper from any directory:
 ~/rigforge/scripts/deploy.sh install lsp
 ~/rigforge/scripts/deploy.sh install dragonfly-reverb
 ~/rigforge/scripts/deploy.sh install mod-host
+~/rigforge/scripts/deploy.sh install reconcile
 ~/rigforge/scripts/deploy.sh install all
 ```
 
-The helper accepts `install|uninstall|reload` and `all|namlv2|lsp|dragonfly-reverb|pipewire|mod-host`. It reads versions, paths, URLs, and quantum from `config/desired-state.yaml`; its deployment registry is stored under `~/.local/state/rigforge/`, and any pre-existing target backup is stored next to that target. It does not use `sudo` or change files outside the declared paths, adjacent backup paths, and registry directory.
+The helper accepts `install|uninstall|reload` and `all|namlv2|lsp|dragonfly-reverb|pipewire|mod-host|reconcile`. It reads versions, paths, URLs, and quantum from `config/desired-state.yaml`; its deployment registry is stored under `~/.local/state/rigforge/`, and any pre-existing target backup is stored next to that target. It does not use `sudo` or change files outside the declared paths, adjacent backup paths, and registry directory.
 
-For PipeWire, install updates only the Rigforge filter fragment, applies the declared quantum as a runtime setting, and restarts `filter-chain.service` only when the fragment changes. It never restarts `pipewire.service` or WirePlumber. `reload pipewire` reapplies the quantum and restarts the filter-chain user service. This restart removes the filter-chain nodes and their graph links; the fragment recreates ports but not links. Installing the explicit `mod-host` target also installs a 15-second reconciliation timer; without that target, reconciliation remains manual. After a PipeWire/filter restart, first inspect with `python3 scripts/observe_pipewire.py`. Uninstall removes only the unchanged managed fragment, restores a file that was present before the first install, returns quantum selection to automatic, and reloads the filter service. Local edits to managed files stop removal or replacement rather than being discarded. Runtime quantum is not persistent across a PipeWire daemon restart.
+For PipeWire, install updates only the Rigforge filter fragment, applies the declared quantum as a runtime setting, and restarts `filter-chain.service` only when the fragment changes. It never restarts `pipewire.service` or WirePlumber. `reload pipewire` reapplies the quantum and restarts the filter-chain user service. This restart removes the filter-chain nodes and their graph links; the fragment recreates ports but not links. Reconciliation is a separate explicit target; installing `mod-host` alone does not install its timer. After a PipeWire/filter restart, inspect with `python3 scripts/observe_pipewire.py`. Uninstall removes only the unchanged managed fragment, restores a file that was present before the first install, returns quantum selection to automatic, and reloads the filter service. Local edits to managed files stop removal or replacement rather than being discarded. Runtime quantum is not persistent across a PipeWire daemon restart.
 
 For NAM LV2, install downloads the declared Raspberry Pi 5 archive with `curl`, checks the archive structure, extracts the `neural_amp_modeler.lv2` bundle under `~/.lv2/`, and records the archive SHA-256 and managed bundle fingerprint. This is a locally computed identity hash, not an independent publisher checksum. An existing same-name bundle is preserved for uninstall; locally modified managed bundles are not overwritten or removed. `reload namlv2` does nothing because plugin installation itself requires no host reload; restart `mod-host` after installing or removing the plugin. On the target, tag `v0.2.3` was installed at `~/.lv2/neural_amp_modeler.lv2`; the observed contents were `manifest.ttl`, `modgui/`, `modgui.ttl`, `neural_amp_modeler.so`, and `neural_amp_modeler.ttl`. The downloaded archive SHA-256 was `80d1a711d573afb7323cbf2ea1a79e39386e58ba449d076c5d89e10b50de3212`; this is an identity hash only, not an independent publisher checksum. The selected NAM model was loaded during the initial manual mod-host chain test; sustained performance and automated startup remain unverified. The release archive is fetched at install time and is not committed to this repository.
 
@@ -123,23 +124,32 @@ For LSP and Dragonfly Reverb, the YAML declares tags and release URLs, and the i
 
 ### mod-host guitar chain
 
-`install mod-host` is an explicit target and is deliberately not included in `install all`: it activates the guitar processing chain. It requires the ARM64 artifact under `artifacts/mod-host/arm64/current/`, the NAM and LSP bundles already installed, the tracked `amp_emul/` assets, and the runtime packages in the target preparation list. It installs and enables a `systemd --user` service and a 15-second reconciliation timer; it does not use `sudo` or directly restart PipeWire/WirePlumber. The generated units refer to the repository checkout from which `deploy.sh` was run, so keep the checkout at that path or uninstall/reinstall after moving it.
+`install mod-host` is an explicit target and is deliberately not included in `install all`: it activates the guitar processing chain. It requires the ARM64 artifact under `artifacts/mod-host/arm64/current/`, the NAM and LSP bundles already installed, the tracked `amp_emul/` assets, and the runtime packages in the target preparation list. It installs and enables only the `systemd --user` mod-host service; it does not use `sudo` or directly restart PipeWire/WirePlumber. The unit refers to the repository checkout from which `deploy.sh` was run, so keep that checkout at that path or uninstall/reinstall after moving it.
 
 At service startup, `scripts/configure_mod_host.py` waits for the control socket, loads the declared NAM and LSP mono-IR instances, sets their model/IR paths and the conservative NAM output level, then creates the PipeWire links. The desired chain is capture AUX0 → `Vox_AC15CH_Crunch_TB.nam` → `VOX_AC30_1964_celestion.wav` → guitar mixer input AUX0. The direct capture-to-mixer bypass is removed. Review the model and IR redistribution terms before using these assets in a public image or package.
 
-`reload mod-host` restarts the service and rebuilds the plugin graph, briefly interrupting the processed guitar path. `PartOf=` couples mod-host restarts to PipeWire, WirePlumber, and `filter-chain.service` restarts; its startup configurator then rebuilds the NAM/IR chain. The separate timer invokes `observe_pipewire.py --reconcile-once --quiet-if-clean` every 15 seconds to repair declared links after graph changes such as an interface reconnect. It removes only explicitly declared stale links and defers removal until every desired managed link exists; other unexpected links are never pruned. It verifies graph topology, not audio signal quality. Inspect it with `systemctl --user status rigforge-pipewire-reconcile.timer` and `journalctl --user -u rigforge-pipewire-reconcile.service -b`. `uninstall mod-host` disables the timer and service and restores any prior unit files; it does not create a dry bypass. The mod-host control socket uses TCP port 5555 and this build listens on `0.0.0.0` without authentication. This is retained for the current test by owner request and must be restricted before treating the setup as hardened.
+`reload mod-host` restarts the service and rebuilds the plugin graph, briefly interrupting the processed guitar path. `PartOf=` couples mod-host restarts to PipeWire, WirePlumber, and `filter-chain.service` restarts; its startup configurator then rebuilds the NAM/IR chain. The mod-host control socket uses TCP port 5555 and this build listens on `0.0.0.0` without authentication. This is retained for the current test by owner request and must be restricted before treating the setup as hardened.
 
-The owner reports enabling lingering with `sudo loginctl enable-linger "$USER"` so the user manager can run without an interactive login. Boot startup, dependency restart propagation, and USB unplug/replug recovery from the new timer require on-target verification. Installation refuses to start if port 5555 is already occupied by an unmanaged/manual mod-host process; stop that process explicitly before retrying.
+### Rigforge graph reconciliation
 
-Inspect the service and timer after installation with:
+`install reconcile` separately installs and enables a `systemd --user` oneshot service and 15-second timer for **all** links in `routing.managed_links`, regardless of whether they belong to mod-host, SooperLooper, or another declared component. It is explicit and not part of `install all`; `install mod-host` does not install it. On each run it repairs declared links and removes only links explicitly listed in `routing.managed_unlinks`, deferring removals until all desired managed links are present. It never prunes other unexpected links. `reload reconcile` runs one reconciliation immediately; `uninstall reconcile` stops and removes the timer/service while restoring any prior unit files. The timer retries after graph changes such as a USB interface reconnect, but verifies topology only, not audio signal quality.
+
+Inspect the timer and its journal with:
 
 ```sh
-systemctl --user status rigforge-mod-host.service
-journalctl --user -u rigforge-mod-host.service -b
 systemctl --user status rigforge-pipewire-reconcile.timer
 journalctl --user -u rigforge-pipewire-reconcile.service -b
 ```
 
+The owner reports enabling lingering with `sudo loginctl enable-linger "$USER"` so the user manager can run without an interactive login. Boot startup, dependency restart propagation, and USB unplug/replug recovery from the reconciliation timer require on-target verification. Mod-host installation refuses to start if port 5555 is already occupied by an unmanaged/manual mod-host process; stop that process explicitly before retrying.
+
+Inspect the service after installation with:
+
+```sh
+systemctl --user status rigforge-mod-host.service
+journalctl --user -u rigforge-mod-host.service -b
+```
+
 On the target, `install pipewire` applied quantum 128 and reported that the installed fragment was already current; the following observer reported no differences. A later `reload pipewire` applied the quantum and restarted the filter-chain service, after which observation found all three managed links missing. One-shot reconciliation requested each link, and the subsequent observer reported `differences: []`. This confirms the graph links were present after reconciliation, not that audio was audible. `install all` and `uninstall all` attempt all four targets and report an overall failure if any action fails. `reload all` restarts the filter-chain service and prints no-op messages for the LV2 plugins. Check the target afterwards with `python3 scripts/validate_desired_state.py`, `python3 -m unittest discover -s tests -v`, and `python3 scripts/observe_pipewire.py`.
 
 ## Development PC

+ 9 - 7
config/desired-state.yaml

@@ -67,14 +67,16 @@ deployment:
     socket_port: 5555
     pw_jack_path: /usr/bin/pw-jack
     python_path: /usr/bin/python3
+  reconcile:
     observer_script: scripts/observe_pipewire.py
-    reconcile_service_source: config/systemd/user/rigforge-pipewire-reconcile.service.in
-    reconcile_service_destination: .config/systemd/user/rigforge-pipewire-reconcile.service
-    reconcile_service: rigforge-pipewire-reconcile.service
-    reconcile_timer_source: config/systemd/user/rigforge-pipewire-reconcile.timer.in
-    reconcile_timer_destination: .config/systemd/user/rigforge-pipewire-reconcile.timer
-    reconcile_timer: rigforge-pipewire-reconcile.timer
-    reconcile_interval_seconds: 15
+    service_source: config/systemd/user/rigforge-pipewire-reconcile.service.in
+    service_destination: .config/systemd/user/rigforge-pipewire-reconcile.service
+    user_service: rigforge-pipewire-reconcile.service
+    timer_source: config/systemd/user/rigforge-pipewire-reconcile.timer.in
+    timer_destination: .config/systemd/user/rigforge-pipewire-reconcile.timer
+    user_timer: rigforge-pipewire-reconcile.timer
+    python_path: /usr/bin/python3
+    interval_seconds: 15
   pipewire:
     fragment_source: config/pipewire/filter-chain.conf.d/rigforge-direct-mix.conf
     fragment_destination: .config/pipewire/filter-chain.conf.d/rigforge-direct-mix.conf

+ 1 - 1
config/systemd/user/rigforge-pipewire-reconcile.service.in

@@ -1,6 +1,6 @@
 [Unit]
 Description=Reconcile declared Rigforge PipeWire links
-After=pipewire.service wireplumber.service filter-chain.service rigforge-mod-host.service
+After=pipewire.service wireplumber.service filter-chain.service
 
 [Service]
 Type=oneshot

+ 84 - 38
scripts/deploy.py

@@ -37,8 +37,13 @@ def load_deployment():
         raise ValueError("deployment must be a mapping")
     namlv2 = deployment.get("namlv2")
     pipewire = deployment.get("pipewire")
-    if not isinstance(namlv2, dict) or not isinstance(pipewire, dict):
-        raise ValueError("deployment.namlv2 and deployment.pipewire must be mappings")
+    reconcile = deployment.get("reconcile")
+    if (
+        not isinstance(namlv2, dict)
+        or not isinstance(pipewire, dict)
+        or not isinstance(reconcile, dict)
+    ):
+        raise ValueError("deployment.namlv2, deployment.pipewire, and deployment.reconcile must be mappings")
     for component, archive_format in PLUGIN_ARCHIVES.items():
         plugin = deployment.get(component)
         if not isinstance(plugin, dict):
@@ -823,19 +828,19 @@ def render_mod_host_service(config):
     return content.encode("utf-8")
 
 
-def render_mod_host_reconcile_units(config):
+def render_reconcile_units(config):
     repository_root = ROOT.resolve()
     state_file = repository_root / "config" / "desired-state.yaml"
     observer_script = repository_root / config["observer_script"]
-    service_template = repository_root / config["reconcile_service_source"]
-    timer_template = repository_root / config["reconcile_timer_source"]
+    service_template = repository_root / config["service_source"]
+    timer_template = repository_root / config["timer_source"]
     for description, path in (
         ("PipeWire observer", observer_script),
         ("reconciliation service template", service_template),
         ("reconciliation timer template", timer_template),
     ):
         if not path.is_file():
-            raise RuntimeError(f"mod-host {description} is missing: {path}")
+            raise RuntimeError(f"reconciliation {description} is missing: {path}")
 
     service_replacements = {
         "@PYTHON@": systemd_quote(config["python_path"]),
@@ -850,20 +855,20 @@ def render_mod_host_reconcile_units(config):
 
     timer_content = timer_template.read_text(encoding="utf-8").replace(
         "@RECONCILE_INTERVAL_SECONDS@",
-        str(config["reconcile_interval_seconds"]),
+        str(config["interval_seconds"]),
     )
     if re.search(r"@[A-Z_]+@", timer_content):
         raise RuntimeError("unexpanded placeholder remains in reconciliation timer template")
 
     return {
         "service": {
-            "name": config["reconcile_service"],
-            "destination": Path.home() / config["reconcile_service_destination"],
+            "name": config["user_service"],
+            "destination": Path.home() / config["service_destination"],
             "content": service_content.encode("utf-8"),
         },
         "timer": {
-            "name": config["reconcile_timer"],
-            "destination": Path.home() / config["reconcile_timer_destination"],
+            "name": config["user_timer"],
+            "destination": Path.home() / config["timer_destination"],
             "content": timer_content.encode("utf-8"),
         },
     }
@@ -886,15 +891,15 @@ def file_sha256(path):
     return hashlib.sha256(path.read_bytes()).hexdigest() if path.is_file() else None
 
 
-def install_mod_host_reconcile_units(config, registry):
-    units = render_mod_host_reconcile_units(config)
-    managed = registry.get("mod_host_reconcile")
+def install_reconcile_units(config, registry):
+    units = render_reconcile_units(config)
+    managed = registry.get("reconcile")
     if managed is not None and managed.get("pending_uninstall"):
-        raise RuntimeError("reconciliation units are pending uninstall; retry uninstall mod-host first")
+        raise RuntimeError("reconciliation units are pending uninstall; retry uninstall reconcile first")
     if managed is None and (
-        mod_host_unit_is_active(config["reconcile_service"])
-        or mod_host_unit_is_active(config["reconcile_timer"])
-        or mod_host_unit_is_enabled(config["reconcile_timer"])
+        user_unit_is_active(config["user_service"])
+        or user_unit_is_active(config["user_timer"])
+        or user_unit_is_enabled(config["user_timer"])
     ):
         raise RuntimeError(
             "an unmanaged Rigforge reconciliation unit is already active or enabled; "
@@ -964,7 +969,7 @@ def install_mod_host_reconcile_units(config, registry):
     managed = managed or {}
     managed["files"] = records
     managed["pending_install"] = True
-    registry["mod_host_reconcile"] = managed
+    registry["reconcile"] = managed
     write_registry(registry)
 
     for key, unit in units.items():
@@ -988,7 +993,7 @@ def install_mod_host_reconcile_units(config, registry):
     for record in records.values():
         record.pop("previous_installed_sha256", None)
     managed.pop("pending_install", None)
-    registry["mod_host_reconcile"] = managed
+    registry["reconcile"] = managed
     write_registry(registry)
 
     timer_name = units["timer"]["name"]
@@ -1007,14 +1012,14 @@ def install_mod_host_reconcile_units(config, registry):
         ]
     )
     run(["systemctl", "--user", "is-active", "--quiet", timer_name])
-    print(f"Installed and activated Rigforge PipeWire reconciliation timer ({timer_name}).")
+    print(f"Installed and activated Rigforge reconciliation timer ({timer_name}).")
 
 
-def uninstall_mod_host_reconcile_units(config, registry):
-    managed = registry.get("mod_host_reconcile")
+def uninstall_reconcile_units(config, registry):
+    managed = registry.get("reconcile")
     if managed is None:
         return
-    units = render_mod_host_reconcile_units(config)
+    units = render_reconcile_units(config)
     records = managed.get("files")
     if not isinstance(records, dict) or set(records) != set(units):
         raise RuntimeError("managed reconciliation unit registry has an unexpected file set")
@@ -1049,11 +1054,11 @@ def uninstall_mod_host_reconcile_units(config, registry):
             raise RuntimeError(f"managed reconciliation unit changed locally; refusing removal: {destination}")
 
     managed["pending_uninstall"] = True
-    registry["mod_host_reconcile"] = managed
+    registry["reconcile"] = managed
     write_registry(registry)
 
-    run(["systemctl", "--user", "disable", "--now", config["reconcile_timer"]])
-    run(["systemctl", "--user", "stop", config["reconcile_service"]])
+    run(["systemctl", "--user", "disable", "--now", config["user_timer"]])
+    run(["systemctl", "--user", "stop", config["user_service"]])
 
     for key, unit in units.items():
         record = records[key]
@@ -1075,19 +1080,53 @@ def uninstall_mod_host_reconcile_units(config, registry):
                 raise RuntimeError(f"recorded reconciliation unit backup is missing: {backup_path}")
 
     run(["systemctl", "--user", "daemon-reload"])
-    registry.pop("mod_host_reconcile")
+    registry.pop("reconcile")
     write_registry(registry)
-    print("Rigforge PipeWire reconciliation timer and units removed.")
+    print("Rigforge reconciliation timer and units removed.")
+
+
+def deploy_reconcile(action, config, registry):
+    if action == "install":
+        install_reconcile_units(config, registry)
+        return
+    if action == "uninstall":
+        uninstall_reconcile_units(config, registry)
+        if "reconcile" not in registry:
+            print("No managed reconciliation units to uninstall.")
+        return
+
+    managed = registry.get("reconcile")
+    if managed is None:
+        raise RuntimeError("reconciliation timer is not managed; install reconcile first")
+    if managed.get("pending_install") or managed.get("pending_uninstall"):
+        raise RuntimeError("reconciliation unit deployment is incomplete; retry install or uninstall reconcile")
+    units = render_reconcile_units(config)
+    records = managed.get("files")
+    if not isinstance(records, dict) or set(records) != set(units):
+        raise RuntimeError("managed reconciliation unit registry has an unexpected file set")
+    for key, unit in units.items():
+        destination = unit["destination"]
+        validate_user_destination(destination)
+        if not destination.is_file() or file_sha256(destination) != records[key].get("installed_sha256"):
+            raise RuntimeError(f"managed reconciliation unit changed locally or is missing: {destination}")
+
+    run(["systemctl", "--user", "start", config["user_timer"]])
+    run(["systemctl", "--user", "is-active", "--quiet", config["user_timer"]])
+    run(["systemctl", "--user", "start", config["user_service"]])
+    print("Rigforge desired PipeWire graph reconciled once.")
 
 
 def mod_host_runtime_digest(config):
     state_path = ROOT / "config" / "desired-state.yaml"
     script_path = ROOT / config["configure_script"]
+    validator_path = ROOT / "scripts" / "validate_desired_state.py"
     binary_path = ROOT / config["binary_source"]
     with state_path.open(encoding="utf-8") as stream:
         state = yaml.safe_load(stream)
-    files = [state_path, script_path, binary_path]
-    for processor in state["routing"]["mod_host_chains"]["guitar"]["processors"]:
+    guitar_chain = state["routing"]["mod_host_chains"]["guitar"]
+    mod_host_config = state["deployment"]["mod_host"]
+    files = [script_path, validator_path, binary_path]
+    for processor in guitar_chain["processors"]:
         asset_path = PurePosixPath(processor["asset_path"])
         if asset_path.is_absolute() or ".." in asset_path.parts:
             raise RuntimeError(f"unsafe mod-host asset path: {processor['asset_path']!r}")
@@ -1097,6 +1136,14 @@ def mod_host_runtime_digest(config):
         files.append(resolved)
 
     digest = hashlib.sha256()
+    digest.update(
+        json.dumps(
+            {"deployment.mod_host": mod_host_config, "routing.mod_host_chains.guitar": guitar_chain},
+            sort_keys=True,
+            separators=(",", ":"),
+        ).encode("utf-8")
+        + b"\0"
+    )
     for path in files:
         if not path.is_file():
             raise RuntimeError(f"mod-host runtime input is missing: {path}")
@@ -1114,7 +1161,7 @@ def mod_host_port_is_open(port):
         return False
 
 
-def mod_host_unit_is_active(service_name):
+def user_unit_is_active(service_name):
     result = subprocess.run(
         ["systemctl", "--user", "is-active", "--quiet", service_name],
         check=False,
@@ -1124,7 +1171,7 @@ def mod_host_unit_is_active(service_name):
     return result.returncode == 0
 
 
-def mod_host_unit_is_enabled(service_name):
+def user_unit_is_enabled(service_name):
     result = subprocess.run(
         ["systemctl", "--user", "is-enabled", "--quiet", service_name],
         check=False,
@@ -1175,8 +1222,6 @@ def deploy_mod_host(action, config, registry):
             registry["mod_host"] = managed
             write_registry(registry)
 
-        uninstall_mod_host_reconcile_units(config, registry)
-
         destination_digest = (
             hashlib.sha256(destination.read_bytes()).hexdigest()
             if destination.is_file()
@@ -1246,7 +1291,7 @@ def deploy_mod_host(action, config, registry):
         backup = managed.get("backup")
         backup_sha256 = managed.get("backup_sha256")
     else:
-        if mod_host_unit_is_active(service_name) or mod_host_unit_is_enabled(service_name):
+        if user_unit_is_active(service_name) or user_unit_is_enabled(service_name):
             raise RuntimeError(
                 f"an unmanaged {service_name} is already active or enabled; "
                 "inspect and disable it before installing Rigforge's unit"
@@ -1313,7 +1358,6 @@ def deploy_mod_host(action, config, registry):
     managed.pop("pending_activation", None)
     registry["mod_host"] = managed
     write_registry(registry)
-    install_mod_host_reconcile_units(config, registry)
     print(f"Installed and activated Rigforge mod-host user service at {destination}.")
 
 
@@ -1322,7 +1366,7 @@ def main(argv=None):
     parser.add_argument("action", choices=("install", "uninstall", "reload"))
     parser.add_argument(
         "target",
-        choices=("namlv2", "lsp", "dragonfly-reverb", "pipewire", "mod-host"),
+        choices=("namlv2", "lsp", "dragonfly-reverb", "pipewire", "mod-host", "reconcile"),
     )
     args = parser.parse_args(argv)
     try:
@@ -1338,6 +1382,8 @@ def main(argv=None):
             deploy_pipewire(args.action, deployment["pipewire"], registry, quantum_frames)
         elif args.target == "mod-host":
             deploy_mod_host(args.action, deployment["mod_host"], registry)
+        elif args.target == "reconcile":
+            deploy_reconcile(args.action, deployment["reconcile"], registry)
         else:
             component = "dragonfly_reverb" if args.target == "dragonfly-reverb" else args.target
             deploy_lv2_archives(args.action, component, deployment[component], registry)

+ 2 - 2
scripts/deploy.sh

@@ -2,7 +2,7 @@
 set -u
 
 usage() {
-    printf 'Usage: %s install|uninstall|reload all|namlv2|lsp|dragonfly-reverb|pipewire|mod-host\n' "$0" >&2
+    printf 'Usage: %s install|uninstall|reload all|namlv2|lsp|dragonfly-reverb|pipewire|mod-host|reconcile\n' "$0" >&2
     exit 2
 }
 
@@ -15,7 +15,7 @@ case "$action" in
 esac
 case "$target" in
     all) targets=(pipewire namlv2 lsp dragonfly-reverb) ;;
-    namlv2|lsp|dragonfly-reverb|pipewire|mod-host) targets=("$target") ;;
+    namlv2|lsp|dragonfly-reverb|pipewire|mod-host|reconcile) targets=("$target") ;;
     *) usage ;;
 esac
 

+ 27 - 17
scripts/validate_desired_state.py

@@ -375,43 +375,53 @@ def validate_state(state):
                 ("configure_script", "scripts/configure_mod_host.py"),
                 ("pw_jack_path", "/usr/bin/pw-jack"),
                 ("python_path", "/usr/bin/python3"),
+            ):
+                if mod_host.get(key) != expected:
+                    errors.append(f"deployment.mod_host.{key} must be {expected}")
+            socket_port = mod_host.get("socket_port")
+            if (
+                not isinstance(socket_port, int)
+                or isinstance(socket_port, bool)
+                or not 1 <= socket_port <= 65535
+            ):
+                errors.append("deployment.mod_host.socket_port must be a valid TCP port")
+
+        reconcile = deployment.get("reconcile")
+        if not isinstance(reconcile, dict):
+            errors.append("deployment.reconcile must be a mapping")
+        else:
+            for key, expected in (
                 ("observer_script", "scripts/observe_pipewire.py"),
                 (
-                    "reconcile_service_source",
+                    "service_source",
                     "config/systemd/user/rigforge-pipewire-reconcile.service.in",
                 ),
                 (
-                    "reconcile_service_destination",
+                    "service_destination",
                     ".config/systemd/user/rigforge-pipewire-reconcile.service",
                 ),
-                ("reconcile_service", "rigforge-pipewire-reconcile.service"),
+                ("user_service", "rigforge-pipewire-reconcile.service"),
                 (
-                    "reconcile_timer_source",
+                    "timer_source",
                     "config/systemd/user/rigforge-pipewire-reconcile.timer.in",
                 ),
                 (
-                    "reconcile_timer_destination",
+                    "timer_destination",
                     ".config/systemd/user/rigforge-pipewire-reconcile.timer",
                 ),
-                ("reconcile_timer", "rigforge-pipewire-reconcile.timer"),
-            ):
-                if mod_host.get(key) != expected:
-                    errors.append(f"deployment.mod_host.{key} must be {expected}")
-            socket_port = mod_host.get("socket_port")
-            if (
-                not isinstance(socket_port, int)
-                or isinstance(socket_port, bool)
-                or not 1 <= socket_port <= 65535
+                ("user_timer", "rigforge-pipewire-reconcile.timer"),
+                ("python_path", "/usr/bin/python3"),
             ):
-                errors.append("deployment.mod_host.socket_port must be a valid TCP port")
-            interval = mod_host.get("reconcile_interval_seconds")
+                if reconcile.get(key) != expected:
+                    errors.append(f"deployment.reconcile.{key} must be {expected}")
+            interval = reconcile.get("interval_seconds")
             if (
                 not isinstance(interval, int)
                 or isinstance(interval, bool)
                 or not 5 <= interval <= 300
             ):
                 errors.append(
-                    "deployment.mod_host.reconcile_interval_seconds must be between 5 and 300"
+                    "deployment.reconcile.interval_seconds must be between 5 and 300"
                 )
 
         pipewire = deployment.get("pipewire")

+ 108 - 45
tests/test_deploy.py

@@ -1,4 +1,4 @@
-import io
+import copy
 import io
 import json
 import os
@@ -27,8 +27,8 @@ class DeploymentTests(unittest.TestCase):
         self.run_patcher.start()
         self.home_patcher = patch.object(deploy.Path, "home", return_value=self.home)
         self.home_patcher.start()
-        patch.object(deploy, "mod_host_unit_is_active", return_value=False).start()
-        patch.object(deploy, "mod_host_unit_is_enabled", return_value=False).start()
+        patch.object(deploy, "user_unit_is_active", return_value=False).start()
+        patch.object(deploy, "user_unit_is_enabled", return_value=False).start()
         self.root_patcher = patch.object(deploy, "ROOT", ROOT)
         self.root_patcher.start()
         self.registry_patcher = patch.object(deploy, "STATE_PATH", self.registry_path)
@@ -105,6 +105,9 @@ class DeploymentTests(unittest.TestCase):
     def mod_host_config(self):
         return deploy.load_deployment()["mod_host"]
 
+    def reconcile_config(self):
+        return deploy.load_deployment()["reconcile"]
+
     def make_archive(self, destination, files=None):
         files = files or {"manifest.ttl": b"<urn:nam> a <urn:Plugin> .\n", "plugin.so": b"binary"}
         with tarfile.open(destination, "w:gz") as archive:
@@ -217,11 +220,6 @@ class DeploymentTests(unittest.TestCase):
         self.assertIn("PartOf=pipewire.service wireplumber.service filter-chain.service", content)
         self.assertIn("-n -p 5555", content)
         self.assertIn("configure_mod_host.py", content)
-        reconcile_service = self.home / config["reconcile_service_destination"]
-        reconcile_timer = self.home / config["reconcile_timer_destination"]
-        self.assertIn("--reconcile-once --quiet-if-clean", reconcile_service.read_text(encoding="utf-8"))
-        self.assertIn("SuccessExitStatus=1", reconcile_service.read_text(encoding="utf-8"))
-        self.assertIn("OnUnitActiveSec=15s", reconcile_timer.read_text(encoding="utf-8"))
         self.assertEqual(
             self.commands,
             [
@@ -229,16 +227,12 @@ class DeploymentTests(unittest.TestCase):
                 ["systemctl", "--user", "enable", "rigforge-mod-host.service"],
                 ["systemctl", "--user", "restart", "rigforge-mod-host.service"],
                 ["systemctl", "--user", "is-active", "--quiet", "rigforge-mod-host.service"],
-                ["systemctl", "--user", "daemon-reload"],
-                ["systemctl", "--user", "enable", "rigforge-pipewire-reconcile.timer"],
-                ["systemctl", "--user", "restart", "rigforge-pipewire-reconcile.timer"],
-                ["systemctl", "--user", "is-active", "--quiet", "rigforge-pipewire-reconcile.timer"],
             ],
         )
         registry = deploy.read_registry()
         self.assertTrue(registry["mod_host"]["installed_sha256"])
         self.assertNotIn("pending_activation", registry["mod_host"])
-        self.assertEqual(set(registry["mod_host_reconcile"]["files"]), {"service", "timer"})
+        self.assertNotIn("reconcile", registry)
 
     def test_mod_host_install_is_idempotent_without_restarting_active_audio(self):
         config = self.mod_host_config()
@@ -253,10 +247,6 @@ class DeploymentTests(unittest.TestCase):
                 ["systemctl", "--user", "enable", "rigforge-mod-host.service"],
                 ["systemctl", "--user", "start", "rigforge-mod-host.service"],
                 ["systemctl", "--user", "is-active", "--quiet", "rigforge-mod-host.service"],
-                ["systemctl", "--user", "daemon-reload"],
-                ["systemctl", "--user", "enable", "rigforge-pipewire-reconcile.timer"],
-                ["systemctl", "--user", "start", "rigforge-pipewire-reconcile.timer"],
-                ["systemctl", "--user", "is-active", "--quiet", "rigforge-pipewire-reconcile.timer"],
             ],
         )
 
@@ -274,6 +264,33 @@ class DeploymentTests(unittest.TestCase):
             self.commands,
         )
 
+    def test_mod_host_runtime_digest_ignores_global_reconcile_settings(self):
+        config = self.mod_host_config()
+        state_path = ROOT / "config" / "desired-state.yaml"
+        with state_path.open(encoding="utf-8") as stream:
+            original = deploy.yaml.safe_load(stream)
+        changed_reconcile = copy.deepcopy(original)
+        changed_reconcile["deployment"]["reconcile"]["interval_seconds"] = 30
+        changed_mod_host = copy.deepcopy(original)
+        changed_mod_host["deployment"]["mod_host"]["socket_port"] = 5556
+
+        with patch.object(
+            deploy.yaml,
+            "safe_load",
+            side_effect=[original, changed_reconcile],
+        ):
+            original_digest = deploy.mod_host_runtime_digest(config)
+            reconcile_digest = deploy.mod_host_runtime_digest(config)
+        self.assertEqual(original_digest, reconcile_digest)
+
+        with patch.object(
+            deploy.yaml,
+            "safe_load",
+            return_value=changed_mod_host,
+        ):
+            changed_digest = deploy.mod_host_runtime_digest(config)
+        self.assertNotEqual(original_digest, changed_digest)
+
     def test_mod_host_uninstall_restores_previous_unit(self):
         config = self.mod_host_config()
         destination = self.home / config["service_destination"]
@@ -288,49 +305,103 @@ class DeploymentTests(unittest.TestCase):
         self.assertEqual(
             self.commands,
             [
-                ["systemctl", "--user", "disable", "--now", "rigforge-pipewire-reconcile.timer"],
-                ["systemctl", "--user", "stop", "rigforge-pipewire-reconcile.service"],
-                ["systemctl", "--user", "daemon-reload"],
                 ["systemctl", "--user", "disable", "--now", "rigforge-mod-host.service"],
                 ["systemctl", "--user", "daemon-reload"],
             ],
         )
-        self.assertFalse((self.home / config["reconcile_service_destination"]).exists())
-        self.assertFalse((self.home / config["reconcile_timer_destination"]).exists())
 
-    def test_mod_host_uninstall_restores_prior_reconcile_units(self):
-        config = self.mod_host_config()
+    def test_reconcile_install_and_uninstall_restores_prior_units(self):
+        config = self.reconcile_config()
         prior_contents = {
-            config["reconcile_service_destination"]: "prior reconcile service",
-            config["reconcile_timer_destination"]: "prior reconcile timer",
+            config["service_destination"]: "prior reconcile service",
+            config["timer_destination"]: "prior reconcile timer",
         }
         for relative_path, content in prior_contents.items():
             destination = self.home / relative_path
             destination.parent.mkdir(parents=True, exist_ok=True)
             destination.write_text(content, encoding="utf-8")
 
-        with patch.object(deploy, "mod_host_port_is_open", return_value=False):
-            deploy.deploy_mod_host("install", config, deploy.read_registry())
-        deploy.deploy_mod_host("uninstall", config, deploy.read_registry())
+        deploy.deploy_reconcile("install", config, deploy.read_registry())
+        reconcile_service = self.home / config["service_destination"]
+        reconcile_timer = self.home / config["timer_destination"]
+        self.assertIn("--reconcile-once --quiet-if-clean", reconcile_service.read_text(encoding="utf-8"))
+        self.assertIn("SuccessExitStatus=1", reconcile_service.read_text(encoding="utf-8"))
+        self.assertNotIn("rigforge-mod-host.service", reconcile_service.read_text(encoding="utf-8"))
+        self.assertIn("OnUnitActiveSec=15s", reconcile_timer.read_text(encoding="utf-8"))
+        self.assertEqual(
+            self.commands,
+            [
+                ["systemctl", "--user", "daemon-reload"],
+                ["systemctl", "--user", "enable", "rigforge-pipewire-reconcile.timer"],
+                ["systemctl", "--user", "restart", "rigforge-pipewire-reconcile.timer"],
+                ["systemctl", "--user", "is-active", "--quiet", "rigforge-pipewire-reconcile.timer"],
+            ],
+        )
+
+        self.commands.clear()
+        deploy.deploy_reconcile("uninstall", config, deploy.read_registry())
 
         for relative_path, content in prior_contents.items():
             self.assertEqual((self.home / relative_path).read_text(encoding="utf-8"), content)
-        self.assertNotIn("mod_host_reconcile", deploy.read_registry())
+        self.assertNotIn("reconcile", deploy.read_registry())
+        self.assertEqual(
+            self.commands,
+            [
+                ["systemctl", "--user", "disable", "--now", "rigforge-pipewire-reconcile.timer"],
+                ["systemctl", "--user", "stop", "rigforge-pipewire-reconcile.service"],
+                ["systemctl", "--user", "daemon-reload"],
+            ],
+        )
 
-    def test_mod_host_uninstall_refuses_local_reconcile_unit_edits(self):
-        config = self.mod_host_config()
-        with patch.object(deploy, "mod_host_port_is_open", return_value=False):
-            deploy.deploy_mod_host("install", config, deploy.read_registry())
-        timer = self.home / config["reconcile_timer_destination"]
+    def test_reconcile_uninstall_refuses_local_unit_edits(self):
+        config = self.reconcile_config()
+        deploy.deploy_reconcile("install", config, deploy.read_registry())
+        timer = self.home / config["timer_destination"]
         timer.write_text("local edit", encoding="utf-8")
         self.commands.clear()
 
         with self.assertRaisesRegex(RuntimeError, "changed locally"):
-            deploy.deploy_mod_host("uninstall", config, deploy.read_registry())
+            deploy.deploy_reconcile("uninstall", config, deploy.read_registry())
 
         self.assertEqual(timer.read_text(encoding="utf-8"), "local edit")
         self.assertEqual(self.commands, [])
 
+    def test_reconcile_reload_runs_one_shot_without_restarting_mod_host(self):
+        config = self.reconcile_config()
+        deploy.deploy_reconcile("install", config, deploy.read_registry())
+        self.commands.clear()
+
+        deploy.deploy_reconcile("reload", config, deploy.read_registry())
+
+        self.assertEqual(
+            self.commands,
+            [
+                ["systemctl", "--user", "start", "rigforge-pipewire-reconcile.timer"],
+                ["systemctl", "--user", "is-active", "--quiet", "rigforge-pipewire-reconcile.timer"],
+                ["systemctl", "--user", "start", "rigforge-pipewire-reconcile.service"],
+            ],
+        )
+
+    def test_mod_host_install_and_uninstall_do_not_manage_reconcile_timer(self):
+        reconcile_config = self.reconcile_config()
+        mod_host_config = self.mod_host_config()
+        deploy.deploy_reconcile("install", reconcile_config, deploy.read_registry())
+        reconcile_paths = {
+            reconcile_config["service_destination"],
+            reconcile_config["timer_destination"],
+        }
+        self.commands.clear()
+
+        with patch.object(deploy, "mod_host_port_is_open", return_value=False):
+            deploy.deploy_mod_host("install", mod_host_config, deploy.read_registry())
+        deploy.deploy_mod_host("uninstall", mod_host_config, deploy.read_registry())
+
+        registry = deploy.read_registry()
+        self.assertIn("reconcile", registry)
+        for relative_path in reconcile_paths:
+            self.assertTrue((self.home / relative_path).is_file())
+        self.assertFalse(any("rigforge-pipewire-reconcile" in " ".join(command) for command in self.commands))
+
     def test_mod_host_pending_uninstall_recovers_after_prior_unit_is_restored(self):
         config = self.mod_host_config()
         destination = self.home / config["service_destination"]
@@ -350,15 +421,7 @@ class DeploymentTests(unittest.TestCase):
 
         self.assertEqual(destination.read_text(encoding="utf-8"), "prior unit")
         self.assertNotIn("mod_host", deploy.read_registry())
-        self.assertEqual(
-            self.commands,
-            [
-                ["systemctl", "--user", "disable", "--now", "rigforge-pipewire-reconcile.timer"],
-                ["systemctl", "--user", "stop", "rigforge-pipewire-reconcile.service"],
-                ["systemctl", "--user", "daemon-reload"],
-                ["systemctl", "--user", "daemon-reload"],
-            ],
-        )
+        self.assertEqual(self.commands, [["systemctl", "--user", "daemon-reload"]])
 
     def test_mod_host_uninstall_refuses_local_unit_edits(self):
         config = self.mod_host_config()

+ 15 - 0
tests/test_desired_state.py

@@ -161,6 +161,21 @@ class DesiredStateValidationTests(unittest.TestCase):
         state["deployment"]["mod_host"]["socket_port"] = 70000
         self.assertIn("deployment.mod_host.socket_port must be a valid TCP port", validate_state(state))
 
+        state = copy.deepcopy(self.state)
+        self.assertEqual(
+            state["deployment"]["reconcile"]["user_timer"],
+            "rigforge-pipewire-reconcile.timer",
+        )
+        state["deployment"]["reconcile"]["interval_seconds"] = 2
+        self.assertIn(
+            "deployment.reconcile.interval_seconds must be between 5 and 300",
+            validate_state(state),
+        )
+
+        state = copy.deepcopy(self.state)
+        del state["deployment"]["reconcile"]
+        self.assertIn("deployment.reconcile must be a mapping", validate_state(state))
+
     def test_return_exclusion_marker_is_not_an_active_connection(self):
         self.assertEqual(validate_state(self.state), [])