Skip to content

[Jobs] Ignore 406 from metrics endpoint for finished jobs - #5091

Merged
hanouticelina merged 2 commits into
mainfrom
jobs-metrics-finished-406
Oct 6, 2026
Merged

hanouticelina merged 2 commits into
mainfrom
jobs-metrics-finished-406

Conversation

@hanouticelina

@hanouticelina hanouticelina commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

The Jobs API now answers 406 Not Acceptable instead of 500 when asked for the live metrics of a job that is no longer running (internal PR: https://github.com/huggingface-internal/workloads/pull/4992). fetch_job_metrics only ignores 500, so it now raises on any finished job, and hf jobs stats fails as soon as one of the requested jobs has finished.

Summary

  • Tolerate 406 on the metrics endpoint. The existing job status check then sees the job is done, and the stream ends without events.
  • 500 is still tolerated, as before.
  • Checked against the Hub: /metrics returns 406 for COMPLETED, ERROR and CANCELED jobs, and only once the job has stopped (SCHEDULING → read timeout, RUNNING → 200 with samples, then 406). Running jobs are not affected.

Example

On main, with a finished job:

$ hf jobs stats 6ac3bc41404719ba37656377
Error: Client error '406 Not Acceptable' for url 'https://huggingface.co/api/jobs/celinah/6ac3bc41404719ba37656377/metrics'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/406

Failed to call backend

With this PR:

>>> from huggingface_hub import fetch_job_metrics
>>> list(fetch_job_metrics(job_id="6ac3bc41404719ba37656377"))
[]

Combined with #5090, hf jobs stats on a finished job prints Warning: No stats available for Job <id>. Is it running? instead of failing.


Note

Low Risk
Narrow change to ignored HTTP status codes on job metrics streaming; running jobs unchanged and 500 handling preserved.

Overview
Updates fetch_job_metrics so the Hub’s new 406 Not Acceptable response for finished jobs is treated like the old 500, instead of surfacing a client error.

tolerated_status_codes for the metrics SSE route is extended from (500,) to (406, 500), with an inline comment noting the API behavior change. Callers such as hf jobs stats can poll mixed running/finished jobs without failing when metrics are no longer available.

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

@bot-ci-comment

bot-ci-comment Bot commented Oct 5, 2026

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@hanouticelina
hanouticelina marked this pull request as ready for review October 5, 2026 15:48
@hanouticelina
hanouticelina requested a review from Wauplin October 5, 2026 15:48
@hanouticelina
hanouticelina merged commit 3b05c63 into main Oct 6, 2026
47 of 51 checks passed
@hanouticelina
hanouticelina deleted the jobs-metrics-finished-406 branch October 6, 2026 09:09
@huggingface-hub-bot

Copy link
Copy Markdown
Contributor

This PR has been shipped as part of the v2.2.0 release.

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.

1 participant