Skip to content

fix(scheduler): dispatch stranded peer handoffs - #4312

Closed
huangruiteng wants to merge 3 commits into
mainfrom
codex/agent-handoff-dispatch-4311
Closed

huangruiteng wants to merge 3 commits into
mainfrom
codex/agent-handoff-dispatch-4311

Conversation

@huangruiteng

Copy link
Copy Markdown
Collaborator

Closes #4311

Motivation / 动机

An executor-excluded independent_handoff could remain globally unclaimed while the origin monitor kept polling. Delivery through a Codex message was not a durable dispatch or claim receipt.

被 origin Agent 排除的 independent_handoff 可能长期保持全局未认领,而 origin monitor 继续轮询;仅发送 Codex 消息不构成持久派发或认领回执。

What changed / 改动

  • distinguish dispatchable and typed no_eligible_peer frontiers; both are non-quiet

  • reuse the existing manager-context inbox for same-Goal peer dispatch, with restart-safe dispatched -> read -> claimed receipts and terminal stale-claim conflict

  • require live canonical Todo eligibility before first dispatch and canonical claim readback before acknowledgement

  • share manager.context_inbox between quota heartbeat and managed turn run-once; project the bounded receipt through the Turn contract capsule used by frontend/Lark consumers

  • add a bilingual RFC and process-restart CLI acceptance test

  • 区分 dispatchable 与类型化 no_eligible_peer frontier,二者均不可静默等待

  • 复用现有 manager-context inbox 完成同 Goal peer 派发,并提供跨重启的 dispatched -> read -> claimed 回执及 stale-claim 冲突终态

  • 首次派发前校验规范 Todo eligibility,确认前再次校验规范认领

  • quota heartbeat 与托管 turn run-once 共享 manager.context_inbox;有界回执进入 frontend/Lark 共用的 Turn contract capsule

  • 增加双语 RFC 与跨进程 CLI 验收

Product surfaces / 产品入口

CLI/quota and managed Turn changed. Lark consumes the same Turn-start inbox projection. No new frontend control is needed because this is internal routing rather than configurable state; the existing frontend consumes the shared Turn capsule.

Validation / 验证

  • ruff check on changed Python and tests
  • pytest -q tests/test_manager_context_handoff.py tests/control_plane/test_quota_selection.py tests/test_turn_envelope.py (55 passed)
  • npm run typecheck:control-plane
  • targeted TypeScript quota-selection and Turn-envelope tests (18 passed)

The full TypeScript suite was also attempted; Python-spawning legacy cases used the host Python 3.9 and failed on the repository's existing dataclass(slots=True) Python >=3.11 requirement. The targeted changed surfaces pass under the pinned Python 3.13 environment.

@huangruiteng
huangruiteng force-pushed the codex/agent-handoff-dispatch-4311 branch from 81a5813 to 7ea69f1 Compare September 13, 2026 04:26

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

结论:REQUEST_CHANGES(exact head 7ea69f114c9ed7c8d3bc315658e7e46c4ebca2aa)。

动机

这个 PR 解决了“quota/Turn 已经选出同一 Goal 的 peer handoff,但没有真正投递”的断路问题:它引入了带确定性 receipt 的 manager-context dispatch,并在创建 peer claim 前重新读取 canonical Todo。问题定义和同 Goal、已注册 peer 的边界是清楚的。

改动思路

整体流转是 typed quota-selection frontier → dispatch_from_quota_decision → 私有 0600 handoff receipt/inbox → canonical Todo claim/readback → quota/Turn payload。no_eligible_peer、未注册 source、replay 和 claim conflict 都有显式分支,没有按可见 agent 顺序猜 recipient。这个分层复用了 manager-context、Todo 与 agent-scope 的现有 owner。

具体改动

新增 loopx/capabilities/manager_context/agent_handoff.py,负责 receipt identity、同 Goal peer 过滤、canonical Todo 重读、claim/ack 和幂等 replay;quota_selection.ts/Python projection 增加 dispatchable 与 no_eligible_peer frontier;quota should-run 和 managed Turn 在 agent id 存在时接入 dispatch,并把 receipt 投影到 payload。对应的 55 个 focused tests(manager handoff、quota selection、Turn envelope)在 exact head 全部通过。

