Skip to content

Forward visitor requests when lazily caching examples - #13822

Draft
abidlabs wants to merge 2 commits into
mainfrom
fix/issue-13821-forward-visitor-request-when-lazily-caching-exam
Draft

Forward visitor requests when lazily caching examples#13822
abidlabs wants to merge 2 commits into
mainfrom
fix/issue-13821-forward-visitor-request-when-lazily-caching-exam

Conversation

@abidlabs

@abidlabs abidlabs commented Sep 4, 2026

Copy link
Copy Markdown
Member

Description

Lazy gr.Examples caching ran the user function through an internal process_api call with request=None, so downstream ZeroGPU clients could not forward the clicking visitor's X-IP-Token. This passes the click request through the lazy cache path while leaving eager startup caching visitor-less. A regression test covers the API request header reaching the example function.

Closes: #13821

AI Disclosure

  • I used AI to investigate the request flow, draft the scoped implementation and regression test, and prepare this PR. I self-reviewed every changed line.
  • I did not use AI

Testing and Formatting Your Code

  • PYTHONPATH=client/python:. MPLCONFIGDIR=/tmp/gradio-13821-mpl pytest -q test/test_helpers.py::TestProcessExamples::test_lazy_cache_examples_preserves_request
  • python3 -m ruff check gradio/helpers.py test/test_helpers.py
  • python3 -m ruff format --check gradio/helpers.py test/test_helpers.py
  • ty check --python /Library/Frameworks/Python.framework/Versions/3.14/bin/python3 --extra-search-path client/python gradio/helpers.py test/test_helpers.py

The repository-wide formatting wrapper could not use its python command in this shell, so the equivalent scoped Ruff commands above were run directly. The full launch-based helper class also requires built frontend assets; the new in-process regression passes and CI will run the configured full suite.

Minimal reproduction

import gradio as gr


def show_visitor(value: str, request: gr.Request) -> str:
    token = request.headers.get("x-ip-token") if request else None
    return f"{value}: {token or 'missing'}"


with gr.Blocks() as demo:
    prompt = gr.Textbox(label="Prompt")
    result = gr.Textbox(label="X-IP-Token seen by the example function")
    gr.Examples(
        examples=["mountain landscape", "city skyline"],
        inputs=prompt,
        outputs=result,
        fn=show_visitor,
        cache_examples=True,
        cache_mode="lazy",
    )

demo.launch()

The demo file is intentionally untracked and was not committed.

@gradio-pr-bot

gradio-pr-bot commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://huggingface.co/buckets/gradio/pypi-previews/resolve/f55db4598ffe9a140a9bc30aeffb87a729468834/gradio-6.26.0-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@f55db4598ffe9a140a9bc30aeffb87a729468834#subdirectory=client/python"

Import Gradio JS Client from this PR via CDN

import { Client } from "https://huggingface.co/buckets/gradio/npm-previews/resolve/f55db4598ffe9a140a9bc30aeffb87a729468834/browser.js";

@gradio-pr-bot

Copy link
Copy Markdown
Collaborator

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
gradio minor

  • Forward visitor requests when lazily caching examples

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

@abidlabs

abidlabs commented Sep 4, 2026

Copy link
Copy Markdown
Member Author

Before / after Spaces

  • Before fix — latest released Gradio, bug present
  • After fix — wheel from this PR, bug gone

Both public Spaces use requested zero-a10g hardware and byte-identical app.py with a real @spaces.GPU function. I clicked the same lazy example in a browser on each Space.

Space Observed result
Before Visitor token received: no; compute device was an NVIDIA ZeroGPU allocation
After Visitor token received: yes; compute device was an NVIDIA ZeroGPU allocation

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.

Forward visitor request when lazily caching Examples

2 participants