Skip to content

Add configurable heartbeat interval for unload events#13357

Draft
fengfeng-zi wants to merge 1 commit intogradio-app:mainfrom
fengfeng-zi:fix/heartbeat-interval-unload-13347
Draft

Add configurable heartbeat interval for unload events#13357
fengfeng-zi wants to merge 1 commit intogradio-app:mainfrom
fengfeng-zi:fix/heartbeat-interval-unload-13347

Conversation

@fengfeng-zi
Copy link
Copy Markdown

@fengfeng-zi fengfeng-zi commented May 3, 2026

Summary

  • add a public heartbeat_interval launch/mount option for the session heartbeat stream
  • use that configured interval in the unload heartbeat route instead of the hidden e2e env shortcut
  • update the unload demo and add regression coverage for launch/mount parity

Closes #13347

Testing

  • python -m pytest test/test_server.py::TestServer::test_server_launch_sets_heartbeat_interval test/test_server.py::test_server_launch_args_match_blocks_launch test/test_routes.py::TestRoutes::test_mount_gradio_app_sets_heartbeat_interval test/test_routes.py::test_mount_gradio_app_args_match_launch_args -q

Note

Medium Risk
Changes the server-side session heartbeat timing that drives unload behavior; misconfiguration (too low/high) could increase server load or delay session cleanup/unload triggers.

Overview
Adds a public heartbeat_interval option (default 15.0s) to Blocks.launch(), gr.mount_gradio_app(), and Server.launch(), storing it on the Blocks instance and validating it must be > 0.

Updates the /heartbeat/{session_hash} route to use the configured interval instead of an internal env-var-based override, making unload event timing tunable.

Updates the unload_event_test demo to launch with a shorter interval and adds regression tests ensuring heartbeat_interval is correctly plumbed through mount_gradio_app and Server.launch.

Reviewed by Cursor Bugbot for commit 32733ad. Bugbot is set up for automated code reviews on this repo. Configure here.

@freddyaboulton freddyaboulton marked this pull request as draft May 4, 2026 13:21
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.

Blocks unload event delayed significantly (~30 min) in Kubernetes environment, resolved by lowering heartbeat interval

1 participant