Repository navigation
fix(scheduler_hint): eliminate Any annotations and deduplicate timestamp parsing - #9459
Conversation
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
动机 / Motivation
让 scheduler hint 保持 TypeScript 调度判断,减少相同时间文本的 Python 解析,显式绑定 ACK/failure transport 字段。 基线遍历多个 monitor 与 failure 观察,重复解析同一个文本;ACK/failure 参数从 locals 动态复制。 Codex App heartbeat 调度者、generic CLI host 与 scheduler ACK/failure 消费者。
四组独立配对走真实 TypeScript owner。基线与 head 的完整 hint、时间 facts 和解包 ACK/failure payload 一致;每组 Python 时间解析从 13 次降到 4 次。等效时区用各自原始文本 lookup,未丢条目。 重复 monitor 观察不耗重复解析,既有等待、恢复、失败与 ACK 边界仍准确。 当前定向 scheduler 57 项本地测试通过,真实 CLI RRULE ACK 路径通过。冻结 retrodiction 在精确 base/head 各 1 项通过。 冻结 retrodiction 用同一命令在精确 base/head 各自通过。PR 描述此前记录两端失败,本轮无法重现;环境差异未归因,远端 CI 未核验。 基线契约
改动思路 / Approach
该改动沿用 build_scheduler_hint → scheduler.hint.project → bounded host follow-up transport → quota scheduler-ack-current。Python 保持现有 transport owner,TypeScript 协议依然只执行一次。明确的 ACK/failure 字典字段维持原 typed 路由。 同一原始文本只解析一次,原 lookup key 保留。带相同 UTC 时间的不同文本分别拥有事实。Follow-up 保留精确 Goal 实例和必要字段。 时间去重按真实字典的文本 key,保留这一解析 owner 和现有 host binder。
具体改动 / Changes
精确提交 9c64771,分叉基线 50aa5b4。两个文件增加 563 行、删除 141 行,调度模块和独立契约用例。
关键代码讲解
-
_timestamp_facts。生成去重后的原文本事实和相对时间。 源码 -
build_scheduler_hint。只调用现有的 typed scheduler owner。 源码 -
build_app_automation_scheduler_ack_hint。复用原 ACK transport,列出允许运送的字段。 源码 -
build_app_automation_scheduler_failure_hint。按当前 schema 精确投递失败观察。 源码 -
scheduler_hint_transport_and_host_binding(implemented)。同一状态保留 action、host action 和正确的原实例 ACK/failure 指令。
对主干的风险 / Risks
active、quiet wait、普通 CLI 与 invalid profile 各保留原 action。普通 CLI 和 invalid profile 均没有 host apply action。真实 CLI ACK 回合写入后重读确认本轮无再 ACK/apply。 当前定向 scheduler 57 项本地测试通过,真实 CLI RRULE ACK 路径通过。冻结 retrodiction 在精确 base/head 各 1 项通过。 冻结 retrodiction 用同一命令在精确 base/head 各自通过。PR 描述此前记录两端失败,本轮无法重现;环境差异未归因,远端 CI 未核验。
我的整体评价 / Verdict
APPROVE。 独立配对同时确认解析调用减少和实际调度状态一致。真实 CLI 完成 ACK 写回并验证无再 ACK/apply。作者指出的冻结基线差异完整带入证据,本机两端均通过。 重复 monitor 观察不耗重复解析,既有等待、恢复、失败与 ACK 边界仍准确。
English verdict: APPROVE at 9c64771. Approve. Exact paired scheduler decisions and ACK/failure transport match. Timestamp parsing drops from 13 calls to 4, and the same frozen retrodiction test passes on base and head.
huangruiteng
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · GPT-5 · OpenAI · self_reported
动机 / Motivation
使用 Codex App heartbeat、generic CLI scheduler 和 host ACK/failure follow-up 的 LoopX 操作者及调度消费者。
修复前,相同时间文本按观察次数重复解析;修复后,只按原文本解析一次,并以同一文本 key 生成原有 timestamp facts。
active、quiet wait、ACK、failure 和空容器路径保持原有 action、host binding、字段 presence 和 bounded transport;重复时间观察减少解析次数。
不改变 TypeScript scheduler decision owner、RRULE 仲裁、host 授权、持久状态或 CLI 命令协议。
改动思路 / Approach
改动保持在既有 scheduler 适配 owner 内,并以较小机制获得类型安全和解析去重。
只改 scheduler_hint 与其契约测试。
入口是 build_scheduler_hint and build_app_automation_scheduler_ack_hint/failure_hint。权威输入为 Quota payload observations, scheduler execution context, arbitration, current time and host/runtime transport bindings。决定边界:Existing scheduler.hint.project TypeScript owner; Python projects facts, deduplicates observations and transports follow-up commands。结果:Read-only scheduler hint projection and bounded follow-up args; no decision or persistence mutation。消费方:Host consumers receive ACK/failure CLI commands and scheduler actions with the original routing fields。失败与重试:Malformed runtime shapes raise at the same adapters; missing optional facts remain skipped; existing host retry owns transport failure。
具体改动 / Changes
按 docs/product/core-control-plane/state-machine.md 的 revision 50aa5b4fd1c88b7225fc30e58423120e3ad5d426 核对,scheduler-decision-owner / transport-and-host-binding / timestamp-observation-parity 分别对应下面的行为与验证。
关键代码讲解
_timestamp_facts:按原始文本去重 observations,并为每个不同文本生成 normalized timestamp fact;相同文本不再重复 parse_timestamp,原有 iso/utc/after_seconds 形状保持。build_scheduler_hint:收集现有 scheduler facts、context 和 deadlines,再交给唯一 TypeScript projection;参数改为 Mapping/object/TypedDict,调用的 projection 和后续 transport 不变。build_app_automation_scheduler_ack_hint:显式构造成功 ACK follow-up 参数并调用同一 projection transport;动态 locals 复制改为固定字段字典,字段、normalization 和 key presence 保持。build_app_automation_scheduler_failure_hint:显式构造 failure follow-up 参数并复用同一 normalization 和 transport;动态 locals 复制改为固定字段字典,失败状态和 observed RRULE 保持。
变更共 2,563 additions、141 deletions。One production scheduler module replaces Any and dynamic dictionaries while preserving the existing TypeScript projection and transport seams; one contract test file pins typing, timestamp deduplication and key-presence behavior.
scheduler-decision-owner:Python scheduler hint 不得复制 TypeScript 调度决策,只投影并传输同一 owner 的结果;当前为 implemented。transport-and-host-binding:ACK/failure follow-up 必须保留原 Goal 实例、runtime routing、字段 presence 与 bounded CLI transport;当前为 implemented。timestamp-observation-parity:相同时间文本只解析一次,不同文本各自保留事实,畸形输入继续跳过;当前为 implemented。
对主干的风险 / Risks
最强回归场景:显式字段字典漏掉 ACK/failure 参数,或时间去重把不同原始文本错误合并,导致 host routing 或等待判断变化。触发状态:Optional field presence differs, same UTC time has different text, malformed monitor entries or non-datetime clock。修复边界:Explicit field lists, raw-text keys, Mapping/Sequence narrowing and existing shape checks preserve the boundary。影响范围:Scheduler hint and host ACK/failure follow-up only。可观察性:Scheduler action, host action, CLI args, timestamp fact keys and transport errors expose the result。恢复路径:Revert the two-file refactor; no persisted migration exists。
changed_invariant_positive=passed (685 passed in 217.67s.);material_negative_or_failure=passed (All expected rejection and skip paths passed.);static_and_contract_checks=passed (Ruff and strict mypy passed; premerge 18/18 with 0 manual holds.);repository_required_checks=passed (All direct checks passed.)。
- PASSED · Scheduler hint, ACK/failure transport and timestamp deduplication:685 passed in 217.67s.
- PASSED · Malformed transport, invalid timestamp clock, missing optional values and bounded native args:All expected rejection and skip paths passed.
- PASSED · Zero Any, zero type-ignore, strict typing and repository premerge:Ruff and strict mypy passed; premerge 18/18 with 0 manual holds.
- PASSED · Diff hygiene and bilingual/RFC checks:All direct checks passed.
我的整体评价 / Verdict
长程效果判断为 improved:长 monitor/failure 观察的热路径减少重复解析,同时决策与恢复边界保持不变。用户体验判断为 preserved:CLI/App 调度行为、ACK/failure 指令和错误边界不变。视觉检查不适用,本 PR 仅改 scheduler Python 适配与测试。
精确 head 的 685 项 scheduler 相关测试、Ruff、strict mypy 和 18/18 premerge 均通过;未发现阻塞问题。
English verdict: APPROVE at 9c64771. The exact head preserves scheduler decisions and ACK/failure transport while removing Any and duplicate timestamp parsing. It passes 685 scheduler-related tests, Ruff, strict mypy and 18/18 premerge.
Summary
Anyannotations (58 -> 0ASTAny,0 # type: ignore) and redundant hot-path work inloopx/control_plane/scheduler/scheduler_hint.pywhile keeping the single module compact (540 <= 550LOC) and preserving exactorigin/main(50aa5b4fd1) projection and transport behavior.TypedDictcontracts (SchedulerHostFollowupGoalRef,SchedulerTimestampFact) and explicitMapping/Sequence/objectsignatures inloopx/control_plane/scheduler/scheduler_hint.py(540LOC, explicitasmonkeypatch re-exports fornow_utc,parse_timestamp,utc_isoformat,effect_runtime_result,loopx_cli_argv,MONITOR_WAIT_PHASE_RANK,MonitorWaitPhase), keeping legacy field module counts unchanged (execution_obligation.py=20/20).dict(locals())construction inbuild_app_automation_scheduler_ack_hintandbuild_app_automation_scheduler_failure_hintwith explicit typed dictionaries, used.get(...)lookups in_timestamp_observations, and deduplicated repeated_timestamp_factsparse_timestampcalls via normalized text keys (11 -> 2calls on duplicate observation fixture; paired counterfactual5/5probes byte-identical toorigin/main).tests/control_plane/test_scheduler_hint_contract.py(314LOC) covering AST0-Any/0-type: ignore/LOC hygiene, timestamp deduplication, transport/followup key-presence vsNoneand bounds, legacy empty containers, ack/failure hint normalization, and non-datetime/MappingProxyTypeedge cases.loopx/control_plane/scheduler/scheduler_hint.py,tests/control_plane/test_scheduler_hint_contract.py),1/1DCO commit,loopx/canary/module_metric_baseline.jsonuntouched, top-levelloopx/*.py == 112.Verification (
9c64771028024b87ef8cf777f697a24b1b55fd77over50aa5b4fd1)ruff check2/2clean;mypy --strict --follow-imports=silent2/2clean; repo[tool.mypy]17/17clean; 12-callerloopx/mypydiff+0/-0regressions (4401 -> 4401pre-existing repo-wide count across checked transitive files).npm run typecheck:control-planeclean;node --test tests/control_plane_ts/content_digest_single_owner.test.ts17/17passed;scripts/check_rfc_bilingual.pypassed; cleangit merge-tree(32565368e3).origin/mainvs9c64771028across 5 probes (quiet_wait,active_work,empty,ack,failure) byte-identical (15,945bytes;parse_timestamp11 -> 2calls); clean-HOMEsmokes passed (semantic-vocabulary-drift-smoke[execution_obligation.py=20/20,heartbeat_recommendation.py=16/17],interaction-contract-state-machine-smoke,control-plane-maintainability-ratchet-smoke[unreviewed=0],control-plane-integrated-canary-smokefile+sqlite,quota-scheduler-hint-compaction-smoke,monitor-scheduler-contract-smoke). Note: runningquota-scheduler-hint-compaction-smokeunder an interactiveHOMEfails pre-existing on bothorigin/mainandHEAD, while isolated cleanHOMEpasses cleanly.pytest -n 4 -rs(tests/control_plane/test_scheduler_hint_contract.py,test_scheduler_*.py,test_external_scheduler_worker.py,test_automation_cadence.py,test_host_loop_runtime_parity.py,tests/canary/,tests/architecture/-k "not test_retrodiction_holds_its_frozen_baseline") ->2,749 passed, 6 skipped(6 filesystem APFS skips intests/canary/test_git_path_display.py;test_retrodiction_holds_its_frozen_baselineexcluded because it already fails identically onorigin/main50aa5b4fd113/15 == 12/15).loopx check(0errors), Change Quality Receiptcqr_017adc05da53ec91c7ce(decision="pass",receipt_valid=true,status="valid"),canary premerge(ok=true,direct=6/6,catalog_run=10/10,risk_profile_run=8/8,manual_hold_count=0,failures=0).