Switching a Policy Group Without a Mixed-State Tunnel | Raven
Frequently asked questions
- Can I switch policy groups without the tunnel ending up in a mixed state?
- Yes. Profile refreshes and policy changes publish versioned snapshots, and the live tunnel accepts only the matching revision.
- What routing modes does Raven support?
- Rule, Global and Direct, with select and URL-test policy groups.
- What does the versioned snapshot prevent?
- Old and new state crossing over — the tunnel never runs a mixture of two configurations.
- Where do profiles and credentials live?
- On device, in the shared app group container, with redacted diagnostics staying local too.
- Does switching a policy group re-download and re-import my whole profile?
- Not when only one group changed. If the profile is byte-identical and exactly one selection differs, Raven issues a single group switch to the running core instead of a full re-import.
- What happens if the tunnel is still connecting when I switch?
- Live provider operations are only attempted while the tunnel is connected or reasserting. Otherwise the change waits for the tunnel, and the tunnel picks it up once it is live.
The short answer
When you switch a policy group in Raven, the app does not reach into the tunnel and change one setting. It publishes a new profile snapshot with a new revision ID, then asks the packet tunnel to apply that specific revision. The tunnel reads the currently published snapshot out of the shared container itself, compares the revision it was handed against the revision actually on disk, and refuses the command if the two disagree. There is no path where a selection from one revision is combined with a profile from another: there is only one snapshot file, and the tunnel accepts only the revision it can prove is that file.
Why mixed state is the failure you are actually avoiding
A network client holds two things that must agree: the configuration you asked for, and the configuration the tunnel is actually running. That is easy to break, because the ways it breaks are ordinary events on iOS. A subscription refresh lands while you are halfway through tapping through policy groups. A Control Center toggle fires the connection while an app-side write is in flight. The provider extension is mid-restart and answers late. In a client that mutates shared state incrementally, each is a chance to run a configuration nobody chose.
The symptom is nasty because it is intermittent. Traffic mostly works. One group points at the old node, another at the new one, and the rule set may be from a profile that no longer exists. Nothing crashes; you get a connection wrong in a way you cannot name, and the settings screen will display a state the tunnel is not running.
Raven removes the possibility structurally rather than adding a check per race. There is a single publisher of state, and the consumer names the exact revision it is willing to accept.
What a revision actually is
The unit that gets published is a complete snapshot, not a diff. It carries:
- a schema version and a revision UUID,
- the source ID of the profile it came from,
- the raw YAML and the resources it references,
- a descriptor: display name, nodes with availability flags, select groups, automatic URL-test groups, and the ordered rule list,
- the full set of selections — one chosen member per select group,
- the routing mode:
rule,direct, orglobalbound to a specific policy ID, - the updated at timestamp.
Every action that changes state constructs a brand-new snapshot, and since the revision defaults to a freshly generated UUID, a tap on a policy group mints a new revision just as downloading a profile does. Switching a group and refreshing a subscription are then the same kind of event to the tunnel — one commit shape means one place where atomicity must hold, instead of two code paths disagreeing about what "applied" means.
Validation runs before publication and again on read, so a written snapshot is one already checked:
schema version must match, YAML must be non-empty and within budget, every resource must have a
unique identity and stay inside both its per-kind and aggregate caps, group IDs must be unique, a
group's default member must be one of its members, every select group must have a selection, and
a global mode must name a policy that exists among the available nodes and groups. A snapshot
failing any of these is never written over the working one.
The file is written atomically into the app group container under Library/Raven/, with iOS file
protection applied, and is capped at 64 MiB encoded. The tunnel is handed only an app group
identifier and a snapshot file name through the network extension configuration — never a payload.
The file name is validated as a single path component, so nothing can redirect the provider
elsewhere.
The handshake the tunnel actually performs
The app talks to the extension through three commands — applySnapshot, select, and queryStatus —
each carrying a protocol version, with a 16 KiB ceiling on both message and reply.
The interesting part is the two-sided check. When the app asks the tunnel to apply revision R:
- The provider loads the active snapshot from disk itself, rather than trusting the app to report what is currently published.
- It compares. If the on-disk revision is not R, it replies
snapshot_mismatchand reports the revision it is actually running. Nothing is applied. - The app verifies the reply independently: a successful apply must return
activeRevisionequal to the revision it asked for. Anything else is a mismatch failure, not a success.
A race between two rapid taps therefore resolves the safe way. Tap group A, then B. If revision A is superseded on disk before the provider reads it, the tunnel rejects A and reports B; if the provider applied A first and then receives B, it applies B. It will never apply a revision that is no longer published, and the app never reports success for a revision the tunnel did not confirm.
Three ways a change is applied
Not every change costs the same. Raven compares the active snapshot against the desired one:
- Unchanged. The profile is identical and no selection differs. No core call at all.
- Single selection. The schema, source, YAML, resources, descriptor, routing mode, and timestamp all match, and exactly one group's selection changed. A single group switch goes to the running core. The profile is not re-imported.
- Full application. Two or more selections changed, or anything about the profile itself changed. The profile is re-imported and applied together with the routing mode and global policy ID in one call.
A single group switch is only issued when the profile is byte-identical, so the rule set the running core holds is provably the one you want. When the profile has changed, Raven does not patch; it re-applies everything together. The comparison is conservative: duplicate or absent selections fall back to a full application rather than a cheap change.
What gets rejected, retried, and discarded
The provider's error vocabulary is specific, because each name means something different about what
the tunnel is running: snapshot_mismatch (stale revision), snapshot_unavailable (nothing to apply
against), profile_invalid (import failed), snapshot_apply_failed (the core refused),
unsupported_version (protocol skew), and provider_unavailable (nothing running).
The app side has to decide whether a reply is still relevant, since it may come back after the world moved on. Every in-flight operation carries a token holding an operation ID, a generation, a connection epoch, and the revision it was issued for. A reply is accepted only if all four still match and the tunnel is still in a state where live operations make sense. A late reply from a superseded operation is discarded, and the pipeline re-drives from current state.
Provider failures are retried before the state settles into failed, and it settles with a named
cause — profile observation, provider query, snapshot apply, or tunnel disconnect — so the failure
tells you which stage gave out rather than just that something did.
Live operations are only attempted while the tunnel status is connected or reasserting; otherwise
the change is held as desired state and applied when the tunnel is ready, so a configuration changed
while the VPN was off takes effect on connection.
Limits worth stating plainly
Raven has no proxy servers, no accounts, and no telemetry system; profiles, credentials, selections, and redacted diagnostics stay on device. The real edges:
- The
selectcommand kind exists in the protocol, and the running extension answers it as an invalid command. Selection changes therefore travel as a new published snapshot and reach the core through the transition logic above — there is no separate fast lane for a bare selection command. - The app and extension must agree on the protocol version; a skew is rejected, not guessed at. If a snapshot write fails, the previous selections are restored, but the failure stays visible rather than leaving you silently half-changed.
- Global mode must name a policy available in the loaded descriptor. Naming one that does not exist is refused before anything is written.
- The app requires iOS 17; the Control Center and Lock Screen control extension requires iOS 18.
What Raven does differently
Most clients treat "the tunnel is running something" and "the UI shows something" as two facts that happen to agree. Raven treats them as one fact with two readers: one publisher of versioned state, and a consumer that refuses anything it cannot identify.
The Control Center toggle does not fire a bare start: it registers a ticket carrying a generation, and the mutation runs only if that ticket is still current. Operations are serialized. Stale replies are rejected on four independent axes. Every provider command and reply is recorded as a diagnostic with its outcome, byte count, and protocol version, so "why is my tunnel running that" is answerable rather than reconstructed.
The honest limit is that this buys correctness, not speed. A full profile change re-imports and a rejected revision means a retry. For the fastest path, keep selections stable and let the automatic URL-test groups do the switching — they move traffic between members without minting a new revision on every hop.
If your client has ever left you wondering which configuration it is running, look past the feature list: can you name the exact revision your tunnel is on, and does the app refuse success for a revision the tunnel did not confirm? Raven builds that in from the snapshot file outward — more on the Raven product page.