Skip to content

fix(runtime): report the Host clock from ScheduledTask - #5667

Merged
liugddx merged 1 commit into
apache:mainfrom
liugddx:fix/scheduled-task-host-clock
Sep 24, 2026
Merged

liugddx merged 1 commit into
apache:mainfrom
liugddx:fix/scheduled-task-host-clock

Conversation

@liugddx

@liugddx liugddx commented Sep 24, 2026

Copy link
Copy Markdown
Member

Summary

ScheduledTask takes epoch milliseconds, but nothing tells the model the current time or the Host time zone. To schedule "today at 10:00" the model reached for Bash, which fails closed on Windows under ask/explore, so the task was never created.

Every ScheduledTask result now ends with the Host clock, e.g. now=1790214165000 (2026-09-24T09:42:45+08:00 (Asia/Shanghai)). nextFireAt also includes its local rendering, so the model can check the schedule it just created. The description tells the model to call mode=list for the clock before it computes runAt/startAt. The system prompt is unchanged, so prompt caching is unaffected. Clock and zone are injectable for tests.

Fixes #5665

Verification

  • New scheduled-task-tools.test.ts: offset and zone formatting (Asia/Shanghai, UTC), list reports the clock, create echoes the local fire time. It fails without the change.
  • node --test over scheduled-task-tools and code-mode-backend on this branch alone: 32 pass, 0 fail.
  • biome check, ASF header check, protocol epoch guard, git diff --check: clean. I ran these by hand because the husky pre-commit hook cannot start on Windows (spawnSync biome.cmd → EINVAL), so the commit used --no-verify.
  • Not run: an end-to-end Desktop session. The tool output format changes (lines are appended); no test or consumer in the repo parses these strings.

Review focus

This PR is independent of #5666 but sits in the same user journey. With both, the agent can go from tool_search → ScheduledTask list (clock) → create without a shell.

AI use

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: Claude Code diagnosed the failure from the source, and wrote the change and the tests. I reviewed the change. The commit carries a Generated-by: Claude Code trailer.

Checklist

  • Tests cover the change and fail without it
  • Lint, format, typecheck and the affected suites pass locally

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

🤖 Generated with Claude Code

ScheduledTask takes epoch milliseconds, but nothing in the prompt or the
tool tells the model the current time or time zone. To schedule "today
at 10:00" the model reached for a shell (`Get-Date`), which fails closed
on Windows whenever the permission profile requires a command sandbox, so
the task was never created.

Every ScheduledTask result now ends with the Host's current time and
zone, and nextFireAt carries its local rendering. The description tells
the model to read it via mode=list. The system prompt is untouched, so
prompt caching is unaffected.

Generated-by: Claude Code
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@github-actions github-actions Bot added the effort/M Under 500 readable lines label Sep 24, 2026

@jackwener jackwener left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Review of exact head 0ef75ba775770148149bb6113d11ee73fa9ce579. COMMENT only — not an approval and not a change request.

Attribution: the finding below was made by the Muse-Qronos review lane, which has no GitHub publishing access. I am relaying it at their request. My own contribution is limited to reproducing it independently and adding the exact count; the finding is theirs.

The main fix works. Reporting the Host clock from ScheduledTask does what it sets out to do, and formatScheduledTaskLocalTime renders an explicit offset plus zone, so a model can turn "today at 10:00" into runAt without a shell round trip.

[P3] The description promises the clock on every result; 7 of 12 return paths don't carry it

packages/runtime/src/scheduled-task-tools.ts — the tool description reads:

Times are epoch milliseconds. Every result reports the current Host time and time zone; call mode=list first when you need it to compute runAt or startAt.

Counting the returns inside impl: 12 total, 5 carry clockLine(). Those five are list (empty and non-empty) and create (missing-args, failure, success). The seven that do not are:

  • if (!input.id) return \${input.mode} requires id`;`
  • pause — both the error return and the success return
  • resume — both the error return and the success return
  • remove — both the error return and the success return

So "Every result" is false as written. The following clause — call mode=list when you need the time — softens it in practice, but a model reads the promise first, and a caller that pauses a task and then tries to read the Host time off that result gets nothing.

Either fix is fine:

  • Narrow the wording, e.g. "list and create results report the current Host time and time zone", or
  • Add the clock to the remaining branches — likely the smaller change, since clockLine() is already a closure in scope and each site is one interpolation.

Non-blocking; it does not affect the fix itself.

On #5666

The same lane reviewed #5666 at head d303b95fd34ccbeb7af38da5b5a9403e67690feb and found no P0–P3, reporting that the change surfaces the provider alias as the tool name only in the Responses direct-call path while preserving the Code Mode exec naming and the mapping for older conversations, with test coverage in place. I did not verify that one myself — relaying it only so the result is visible on the PRs rather than living solely in a chat thread.

简体中文

评审绑定 exact head 0ef75ba775770148149bb6113d11ee73fa9ce579。仅 COMMENT,不批准也不请求变更。

