Skip to content

perf(cli): reuse selected dispatch for handoff commands - #7257

Merged
huangruiteng merged 1 commit into
mainfrom
codex/handoff-selected-dispatch
Oct 24, 2026
Merged

huangruiteng merged 1 commit into
mainfrom
codex/handoff-selected-dispatch

Conversation

@hhyykk

@hhyykk hhyykk commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Goal And Delivered Outcome

handoff and handoff-mode currently load the full compatibility CLI before reaching their existing typed owners. Route both families through the existing selected parser/common dispatcher and executable-revision request scope. Remove the two legacy dispatch blocks; preserve parser registration and handler bodies.

Author Declaration

  • Written by: model_agent — OpenAI Codex (GPT-6 family).
  • Specification and revision: docs/architecture/rfcs/typescript-control-plane-migration-v0.md at b8b26559749f6c2587ea25eddb759bcddd5d1ef8, plus the existing CLI interface.
Criterion Disposition Implementation / evidence
§2.8 locality; §3.2 payoff implemented one common dispatch path for selected and compatibility callers; measured complete commands below
§5 migration economics implemented receipt below; no new semantic cutover claimed
§6 correctness/performance implemented for this source CLI slice real File/SQLite calls, persistent readback, replay/recovery, baseline parity and mutation sensitivity
Stage 3 native TS CLI; Stage 4 distribution out_of_scope this is caller adoption inside the existing Python adapter

Migration Economics

Field Before → after
Canonical owner existing TypeScript continuation and handoff-mode transaction owners remain unchanged
Legacy semantic code deleted 0; two Python routing blocks retired (17 lines including spacing), plus unused imports
Bridge code added 0
Cross-runtime calls show: 1 → 1 snapshot; set/replay: 1 → 1 mode transaction; inspect: 1 → 1 continuation transaction, verified on both local backends
Product-code net change +32 / −21 = +11 lines across 3 files; includes missing callable annotations, with registration/handler bodies unchanged
Migration scaffolding no product scaffolding; durable public-entrypoint and real-backend tests use the existing fixtures
Facade exit existing Python CLI/provider IO remains required; remove only when its compatibility callers migrate to the native CLI
Scope-fit reuse the current dispatcher/registrations; wider registry/Goal refactors and new bridges deferred

Validation

  • Tested revision: 4ba321303c4efcdca8606c37948624084aee969b.
  • Run state: finished. Input classes: synthetic, public_fixture.
Check kind Result Public-safe evidence / limitation
static passed Ruff on all 6 changed Python files; bilingual staged/exact-head gate; RFC status index; semantic advisory; diff hygiene; 3 guard skills
real_entrypoint passed 58 related cases at the final head with pytest 9.1.1: selected/full help, parser diagnostics, semantic refusals, lossless restore, real prepare→inspect→adopt→replay on File/SQLite × both CLI entrypoints
integration passed native continuation, leased continuation and mode-plan suites: 67 passed, 2 PostgreSQL cases skipped
regression_parity passed complete read JSON identical; 144 final-head A/B commands with independent durable-state oracles; 8 explicit-runtime baseline/head probes pass and 4 dropped-argument mutations are rejected; RPC counts checked separately
regression_parity passed corrected mode CLI suite passes all 10 cases on baseline and head with pytest 9.1.1
static failed configured bare mypy: 5248 baseline errors → 5241 head errors; no new normalized diagnostic
integration passed python -m loopx.entrypoint canary premerge --from-git-diff --git-diff-base origin/main --tier quick --timeout-seconds 120 --format json

An earlier broader Python run, using pytest 9.0.2 below the declared minimum, had 143 passes and two failures from retired Markdown fallback expectations. Both failures reproduce with the immutable baseline CLI. The repaired tests preserve refusal/no-mutation coverage. Final validation uses pytest 9.1.1: 58 related cases pass at this head, and all 10 mode CLI cases pass on the immutable baseline. The source/head did not change during this environment correction. Initial native run lacked pg; after installing the lockfile version, it passed as shown above.

Bare configured mypy is still failing: baseline 5248 errors → head 5241 in the same environment; no added diagnostic after normalizing source line positions. No checker configuration or ignore rule changed.

Complete-command cost