关键代码讲解

唯一必须修复的阻塞点在 loopx/cli_commands/quota.py:736-749:handle_quota_command 内联了 dispatch_from_quota_decision 的 import/call。这个函数本来已经是仓库维护性 ratchet 关注的决策热点;基线 58dbaeaec9bfad537f5b8ad2b1def9b2dcbd5197 的 ratchet 通过且没有 oversized decision finding,而 exact head 新增了 oversized_decision_function:loopx.cli_commands.quota:handle_quota_command。请把这段调用抽成现有 quota command seam 下的有界 helper(保持 agent-id/should-run guard 和同一 payload receipt),不要用 reviewed exception 掩盖增长。

对主干的风险

这是 P1:GitHub hosted run 34737896084 的 test-shard (3)、pytest 和 merge-gate 都因该 maintainability finding 失败,故当前 exact head 不具备可合并状态。功能性测试虽绿,但不能抵消仓库级门禁;若直接合入,后续 quota 控制面会继续在一个已超限的 orchestration function 上叠加逻辑。其余 handoff 风险(跨 Goal、未注册 recipient、stale claim)在本次代码和 negative tests 中已有明确拒绝路径。

我的整体评价

协议边界、canonical Todo authority 和 replay 设计是合理的,变更也落在正确的 manager-context owner;但当前提交必须先修复 quota handler 的 ratchet 回归,再重新跑完整 hosted checks。修复后请回读新的 exact head,并至少确认 maintainability、pytest、test-shard (3) 与 merge-gate 全部通过。

English verdict: REQUEST_CHANGES — extract the new inline handoff dispatch from handle_quota_command; the exact head fails the repository maintainability ratchet and therefore hosted pytest/test-shard/merge-gate.

Signed-off-by: huangruiteng <14976749+huangruiteng@users.noreply.github.com>
Signed-off-by: huangruiteng <14976749+huangruiteng@users.noreply.github.com>
Signed-off-by: huangruiteng <14976749+huangruiteng@users.noreply.github.com>
@huangruiteng

huangruiteng commented Sep 13, 2026 •

Copy link
Copy Markdown
Collaborator Author

Rebased onto merged main 7eb4b7b and addressed the requested maintainability failure by extracting the heartbeat receipt reconciliation path from handle_quota_command.

Validation on exact head 1308566:

  • tests/canary/test_maintainability_ratchet.py: 8 passed
  • manager handoff/quota selection/turn envelope focus: 55 passed
  • tests/control_plane/test_quota_settlement_cli.py: 45 passed
  • Ruff and git diff --check: passed

The conflict resolution retained latest main reward-memory/periodic imports and todo presentation ordering while preserving this PR manager handoff dispatch semantics. Requesting a fresh independent review; this PR is not being self-merged.

@huangruiteng

Copy link
Copy Markdown
Collaborator Author

Closing this implementation as superseded by the merged capable-manager semantic-handoff RFC (#4330, commit ddf6efa).

The defect remains real, but this PR makes same-Goal, pre-existing Todo, source-excluded quota selection, and manager_context inbox ownership part of the handoff architecture. The accepted M2 direction requires one typed Core collaboration request/assessment/result contract that also supports pre-Todo and cross-Goal work; #4312 records are migration inputs, not the new universal gate.

保留并迁移的验收义务:dispatchable / no_eligible_peer 可观察性、确定性 legacy alias、重启后的 dispatched→read→claimed 关系、stale claim 冲突、canonical Todo claim readback、duplicate ingress 与 effect-after-crash 对账。它们将进入 M2 的 characterization / compatibility fixtures,并与 #4094 的 continuation adapter 一起验证;不会把当前分支直接并入新 owner。

No accepted request or Todo is being marked complete by closing this PR; the canonical implementation Todo will retain a supersedes link to #4312.

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.

fix(scheduler): dispatch executor-excluded handoffs instead of repolling origin monitor

1 participant