Skip to content

fix(trainer): memoize GitHub runtime loading, remove dead cache layer - #784

Open
brightyorcerf wants to merge 1 commit into
kubeflow:mainfrom
brightyorcerf:fix/cache-github-runtime-loads
Open

fix(trainer): memoize GitHub runtime loading, remove dead cache layer#784
brightyorcerf wants to merge 1 commit into
kubeflow:mainfrom
brightyorcerf:fix/cache-github-runtime-loads

Conversation

@brightyorcerf

@brightyorcerf brightyorcerf commented Sep 6, 2026

Copy link
Copy Markdown

runtime_loader documented a 24-hour cache for runtimes fetched from GitHub, but nothing was ever cached, the two cache-aware wrappers had no callers, and the live path fetched directly. See #783 for the full analysis.
(per-job amplification via list_jobs(), and a silent-image-divergence consequence on the fallback path)

Fix: @functools.cache on _load_from_github_url (process-lifetime, returns a tuple) instead of reinstating the disk cache, the disk cache keyed on bare filename while sources accepts arbitrary owner/repo/path, and a 24h TTL against an unpinned branch reintroduces the same staleness problem. This does mean a long-lived process (a notebook kernel, a long-running service) won't see upstream runtime changes until restart, an explicit tradeoff given the alternative's own staleness problem.

Also deletes the now-unreachable cache helpers, the unused TRAINING_RUNTIMES_DIR, GITHUB_RUNTIMES_BASE_URL and GITHUB_RUNTIMES_TREE_URL constants, and corrects the module docstring, which additionally promised a fallback to kubeflow/trainer/config/training_runtimes/, a directory that does not exist.

Which issue(s) this PR fixes :
Fixes #783

Checklist:

  • Verified:
    uv run pytest kubeflow/ -q — 696 passed. ruff check . clean.
    ruff format --check . has 4 pre-existing failures in README files,
    confirmed identical on clean main, untouched here. ty check clean.
    pre-commit run clean on the staged diff. (Ran pytest directly rather than
    make test-python, that target is broken on macOS, unrelated to this change.)
  • Docs included if any changes are user facing, none needed, internal caching behavior only.

…ayer

`runtime_loader` documented a 24-hour cache for runtimes fetched from GitHub,
but nothing was ever cached: `_get_github_runtime_files` and
`_load_runtime_from_github_with_cache` had no callers, and the live path
`_load_from_github_url` called `_discover_github_runtime_files` /
`_fetch_runtime_from_github` directly. Both the wrappers and the loader that
bypasses them were introduced together in kubeflow#119, so the layer was never wired up.

This matters because `runtime_source.sources` defaults to
`github://kubeflow/trainer` and `__get_trainjob_from_containers` resolves a
runtime per job, so `list_jobs()` over N jobs cost N directory scrapes plus N
YAML downloads against unauthenticated GitHub. Fetch failures are swallowed and
fall through to `_create_default_runtimes()`, which emits the same runtime name
with a different image, so a rate-limited user could silently train on an image
other than the one the runtime pins.

Memoize `_load_from_github_url` per process instead of reinstating the disk
cache: the disk cache keyed on bare filename while `sources` accepts arbitrary
`owner/repo/path`, and a 24-hour TTL against an unpinned branch reintroduces the
stale-image problem. Returns a tuple so the memoized value is not mutable by
callers.

Also removes the now-unreachable cache helpers and the unused
`TRAINING_RUNTIMES_DIR`, `GITHUB_RUNTIMES_BASE_URL` and
`GITHUB_RUNTIMES_TREE_URL` constants, and corrects the module docstring, which
additionally promised a fallback to `kubeflow/trainer/config/training_runtimes/`
— a directory that does not exist.

Signed-off-by: brightyorcerf <thetejaansh@gmail.com>
@google-oss-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign andreyvelich for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@brightyorcerf brightyorcerf changed the title fix(trainer): cache GitHub runtime loads and drop unreachable cache l… fix(trainer): memoize GitHub runtime loading, remove dead cache layer Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: runtime cache never activates: every list_jobs() re-fetches from GitHub per job

1 participant