Fresh Python process per command, warm managed native runtime, six alternating ABBA blocks; exclude one warmup block, leaving 10 samples per arm/provider/workload. Baseline and candidate run the same fixture and all source except the three changed Python modules. Both arms are pinned to immutable source bytes; the final candidate matches the tested commit. No tests/builds overlapped timing. Python 3.11.6, Node 26.12.1 on Linux.

Backend Complete CLI workload Baseline median / p95 ms Candidate median / p95 ms Median reduction
file mode-show 975.9 / 1137.6 172.1 / 208.3 82.4%
file mode-write 1029.6 / 1153.6 215.1 / 237.8 79.1%
file handoff-inspect 1027.2 / 1141.9 247.2 / 331.0 75.9%
sqlite mode-show 977.1 / 1043.5 181.4 / 299.1 81.4%
sqlite mode-write 1030.1 / 1148.5 202.2 / 229.7 80.4%
sqlite handoff-inspect 1030.6 / 1130.2 273.4 / 282.4 73.5%

Read payloads match exactly between baseline and candidate. Every command has independent native before/after readback: read requests leave authority unchanged; durable mode writes advance the revision, preserve Todos/leases and leave the Markdown display unchanged. A separate explicit-runtime override probe has 8 baseline/head passes; deliberately dropping that argument makes all 4 corresponding mutation probes fail the public-entrypoint oracle.

  • Coverage and gaps: no PostgreSQL owner/transport/provider route changed; its 2 optional native cases skipped without an isolated server. No wheel/sdist installation, cold native startup, minimum-version/Windows run, live Host/model/provider adoption or full repository test suite is claimed. CI/review and merge authorization remain separate.
  • Self-check: clean-code-guard, test-guard and docs-guard passed; no new module, dependency, semantic owner, data cache or bridge.

Frontend / Visual Evidence

UI impact: none. Before/after screenshots, viewports and source data: N/A; existing CLI text/JSON/digest contracts preserved.

Shared-authority RFC fixture impact

Existing canonical fixture schema; File/SQLite crossed with both public entrypoints. No authority schema, decision rule, provider selection, authority runtime routing or compatibility projection changed. Three-arm authority promotion rehearsal is not applicable; this PR does not promote a store or provider.

Type / Area

Refactoring, documentation and tests; control-plane CLI caller integration.

Boundary Checklist

  • Public-safe diff/body; no private state, raw logs, local paths or credentials.
  • Existing PR scopes checked; no duplicate maintainer-owned work.
  • Scoped to the accepted caller-adoption request.
  • Both RFC languages changed; staged and exact-head bilingual checks pass.
  • UI impact marked none.
  • Every commit has DCO sign-off.

Signed-off-by: aihop <4408344+hhyykk@users.noreply.github.com>
@hhyykk

hhyykk commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator Author

Validation for 4ba321303c4efcdca8606c37948624084aee969b, rebased on main@b8b265597:

  • Changed surfaces: selected and compatibility CLI callers for handoff and handoff-mode; their registration/handler bodies are unchanged. Callable types are now explicit.
  • Direct checks: clean diff, changed Python compilation, bilingual RFC gate and maintainability ratchet pass. Quick premerge passes all selected catalog/boundary checks, with no failure or manual hold. Ruff and the three guard passes are clean.
  • Real entrypoints/backends: 58 related Python cases pass at this head with pytest 9.1.1, including File/SQLite prepare→inspect→adopt→replay. Native continuation/mode suites: 67 pass, 2 PostgreSQL cases skipped.
  • Parity/sensitivity: 144 fresh-process A/B commands, 10 measured samples per arm/backend/workload after warmup; exact read payload equality and independent persistent-state readback. Explicit-runtime probes: 8 base/head passes; all 4 argument-dropping mutants fail the oracle. See the description for median/p95 results.

Migration economics receipt: the existing TypeScript continuation/mode transactions remain canonical before and after; semantic rules deleted 0, duplicate routing blocks retired 17 lines including spacing; bridge additions 0; checked show/set/replay/inspect paths remain 1 RPC before and after on File/SQLite. Product diff +32/−21 = +11 lines; no product scaffolding, new module, cache or dependency. Existing Python CLI/provider IO exits only when its remaining compatibility callers migrate to the native CLI. Tests retain public-interface and durable-state coverage; temporary qualification environments are being reclaimed.

Failures/skips: bare configured mypy remains failing (5248 baseline → 5241 head, no added normalized diagnostic). Real PostgreSQL, wheel/sdist, cold startup, minimum versions/Windows, live host/model/provider behavior and the full repository suite were not qualified here. Public-boundary scan passes; no raw logs or private fixtures are attached.

