Repository navigation
Fix gRPC trial datetime serialization - #6832
Conversation
|
@yen-0 Could you review this PR? |
|
This pull request has not seen any recent activity. |
|
Certainly! |
yen-0
left a comment
There was a problem hiding this comment.
LGTM. The timestamp conversion looks correct and is consistent with the previous storage fixes.
One note: changing the existing wire representation from the legacy format to timezone-aware ISO-8601 makes new servers incompatible with older gRPC storage proxy clients. I think this behavior should be documented in the gRPC storage proxy documentation or release notes.
yen-0
left a comment
There was a problem hiding this comment.
LGTM! To verify gRPC trial timestamp serialization with multiple concurrent clients in different timezones, using both SQLite and MySQL backends, one gRPC server was started for each backend on ubuntu. Three clients connected concurrently to each server:
Client 1: Asia/Tokyo
Client 2: America/Los_Angeles
Client 3: UTC
The server process used TZ=UTC. Each client created and completed a trial through GrpcStorageProxy, then read both timestamps back.
Server code
import os
import time
from optuna.storages import get_storage
from optuna.storages._grpc.server import make_server
server = make_server(get_storage(os.environ["STORAGE_URL"]), "127.0.0.1", 13001)
server.start()
print("READY", flush=True)
time.sleep(60)The server was started for each backend with:
STORAGE_URL="$storage_url" TZ=UTC uv run python server.py > server.log 2>&1 &Client code
import os
from optuna.storages import GrpcStorageProxy
from optuna.study import StudyDirection
from optuna.trial import TrialState
backend = os.environ["BACKEND"]
zone = os.environ["CLIENT_ZONE"]
storage = GrpcStorageProxy(host="127.0.0.1", port=13001)
storage.wait_server_ready(timeout=10)
study_id = storage.create_new_study(
[StudyDirection.MINIMIZE], study_name=f"{backend}-{zone}"
)
trial_id = storage.create_new_trial(study_id)
storage.set_trial_state_values(trial_id, TrialState.COMPLETE, [1.0])
trial = storage.get_trial(trial_id)
assert trial.datetime_start is not None
assert trial.datetime_complete is not None
print(backend, zone, trial.datetime_start.isoformat(), trial.datetime_complete.isoformat())
storage.close()For each backend, the three clients were launched concurrently with:
for entry in "Asia/Tokyo" "America/Los_Angeles" "UTC"; do
BACKEND="$backend" CLIENT_ZONE="$entry" TZ="$entry" uv run python client.py \
> "client-${entry//\//_}.log" 2>&1 &
done
wait
cat client-*.log
cat server.logResults
SQLite results:
sqlite America/Los_Angeles 2026-09-17T18:04:18.477684 2026-09-17T18:04:18.483003
sqlite Asia/Tokyo 2026-09-18T10:04:18.465569 2026-09-18T10:04:18.470433
sqlite UTC 2026-09-18T01:04:18.408082 2026-09-18T01:04:18.415874
MySQL results:
mysql America/Los_Angeles 2026-09-17T18:05:19 2026-09-17T18:05:19
mysql Asia/Tokyo 2026-09-18T10:05:19 2026-09-18T10:05:19
mysql UTC 2026-09-18T01:05:19 2026-09-18T01:05:19
All six client runs completed successfully. The local times differ by the expected timezone offsets, while representing the same server-side instants. The MySQL run also confirms that the behavior works with the database backend relevant to typical GrpcStorageProxy deployments.
Compatibility note
This change updates the gRPC timestamp wire representation from the legacy format to timezone-aware ISO-8601. New servers are therefore incompatible with older GrpcStorageProxy clients. This behavior should be noted.
Motivation
This is the gRPC-side follow-up to #6708.
Although #6776 made timestamp handling in the storage backends consistent, gRPC still serialized trial datetimes without timezone information. As a result,
datetimes could be interpreted using the gRPC server's local timezone.
Description of the changes
FrozenTrial.Checklist