Skip to content

fix(hosts): dump host FinalMask with Xray field names for Hysteria2 and the NATS cache - #973

Closed
mark-avd wants to merge 1 commit into
PasarGuard:devfrom
mark-avd:fix/hysteria-host-finalmask
Closed

mark-avd wants to merge 1 commit into
PasarGuard:devfrom
mark-avd:fix/hysteria-host-finalmask

Conversation

@mark-avd

@mark-avd mark-avd commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Host-level final_mask_settings reach SubscriptionInboundData as a FinalMask model. That breaks Hysteria2 output twice:

  1. _get_hysteria_data_from_finalmask calls .get() on the model, so links, Clash Meta and sing-box fail for a Hysteria2 host with a FinalMask: AttributeError: 'FinalMask' object has no attribute 'get'.
  2. HostManager._persist_state writes SubscriptionInboundData.model_dump() (no aliases) to NATS KV. After _load_state_from_cache the host mask is a dict with model field names (quic_params), so the builders find no quicParams and drop udpHop, brutalUp/Down and bbrProfile.

_prepare_subscription_inbound_data now dumps a host FinalMask with by_alias=True, exclude_none=True, mode="json", so the builders and the KV copy get a dict with Xray field names. The builders are unchanged.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Refactor / cleanup
  • Documentation
  • Tests / CI

Checklist

  • I tested the change locally or explained why it cannot be tested.
  • I added or updated tests for behavior changes.
  • I updated documentation, translations, or examples if needed. (not needed)
  • I checked database migrations when models or schema changed. (no schema change)
  • I did not include secrets, tokens, private keys, or unrelated changes.

Testing

Validation Result
uv run pytest -q tests/test_subscription_hysteria_finalmask.py 4 passed; 3 of them fail without the fix
SQLALCHEMY_DATABASE_URL=sqlite+aiosqlite:///./test.db uv run pytest -q 732 passed, 34 skipped
ruff check / ruff format --check on touched files Clean

The tests prepare a Hysteria2 host through _prepare_subscription_inbound_data (core_manager.get_inbound_by_tag mocked), optionally pass it through the same JSON round trip as the KV cache, and check links, Clash Meta and sing-box output for a host mask and for an inbound mask.

Screenshots

Not applicable (backend only).

Notes for reviewers

  • Hosts already in NATS KV keep the old copy until the host or core is saved again.
  • Host masks now take the dict branch of XrayConfiguration._stream_setting_config; the Xray JSON output is the same.
  • Already on dev and not touched here: sing-box server_ports needs start:end, sing-box up_mbps/down_mbps must be integers, and mihomo hop-interval does not take an s suffix. The tests do not assert these values.

- Hysteria2 links, Clash Meta and sing-box no longer fail for hosts with FinalMask settings
- Host QUIC params survive a reload of the NATS host cache
@coderabbitai

coderabbitai Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c773e256-e897-42f7-9010-8e3c8902c723

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@mark-avd
mark-avd deleted the fix/hysteria-host-finalmask branch October 11, 2026 12:07
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