Environment correction: earlier Python checks used pytest 9.0.2, below the declared minimum. After upgrading to pytest 9.1.1, the final 58 related cases and 10 immutable-baseline mode cases pass. Source and head are unchanged.

Submitted for review. Premerge success grants no merge authority; this PR is not merged.

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator

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

动机

通过 CLI 交接当前工作、恢复上下文或修改协作模式的用户。

同一份实际 File 或 SQLite 状态下,用户查看协作模式或准备并采用交接上下文;现在两个入口进入原 handler,完整输出与写回结果保持相同,本机源代码调用耗时下降。

8组 File/SQLite×两个入口×两个命令族的实际流程,完整 stdout/stderr/退出码和持久化 head 全部相同;26组帮助、解析错误和中英文恢复正文也完全相同。4个在新分派调用处故意丢弃 runtime-root 的变体均被实际 typed 拒绝检出。

交付是既有 Python CLI 调用者采用原共享分派和请求内源版本缓存;没有迁移新的领域规则、增加 bridge、修改 authority/provider,或宣称完成 native TypeScript CLI、安装分发和完整迁移路线图。

改动思路

复用原 parser 注册和原 handler,把重复分派从 full CLI 删除,能在同一请求内复用 native 可执行源码版本;缓存只固定可执行版本,不缓存 Goal、registry 或 provider 数据,因此每次调用仍读取当前权威状态。无需另造 entrypoint、CLI 协议或 Python 决策 owner。

selected parser 加入两个命令族;公共 dispatcher 原样传递 registry、显式 runtime-root、输出格式和打印函数;full CLI 删除对应旧分支。todo_continuation 只增加类型注解,handoff_mode handler 字节不变,原 guard 保持在 dispatch 前。 只做类型注解不能缩短实际调用;另建快速 handler 会复制解析和 authority 规则。删除旧17行分派并复用既有 owner 是当前有界方案;不要求把整套 CLI 或 Python 模块迁走才能交付。

交付是既有 Python CLI 调用者采用原共享分派和请求内源版本缓存;没有迁移新的领域规则、增加 bridge、修改 authority/provider,或宣称完成 native TypeScript CLI、安装分发和完整迁移路线图。

具体改动

受控全进程 ABBAABBA 比较:每分层每臂4次,两个入口×File/SQLite,handoff-mode show 中位数约458–533ms →112–132ms,handoff inspect 约479–537ms →161–180ms。64个新Python进程,原native daemon预热、fixture还原在计时外,同一loader开销/源码根/私有固定Node时钟;后台负载未控制。完整记录保留,不能外推冷启动SLA或安装版收益。

不可变已接受规格:docs/architecture/rfcs/typescript-control-plane-migration-v0.md,版本 b8b26559749f6c2587ea25eddb759bcddd5d1ef8。先按原规格审查;下列是本审计映射标签,非伪造原编号:

  • existing-caller-adoption(implemented):Adopt existing callers without introducing parallel Python semantic owners.
  • full-cli-semantic-parity(implemented):Validate actual CLI outputs, exit codes, diagnostics, persistence, replay and refusal behavior against the immutable baseline.
  • bounded-migration-economics(implemented):Measure complete affected command costs under comparable conditions and retain migration limits rather than claiming completion from code movement.

8 files +162/-53; production +32/-21。全差异、原调用者、完整讨论、DCO与公开边界已读。产品3文件+32/-21,净增11;删17行重复分派,删除领域语义规则0,增加bridge 0。RFC英文/中文新增段落含义对应,未把它们当原规格。

_build_selected_parser(loopx/cli_runtime.py:295):为两个原命令族复用原 registrar,不另写参数/默认值;坏 selected parse 保留原 full CLI 诊断回退。

_dispatch_common_command(loopx/cli_runtime.py:439):根据原 command 选原 handler,显式传入 registry/runtime-root/format;遗漏 runtime-root 的私有变体会被4个真实拒绝反例检出。

dispatch_common_command(loopx/cli_runtime.py:624):原 request scope 只固定 executable revision;范围退出即清理,authority数据不进入此缓存。

main(loopx/cli.py:386):原 native guard 在公共 dispatcher 之前执行;旧17行 handoff 分派移除,后续其他命令分派不改。

