Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(jobs): derive the default Job name from the last path component o…
…n both separators

`_default_job_name_from_script` split the script path only on `/`, so
Windows paths leaked straight into the auto-generated Job name:
`.\train.py` (what PowerShell tab completion inserts) became
`--train-<hash>`, and an absolute `C:\Users\...\train.py` became
`C--Users-alice-projects-sft-train-<hash>` -- putting the local
directory layout and the username into the Job's `name` label. A long
path also made the 100-character cut from #5306 land before the script
name.

Split the last component on both separators and strip both of them from
the tail before hashing. The hash input is unchanged, and POSIX paths
behave exactly as before.

Regression tests: `.\train.py`, an absolute Windows path, `./train.py`
and a POSIX absolute path all resolve to `train-<hash>`; they fail on
main (`--train-<hash>` / `C--Users-...-train-<hash>`).

Closes #5359

AI-assisted change, disclosed per repo policy.

Signed-off-by: inchang-ing <197932532+inchang-ing@users.noreply.github.com>
  • Loading branch information
inchang-ing committed Nov 14, 2026
commit 1b6f2d4b8841d56eb252b131854f1e002d964762
5 changes: 4 additions & 1 deletion src/huggingface_hub/_jobs_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,10 @@ def _default_job_name_from_script(
hash. The CLI passes it so that the name reflects the values actually submitted, including those
coming from a script's `[tool.hf-jobs]` header rather than from the command line.
"""
name = script.split("?", 1)[0].split("#", 1)[0].rstrip("/").split("/")[-1]
# Windows paths use `\` as the separator (PowerShell tab completion inserts `.\train.py`,
# absolute paths are `C:\...`), so the last component must split on both separators
# or the whole directory path leaks into the Job name (issue #5359).
name = re.split(r"[\\/]", script.split("?", 1)[0].split("#", 1)[0].rstrip("/\\"))[-1]
if name.endswith(".py"):
name = name[: -len(".py")]
return _default_job_name(name or script, [script, *script_args, *(config_parts or [])])
Expand Down
17 changes: 17 additions & 0 deletions tests/test_jobs_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,20 @@ def test_job_info_parses_network(network, expected) -> None:
network=network,
)
assert job.network == expected


@pytest.mark.parametrize(
"script, expected",
[
# Windows relative path as inserted by PowerShell tab completion.
(r".\train.py", "train"),
# Windows absolute path: the directory layout must not leak into the name.
(r"C:\Users\alice\projects\sft\train.py", "train"),
# POSIX paths keep working.
("./train.py", "train"),
("/home/alice/sft/train.py", "train"),
],
)
def test_default_job_name_from_script_windows_paths(script: str, expected: str) -> None:
# The base name is derived from the script's last path component on both separators.
assert _default_job_name_from_script(script, []).startswith(expected + "-")