Skip to content

backend, vpn: integrate lantern-box MutableAutoSelect outbound#492

Draft
garmr-ulfr wants to merge 2 commits into
mainfrom
autoselect
Draft

backend, vpn: integrate lantern-box MutableAutoSelect outbound#492
garmr-ulfr wants to merge 2 commits into
mainfrom
autoselect

Conversation

@garmr-ulfr
Copy link
Copy Markdown
Collaborator

Adapts radiance to consume the new MutableAutoSelect outbound from lantern-box (PR #266). Replaces the prior MutableURLTest selector with one that distinguishes probe-URL health from user-traffic health.

  • Build auto as TypeMutableAutoSelect with per-tag bandit URL overrides. The demote / dedupe / proved-read knobs inherit documented lantern-box defaults.
  • Bridge the group's ExhaustionSignal onto a vpn.ExhaustionEvent so subscribers can react without the tunnel knowing about them. LocalBackend subscribes and refetches /config-new through an exhaustionGate that rate-limits to one minute.
  • Register a lantern-box AutoSelectHistoryStorage on the tunnel and run a ticker-coalesced flush listener that mirrors per-tag TagHistory snapshots (probe scalars + user_failures window) into the persisted servers file. Lifecycle tied to Connected/ Disconnected VPN status events.
  • Seed cold-start ranking via the offline URL-test path: results are shaped as TagHistory entries and persisted so the next tunnel start picks them up via SelectionHistorySeed.

Adapts radiance to consume the new MutableAutoSelect outbound from
lantern-box (PR #266). Replaces the prior MutableURLTest selector
with one that distinguishes probe-URL health from user-traffic
health.

- Build `auto` as TypeMutableAutoSelect with per-tag bandit URL
  overrides. The demote / dedupe / proved-read knobs inherit
  documented lantern-box defaults.
- Bridge the group's ExhaustionSignal onto a vpn.ExhaustionEvent
  so subscribers can react without the tunnel knowing about them.
  LocalBackend subscribes and refetches /config-new through an
  exhaustionGate that rate-limits to one minute.
- Register a lantern-box AutoSelectHistoryStorage on the tunnel
  and run a ticker-coalesced flush listener that mirrors per-tag
  TagHistory snapshots (probe scalars + user_failures window)
  into the persisted servers file. Lifecycle tied to Connected/
  Disconnected VPN status events.
- Seed cold-start ranking via the offline URL-test path: results
  are shaped as TagHistory entries and persisted so the next
  tunnel start picks them up via SelectionHistorySeed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Radiance’s VPN tunnel and backend integration to use lantern-box’s new MutableAutoSelect outbound, including persisting per-tag selection/probe history and emitting an exhaustion signal to trigger rate-limited config refetches.

Changes:

  • Replace the previous URL-test selector/history path with MutableAutoSelect + per-tag TagHistory persistence and seeding.
  • Bridge MutableAutoSelect exhaustion signaling into a vpn.ExhaustionEvent, and add a backend refetch gate (1/min) on exhaustion.
  • Update CLI/server models to surface selection history (and latest latency derived from it) instead of urlTestResult.

Reviewed changes

Copilot reviewed 15 out of 18 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
vpn/vpn.go Switch tunnel startup to pass SelectionHistorySeed; tighten offline URL-test outbound lookup/type checks.
vpn/types.go Add AutoSelectHistoryStorage alias and new ExhaustionEvent type.
vpn/tunnel.go Register lantern-box AutoSelectHistoryStorage, seed it, and emit exhaustion events from the auto group.
vpn/session_history.go Formatting/alignment only.
vpn/clash.go Formatting changes; still pulls adapter.URLTestHistoryStorage from context.
vpn/boxoptions.go Build TypeMutableAutoSelect outbound and add SelectionHistorySeed to BoxOptions.
vpn/boxoptions_test.go Update bandit override test to assert MutableAutoSelect options type.
servers/manager.go Persist selection history (TagHistory) per server instead of urlTestResult; rename JSON field to selection_history.
cmd/lantern/vpn.go Filter group tags from throughput output; derive displayed latency from selection history.
cmd/lantern/servers.go Replace urlTestResult output with selection_history/latest-success delay.
cmd/lantern/monitor.go Update pool summary to incorporate selection history and avoid group-tag phantom throughput entries.
config/config.go Rename ConfigHandler.Update() to Fetch().
backend/radiance.go Listen for selection-history changes and persist snapshots; add exhaustion-triggered config refetch with rate limiting; seed tunnel from persisted history; shape offline URL-test results into TagHistory.
backend/radiance_test.go Remove empty placeholder test.
backend/exhaustion_test.go Add unit test for exhaustion refetch rate-limiting gate.
go.mod / go.sum Bump github.com/getlantern/lantern-box dependency for MutableAutoSelect.
AGENTS.md Update example comment text to match renamed listener.
Comments suppressed due to low confidence (1)

servers/manager.go:146

  • UnmarshalJSON only reads the new selection_history field; any existing persisted servers files from older versions that contain urlTestResult will silently drop prior latency data on upgrade. Consider accepting the legacy urlTestResult field in serverJSON and converting it into a TagHistory snapshot during unmarshal to preserve cold-start ranking/history across upgrades.
func (s *Server) UnmarshalJSON(data []byte) error {
	sj, err := json.UnmarshalExtendedContext[serverJSON](box.BaseContext(), data)
	if err != nil {
		return err
	}
	s.Tag = sj.Tag
	s.Type = sj.Type
	s.IsLantern = sj.IsLantern
	s.Location = sj.Location
	s.Credentials = sj.Credentials
	s.SelectionHistory = sj.SelectionHistory
	if sj.Outbound != nil {
		s.Options = *sj.Outbound
	} else if sj.Endpoint != nil {
		s.Options = *sj.Endpoint
	}
	return nil

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/lantern/vpn.go
Comment thread cmd/lantern/servers.go
Comment thread servers/manager.go
Comment thread vpn/clash.go
Server.Clone deep-copies SelectionHistory (including UserFailures) so
AllServers and GetServerByTag callers can't alias the Manager's shared
state. The clashServer's unused urlTestHistory field is removed, and
HistoryStorage now returns nil to satisfy adapter.ClashServer.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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