handle_todo_continuation(loopx/cli_commands/todo_continuation.py:128):仅补 callable/返回值注解;原 prepare/inspect/adopt/restore 参数约束、typed操作、receipt与正文渲染保持。

对主干的风险

独立专项 Python 57通过/88未选;native owner 67通过/2项 PostgreSQL 环境跳过;标准 premerge 5项直接/编译检查和19项选中检查通过。全量同配置 mypy 从5240降到5233,按路径、诊断码和完整消息比较,无新增诊断;检查仍为失败,保留独立验证限制。

实际 stale revision 和重复 operation 的不同 intent 拒绝且不写状态;缺失/旧 display 不替代 canonical authority;restore 不创建 registry/runtime;帮助与坏参数输出完整保持。原 registered actor、同/跨 agent、租约和失效上下文边界由原 native owner suite 覆盖。

mypy 全量仍未绿,5233个当前诊断与基线逐项同签名,不能当作通过。native 两项 PostgreSQL 环境跳过未计为通过;本 PR 不修改 PostgreSQL provider/owner。耗时仅为本机源代码、私有 warm native runtime、相同 fixture 的64个完整新 Python 进程测量,每分层每组4样本;不代表冷 OS cache、已安装分发、广泛 SLA 或长期净收益。

基线探针只从不可变base加载三个改变Python模块,其余生产源码及__file__根相同;两臂采用相同非提前加载的loader,不替代parser、handler、typed owner或provider。私有子进程固定Node时钟;正常时钟下专项/native suite另行执行。第一版故意变体定位器本身报错,已保留且未计入证明;修正后4例均为真实typed refusal且无traceback。

CI按当前契约未查询、轮询或等待。未执行安装、模型调用或合并。

我的整体评价

APPROVE,对应 7257@4ba321303c4efcdca8606c37948624084aee969b。未发现本次改动新增的阻塞代码问题;本地caller采用的目标已实现,原全量mypy验证限制继续保留。

复用原 parser 注册和原 handler,把重复分派从 full CLI 删除,能在同一请求内复用 native 可执行源码版本;缓存只固定可执行版本,不缓存 Goal、registry 或 provider 数据,因此每次调用仍读取当前权威状态。无需另造 entrypoint、CLI 协议或 Python 决策 owner。

交付是既有 Python CLI 调用者采用原共享分派和请求内源版本缓存;没有迁移新的领域规则、增加 bridge、修改 authority/provider,或宣称完成 native TypeScript CLI、安装分发和完整迁移路线图。

长期工作:preserved,保留原重放、拒绝与后续读回,未测多轮净收益;使用体验:improved,8组 File/SQLite×两个入口×两个命令族的实际流程,完整 stdout/stderr/退出码和持久化 head 全部相同;26组帮助、解析错误和中英文恢复正文也完全相同。4个在新分派调用处故意丢弃 runtime-root 的变体均被实际 typed 拒绝检出。

已检查既有 CLI 完整输出、错误/恢复正文及原调用者;没有页面、布局、组件或视觉素材变更,截图与构图检查不适用。

mypy 全量仍未绿,5233个当前诊断与基线逐项同签名,不能当作通过。native 两项 PostgreSQL 环境跳过未计为通过;本 PR 不修改 PostgreSQL provider/owner。耗时仅为本机源代码、私有 warm native runtime、相同 fixture 的64个完整新 Python 进程测量,每分层每组4样本;不代表冷 OS cache、已安装分发、广泛 SLA 或长期净收益。

有界重构:只做类型注解不能缩短实际调用;另建快速 handler 会复制解析和 authority 规则。删除旧17行分派并复用既有 owner 是当前有界方案;不要求把整套 CLI 或 Python 模块迁走才能交付。 审批、approval-closeout、merge-readiness和维护者合并权限各自核验;本评审不合并。

English verdict: APPROVE. APPROVE. Both CLI entrypoints reuse the original handlers and request-scoped executable revision, with complete File/SQLite output, persistence, replay and refusal parity. Controlled full-process measurements show a local source-call reduction. Full mypy remains red with identical pre-existing diagnostics; PostgreSQL, installed distribution and long-horizon benefit are not newly qualified.

@huangruiteng
huangruiteng merged commit 0de5db3 into main Oct 24, 2026
28 of 39 checks passed
@huangruiteng
huangruiteng deleted the codex/handoff-selected-dispatch branch October 24, 2026 17:18
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