Skip to content

Contributor wave 14: VMess link TLS fields, provider app-message hook, traffic-triggered re-probes (#346, #347, #349, #308) - #350

Merged
aimalygin merged 11 commits into
mainfrom
claude/contributor-wave-14
Nov 24, 2026
Merged

aimalygin merged 11 commits into
mainfrom
claude/contributor-wave-14

Conversation

@aimalygin

Copy link
Copy Markdown
Owner

Merge commits of the unchanged heads of #346, #347 and #349, and of #308 with one commit on top of its head, on current main (06ad5e2), so that the original PRs close as merged. One fix on top of #349.

PR Merged at What
#346 0c8e799 A base64 JSON vmess:// link without TLS imports when it carries sni, alpn or fp; the fields are ignored instead of failing the import
#347 51e7123 The Swift and Kotlin doc comments of the outbound probe say what a core that is loaded and not started answers
#349 7d52237 XrayPacketTunnelProvider has an open handleCustomAppMessage(_:core:) hook for a subclass's own app messages
#308 1a0eedb A flow that fails to open through an outbound the observatory watches has it probed again within seconds instead of at the next probeInterval

#308 and the commit on top of it

The review of #308 left one point open: re-probe results went into the 16-sample window leastLoad reads for tolerance, the average and the deviation, so one outage wrote several failures where the scheduled round would have written one, and they outlived the outage. The author has not answered since 2026-11-17.

dec0iiyy wrote that change as one commit on top of the pull request's head and offered it to the author's branch. It is merged here at 1a0eedb, whose parent is #308's head 7b68352, so the pull request's own two commits are in unchanged and it closes as merged.

What the commit does: a re-probe still sets the health state, the last delay and the failure count, so leastPing and the quick move away from a dead server are as #308 made them; only a probe of the scheduled round adds a sample to the window. reprobes_leave_the_least_load_window_to_the_scheduled_round runs three scheduled probes, then a failed re-probe, the confirming probe, a recheck and a successful recheck against a SOCKS server that is switched off and on, and holds the window at (3, 1) throughout while the state goes unhealthy and back. docs/config-compatibility.md and the CHANGELOG.md entry say that the window counts scheduled probes only.

Conflicts

Fix on top of #349 (e98a08a)

apple: hand app messages that are not text to handleCustomAppMessage

handleAppMessage dropped a message that is not valid UTF-8 before the new hook could see it, while the hook's documentation promises every message the provider does not handle itself. A host whose app and extension speak a binary format, a property list or protobuf, would have had its messages answered with nil.

The provider now decodes the text only to recognise its own requests, which are text. A message that is not text names none of them, goes to the hook, and without an answer from it gets nil as before. A host that does not override the hook sees no change. The doc comment and platform/apple/README.md say that the message need not be text.

Review notes

#346:

  • With tls absent, empty or none, the JSON dialect removes sni, alpn and fp before the stream mapping. The REALITY fields are not removed, so a plain link that carries pbk still fails. A link with TLS and the URI dialect are untouched.
  • The pull request says v2rayN builds TLS settings only when tls names a security. That was not checked against v2rayN's source here.

#347:

  • Comments only. The three facts they state hold in the code: the Swift wrapper throws XrayCoreError.notRunning from withDataPathHandle before the C call, the C API documents RUNTIME_ERROR for a loaded core that is not running, and preflightStartupProbe exists in both wrappers.

#349:

  • App messages reach a provider only from its containing app, so the hook adds no surface towards anything outside the host's own code.
  • The hook is not called for the stats request, and the close-connections request is answered before it, so a subclass cannot change either.
  • The subclass is handed the live XrayCore, whose start and stop are public. Nothing but the doc comment keeps a host from calling them. A subclass that keeps the core past the call still goes through the wrapper's call gate on every call, which checks the handle and throws once it is gone.
  • The handler had no test before this pull request and has none now: the hook is reached only with an active runtime.

#308:

Security check of the five commits that are new to this repository (#346, #347, #349, the two of #308, and the one on top): gitleaks with the repository's configuration finds nothing in them; none touches a workflow, a script, a manifest, a build script or Cargo.lock; none adds unsafe or a binary file. The fix on top touches one Swift file and one README.

Verification

🤖 Generated with Claude Code

Loretiks and others added 11 commits November 17, 2026 19:32
Outbound health only changed through the observatory's periodic probes,
and its interval sleep could not be woken. With leastPing and a long
probeInterval, a server that died stayed selected until the next round:
up to ten minutes with probeInterval 10m, every new flow failing.

Flows now report failed opens. SOCKS/HTTP CONNECT, HTTP forwarding and
TUN TCP (DNS TCP proxy included), and TUN UDP report the leaf they were
routed to when its open times out or fails with a refused, reset or
timed-out connection or a TLS, REALITY or transport handshake error.
Remote closes, target refusals, DNS errors and a down local network are
not reported. A report is a per-leaf atomic flag in the selection
overlay plus one Notify wake-up, and only on the error path.

The observatory watches its observed leaves and each observed balancer's
fallback (fallbackTag or the default outbound). Its interval wait is now
woken by reports: a reported leaf is probed again once 10 s have passed
since its last probe, and when no observed member of a balancer is
healthy, a failure through a member or the fallback has all members
probed again, at most once per 15 s. Probe results go through the
existing record path, so a failed re-probe moves leastPing to the next
healthy member and a success keeps or restores the leaf. The scheduled
round is unchanged and re-probes reuse its concurrency bound; without
reports behaviour is as before. State is bounded by the leaf and
balancer counts; no task or queue grows with the number of failures.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013187aoMHvrWEfXT9ArqxdU
A failed open could mark a healthy server unhealthy during a short local
outage: re-probes run exactly when traffic fails, one failed probe set a
leaf unhealthy, and nothing probed it again before the scheduled round.

- A failed traffic-triggered re-probe of an outbound that is not
  unhealthy is no longer recorded. The outbound is probed again 10 s
  after that probe finished, and only that result counts. An outbound
  re-probes marked unhealthy is probed again 10 s later, then at
  doubling intervals up to probeInterval. Scheduled-round results are
  recorded as before and end any follow-up.
- Cooldowns count from when a probe or a balancer pass finished, not
  when it started. A balancer's cooldown doubles after each pass in
  which every member's probe failed, capped at probeInterval, and
  resets when a member answers.
- Reports are classified from typed io kinds only: refused, reset or
  timed out, EOF or InvalidData inside a TLS handshake, and REALITY
  RealCertificate. ConnectionAborted and HostUnreachable count as local
  network errors. Message-only errors (XHTTP, gRPC, XDRIVE, WebSocket,
  HTTP upgrade, HTTP/2 CONNECT, chained hop), Hysteria Connect and
  MASQUE Dial are no longer reported; their timeouts still are.
- Leaves without a server of their own (freedom, blackhole, DNS,
  loopback) are not watched, observed or as a fallback.
- Open timeouts stay reported, since a server that drops packets gives
  nothing else; the docs no longer claim a down local network is never
  reported.

Tests drive a running core: SOCKS CONNECT, HTTP CONNECT, HTTP
forwarding, TUN TCP, TUN UDP and TUN VLESS UDP report a refused open;
SOCKS, HTTP forwarding, TUN TCP and TUN UDP report an open timeout; a
SOCKS target refusal is not reported. The end-to-end test goes from a
SOCKS flow through a leastPing balancer to failover on the other
server. Unit tests cover the confirmation, the follow-ups, the cooldowns
and the group back-off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013187aoMHvrWEfXT9ArqxdU
…ad window

A re-probe still sets the health state, the last delay and the failure
count, so leastPing and the quick move away from a dead server are
unchanged, but only the scheduled round adds samples to the 16-sample
window leastLoad reads for tolerance, average and deviation.
Panels such as V2Board write `fp` on every base64 JSON vmess:// link,
also when `tls` is empty. v2rayN builds TLS settings only when `tls`
names a security, so there the field configures nothing. Here the
importer kept it and stream_settings refused the leftover parameter, so
a plain WebSocket link failed with "profile contains an unsupported
setting".

With `tls` absent, empty or `none`, the JSON dialect now drops `sni`,
`alpn` and `fp` before the stream mapping. A link with TLS maps them
into tlsSettings as before; the URI dialect and the REALITY fields are
unchanged.
The Swift and Kotlin doc comments of probeOutboundURL/probeOutboundUrl
say "the running core", but not what a host gets on a core it loaded
and has not started yet: Swift throws XrayCoreError.notRunning before
reaching the C call, Kotlin XrayCoreException with RUNTIME_ERROR from
it. docs/ffi.md and the C header already document the RUNTIME_ERROR,
and ffi_outbound_probe_validates_outputs_handle_and_lifecycle tests it.

Name the error in both comments and point to preflightStartupProbe,
which runs the configured startup probe before start. No code change.
XrayPacketTunnelProvider keeps its runtime private and answers only the
stats and close-connections requests, so a host app could not ask its
tunnel for the connection, accounting, selection or health snapshot, pin
a selector group or replace the routing policy without forking the
provider.

Add an open handleCustomAppMessage(_:core:) hook. handleAppMessage calls
it with the active core for every message after the close-connections
request and before the stats request; a non-nil result is sent back,
nil falls through to the built-in handling. The default returns nil, so
existing hosts see no change.
profile import: ignore TLS fields of a VMess JSON link without TLS
docs: say that an outbound probe needs a started core
apple: let a provider subclass answer its own app messages

CHANGELOG.md: both Unreleased entries kept, this one after #346's.
Re-probe observed outbounds when real traffic fails to dial them

Merged at 1a0eedb: the pull request's head 7b68352 and, on top of it,
dec0iiyy's commit that keeps traffic-triggered re-probes out of the
leastLoad window, the last open point of the review.

CHANGELOG.md: the entry goes to the end of the Unreleased list.
handleAppMessage dropped a message that is not valid UTF-8 before the
hook #349 added could see it, while the hook's documentation promises
every message the provider does not handle itself. A host whose app and
extension speak a binary format, a property list or protobuf, would
have had its messages answered with nil.

The provider now decodes the text only to recognise its own requests,
which are text: a message that is not names none of them, goes to the
hook, and without an answer from it gets nil as before. Hosts that do
not override the hook see no change.
@aimalygin
aimalygin merged commit 3a70b2d into main Nov 24, 2026
16 checks passed
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.

4 participants