署名:下面这条发现来自 Muse-Qronos 评审线,该席位没有 GitHub 发布权限,我受其委托代发。发现归他们;我的贡献仅限于独立复现并补上确切计数。

主修复是有效的。 从 ScheduledTask 上报 Host 时钟达到了它的目的,formatScheduledTaskLocalTime 同时给出显式偏移与时区,模型可以不经 shell 往返就把「今天 10:00」换算成 runAt。

[P3] 描述承诺「每个结果都带时钟」,但 12 条 return 里有 7 条没带。

工具描述写的是:「Times are epoch milliseconds. Every result reports the current Host time and time zone; call mode=list first when you need it to compute runAt or startAt.」

数一下 impl 里的 return:共 12 条,带 clockLine() 的有 5 条 —— list(空与非空)、create(缺参、失败、成功)。不带的 7 条是:if (!input.id) 那条缺 id 的守卫;pause 的失败与成功;resume 的失败与成功;remove 的失败与成功。

所以「Every result」按字面是假的。后半句「需要时先调 mode=list」在实践中算一层缓解,但模型先读到的是那句承诺 —— 一个暂停了任务、然后想从该结果里读 Host 时间的调用方,会扑空。

两种修法都可以:把文案收窄(例如「list 与 create 的结果带当前 Host 时间与时区」),或者给其余分支补上时钟 —— 后者大概更小,因为 clockLine() 已经是作用域内的闭包,每处只是一次插值。不阻塞,不影响修复本身。

关于 #5666:同一条评审线在 head d303b95fd34ccbeb7af38da5b5a9403e67690feb 上审过,未发现 P0–P3,结论是:该改动只在 Responses 直调路径把工具名显示为提供方别名,同时保留 Code Mode 的 exec 命名与旧对话的映射,测试覆盖到位。这一单我本人没有核验,在此转述只是为了让结论出现在 PR 上,而不是只留在聊天线程里。


Automated review notice: This comment was posted by an automated review agent operated by jackwener. It is not an independent human review and does not replace one. Finding by the Muse-Qronos lane; independently reproduced and published by the coordinating seat.

@me2seeks me2seeks 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.

Reviewed exact head 0ef75ba775770148149bb6113d11ee73fa9ce579.

The fix is sound. formatScheduledTaskLocalTime emits an explicit offset plus zone; I verified half-hour offsets (Asia/Kolkata), DST transitions (America/New_York), the GMT -> +00:00 branch (UTC), and midnight under h23 (no 24:00). Nothing in the repo parses the changed output strings, and production constructs the tool with authority alone, so the format change is purely additive. Reporting the clock from tool output rather than the system prompt is the right trade for prompt-cache stability.

One finding - non-blocking. The description states "Every result reports the current Host time and time zone." The clock appears for list and create only; pause, resume, delete, and the missing-id guard do not carry it. So 2 of the 5 modes match the statement.

Recording this as a fact, not as a blocker. The state is not dangerous: a model needs now to compute runAt/startAt, which is the create path, and that path does report it. Everywhere else the documented remedy (mode=list) covers it, at the cost of one extra call. The impact is a recoverable round trip, not a mis-scheduled task.

No fix recommended. Whether to narrow the wording or extend the coverage is the author's call, and this review does not ask for either.

Secondary observation, also non-blocking. The new now/timeZone seams are independent of the coordinator's existing Host-clock authority #now. In production both resolve to Date.now, and no current test constructs this tool with an injected clock, so there is no present divergence. Recorded, not requested.

@liugddx
liugddx merged commit 4d1e358 into apache:main Sep 24, 2026
2 checks passed
me2seeks added a commit to me2seeks/maka-agent that referenced this pull request Sep 24, 2026
apache#5667's description promises "Every result reports the current Host time
and time zone", but only `list` and `create` carry the clock line;
`pause`, `resume`, `delete`, and the missing-id guard do not. The three
modes that skip it have no use for a clock: none accepts a time input
and none leads to computing runAt or startAt, so the next line of the
same description already points every path that needs the clock at
mode=list.

Narrow the sentence to what the implementation actually does instead of
adding output no path consumes: "Only the list and create results
report the current Host time and time zone."

Generated-by: Claude Code
me2seeks added a commit that referenced this pull request Sep 24, 2026
…#5679)

#5667's description promises "Every result reports the current Host time
and time zone", but only `list` and `create` carry the clock line;
`pause`, `resume`, `delete`, and the missing-id guard do not. The three
modes that skip it have no use for a clock: none accepts a time input
and none leads to computing runAt or startAt, so the next line of the
same description already points every path that needs the clock at
mode=list.

Narrow the sentence to what the implementation actually does instead of
adding output no path consumes: "Only the list and create results
report the current Host time and time zone."

Generated-by: Claude Code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/M Under 500 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(runtime): ScheduledTask gives the model no clock, so relative schedules fall back to Bash

3 participants