Skip to content

Forward visitor request when lazily caching Examples #13821

Description

@abidlabs

Describe the bug

When gr.Examples uses lazy caching, the first click executes the example function through an internal Blocks.process_api(..., request=None) call. As a result, the visitor request context is discarded. In a Space or Pod that calls a downstream ZeroGPU Space with gradio_client, the downstream call therefore cannot forward the visitor's X-IP-Token and is charged as visitor-less Space GPU usage.

Expected behavior

The first visitor who clicks a lazily cached example should provide the request context used to compute that cache entry, so downstream ZeroGPU calls receive that visitor's X-IP-Token. Subsequent clicks should continue to use the shared cached result without rerunning the function. Eager startup caching can remain visitor-less because no request exists.

Reproduction

  1. Build a Gradio app with gr.Examples(..., cache_examples=True, cache_mode="lazy").
  2. In the example function, inspect gradio.context.LocalContext.request or create a gradio_client.Client for a downstream ZeroGPU Space.
  3. Click an example while sending an X-IP-Token header.
  4. Observe that the example function runs with no request and the token is not forwarded.

Additional context

Pod/Space GPU usage without X-IP-Token is being deprecated, so lazy example execution needs to be attributed to the clicking visitor.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions