Skip to content

[Agent Core] 为 Python Run 建立墙钟截止时间基础 - #159

Merged
rojim666 merged 1 commit into
rojim666:mainfrom
z2Ace0107:codex/issue-69-pr01-deadline-foundation
Sep 11, 2026
Merged

rojim666 merged 1 commit into
rojim666:mainfrom
z2Ace0107:codex/issue-69-pr01-deadline-foundation

Conversation

@z2Ace0107

Copy link
Copy Markdown
Contributor

Summary

这是 Issue #69 的第一个可独立 Review 的 PR,范围仅限 Python runtime 的 Run deadline foundation。

  • 在 Run 开始时基于 monotonic clock 建立一次绝对 deadline。
  • 在 ExecutionContext 中提供 remaining_s()。
  • 保证同一个 Run 重入时不重置 deadline。
  • 统一使用 max_wall_clock_exceeded 表示墙钟预算耗尽。
  • late end_turn 保留已生成结果,同时将 Run 标记为 interrupted。

Behavior

Runner 会在发布 run.started 之前固定墙钟起点,直接调用 AgentLoop.run() 时也会初始化 deadline。deadline 到达后,AgentLoop 不会再开始新的模型请求;如果模型响应已经迟到,仍保留其文本结果,但不会错误地报告为 success。

本 PR 基于当前 main。当前 main 已包含已合并的 #158(权限审批取消流程清理),本 PR 不重复修改权限生命周期逻辑。

Provider、工具、权限等待、Subagent、retry、compaction、cleanup 和 Trace 的剩余时间传播属于后续独立 PR,本 PR 不声称完整解决 #69。

Validation

  • 定向 Python 测试:100 passed
  • Ruff:通过
  • 生产代码 mypy:通过
  • CRLF-aware git diff --check:通过
  • Python 全量测试:1293 passed、6 failed、2 skipped
  • 全量测试的 6 个失败位于既有 multi-agent workflow 和 session IPC 测试,失败文件不在本 PR 改动列表,与此前基线结果一致。
  • 未修改 TypeScript、桌面端、协议或 UI,因此未运行对应构建和视觉检查。

Risk

本 PR 只提供统一 deadline 的基础设施,不会取消正在执行的 Provider 或工具 await,也不会改变权限响应协议。后续 PR 将在此基础上接入剩余时间、硬截止、取消清理和统一终止事件。

UI evidence

N/A:无 TUI 或桌面端视觉变化。

Checklist

  • 变更范围与关联 Issue 一致,没有混入无关重构。
  • 没有提交凭据、日志、缓存、私有源码或本地评测产物。
  • 已添加与风险匹配的回归测试。
  • 无协议变化,无需重新生成协议文档。
  • 无用户文档、配置示例或迁移变化。
  • 提交包含 Signed-off-by(DCO)。

Refs #69

Signed-off-by: Ace <1160684883@qq.com>
@z2Ace0107
z2Ace0107 force-pushed the codex/issue-69-pr01-deadline-foundation branch from fb09b1d to c7c15f2 Compare September 11, 2026 06:29
@rojim666
rojim666 marked this pull request as ready for review September 11, 2026 07:46
@rojim666
rojim666 self-requested a review as a code owner September 11, 2026 07:46
Copilot AI lite review requested due to automatic review settings September 11, 2026 07:46
@rojim666
rojim666 merged commit d41e84d into rojim666:main Sep 11, 2026
1 of 2 checks passed

Copilot AI 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.

🟡 Changes recommended

Deadline enforcement remains incomplete around late model requests and the verification/repair phase.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR establishes monotonic wall-clock deadlines for Python runtime runs.

Changes:

  • Adds non-resetting deadlines and remaining_s().
  • Initializes deadlines before run execution.
  • Handles timeout outcomes and late results.
  • Adds unit and integration coverage.
File summaries
File Summary
py-runtime/tests/unit/test_runner.py Tests deadline initialization order.
py-runtime/tests/unit/test_loop.py Tests loop timeout behavior.
py-runtime/tests/unit/test_context.py Tests deadline lifecycle and exhaustion.
py-runtime/tests/integration/test_deadline_foundation.py Adds deadline integration coverage.
py-runtime/src/sztu_code/core/runner.py Initializes deadlines before run.started.
py-runtime/src/sztu_code/core/loop.py Adds deadline checks and late-result handling.
py-runtime/src/sztu_code/core/context.py Implements deadline state and remaining-time API.
Review details
  • Files reviewed: 7/7 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 764 to +765
elif context.wall_clock_exceeded():
context.mark_interrupted("max_wall_clock_exceeded")
context.mark_interrupted(TerminationReason.MAX_WALL_CLOCK_EXCEEDED)
Comment on lines +371 to +372
# 固定完整 Run 的墙钟起点,覆盖 run.started 事件之后的 provider/registry 初始化。
context.start()
Comment on lines +379 to +381
context.mark_interrupted(TerminationReason.MAX_WALL_CLOCK_EXCEEDED)
else:
context.mark_failed("max_wall_clock_exceeded")
context.mark_failed(TerminationReason.MAX_WALL_CLOCK_EXCEEDED)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants