Skip to content

fix(heartbeat): yield timed waits to the host scheduler - #7662

Merged
huangruiteng merged 3 commits into
mainfrom
codex/heartbeat-host-timed-wait
Oct 29, 2026
Merged

huangruiteng merged 3 commits into
mainfrom
codex/heartbeat-host-timed-wait

Conversation

@loopx-agent

@loopx-agent loopx-agent commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

When an admitted heartbeat had no useful independent work until a known future time, its guidance still said to keep the Todo open. That encouraged repeated model sleeps and clock checks despite the existing ordinary deferred/resume-at scheduler path.

Shared heartbeat guidance now says to preserve progress, defer the original Todo to an evidenced due time, settle the original Turn and yield to the Host scheduler. Resume requires fresh admission; unknown-time waits keep the projected monitor/continuation path, and waiting alone earns no quota spend. Useful independently authorized work remains possible. Full, compact, brief, thin and captured-envelope prompts use the same rule. The native Goal lifecycle, scheduler, claim/lease API, timers and execution authority remain unchanged.

Current head: 8cc03561a9af5aa48f86fec3295d2176b8de4ffc; integrated target main at 33d9ecd9fd29bce4986da6c9e9a6b758a24f91b3.

The review refinement aligns remaining captured-envelope and obligation consumers with this rule. Ordinary thin retains 4,500 characters; captured envelopes alone add the existing 400-character allowance. The generic-CLI brief fixture with a 320-character scope and explicit registry/runtime routes measures 5,715 normalized characters, so its soft presentation allowance is 5,800 instead of 5,700. The task body is identical under those two budgets. Reward-Memory headroom and overflow checks remain isolated; the native Goal hard limit remains 4,000. No useful instruction or executable route is shortened to fit a historical allowance.

Validation:

  • Expanded prompt/notification/long-route/envelope suite: 141 passed, 8 failed. All five newly failing envelope-budget consumers from the review are corrected. The expanded scope/profile/explicit-route matrix and three additional stale closeout-obligation consumers pass. A focused selection excluding the existing worker matrix passes 133 cases (16 deselected).
  • The eight remaining failures are the previously identified file-first worker fixtures that still read interaction_contract or action_signature from the manifest itself. The prior review reproduced the same eight on the original baseline; this revision does not claim them passed or hide them behind premerge. Their existing context-recovery integration owner remains responsible.
  • Ruff, bilingual diff/public-boundary checks and standard local premerge pass (6 direct, 8 catalog, 8 risk and 1 public-boundary check, zero holds). Source was committed unchanged after these checks.
  • Earlier real File/SQLite ordinary claim → verified work → defer/release → same-Turn recovery → once-only writeback/spend and scheduler pending/due/independent-work/stop tests remain recorded at 817a1d8b. This refinement changes their presentation budgets and test consumers, not their runtime semantics; it does not assert a new live-model adoption result.

Original budget failures remain historical failures. Presentation growth is disclosed; this is a guidance correction, not fewer prompt bytes, installed model compliance or measured model-fee savings. It introduces no new settings journey or rendered UI. Bounded refactoring shares the existing rule and budget owner; no second scheduler or waiting protocol is added. The new exact head awaits the designated review lane before merge or installation.

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Reviewer: model_agent; gpt-6.1-sol; OpenAI; runtime_reported; reasoning_effort=max.

Request changes conclusion (author-owned PR; GitHub blocks formal self-review)

动机 / Motivation

等待已知未来恢复时刻的 heartbeat Agent 是这次修正的直接使用者。原指引要求所有外部等待保持 open,容易让 Agent 在没有独立工作时持续睡眠或查时钟;新指引让它保存进展、按已知时间延后原 Todo 并交还宿主。当前 head 已在各 prompt 模式交付正确的定时等待指引,原有 File/SQLite 生命周期与一次结算可用;预算消费者尚未全部对齐。本切片不新增 scheduler、租约接口或执行权限,也不证明真实模型已采用指引或产生费用节省。剩余缺口是对齐 captured-envelope 的预算断言并核清合法参数组合的预算边界;模型采用留待后续有授权的轨迹比较。

改动思路 / Approach

