Skip to content

Studio: keep fine-tuning job pages complete when a batch starts - #16823

Merged
danielhanchen merged 5 commits into
unslothai:mainfrom
NilayYadav:fine-tuning-cursor-batch-start
Nov 6, 2026
Merged

danielhanchen merged 5 commits into
unslothai:mainfrom
NilayYadav:fine-tuning-cursor-batch-start

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

When a Multi-LoRA batch started while a fine-tuning list request was in flight, a client paging with after= set to one of that batch's job IDs could get back an empty page with has_more false, or a page that silently skipped another job of the same batch. Those jobs had left the queue but were not yet in the live status or the run history, so the cursor matched nothing, or matched and jumped straight to older history.

The list now remembers the queue as it was when the request began. A job that started during the request still matches its cursor and is listed once, as its run when it already has one and as it was queued otherwise.

Fixes #16719

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-06T09:51:30.224675Z d52413f Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: a088312230

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 5, 2026
@Lyxot Lyxot self-assigned this Nov 6, 2026
… atomically

A started job's alias mapping was recorded only inside _save_alias, on a worker thread after an await, and its queue entry was removed only after that. A job listing in between showed the job under its run id next to its queued id. Record the mapping and retire the queue entry before any await, then persist. Drop the list handler's redundant live-id set, and cover the persistence window with a test.
@Lyxot

Lyxot commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

Pushed 044abf1 on top of the branch:

  • Atomic queue → run handoff. A started job's alias mapping was set only inside _save_alias, on a worker thread after an await, and its queue entry was removed only after that. A listing in that window showed the job as ftjob_<run_id> (an id the client never got) alongside its queued id. The mapping is now recorded (_record_alias) and the queue entry retired before any await in _start_queued and _start_batch; _save_alias only persists.
  • List handler: dropped the listed set; run[0] in live already covers it once the mapping is set synchronously.
  • Tests: replaced the run-id-mid-request test with one that holds alias persistence mid-batch and asserts both members list once under their job ids; added a timeout to the cursor test's wait so a regression fails instead of hanging.

A randomized race (real drainer and routes, concurrent limit=1 walks and full lists, 200 trials, distinct creation times) failed 64 trials on main, 76 on the previous head, and 0 now. This composes with #16835; merged together, the same race passes 200/200 even with same-second creation times.

@Lyxot

Lyxot commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 044abf1435

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen danielhanchen self-assigned this Nov 6, 2026
Same-second jobs now list by job id (unslothai#16832), so the cursor tests and the
queue order test expect that order instead of queue order.
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: d52413f619

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 2e10d80 into unslothai:main Nov 6, 2026
danielhanchen pushed a commit that referenced this pull request Nov 7, 2026
…restarts (#16835)

Follow-up to #16720, #16832 and #16823.

When several fine-tuning jobs are created within the same second (a script submitting jobs in a loop), `GET /v1/fine_tuning/jobs` broke the `created_at` tie by the random public job id. So `jobs.list(limit=1)` could return an older job instead of the one just submitted, and the order among those jobs had nothing to do with submission order. An earlier revision of this branch fixed that with an in-process counter. That counter was lost when Studio restarted, so a client paging with `after=` across a restart could skip a job (three same-second jobs, page 1 before a restart, page 2 after: `ftjob_qa` never returned).

Jobs now get a nanosecond creation stamp when they are queued (kept strictly increasing, since Windows clocks can tick only every ~16 ms). It is saved with the job id mapping in the alias table, in a new nullable `created_ns` column, and loaded back on start. Same-second jobs are ordered by that stamp, then by public id, so a job keeps its place from queued to running to history, and across restarts. Older alias tables gain the column the first time they are opened. Jobs the API starts directly, without queueing, get a stamp too: it is saved under their usual public id, and their `created_at` still comes from the run. Rows without a stamp (runs started from the Studio UI, jobs from older builds) keep the public id order. Older builds name their columns explicitly when they read and write this table, so a downgrade still works.

Verification:

- `test_a_job_batched_past_keeps_its_place_when_it_starts_between_pages` now also runs across a simulated restart and asserts submission order when jobs share a second. On main, the 3 same-second cells fail and the 3 others pass. Here, all 6 pass.
- New `test_an_alias_table_from_an_older_build_loads_and_gains_the_ns_column`: an alias table from an older build loads, gains the column, and saves new stamps.
- New `test_jobs_created_within_one_clock_tick_list_newest_submitted_first`: with a frozen clock, jobs still list newest submitted first (fails without the strictly increasing stamp).
- New `test_a_job_started_directly_lists_ahead_of_an_older_same_second_job`: a queued job is cancelled and a replacement starts directly in the same second. The replacement lists first, before and after a restart.
- Three tests computed their expected order from the random job id tie break. They now expect newest submitted first.
- `test_openai_fine_tuning.py`: 125 passed. `test_training_api_snippet_contract.py` + `tests/multi_account` (fine-tuning/training selection): 129 passed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Studio: a Multi-LoRA batch starting during a fine-tuning list request can invalidate a public cursor

3 participants