Version check on the import path makes `--version` and `--help` do network I/O

Aperta
#171 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python
Ambito
cli, networking

Direzione di ricerca

Start with lightning_sdk/init.py:59-60 to trace the import-time check, then read lightning_sdk/helpers.py:25, 48, and 60 for caching, requests, and exception handling. Decide where the check should run and verify that --help, --version, and offline commands no longer perform network I/O or traceback with an invalid certificate path.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

What happens

lightning --version and lightning --help reach out to PyPI over the network. Neither command
needs to. A PyPI version check runs while the package is being imported, which happens before the
CLI ever looks at the arguments it was given.

flowchart LR
    A["lightning --version"] --> B[import lightning_sdk]
    B --> C["version check<br/>calls pypi.org"]
    C --> D[CLI parses the arguments]
    D --> E[prints the version]
    C -.->|"slow, unreachable<br/>or misconfigured TLS"| F[hangs or fails<br/>before D]

Three consequences, all reproducible today:

  1. An offline-looking command can fail. With REQUESTS_CA_BUNDLE or SSL_CERT_FILE pointing at
    a path that does not exist, requests raises a plain OSError, the version check only catches
    requests.exceptions.RequestException, and the error escapes — so --version and --help both
    traceback. (A bundle that exists but cannot be read is fine; that arrives as SSLError, which is
    caught.)
  2. Any command can stall. The request has no timeout, so a slow or unresponsive pypi.org
    holds up whatever the user typed, for as long as it takes.
  3. Every invocation pays for it. The result is cached on the checker instance, which lives and
    dies with the process, so there is no reuse between commands. An agent or script running 40
    lightning commands makes 40 PyPI requests. Library users pay it too: any import lightning_sdk
    in a notebook, a training script or a service's startup path makes the same call.

Repro

$ REQUESTS_CA_BUNDLE=/tmp/does-not-exist.txt lightning --version
...
  File ".../requests/adapters.py", line 332, in cert_verify
    raise OSError(
OSError: Could not find a suitable TLS CA certificate bundle, invalid path: /tmp/does-not-exist.txt

Verified on lightning-sdk==2026.9.15, macOS, Python 3.14. The same command succeeds with
LIGHTNING_DISABLE_VERSION_CHECK=1, which confirms where the failure comes from.

For consequence 3, any lightning --version shows an outbound connection to pypi.org:443.

Where it comes from

  • lightning_sdk/__init__.py:59-60 runs the check at module scope, so importing the package
    performs network I/O.
  • lightning_sdk/helpers.py:48 makes the request with no timeout.
  • lightning_sdk/helpers.py:60 catches only requests.exceptions.RequestException.
  • lightning_sdk/helpers.py:25 holds the cache per instance, and the instance is per process.

Why it matters

A version check is advisory. It should never be able to break --help, and it should not be on the
critical path of commands that do not talk to the platform. The failure is also hard to place from
the outside: users see a TLS or network error from a command they expect to be local, and the
message says nothing about a version check. Agent sandboxes make this more likely, since they
routinely redirect or restrict certificate paths.

Suggested direction

Smallest first, and the first one is worth doing on its own:

  1. Give the request a timeout, and catch OSError rather than RequestException (the latter is a
    subclass of the former, so this widens the net without losing anything).
  2. Move the check off the import path. Run it when a command is already talking to the platform, or
    after the command's work is done, so --version, --help and every offline command cost nothing.
  3. Cache the answer on disk with a TTL, so it is at most one request per day per machine instead of
    one per process.

Happy to take this on if the direction looks right. (2) is the real fix and the one that needs a
decision on where the check should live; (1) is a couple of lines and could land immediately.

Lingua principale
Python
Stelle
13
Fork
4
Merge medio
1g 2h
PR unite (30g)
40

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Lightning-AI/sdk

Tutte le issue di Lightning-AI/sdk

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.