把定时等待规则放进共享 heartbeat 指引并复用普通 Todo deferral 是最小合理边界;scheduler、时钟、claim/lease 与结算仍由原 typed owner 管理。本 PR 交付指引修正和现有机制的真实入口验证;预算调整必须同时覆盖既有 envelope 消费者,不能以缩短有价值条款或降低硬上限要求替代。已知时刻且没有有用独立工作才进入定时延后,未知时间继续原 monitor;Agent 的操作建议与机器实际执行资格分开。指引不能重置 service cooldown、扩大预算或越过停止条件。这个修正可独立交付,不需要新增设置页面、手动租约流程或先启动模型实验。

具体改动 / Changes

完整审查 817a1d8b6ae54033c75ef55b31bc5ef26c8307f4 相对 b201da8bab305d053866aa0d4516b97ba4a4499e 的 6 文件 diff:生产 +21/-17,测试 +38/-4,文档 +31/-0。

关键代码讲解

  • HOST_LOOP_WAIT_RULE 共用 ordinary deferral、original Turn 结算、host handoff、fresh admission 与 no-wait-credit 条款。它只生成建议,实际 state 仍由原 Todo owner 写入。
  • render_thin_heartbeat_task_body 删除独立 Wait=open,改为共享 closeout;其余 full/compact/brief/envelope 同样消费该规则,native Goal host 保持原生命周期。
  • INTERFACE_BUDGET_CHARS 有意把 thin 4,200 调到4,500,captured 的额外400仍单列;native Goal硬上限4,000未改变。现有 envelope 测试的消费者未一并更新。

先读规范 docs/project-agent-todo-contract.md,不可变版本 b201da8bab305d053866aa0d4516b97ba4a4499e。原文无验收编号,使用以下审查映射:WAIT-1(原一次性 resume_at、到期不直接授权)有现有 dated CLI 与20组 prompt 输出;WAIT-2(未知时间 monitor、独立任务可继续)有真实 worker/独立任务/stop 负例;WAIT-3(原 Turn 一次结算)用同一冻结 hard-lease oracle,在 base 与 head 的 File/SQLite 均通过:claim → 17×23成果验证 → deferred自动释放execution → 原身份recovery → writeback/spend各一次 → 新Turn独立候选。此机制 base 已可用,head 改进的是指引。

对主干的风险

[P2] 同步剩余 envelope 预算消费者并核清边界。 tests/control_plane/test_heartbeat_envelope_transport.py:85 仍要求 ordinary4,200,:166 的四个 scope/provider 组合仍要求 captured4,600。相同完整40-case命令在 base 为32通过/8失败,在本 head 为27通过/13失败:新增五项确定性失败分别是 4500 != 4200 和 4900 != 4600。这些直接来自新预算,不能用标准 premerge 或所选 prompt 测试的通过覆盖。

另用公开 builder 的合法 generic_cli + brief + scope_summary=320字符 + 显式registry/runtime 组合量测,base 为5,465/5,400,head 为5,725/5,700,当前仍超25字符;原base的超65也保留,未冒充新增故障。请同步遗漏的预算消费者,按同一工作量核清 headroom,保留 overflow/headroom 隔离断言和有价值条款,native硬4,000保持不变。

其余八条 file-first fixture 错误在 base 已存在:对每条完整 failure payload,仅规范化临时目录、MonkeyPatch内存地址和临时IPC socket 后与 head 完全相同;分别在 manifest 顶层误取 interaction_contract 或 action_signature。这八条与新增预算失败单独归因,不要求本 PR 修理无关旧实现,也不把它们算作已通过。

实际组合运行结果为 292 PASS / 13 FAIL。20组新等待条款输出及冻结 File/SQLite 生命周期均通过;真实 scheduler worker 的 pending wait 不唤模型、due仍走恢复资格、独立工作可执行、explicit stop优先。标准 premerge(6 direct / 8 catalog / 8 risk / 1 public-boundary)与Ruff通过,不能替代上述失败。

语义与 CI 对齐

复用原 deferred / resume_at vocabulary;没有第二timer或新增must-attempt授权。指引增长有实际语义价值,适合基于同工作量调整presentation预算;遗漏测试消费者仍是本head必须修复的回归。wait_for_ci=false,未查询、轮询或等待CI。

我的整体评价

共享等待指引的架构和范围合理,long_horizon 的既有安全/结算机制得到保留,Agent 找到既有合法等待路径更容易;原模型是否因此少轮询仍未验证。已检查 heartbeat Python、普通 Todo guide 与现有 App/Chat 生命周期入口;本 PR 没有渲染页面、布局或组件修改。无适用视觉变化;真实模型是否遵从和费用收益未测试。本 head 因五项新增预算测试回归和仍待核清的边界暂不批准;修复限于当前预算与消费者,不要求扩大成调度器重构。没有merge或安装动作。

