# Shadow Mode and Safe Rollback: Shipping Model Updates to an Edge Fleet

> Source: <https://dev.to/mp3sss31/shadow-mode-and-safe-rollback-shipping-model-updates-to-an-edge-fleet-4i9m>
> Published: 2026-12-01 00:42:59+00:00

**Recommendation:** Ship signed model bundles with a manifest the device verifies before swapping models, and gate rollouts on shadow-mode disagreement rates and cohort canaries rather than redeploying blindly.
More in the playbook "Running AI in production": <https://wpnews.pro/playbooks/production-ops>

Updating a model on 5,000 devices behind NAT, on cellular links, is a different discipline from updating a web service. You cannot roll back by redeploying. You cannot read the logs. Some devices are offline for days. And a bad update can make every device confidently wrong at once.

This post describes the pipeline that makes that survivable: shadow mode, cohort canaries, guardrail metrics, and a manifest that keeps version skew visible.

A model is not one file. Ship a signed bundle with everything inference needs, described by a manifest that the device can verify *before* it stops running the current model:

```
{
  "model_id": "vib-anomaly",
  "version": "3.2.0",
  "created_at": "2026-11-20T04:12:00Z",
  "framework": "tflite-micro",
  "files": {
    "model.tflite": { "sha256": "9f2c...", "bytes": 98304 },
    "normalizer.json": { "sha256": "41ab...", "bytes": 512 }
  },
  "input": { "shape": [1, 512, 3], "dtype": "int8", "scaler": "rolling_zscore_v2" },
  "feature_set_hash": "7d19c0e2",
  "min_firmware": "1.8.0",
  "target": { "ram_kb_max": 160, "latency_ms_p99_max": 25 },
  "metrics": { "alarm_rate_expected": 0.0041, "alarm_rate_tolerance": 0.5 },
  "signature": "MEUCIQ..."
}
```

Four fields carry disproportionate weight:

`feature_set_hash`` min_firmware``alarm_rate_expected`` signature`
Shadow mode is the highest-value step in the whole pipeline and the one teams skip most often. The new model runs on live data alongside the old one; only the old one's decisions are acted upon.

```
class ShadowRunner:
    """Run a candidate model beside production; log divergence, act on nothing."""

    def __init__(self, prod_model, shadow_model, sink, warn_ratio=1.5):
        self.prod, self.shadow, self.sink = prod_model, shadow_model, sink
        self.warn_ratio = warn_ratio
        self.n = self.disagree = self.shadow_only = self.prod_only = 0

    def step(self, window, context):
        p = self.prod.score(window)
        s = self.shadow.score(window)
        p_alarm, s_alarm = p > self.prod.threshold, s > self.shadow.threshold

        self.n += 1
        self.disagree += int(p_alarm != s_alarm)
        self.shadow_only += int(s_alarm and not p_alarm)
        self.prod_only += int(p_alarm and not s_alarm)

        # sample aggressively on disagreement, sparsely otherwise
        if p_alarm != s_alarm or self.n % 500 == 0:
            self.sink.write({
                "ts": context["ts"],
                "device": context["device_id"],
                "prod_score": round(float(p), 4),
                "shadow_score": round(float(s), 4),
                "corroboration": context.get("corroboration"),
                "window_ref": context.get("ring_buffer_ref"),
            })
        return p_alarm

    def report(self) -> dict:
        return {
            "n": self.n,
            "disagreement_rate": self.disagree / max(self.n, 1),
            "shadow_only": self.shadow_only,
            "prod_only": self.prod_only,
        }
```

Two details make shadow mode actually usable:

**Log the corroborating signals, not just scores.** When the shadow model disagrees, you need to know whether it did so with or without a second independent signal (temperature rising, current anomaly). Divergence *with* corroboration is a potential catch; divergence *without* is probably a false positive.

**Sample the raw window reference.** A ring-buffer reference lets you pull the actual waveform for a sample of disagreements, which is the difference between "the new model is worse" and "the new model is better and we can prove it".

It can tell you: disagreement rate, which direction the disagreement goes, whether the new model fires on windows with corroborating evidence, and whether latency and memory fit in the real duty cycle.

It cannot tell you: whether the new model is *right*. Shadow mode has no labels. It reduces the risk of shipping a catastrophically wrong model; it does not validate accuracy. For that you need the labelled incidents from a later post in this series.

Randomly selecting 1% of devices is a bad idea when your fleet is heterogeneous. Select a cohort that is representative and low-stakes:

```
cohort A: 12 devices, one site, mixed models, monitored by an engaged technician
cohort B: 60 devices, three sites, all machine types
cohort C: remainder
```

Promotion gates, checked after a fixed observation period (not a fixed event count):

| Gate | Threshold | Action on breach | 
|---|---|---|
| Alarm rate vs. expected | within ±50% | auto-rollback | 
| p99 latency | ≤ manifest budget | auto-rollback | 
| Crash / watchdog resets | ≤ baseline + 0 | auto-rollback | 
| Shadow disagreement on cohort | ≤ 20% | hold, investigate | 
| Operator disposition (spot check) | ≥ 70% actionable | hold | 

The alarm-rate gate is the one that catches the most real failures, because a broken model usually fails *loudly* — it fires constantly. Note that the tolerance is relative to `alarm_rate_expected` from the manifest, which is why that field must be computed from the validation set at training time, not guessed.

Design rollback as "switch a pointer back", not "download and reinstall":

``` php
def activate(bundle_path: str, expected_sha: str, pubkey: str, slot: str) -> None:
    verify_signature(bundle_path, pubkey)
    assert sha256_file(bundle_path) == expected_sha
    self_test(bundle_path)                 # run one inference with a fixture, check output
    nvs_write("active_model_slot", slot)   # single atomic-ish write
    reboot()
```

If `self_test()` fails at boot, the bootloader falls back to the other slot. This is the same A/B slot pattern used by firmware update systems, and there is no reason models should be less careful than firmware.

Real fleets are never uniformly up to date. A model rollout will stall at 85% and the rest will be a long tail of devices that are offline, behind a broken gateway, or have an old firmware.

Make skew visible and bounded:

``` python
def fleet_skew(inventory):
    from collections import Counter
    c = Counter(d["active_model_version"] for d in inventory)
    total = sum(c.values())
    return {v: {"count": n, "share": round(n / total, 3)} for v, n in c.most_common()}

# alert when an old version persists beyond its support window
def stale_versions(skew, supported: set[str], max_unsupported_share=0.02):
    unsupported = sum(v["count"] for ver, v in skew.items() if ver not in supported)
    return unsupported / sum(v["count"] for v in skew.values()) > max_unsupported_share
```

Two policies that keep this from becoming permanent debt:

That last item matters more than it looks. A rollback path that has never been executed is a hypothesis, and the worst time to discover it does not work is during a bad rollout at 2 a.m.

*Next: LLM-Assisted Triage for IoT Alerts — Turning 10,000 Alarms into 10 Tickets.*
