Commit Graph
1 Commits
  • fix(flow): restore XTLS Vision when an inbound becomes flow-eligible (#5520)
    * fix(flow): restore XTLS Vision when an inbound becomes flow-eligible
    
    clientWithInboundFlow strips Vision from a VLESS client whenever the target
    inbound is not flow-eligible at client-write time — e.g. an XHTTP inbound
    before its vlessenc (ML-KEM) encryption is set, or a client attached to such
    an inbound. Nothing restored the flow once the inbound later became eligible:
    an inbound edit stores its settings verbatim and never re-gates the clients.
    So enabling encryption on an existing XHTTP inbound left every client without
    flow, and the generated configs, share links and subscriptions silently
    dropped flow=xtls-rprx-vision — most visibly on node inbounds and on any
    inbound where encryption was turned on after the clients existed.
    
    Restore the flow at the two points where an inbound can become eligible:
    
    - UpdateInbound: after the new stream/settings are final, re-add Vision to
      clients that currently carry no flow but whose intended flow (their
      flow_override on a sibling inbound, via EffectiveFlowByEmail) is Vision —
      only when the inbound is now flow-eligible.
    - MigrationRestoreVisionFlow: a one-time, idempotent boot migration that
      applies the same repair to existing installs and refreshes flow_override
      via SyncInbound.
    
    The repair is conservative: it never invents a flow for a client that has
    none anywhere, never overwrites an explicit flow, and is a no-op on healthy
    installs. Adds EffectiveFlowByEmail and a unit test covering keep/skip/no-op
    cases.
    
    Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
    
    * style(flow): serialize restored settings with MarshalIndent
    
    Match the indented JSON used by the adjacent timestamp block in UpdateInbound
    and the externalProxy migration, so a restored inbound's settings column keeps
    the same multi-line format as everything else (review nit on #5520).
    
    Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
    
    * perf(flow): batch the intended-flow lookup and run it on the active tx
    
    restoreVisionFlowForEligibleInbound resolved each empty-flow client's intended
    flow with EffectiveFlowByEmail, which issued two queries per client
    (GetRecordByEmail + EffectiveFlow). A client that genuinely uses no Vision keeps
    an empty flow forever, so it was re-queried on every UpdateInbound and every
    boot — O(clients) queries per save on a Reality/TCP or XHTTP+vlessenc inbound
    carrying many non-Vision clients, executed inside the serialized writer
    transaction.
    
    Replace it with EffectiveFlowsByEmails: collect every empty-flow email first and
    resolve them in a single batched join over client_inbounds + clients (lowest
    inbound_id wins, same rule as before), chunked for the SQLite bind-var limit.
    
    Also thread the active tx through restoreVisionFlowForEligibleInbound so the
    read runs on the writer's own connection while it holds the lock instead of a
    separate pooled connection (UpdateInbound passes its tx; the boot migration
    passes nil → GetDB() as before).
    
    Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
    
    ---------
    
    Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>