Skip to content

feat: add Smart sticky sessions#10

Open
eyaeya wants to merge 1 commit into
vernesong:Alphafrom
eyaeya:codex/smart-sticky-sessions
Open

feat: add Smart sticky sessions#10
eyaeya wants to merge 1 commit into
vernesong:Alphafrom
eyaeya:codex/smart-sticky-sessions

Conversation

@eyaeya

@eyaeya eyaeya commented Jun 30, 2026

Copy link
Copy Markdown

Dependency chain

This PR is part of a three-PR change set for Smart strategy: sticky-sessions support:

  1. OIX core support: vernesong/mihomo-oix#6
  2. Matching non-OIX core support, this PR: vernesong/mihomo#10
  3. OpenClash LuCI/YAML wiring: vernesong/OpenClash#5198

This non-OIX core PR does not depend on the OpenClash PR to build or test. It is, however, a required core-side dependency for OpenClash users who select a non-OIX Smart-capable core and enable Smart sticky sessions. vernesong/OpenClash#5198 should only be considered functionally complete for non-OIX users after this PR, or an equivalent non-OIX core implementation, is merged and released.

The OIX core PR vernesong/mihomo-oix#6 should stay behaviorally aligned with this PR so OpenClash exposes one consistent Smart strategy option across OIX and non-OIX cores.

Recommended merge/release order:

  1. Merge/release core support: vernesong/mihomo-oix#6 for OIX and this PR for non-OIX.
  2. Merge vernesong/OpenClash#5198 after the supported cores can parse and enforce Smart strategy: sticky-sessions.

Summary

Add explicit strategy: sticky-sessions support for Smart proxy groups.

This keeps the non-OIX Smart implementation aligned with the OIX core patch. OpenClash can only expose and generate YAML after the core accepts and enforces the option.

Root cause

Investigation showed Smart groups can route the same service/domain through multiple nodes. This also happens on non-OIX Smart cores, which indicates the issue is Smart group semantics rather than an OIX-specific TLS failure. In current core code, strategy is parsed for load-balance only; Smart does not accept strategy and instead relies on SmartTarget/ASN/cache/weight selection.

Design

  • Add Strategy string to SmartOption.
  • Accept empty strategy and sticky-sessions; reject unsupported Smart strategies.
  • Preserve existing Smart behavior when strategy is empty.
  • Enable a bounded 10 minute / 1000 entry sticky cache only for sticky-sessions.
  • Key affinity by source IP plus effective destination host/IP instead of broad SmartTarget labels.
  • Reuse cached proxies only when still healthy, present, not Smart-blocked, not host-failed, and UDP-capable when required.
  • Store affinity after successful TCP/UDP dial and clear stale entries on invalid sticky hits.
  • Clear sticky entries when the only selected proxy fails and Smart deletes the corresponding unwrap cache, so the next retry can choose a fresh candidate.

Validation

  • go test ./adapter/outboundgroup -run 'TestNewSmartRejectsUnsupportedStrategy|TestNewSmartKeepsEmptyStrategyNonSticky|TestSmartSticky' -count=1
  • go test ./adapter/outboundgroup ./component/smart/... -count=1

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.

1 participant