Skip to content

fix(runtime): enforce wall-clock budget while the event stream is silent - #85

Open
Sthreal wants to merge 1 commit into
helsome:mainfrom
Sthreal:fix/83-wall-clock-budget
Open

fix(runtime): enforce wall-clock budget while the event stream is silent#85
Sthreal wants to merge 1 commit into
helsome:mainfrom
Sthreal:fix/83-wall-clock-budget

Conversation

@Sthreal

@Sthreal Sthreal commented Sep 11, 2026

Copy link
Copy Markdown

改动说明

RunManager 增加显式的 wall-clock deadline,使 wallClockMs 不再依赖 runtime 产生新事件。

具体包括:

  • 增加可注入的 RunManagerScheduler,生产环境使用 setTimeout,测试使用手动 scheduler
  • run 启动时创建 wall-clock deadline
  • event-driven budget 和 wall-clock deadline 共用一条幂等 safeguard stop path
  • timer 到期后设置 stopReason = budget_exhausted
  • stopDetail 标明 key = wallClockMs、limit 和实际使用量
  • 正常完成、用户取消、budget stop 都会清理 timer
  • 防止 deadline 在 ensureSession 期间到期后仍启动 runtime
  • 旧 run 的 timer callback 不会影响后续 run

关联 Issue

Closes #83

验证

  • 已完成与本次改动相关的验证
  • 如果存在已知 baseline / 环境失败,已在下方说明

测试环境:

  • Bun 1.4.2 (744846f84)
  • Windows 10.0.22631
  • x64 / AMD64

执行命令及结果:

bun test packages/shared/src/kernel/run-manager.test.ts
20 pass / 0 fail

bun test packages/shared/src/kernel
61 pass / 0 fail

bun test packages/shared/src/evidence
4 pass / 0 fail

bun run typecheck
@finagent/core       passed
@finagent/i18n       passed
@finagent/shared     passed
@finagent/ui         passed
@finagent/electron   passed

git diff --check
passed

已在最新 upstream/main (4eca2d1) 上完成 rebase。已确认 #60 的 structured financial evidence wiring 与本次 wall-clock deadline 修改同时保留;evidence 测试 4/4 通过。

覆盖场景:

  • stream 在第一个事件前卡住
  • stream 在 partial output 后卡住
  • ensureSession 期间 deadline 到期
  • timer callback 重复触发只 cancel 一次
  • 旧 run 的 deadline 不影响新 run

UI 截图(涉及 UI 时必填)

  • 本 PR 不涉及 UI 变化
  • 已提供修改后的 UI 截图
  • 已提供 Before / After 对比截图(适用时)

Before(适用时)

不适用。

After

不涉及 UI。

Scope / 后续

本 PR 完整关闭 #83,不包含 checkpoint、恢复协议或底层存储重构。无已知未完成项。

@helsome helsome left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

实现与 focused tests 方向够了,不要求扩大 scope。合入前只补两点:

  1. 测试报告补 Bun 版本 + OS/平台;现有 run-manager.test.ts 20/0、kernel 61/0、全 workspace typecheck 无需重跑扩大。
  2. 最新 main 已合入 #60,而 #60 同样修改 packages/shared/src/kernel/run-manager.ts/test.ts。请 rebase 最新 main,解决该真实重叠后跑基础 CI,确认 financial evidence wiring 与 wall-clock deadline 都保留。

补齐后即可继续审核;本 PR 不涉及 UI,无需截图。

@Sthreal
Sthreal force-pushed the fix/83-wall-clock-budget branch from b2a53ab to 06ccc4d Compare September 12, 2026 12:21
@Sthreal

Sthreal commented Sep 12, 2026

Copy link
Copy Markdown
Author

@helsome 已补齐两项:

  1. PR 描述补充了测试环境:Bun 1.4.2 (744846f84),Windows 10.0.22631,x64 / AMD64。
  2. 已 rebase 到最新 upstream/main (4eca2d1),解决与 feat(evidence): persist structured financial lineage #60run-manager.ts / run-manager.test.ts 的重叠;确认 structured financial evidence wiring 与 wall-clock deadline 均保留。

Rebase 后验证:

  • bun test packages/shared/src/kernel/run-manager.test.ts: 20 pass / 0 fail
  • bun test packages/shared/src/kernel: 61 pass / 0 fail
  • bun test packages/shared/src/evidence: 4 pass / 0 fail
  • bun run typecheck: 全部 workspace 通过

已 force-with-lease 更新 PR 分支,请再次 review。

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.

[Runtime] Enforce wall-clock budgets while the event stream is silent

2 participants