Skip to content

Studio: use the browser's timezone for today's date in chat - #11852

Merged
mahiatlinux merged 3 commits into
unslothai:mainfrom
NilayYadav:durable-run-timezone
Sep 25, 2026
Merged

mahiatlinux merged 3 commits into
unslothai:mainfrom
NilayYadav:durable-run-timezone

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

Chat replies now run in the background so they survive a page reload. That background run lost the browser's timezone, so the date given to the model came from the server's timezone instead. On Docker, Colab or a remote machine, the model could be told the wrong day for several hours each day.

The browser's timezone is now saved with the run and used when the reply is generated, the same way Deep Research already does it. I tested it on a Studio set to UTC with a browser in Tokyo. The model was told 24 September before this change and 25 September after, which was the correct date in Tokyo.

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

Review + UI evidence

Pinned head: 3901e105d. Review converged; the last round found no issues.

Date the model is told on a chat turn, with Studio and the browser in different timezones. Real Studio in Chromium (1280×800). Before is the merge base f9bffe265, after is this PR (f17f8ed85; 3901e105d only rewraps a line), on a CPU host. Studio ran with TZ=UTC and the browser in Pacific/Kiritimati (UTC+14), so the two calendar dates differ. A real unsloth/Qwen3-0.6B-GGUF (Q4_K_M) was loaded with a chat template that makes it repeat the system turn, where Studio writes The current date is YYYY-MM-DD.. The reply shows the date llama-server was given. I sent "What is the current date?" from the chat box, which goes through POST /api/inference/chat-runs.

Before After
X-Unsloth-Timezone on the chat-runs POST Pacific/Kiritimati (offset -840) Pacific/Kiritimati (offset -840)
Browser date / Studio (UTC) date 2026-09-25 / 2026-09-24 2026-09-25 / 2026-09-24
Model's reply "The current date is 2026-09-24." (server date) "The current date is 2026-09-25." (browser date)

PR 11852 before/after

Review fix pushed

  • f17f8ed85: the browser timezone is stored with the run but left out of the run's retry identity. Without this, a create retried after the browser's UTC offset changed (for example across a DST switch after a lost response) got a 409, and the UI failed the turn while the run kept generating. It now returns the run that was already committed. Regression test added.
  • Each new test fails on the code before its fix and passes after it: test_producer_dates_the_prompt_in_the_browser_timezone gives 2026-09-24 instead of 2026-09-25 on base, and test_a_create_retried_across_a_dst_change_returns_the_committed_run gets a 409 on bdbc09a42.

Tests: 380 related backend tests pass (chat-generation runs, supervisor, lease, account fences, current-date settings, chat history, tool approvals).

CI: upstream 32 passed, 7 pending. Staged on fresh main: NilayYadav/unsloth-staging#162 (still running).

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

Codex review, via a mirror

Codex does not answer on this repository, so it ran against a copy of this pull request's commits at NilayYadav#58. The copy is based on main f9bffe265, which is also this PR's merge base, so the commits are the same as here.

Round 1 looked at bdbc09a42 and raised 1 finding:

  • P2, studio/backend/routes/chat_generation_runs.py: keep timezone metadata out of the idempotency hash. The stored browser timezone was part of the run's request hash. A create retried after the browser's offset changed (for example across a DST switch after a lost response) got a 409, and the UI failed the turn while the run kept generating. Reproduced with a regression test that gets the 409 on bdbc09a42. Fixed in f17f8ed85: the timezone stays with the run but is left out of the identity hash, so the retry returns the run that was already committed.

Round 2 looked at f17f8ed85: "Didn't find any major issues."

The current head, 3901e105d, only adds a pre-commit.ci line wrap on top of f17f8ed85. Codex review has converged.

@mahiatlinux

Copy link
Copy Markdown
Contributor

Reviewed source head 3901e105d against merge base f9bffe265 and the current integration mirror e2041047b. I found no actionable correctness, compatibility, security, or performance defects, so no source changes were needed.

Executed verification:

  • Focused durable-run storage, supervisor, current-date, account-fence, lease, and UI-stream suites: 271 passed on the merge base, 273 passed on the source head, and 273 passed on the integration commit.
  • Direct A/B reproduction: the merge base lost the browser timezone headers and injected the UTC date; the source head and integration commit forwarded Pacific/Kiritimati / -840 and injected the browser date.
  • DST retry reproduction: the initial PR commit returned HTTP 409 when only the browser offset changed; the final head returns the original run and retains its committed offset. A real request-payload change still conflicts.
  • Mutation control: removing the production forwarding call makes the new browser-date regression fail, proving the test exercises the intended path.
  • Three independent edge tests passed at the source head and integration commit, covering the 64/65-character boundary and allowlist, exact ASGI forwarding, metadata persistence, and timezone-independent idempotency.
  • Repository formatting reached a clean fixed point. ruff check and git diff --check passed on all five changed files.
  • All current source PR checks are successful or intentionally skipped.

Real UI evidence used separate exact-revision Studio installs, Chrome for Testing 153 via Playwright 1.63, and the real unsloth/Qwen3-0.6B-GGUF Q4_K_M model on GPU. Studio ran in UTC while the browser ran in Pacific/Pago_Pago. BEFORE answered 2026-09-25; AFTER answered 2026-09-24. Both UI POSTs carried x-unsloth-timezone: Pacific/Pago_Pago and offset 660.

UTC server date before and browser-local date after

The mirror review converged on e2041047b: mahiatlinux/unsloth-staging-review#49

@mahiatlinux mahiatlinux left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Ready to merge, all manually checked.

@mahiatlinux

Copy link
Copy Markdown
Contributor
image

@mahiatlinux
mahiatlinux merged commit 6a16993 into unslothai:main Sep 25, 2026
43 checks passed
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…i#11852)

* Studio: keep the browser timezone on durable chat runs

* Studio: keep the browser timezone out of the chat run's retry identity

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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.

3 participants