Skip to content

feat: expose Smart sticky sessions#5198

Open
eyaeya wants to merge 1 commit into
vernesong:devfrom
eyaeya:codex/smart-sticky-openclash
Open

feat: expose Smart sticky sessions#5198
eyaeya wants to merge 1 commit into
vernesong:devfrom
eyaeya:codex/smart-sticky-openclash

Conversation

@eyaeya

@eyaeya eyaeya commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

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: vernesong/mihomo#10
  3. OpenClash LuCI/YAML wiring, this PR: vernesong/OpenClash#5198

This OpenClash PR depends on compatible core support. It only exposes and writes strategy: sticky-sessions; the actual affinity behavior must be implemented by the selected core.

Compatibility dependency by selected core:

  • OIX users need vernesong/mihomo-oix#6, or an equivalent OIX core release, before enabling this option.
  • Non-OIX users need vernesong/mihomo#10, or an equivalent non-OIX core release, before enabling this option.

Recommended merge/release order:

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

On older cores, generated YAML containing Smart strategy may fail config parsing. That is why this PR keeps the option opt-in, leaves defaults unchanged, and includes LuCI wording that calls out the core dependency.

Summary

Expose Smart strategy: sticky-sessions in OpenClash without changing existing defaults.

This PR only wires configuration and LuCI. The actual sticky behavior must be provided by a compatible Smart-capable core.

Root cause

Router-side investigation found that OpenClash had partial Smart strategy plumbing but no working end-to-end path:

  • yml_groups_get.sh could import a Smart YAML strategy into UCI as strategy_smart.
  • yml_groups_set.sh did not read or write strategy_smart, so exporting/regenerating YAML dropped it.
  • LuCI exposed strategy only for load-balance, not Smart.
  • Smart auto-switch converted url-test/load-balance groups to smart and added LightGBM/collect/prefer-ASN fields, but never wrote a Smart strategy.
  • Current cores before the paired core PRs do not parse Smart strategy, so OpenClash must not present this as an OpenClash-only fix.

Design

  • Add per-group strategy_smart LuCI option for Smart groups.
  • Only offer sticky-sessions for Smart groups; do not offer round-robin or consistent-hashing because those remain load-balance strategies.
  • Read strategy_smart in yml_groups_set.sh and write strategy: sticky-sessions only when explicitly set.
  • Add global smart_strategy, defaulting to 0, for Smart auto-switch/overwrite flows.
  • Pass smart_strategy into yml_rules_change.sh and only write group['strategy'] = 'sticky-sessions' when the user explicitly selects it.
  • Keep default behavior unchanged: no Smart group receives strategy unless explicitly configured.
  • Restrict global smart_strategy to groups newly converted by Smart auto-switch; existing Smart groups continue to use their per-group strategy_smart setting.
  • Add a small offline regression script checking the critical wiring paths.

Validation

  • bash -n luci-app-openclash/root/usr/share/openclash/*.sh luci-app-openclash/root/etc/init.d/openclash tests/openclash_smart_strategy_test.sh
  • tests/openclash_smart_strategy_test.sh
  • git diff --check HEAD^ HEAD

@Pluviophile714

Copy link
Copy Markdown

用ai用魔怔了?

@eyaeya

eyaeya commented Jun 30, 2026

Copy link
Copy Markdown
Contributor Author

用ai用魔怔了?

@Pluviophile714
如果是 PR 质量问题,请明确指出。
如果是情绪问题,那么,烦请大佬你出手解决 Smart 模式下 strategy: sticky-sessions 失效的问题,例如短时间内 chatgpt.com:443:170 条连接命中过 9 个节点。我会认真阅读大佬你的PR。

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.

2 participants