English verdict: REQUEST_CHANGES at 817a1d8; timed-wait guidance and original-Turn lifecycle are verified, but five existing envelope-budget tests newly fail and one valid brief configuration remains over budget.

Comment thread loopx/control_plane/heartbeat/budget.py Resolved
…timed-wait

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Reviewer: model_agent; gpt-6.1-sol; OpenAI; runtime_reported; reasoning_effort=max.

Approval conclusion (author-owned PR; GitHub blocks formal self-approval)

动机 / Motivation

执行 heartbeat 工作的 Agent,在保存阶段成果后只剩一个有明确到期时间的等待时,需要知道怎样退出当前工作回合。
旧提示一概要求等待任务保持 open,容易让 Agent 继续睡眠或轮询;新提示只在没有可做的独立工作且到期时间有证据时,指向已有延后操作,先结算原回合,再交回宿主调度。
当前 head 在两类宿主、全部五种输出模式中提供一致的条件与顺序,真实 CLI 检查确认延后释放适用 lease、保留成果、按原身份只结算一次,并让之后的工作重新准入。
本 PR 修正默认指导和展示软预算;不新增计时器、权限、结算 owner 或设置,不重置服务冷却、成本限制与停止条件,也不证明模型实际遵循或长期收益。

改动思路 / Approach

复用共享提示 owner 与已有普通 Todo/lease/结算路径;新增 timer、手工 lease release 或另一套决策状态都无必要。 本 PR 完整交付五种模式的条件化等待指导、据相同负载测量的展示软预算与原 Turn 恢复回归;不承担 scheduler 重写、安装或模型收益资格。

正常路径是:保存实际成果 → 普通 todo update --status deferred --resume-when resume_at:<RFC3339> --reason ... → 原 Turn 按当前 plan 结算 → 宿主调度 → 新执行重新准入。Turn 指一次带原身份的工作回合;修改 Todo 状态并不结算它。没有确切到期证据时保留 monitor/continuation;有可做的独立任务时继续该任务。原有停止、成本限制和服务冷却仍由各自 owner 决定。

对 base/head 的 rules.py、所有 renderer、普通 Todo CLI、既有 resume_condition.ts/resume_planning.ts 及 dashboard 延后入口作过范围搜索。底层普通延后、自动退 lease、身份 fence 与结算机制在 base 已存在;这里修复的是实际默认提示发现并正确使用它的路径。没有新 schema、同步字段、timer、设置或另一套 TypeScript/Python 决策 owner,额外用户确认轮次为0。

具体改动 / Changes

完整9文件为 +119/-36:三生产文件 +23/-17、合同文档 +31、五测试文件 +65/-19。规范依据是变更前 docs/project-agent-todo-contract.md,固定 revision 33d9ecd9fd29bce4986da6c9e9a6b758a24f91b3,同 revision 的 docs/heartbeat-automation-prompt.md 用于核对宿主等待。原文相关段落无编号,下列 WAIT 标签仅为评审映射:WAIT-1(有据的 resume_at、独立工作优先、未知等待走原路径)、WAIT-2(原 Turn 身份、成果和一次结算)、WAIT-3(宿主调度后 fresh admission,不因等待扣款、不绕过停止/预算/冷却)均由输出和真实 CLI 证据实现。

关键代码讲解

  1. HOST_LOOP_WAIT_RULE(loopx/control_plane/heartbeat/rules.py:114)集中表达触发条件、普通延后命令和“原结算先于 yield”的顺序。full/compact closeout 保留原身份、current lease、禁止虚构 successor、只继续已准入工作;其它等待继续走投影出的 monitor。
  2. render_thin_heartbeat_task_body(task_body.py:642)将 thin 的 Wait=open 字面量换为共享 compact closeout。full、compact、brief、thin、envelope 在 generic CLI 和 Codex profile 下共用该规则;这是一项有意的默认指导变更,不能称为 feature-off 正文字节等价。
  3. INTERFACE_BUDGET_CHARS(budget.py:12)只调整展示回归软预算;native Goal 的硬上限仍为4000,captured envelope +400 与 Reward Memory +640 各自保持独立。不以缩掉证据、独立工作或结算条款来迁就旧展示上限。
  4. test_same_turn_bound_p0_does_not_project_p1_after_p0_becomes_deferred(test_quota_settlement_cli.py:5309)经真实 CLI 检查 hard lease 自动退休、artifact 391 保留、原身份拒绝改绑、重复 refresh/spend 一次生效,之后 fresh Turn 可选 P1。同一个冻结当前函数在不可变 base 和 head 的 File/SQLite 上共4例均 PASS,说明既有机制本来存在,本 PR 并未新造它。

