Per-prompt SDK time zone
SDK prompt 逐条上报时区
Web and Desktop prompts carry the browser zone that the Host canonicalizes and records on that user message, and [time-context](../../../../packages/context/time-context/README.md) tells the model to interpret unqualified dates and times in it. SDK prompts recorded `{ kind: 'user' }`, and time-context read a zone only from a user source that also had a Web `rpcId`. Every SDK request therefore showed `Browser time zon
Source compatibility: Chinese title uses a compatible non-canonical header
English
Problem
Web and Desktop prompts carry the browser zone that the Host canonicalizes and records on that user message, and time-context tells the model to interpret unqualified dates and times in it. SDK prompts recorded { kind: 'user' }, and time-context read a zone only from a user source that also had a Web rpcId. Every SDK request therefore showed Browser time zone for this request: unavailable., and the model asked about dates that a Web user would never be asked about. The SDK protocol had no field through which an embedding application could report its user's zone.
Decision
The zone stays request-local message source data, as in the explicit Schedule time-zone decision; the SDK supplies it per prompt.
session/promptandsession/queryaccept an optionaltimeZone. The TypeScript client accepts it inHarnessClient.prompt()options andrun()options; the Python client accepts thetime_zonekeyword insession_prompt()andrun().- The SDK server canonicalizes an explicit value with
canonicalClientTimeZone, the check the Web Host uses. A rejected value fails that request with aTypeError, answered as JSON-RPC-32603like the server's other parameter errors, before a Session is created or input is routed. - An omitted value samples
Intl.DateTimeFormat().resolvedOptions().timeZonewhen each prompt is accepted. A sampled value that does not canonicalize, such as+00:00underTZ=GMTorEtc/Unknown, records no zone and does not fail the prompt. - The prompt records the
sdk-usermessage source{ kind: 'user', clientTimeZone? }withoutrpcId. TherpcIdidentifies a Web submission for prompt acknowledgement and attachment reclamation, which the SDK does not have. reportedBrowserTimeZonereads a stringclientTimeZonefrom anyusersource. Writers canonicalize before commit, and request preparation still refuses a noncanonical value, so the Web path and the model-visible text stay unchanged.- Native commands record no zone. Web executes slash commands through
commands.executewithoutclientTimeZone, and SDKsession/queryroutes commands to the same handlers, so/plan <text>steers a zone-less message on both paths.
Alternatives considered
Inject one runtime-wide zone into every request. A process or configuration zone applied by time-context would also cover in-process children and plugin messages, but it would present a deployment fact as user authority. The time-context fallback display zone already exists and deliberately keeps the unavailable policy.
Write a synthetic rpcId on SDK prompts. This reuses the Web source variant unchanged, but Web clients use rpcId to settle submissions and reclaim attachments, so a synthetic identity would claim a Web submission that never existed.
Fix the zone at initialize. One value per connection saves a field per prompt, but a long-lived runtime can serve users in different zones and a process zone can change, so the value would become stale. A per-prompt value matches the Web browser sample.
Consequences
- SDK embeddings that pass no zone now report the runtime process zone. In a container this is usually
UTC, which may differ from the user's zone; the upgrade guide tells consumers to passtimeZoneortime_zone, or to setTZ. - SDK subagent children receive prompts without a zone, so they report their own process zone; in-process children see
unavailable, as on Web. - A reader that predates the relaxed check ignores an SDK prompt zone; the persistence record keeps the format version.
packages/sdk/server/tests/time-zone.spec.tspins canonical, rejected, sampled, and unusable zones, thesession/queryroute, and matching/plansources on the SDK and native command paths.apps/cli/tests/profiles/sdk/keyless-smoke.e2e.tsasserts the model-visible line through the shippedsdkprofile. The SDK snapshot driver sendstimeZone: 'UTC'and runs withTZ=UTC.
中文
问题
Web 与 Desktop 的 prompt 携带浏览器时区,Host 规范化后把它记录在该条用户消息上,time-context 随后让模型按该时区解释未限定时区的日期与时间。SDK prompt 记录的是 { kind: 'user' },而 time-context 只从同时带有 Web rpcId 的 user 来源读取时区。因此每个 SDK 请求都显示 Browser time zone for this request: unavailable.,模型会就 Web 用户从不会被追问的日期去询问用户。SDK 协议也没有字段让嵌入方应用上报其用户的时区。
决定
时区仍是请求本地的消息来源数据,与显式定时任务时区决定一致;SDK 逐条 prompt 提供它。
session/prompt与session/query接受可选的timeZone。TypeScript 客户端在HarnessClient.prompt()选项和run()选项中接受它;Python 客户端在session_prompt()和run()中接受time_zone关键字参数。- SDK server 用 Web Host 所用的同一检查
canonicalClientTimeZone规范化显式值。被拒的值让该请求以TypeError失败,与 server 的其他参数错误一样应答为 JSON-RPC-32603,发生在创建 Session 或路由输入之前。 - 省略时,在接受每条 prompt 时采样
Intl.DateTimeFormat().resolvedOptions().timeZone。采样值无法规范化时(例如TZ=GMT下的+00:00或Etc/Unknown),不记录时区,也不让 prompt 失败。 - prompt 记录不带
rpcId的sdk-user消息来源{ kind: 'user', clientTimeZone? }。rpcId标识一次 Web 提交,用于 prompt 确认和附件回收,SDK 没有这样的提交。 reportedBrowserTimeZone从任何user来源读取字符串clientTimeZone。写入方在提交前规范化,请求准备阶段仍拒绝非规范值,因此 Web 路径和模型可见文本都不变。- 原生命令不记录时区。Web 通过
commands.execute执行 slash 命令且不带clientTimeZone,SDKsession/query把命令路由到同一批 handler,因此两条路径上的/plan <text>都 steer 一条不带时区的消息。
备选方案
向每个请求注入一个运行时级时区。 由 time-context 应用的进程或配置时区也能覆盖进程内子 agent 与插件消息,但它会把部署事实当作用户依据呈现。time-context 已有回退显示时区,并且有意保留 unavailable 策略。
在 SDK prompt 上写入合成的 rpcId。 这样可以原样复用 Web 来源变体,但 Web 客户端用 rpcId 结算提交并回收附件,合成标识会声称存在一次从未发生的 Web 提交。
在 initialize 时固定时区。 每个连接一个值可以省去每条 prompt 的字段,但长期运行的运行时可能服务不同时区的用户,进程时区也可能变化,该值会过时。逐条 prompt 的值与 Web 浏览器采样一致。
影响
- 不传时区的 SDK 嵌入方现在上报运行时进程时区。容器中通常是
UTC,可能与用户时区不同;升级指南要求使用方传入timeZone或time_zone,或设置TZ。 - SDK subagent 子运行时收到的 prompt 不带时区,因此上报自身进程时区;进程内子 agent 与 Web 上一样看到
unavailable。 - 早于放宽检查的读取方会忽略 SDK prompt 的时区;持久化记录保持格式版本不变。
packages/sdk/server/tests/time-zone.spec.ts固定规范化、拒绝、采样与不可用时区,session/query路由,以及 SDK 与原生命令路径上一致的/plan来源。apps/cli/tests/profiles/sdk/keyless-smoke.e2e.ts通过随发行版交付的sdkprofile 断言模型可见的那一行。SDK snapshot 驱动发送timeZone: 'UTC'并在TZ=UTC下运行。