[CLI] Parse initiator field on jobs API responses#4212
Merged
Conversation
Adds a `JobInitiator` dataclass and `JobInfo.initiator` field, surfacing the `initiator` object the Hub returns on jobs responses. Variants: user/org (ad-hoc runs), scheduled-job (cron-triggered runs), duplicated-job (`POST /duplicate` runs). All share `type` and `id`; `name` is only set for user/org. Mirrors the lightweight shape of the existing `JobOwner`. `hf jobs inspect --json` and `hf jobs ps --json` auto-surface the new field via `asdict`. No `ps` table column added — kept minimal; column or filter flag is a separate UX decision. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
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. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4212 +/- ##
==========================================
+ Coverage 75.00% 77.09% +2.09%
==========================================
Files 145 171 +26
Lines 13978 19493 +5515
==========================================
+ Hits 10484 15028 +4544
- Misses 3494 4465 +971 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Drop the custom JobInitiator.__init__ in favour of a plain @DataClass with `name: str | None = None`. Switch the call site in JobInfo to explicit kwargs (matches the JobOwner / JobStatus construction style in this file), which also drops server-side extras like `avatarUrl` without needing to absorb them inside the dataclass. - Re-export JobInitiator from huggingface_hub.__init__ alongside the existing job dataclasses, so users can type-annotate `job.initiator` without reaching into the private _jobs_api module. - Bring the JobInfo docstring example up to date with the new `initiator=...` field. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
lhoestq
approved these changes
May 11, 2026
Co-authored-by: célina <hanouticelina@gmail.com>
Removes test_job_info_parses_initiator_variants and test_job_info_initiator_default_none from tests/test_cli.py: they weren't CLI tests, and the parametrized variants exercised the same constructor line with different strings rather than meaningful behavior. Also applies ruff format to the JobInitiator docstring whitespace. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
davanstrien
added a commit
to davanstrien/huggingface_hub
that referenced
this pull request
May 20, 2026
Resolve JobInfo conflict from huggingface#4212 (initiator) by keeping both the runtime fields (started_at/finished_at/durations + JobDurations) and the new initiator field/dataclass. Add JobStage.SCHEDULING (+ docstring) per review — fixtures rely on it. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
|
This PR has been shipped as part of the v1.16.0 release. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Independent of #4211 (off main, no merge-order dependency).
Summary
Parses the
initiatorfield the Hub returns on jobs API responses. Adds aJobInitiatordataclass +JobInfo.initiatorfield. Pure data-layeraddition — no
pstable column in this PR._jobs_api.py: newJobInitiatordataclass + newJobInfo.initiatorfield__init__.py: re-exportJobInitiatoralongside the existing job dataclassesVariants the Hub returns:
user/org— ad-hoc runs (namepopulated)scheduled-job— cron-triggered runs (id only)duplicated-job— runs created viaPOST /duplicate(id only)All share
typeandid;nameis only set for user/org. Matches thelightweight shape of the existing
JobOwner(noavatar_url— keepsinspectoutput tight). The server-sideavatarUrlis dropped at thecall site rather than absorbed into the dataclass, matching how
JobOwner/JobStatusare constructed in this file.Why
Useful for both human users (knowing at-a-glance what triggered a job in
inspectoutput) and agents inspecting a user's job history programmatically.When scanning many jobs from the same user,
initiatoris the only way todisambiguate manual runs from automated/scheduled ones. The data was already
available server-side; the Python library was silently dropping it on parse.
Where it surfaces
hf jobs inspect <id>hf jobs ps --format jsonhf jobs ps(default table)Sample output
Two real jobs run by the same user — one ad-hoc, one cron-triggered. Note how
initiatordisambiguates them whileowneris identical:For cron-triggered runs,
initiator.type == "scheduled-job"andinitiator.idpoints at the schedule definition. Agents can filter the fulllist directly off
--format json:Open question for reviewers
Should we add an
INITIATORcolumn to the defaulthf jobs pstable?psis already 5 cols (6 if [CLI] Surface job runtime fields in ps + inspect #4211 lands),150+ chars wide on standard terminals
rows — better addressed by a
--sort statusflag or--active-onlyshortcutKept this PR minimal so the display decision can have its own discussion.
Test plan
initiatorfield absent)userandscheduled-jobinitiators both parse; server-sideavatarUrlextra is silently filtered🤖 Generated with Claude Code
Note
Low Risk
Low risk: adds an optional parsed field to
JobInfoand re-exports a new dataclass, with minimal impact on existing job APIs unless callers rely on strict attribute sets/serialization.Overview
Adds support for the Jobs API
initiatorfield by introducing a newJobInitiatordataclass and wiring it intoJobInfoas an optionalinitiatorattribute during response parsing.Updates public exports in
__init__.py(lazy/static imports and__all__) soJobInitiatoris available at the package top level.Reviewed by Cursor Bugbot for commit 460db26. Bugbot is set up for automated code reviews on this repo. Configure here.