相同公开合成负载(scope320、显式 registry/runtime、无 Reward Memory)的规范化字符数如下,测量保留路由与全部正文,只用既有指标排除生成 Turn ID 差异:

generic CLI 模式 base 字符/软上限 当前字符/软上限
full 12781 / 12800 13032 / 13100
compact 7701 / 7600,原已超限 7961 / 8000
brief 5455 / 5400,原已超限 5715 / 5800
thin 4107 / 4200 4428 / 4500

两 profile × 四模式 × scope0/320 × 显式/隐式路由的32组当前均在软上限内。仅把当前 brief cap 从5800改回5700时,仍是同一份5715字符正文,within_budget 从 true 变 false;两份正文 SHA 相同。这个反例支持100字符软上限修复,不代表任意长路由都能容纳,更没有重标历史硬限制或冻结实验的失败。

对主干的风险

主要风险是 Agent 将未知等待误判成定时等待,或忽略独立工作、原结算与 fresh admission。逐条比较 base/head 的 actor、触发条件、证据来源、顺序、权限、继续/停止和结算义务后,唯一有意例外是有据 timed wait;原身份、monitor、仅准入工作、无等待扣款均保留。独立 public builder oracle 在20个 profile/模式/scope输出中全部检出这些义务(base 为0/20);另有 6 PASS 实际 CLI 检查覆盖 pending P0 不遮蔽 P1、到期优先级仅建议,以及停止 Goal 后缓存失效。文本是指导,不是新增 machine gate;真实模型采用仍未知。

语义与 CI 对齐

当前四文件整体测试为 141 PASS / 8 FAIL;同命令在不可变 base 33d9ecd9fd29bce4986da6c9e9a6b758a24f91b3 为 107 PASS / 8 FAIL。原817 head暴露的5项预算断言回归在当前真实消费者中均已通过。剩余八项 worker context_delivery 分支逐个比较了完整错误内容,归一化只涉及 pytest 临时根、MonkeyPatch 地址和 fixture socket 临时根,八对摘要均完全一致;对应 worker 函数 AST 也一致。其旧 complete_page 不识别 file manifest,随后误取 interaction_contract/action_signature;提示规则与软预算没有改变该解析因果路径。独立输出、32预算组合和两后端原 Turn 证据均通过,因此八项标为 pre_existing_unrelated,仍保留为失败,由 #7668 修复 observer;没有借该 PR 的集成结果宣称本 head 全绿。

本地 premerge 的 6 direct + 8 catalog + 8 risk + 1 public-boundary 及 Ruff 均 PASS,覆盖编译、双语差异、Todo/调度/配额、语义与公开边界。没有查询、轮询或等待 CI。新指导复用既有 deferred/resume_at 词汇,未引入 substring 分类、业务专用义务或权限状态。测试无法证明模型会遵循文本;展示字数增长约251至321字符是明确代价,最紧的被测组合余68字符,需要继续如实观察。

我的整体评价

对“修正全部默认输出的 timed-wait 指导并对齐其消费者”这一切片,判断为 goal_achieved;long_horizon 为 preserved,user_experience 为 improved:原成果、一次结算、独立工作和恢复资格得到保持,已有信息和权限下不增加用户问答。thin 重复规则已就地归并,进一步拆新模块、timer 或设置会增加没有证据支持的成本。真实模型采用、长期效果、完整成本和安装资格均未验证;当前八个基线 fixture 失败及其后续集成/readiness 必须独立处理。

已检查 heartbeat/rules.py、task_body.py、budget.py、Todo合同,以及现有 attention-details.ts/attention-actions.tsx 的延后入口;本diff不改页面、布局或渲染呈现。 未声称页面视觉、已安装行为、真实模型采用或长期效果得到验证。

English verdict: APPROVE — 8cc0356: the complete default-guidance change preserves the existing authority and settlement boundaries, and the soft-budget adjustment is supported by matched caller measurements. Eight identical baseline fixture failures remain disclosed; model benefit, merge readiness and merge authority are separate.

@huangruiteng
huangruiteng merged commit b76b333 into main Oct 29, 2026
21 of 37 checks passed
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.

2 participants