Skip to content

refactor(chat): modularize todo_actions and eliminate Any annotations - #9470

Open
loopx-agent wants to merge 1 commit into
mainfrom
codex/slim-chat-todo-actions-zero-any-20261126
Open

loopx-agent wants to merge 1 commit into
mainfrom
codex/slim-chat-todo-actions-zero-any-20261126

Conversation

@loopx-agent

Copy link
Copy Markdown
Collaborator

Delivery Brief

  • Source / Goal: Eliminated all AST Any annotations (54 -> 0) and modularized loopx/chat/todo_actions.py (770 -> 243 LOC) into cohesive Zero-Any helper modules without adding top-level compatibility shims or changing runtime behavior.
  • Owning Boundary: Keeps class ChatTodoActionMixin defined inside loopx.chat.todo_actions (preserving ChatTodoActionMixin.__module__ == "loopx.chat.todo_actions" and importlib.util.find_spec("loopx.chat_todo_actions") is None per tests/test_chat_internal_module_layout.py).
  • Implementation:
    • loopx/chat/todo_action_contracts.py (402 LOC, 0 AST Any): typed host/store/session/runtime Protocols (ChatTodoActionHost, TodoActionServiceSelf, ActionStoreProtocol, TodoTurnLoaderProtocol, TodoSessionStoreProtocol, TodoRuntimeControllerProtocol, GoalCommitSubmitController), schema constants, option parsers (parse_reviewed_terminal_options, parse_reviewed_update_options), and narrow coercion helpers.
    • loopx/chat/todo_action_tasks.py (493 LOC, 0 AST Any): task assignment CAS recovery (apply_created_todo_assignment), cross-runtime lock fence (confirmed_task_commit), task session/turn lookup and recovery (read_task_start, read_confirmed_task, pending_applied_task_receipt, project_task_dispatch, recover_applied_task, start_confirmed_task).
    • loopx/chat/todo_action_create.py (295 LOC, 0 AST Any): legacy creation recovery (_recover_legacy_todo_source, _recover_created_todo_step), new review creation (_create_new_todo_step), assignment dispatch (_assign_created_todo), and apply_todo_create.
    • loopx/chat/todo_action_updates.py (401 LOC, 0 AST Any): run_todo_update, run_gate_resolve, canonical_update_basis (preserving double resolve_chat_todo_source TOCTOU verification), apply_reviewed_todo_edit (preserving fail-closed malformed basis handling and error/projection recovery states), and apply_todo_update.
    • loopx/chat/todo_actions.py (243 <= 550 LOC, 0 AST Any, max_span=23): thin ChatTodoActionMixin delegation and _decision_readback wrapper.
    • tests/control_plane/test_chat_todo_actions_contract.py (637 LOC, 0 AST Any): AST/LOC/Zero-Any/Zero-ignore/layout-pin checks, parser/coercion unit bounds, pending_applied_task_receipt and project_task_dispatch boundary checks, _canonical_update_basis TOCTOU and _apply_reviewed_todo_edit error-state recovery, and task-start/recovery negative paths.
  • Boundary & Hygiene Scan: Clean (0 # type: ignore, 0 # noqa, 0 local/private paths, module_metric_baseline.json untouched, loopx/*.py == 112).

Validation Summary

  • ruff check on all 5 source modules + tests/control_plane/test_chat_todo_actions_contract.py: passed.
  • mypy --strict --no-incremental --follow-imports=silent on all 5 source modules + loopx/chat/action_store_common.py + tests/control_plane/test_chat_todo_actions_contract.py: Success: no issues found in 7 source files (todo_actions.py: 43 -> 0 errors).
  • Repo [tool.mypy] (17/17): Success: no issues found in 17 source files.
  • Caller mypy --no-incremental --follow-imports=silent: loopx/chat_actions.py 0 -> 0 errors, loopx/chat/monitor_actions.py 16 -> 16, loopx/chat_server.py 28 -> 28.
  • npm run typecheck:control-plane clean; node --no-warnings --experimental-sqlite --experimental-strip-types --test tests/control_plane_ts/content_digest_single_owner.test.ts tests/control_plane_ts/action_review_plan.test.ts: 38/38 passed.
  • python scripts/check_rfc_bilingual.py --base origin/main --head HEAD & git diff --check origin/main: passed.
  • Clean-HOME smokes: semantic-vocabulary-drift-smoke.py, control-plane-maintainability-ratchet-smoke.py, control-plane-integrated-canary-smoke.py (file & sqlite), loopx-chat-actions-smoke.py, user-todo-review-material-smoke.py all passed.
  • Paired counterfactual parity (57c4c43b52 vs candidate on file & sqlite fixtures): 12/12 keys matched (PARITY_DIFFS: {}).
  • pytest:
    • tests/control_plane/test_chat_todo_actions_contract.py + tests/test_chat_internal_module_layout.py: 8 passed
    • tests/control_plane/test_reviewed_terminal_actions.py (with loopx/web/chat assets linked): 24 passed
    • Broad chat/todo/architecture/canary sweep (pytest -q -n 6 -rs across 17 suites without loopx/web/chat assets): 2,376 passed, 6 skipped (6 APFS non-UTF-8/root skips in test_git_path_display.py), 4 failed (test_packaged_chat_http_recovers_terminal_action 404 on /chat before linking loopx/web/chat; passed separately 24/24 with assets linked).
  • Pre-merge gates: Goal loopx check (5 checks, errors=0), Goal CQR (cqr_266a509729548cf01627, decision="pass", status="valid"), Goal canary premerge --from-git-diff --git-diff-base origin/main (ok=true, 5/5 selected checks, manual_hold_count=0).

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.2-sol · OpenAI · runtime_reported · xhigh

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

动机 / Motivation

把 Chat Todo 的创建、分配、Task Session 恢复和更新拆到有类型的同域模块,保持原 HTTP、CAS 回执及重入时序。 基线将创建、恢复、写入和投影都放在 ChatTodoActionMixin。Task Session 与 provider 结果多用动态字典传递。 在 Chat 中确认创建、分配、编辑、完成 Todo 或停止 Monitor 的用户,以及恢复挂起 Task 的现有运行时。

如果重构误把旧回执当新申请,会丢失有效恢复或重复业务写。投影未交付便确认成功会误报 Todo 当前状态。 基线与 Head 的实际 HTTP 观测相同。File 和 SQLite 上,预览不写,确认后创建一个 Todo 并分配给原 Agent。重放沿用同一收据。普通编辑提交后模拟投影中断,再次确认读回同一 operation 的 replayed 状态和已恢复的当前投影。 Python 3.12 下基线 173 项、Head 178 项定向测试通过。另独立完成两版各 2 组真实 File 和 SQLite HTTP 创建、分配、过时编辑和投影恢复。git diff --check 通过。 两版使用同一份静态 Chat 资源。HTTP handler 与 canonical provider 为精确工作树。Task 开始恢复测试使用受控执行器。实时模型执行、当前安装和远程 CI 未核验。 基线契约

改动思路 / Approach

该改动沿用 Chat POST /api/actions/preview → POST /api/actions/{id}/apply → canonical Todo 与当前投影。ChatTodoActionMixin 保留原调用形式,子模块继续调用原写入和状态所有者,将 proposal 及 receipt 解析与 provider 判定留在各自边界。 以已审阅的 provider revision、registry 指纹和 operation ID 约束新写入。按精确历史收据恢复已提交业务,经当前投影确认后交付回执。 复用 action_store 的 digest、ID 和类型校验。提交、权威状态与投影沿用现有实现,原有提案和回执无需迁移。

具体改动 / Changes

精确提交 c753f12,分叉基线 57c4c43。6 个文件,新增 2,413 行、删除 712 行。保留原门面,拆出创建、更新、Task 调度及 host 契约,新增 637 行契约测试。

关键代码讲解

  • apply_todo_create。保留原预览指纹、创建检查点、分配和幂等读回。 源码

  • confirmed_task_commit。提交 Task Turn 前重验 Goal、project、受领者和原租约。 源码

  • canonical_update_basis。连续两次 resolve 同一来源,比对 registry 与 source identity。 源码

  • apply_reviewed_todo_edit。保留更新 CAS、原 operation 回执及当前投影恢复。 源码

  • preserve-reviewed-cas-and-current-projection-retry(implemented)。已审阅命令按 provider 和 registry 的基线写入。业务已提交而展示未交付时,重试须恢复原 operation 并确认当前视图。

对主干的风险 / Risks

确认前插入另一 Todo 改变 provider head,两版均返回 HTTP 409、stale、无回执,canonical 状态保持。业务提交后的投影错误保留原 canonical_update_projection_pending,重放恢复同一结果。 重试若再次写入,投影故障会把原确认变成重复修改。隔离 HTTP 反例经过真实 canonical store。 保留原 source/CAS basis 与不可变 operation 收据,经当前 outbox 确认展示。

我的整体评价 / Verdict

APPROVE。 实际 File 和 SQLite 路径保持创建、写入拒绝、业务恢复与投影读回。 中断后凭原 operation 恢复业务结果和当前投影,避免重复 Todo 和用过期意图覆盖后续进展。

English verdict: APPROVE at c753f12. Exact-base/head File and SQLite HTTP runs preserve reviewed Todo creation, stale-preview rejection, and same-operation recovery after projection failure.

This branch has not been deployed

No deployments
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.

1 participant