Engine

How RCX gathers evidence, recognizes networks, decides, switches and spends probes, with the exact rules and defaults.

On this page

Evidence

Evidence is kept per server and per network environment (Wi-Fi, carrier or gateway, hashed with an install salt). At most 16 environments are kept; the least recently used is evicted.

FactRule
Latency samplesThe last 8 within 6 hours. p50 is the median; spread is p90 − p50.
EpisodesFailure episodes in the last 24 hours, at most 16.
FreshnessA success is fresh for 45 minutes, or 3 hours once the environment is 2 hours old.
Check resultsKept 6 hours. A pass is overturned only by a second consecutive failure; one failure after a pass makes the result unknown.
Exit countryGlobal per server, 24 hours. A disagreeing lookup is retried after 2 hours.
Dial failures3 failed dials within 20 seconds, with no success between them, make the server suspect.

Sources: engine probes, mihomo URL tests and real traffic, which counts as a success.

Health

HealthCondition
deadMarked dead and no success since.
aliveA fresh success and no failure after it.
staleA success exists but is not fresh, or a failure followed it.
unknownNever succeeded.

Score

rank.byScore
latencyp50 + spread/2 + 50 × episodes
stabilityp50 + spread + 300 × episodes

An unmeasured server scores 2²⁰. Lower is better.

Exit country

Echo services are queried through the server one at a time until the answer settles; each service host is one vote. A local GeoIP lookup of the reported address adds one vote. A country is accepted only when every valid vote names it and at least agree distinct sources voted (default 2). XX, T1 and EU are rejected; until then exit.country is unknown. Default echo services: https://www.cloudflare.com/cdn-cgi/trace and https://ipinfo.io/json.

Network kinds

A profile or scenario declares kinds as an ordered list of rules over network conditions and direct diagnostics.

  • The first rule whose condition is true names the kind; an unknown rule leaves the kind undecided.

  • Moving from no kind to a kind applies at once. Moving between kinds, or back to none, needs 2 agreeing rounds.

  • The kind is remembered per environment, separately for each profile and for the scenario.

  • A kind with pause: true holds the group (hold.paused) and stops its checks while it lasts.

  • Diagnostics are shared by all groups and the scenario, deduplicated per target, and retried after 5, 10, then 30 minutes.

Decision

The decision for a group runs on every change of policy, evidence or context. It is a pure function of them, its explanation is the ranking it decided on, and it never performs I/O.

Eligibility

Each member is tested in this order; the first match excludes it.

CodeExcluded when
pool.no-matchpool.include is false (unknown admits).
pool.excludedpool.exclude is true.
pool.unroutableThe member is REJECT, REJECT-DROP, PASS, COMPATIBLE, DIRECT or DNS.
cooldownIt was left by Change server less than 15 minutes ago.
deadIts health is dead.
pendingNo tier is true yet, but one is unknown; the first unknown tier is recorded.
no-tierEvery tier is false.

An eligible member takes the first tier whose condition is true. Last-resort tiers sort after all other tiers, wherever they are.

Ranking

Members sort by: eligible first, tier, health (alive, stale, unknown, dead), effective score, name. The current member's effective score is its score minus rank.tolerance, when measured. The first row is the best candidate. Up to 2 pending members whose unknown tier beats the best candidate's are queued for a check each decision.

Order

  1. Control manual: action manual; nothing else runs.

  2. Scenario to member, unless pinned: hold.fixed, switch.fixed or fixed.missing, which keeps the current member.

  3. Network kind with pause: hold.paused.

  4. Pin, if the pinned member is present, not dead and not excluded: hold.pinned or switch.pinned. Otherwise the pin waits and the pinned member is queued for a check.

  5. No best candidate: hold.no-alternative if the current member is on cooldown, else stranded.

  6. Switching rules below.

Switching

StepConditionResult
1No current memberswitch.initial
2Change server was requested and the best is another memberswitch.change-server
3Current member is deadswitch.failover; its connections are closed
4Current member is excluded for any reason but cooldownswitch.out-of-pool
5Current member on cooldown and no alternativehold.no-alternative
6Best is the current memberhold.best
7Best is in a better tierswitch.better-tier if it is alive and was checked within 5 minutes; otherwise hold.checking until a check
8improve: falsehold.working
9Either side unmeasured, or the score gain is below the needhold.best
10Last switch within dwellhold.dwell
11max-per-hour switches reachedhold.flap-limit
12Fewer than confirm fresh samples beat the current member by the needhold.confirming
13Otherwiseswitch.faster

The need is max(min-gain-ms, score × min-gain-pct / 100, tolerance), computed on the current member's score. confirm counts the most recent consecutive fresh samples of the candidate at or below current score − need.

Stranded

strandedResult
hold (default)Keep the current member: stranded.no-candidates.
directSelect DIRECT: switch.stranded.
group:<name>Select the member <name> if the group has it: switch.stranded.

Feel presets

feeldwellmin-gain-msmin-gain-pctconfirmmax-per-hour
calm30m603032
balanced (default)10m302024
eager2m151028

Explicit switch fields override the preset.

Probing

The planner buys only probes that can change a decision. At most 2 run at once, each with a 5-second timeout. A server is not probed again within 1 minute, except to confirm a failure.

Modes

The first matching mode applies.

ModeWhenAllowed
StoppedThe core is not runningNothing
SleepAndroid DozeNothing
BackgroundScreen offRecovery, only after real dial failures
EcoMetered network, power saving, low battery or on batteryRecovery; needs and maintenance within a window; forced diagnostics
ActiveWithin 10 s of traffic or 30 s of a network changeEverything, including discovery
IdleOtherwiseRecovery

A window opens for 10 s on traffic and for 30 s on a network change. Needs, maintenance and discovery need an open window and wait 10 seconds after wake. Diagnostics run in Active, or in Eco after a network change or while a kind awaits confirmation.

Budgets

Each group's energy sets hourly token buckets. The machine uses the highest level among its groups; any Eco condition forces eco.

energyMaintainDiscoverRecoverNetworkStandby check every
eco401282 h
balanced (default)1012241245 min
precise2040402030 min

Each request counts as 6 KiB against a daily cap of 20 MiB. Only user checks and recovery may exceed the cap; user checks are never rationed.

Probe kinds

KindWhat
RecoverDead or suspect servers, 4 per pass, with backoff 0, 5, 10, 20, 40 minutes.
NeedPending members, the pinned member, or a better-tier candidate; paid from the discover bucket.
MaintainTwo standbys, plus the current member when the profile improves or uses checks or exit country, every standby interval.
DiscoverTwo unmeasured members per window with distinct server addresses; only with improve: true and in Active.
ExtrasChecks and the exit lookup ride on a successful probe, one request each from the same bucket.
UserThe check action: every routable member with all extras.

Failure handling

Failures seen while nothing gets through condemn no server.

  • The link is proven when anything succeeded within the last minute. A resume or network change resets it.

  • A failed probe marks a server dead only when the link is proven and the server failed at least twice in a row.

  • A suspect current member is confirmed together with the best standby. If both fail, or there is no standby on an unproven link, the journal records network.suspect and the server backs off. Only the current member failing marks it dead (failure.confirmed), which triggers switch.failover.

Direct split

While active, connections that matched an explicit DIRECT rule go through the group instead.

  • It needs both the profile's direct-split condition and the user's toggle on the group; a subscription cannot turn it on.

  • It never applies to the final MATCH rule or to local destinations: private, loopback, link-local, multicast, unspecified, 100.64.0.0/10, and names that resolve only on the LAN. UDP is split only when the group's member supports UDP.

  • Per-group state: off, standby (core stopped, no members, manual control, paused kind, or condition not true), or active. The first active group in order takes the traffic. Transitions are journaled as split.on and split.off.

Control

ActionEffect
AutoThe decision runs as above; clears a pin.
PinHolds the chosen member while it works and returns to it when it recovers. The core can limit a pin to the current network; the app pins on every network.
ManualThe engine never switches and runs no checks; provider health checks are not suppressed.
Change serverPuts the current member on a 15-minute cooldown, clears a pin and forces a switch.
CheckOne user-bucket probe of every routable member. The core accepts it; the app does not offer it.

Picking a server by hand in the proxies list pins it (pin.manual in the journal) unless the group is in Manual. While a group is smart and not manual or idle, the engine replaces the automatic health check of every provider that serves its members.

Explanations and journal

Why this server returns the decision: action, target, reason, tier, the time a hold expires (until), and the full ranking. Each row carries name, tier and label, health, latency, spread, score, episodes, last check, current flag, exclusion reason, exit country, check results (pass, fail, soft) and the pending tier.

The journal keeps the last 200 entries of kinds switch, stranded, change, pin, auto, manual, network, mode, split and failure. It is saved with the engine state, at most 1 MiB.

Guarantees

GuaranteeStatement
LayersProvider and user layers only narrow a profile's pool; an invalid profile or unusable group is a visible problem.
ConsentA provider profile contacts third-party hosts only after the user allows them; until then the group runs builtin/simple and says why.
Server orderAn order falls through once every server on a step is down; a last-resort step yields to every other step; a scenario program's order beats the user's, which beats the profile's.
ScenarioA scenario sets the tunnel mode only until the user picks one, and drives only the groups it names.
RoutesRoutes become groups and rules only at config apply, steer traffic only in rule mode, never take over an existing group, and a route that cannot apply is a visible problem.
BundleAn export carries every non-built-in profile it references; an import never replaces a profile the user already has.
Thin forkThe mihomo fork carries provider health-check suppression, route fingerprints and direct-split hooks plus minimal safety hooks; policy interpretation stays in the ReClash core.

Searches every section: providers and RCX