Skip to content

[Work] 建立 Autopilot runtime 与 action lane executor #642

Description

@kxn

父 issue

背景

Autopilot V1 的 runtime 已在母单里明确收敛为双路径:

  • turn_terminal -> source materialize -> one model reasoning -> skip | one primary action
  • schedule_tick -> direct dispatch compiled action -> launch turn / send message

但当前代码库里还没有一层统一的 event-driven automation runtime。现有相关能力分别散落在三条老骨架里:

  1. autocontinue
    • 参考:internal/core/orchestrator/service_autocontinue.go
    • 特点:前台 surface、frozen dispatch plan、turn 终态后补发 prompt
  2. autowhip
    • 参考:internal/core/orchestrator/service_autowhip.go
    • 特点:前台 surface、固定 stop phrase/backoff、再次补发 prompt
  3. /cron
    • 参考:internal/app/daemon/app_cron_scheduler.goapp_cron_launch.goapp_cron_runtime.go
    • 特点:daemon-owned schedule tick、hidden run、launch turn、writeback

与此同时,母单已经明确了 runtime 的关键边界:

  1. V1 只支持两类 event:
    • turn_terminal
    • schedule_tick
  2. V1 只支持三类 lane:
    • same_thread_prompt
    • new_thread_prompt
    • feishu_message
  3. turn_terminal 必须只对:
    • 当前 frontstage mainline turn
    • attached surface
      生效
  4. detach、subagent、fork/detour、review、internal helper turn 一律不触发
  5. schedule_tick 不能依赖某个当前活跃窗口,而必须走 frozen runner contract 直接 dispatch

因此,这张子单的职责是:把现有三套老骨架收口成一套真正消费 compiled entries 的 runtime 与 lane executor。

目标

  1. 建立 Autopilot runtime:
    • 订阅 turn_terminal
    • turn_terminal 按 entry 的 source 列表 materialize 事件上下文
    • turn_terminal 做 one-off decision
    • 订阅 schedule_tick
    • schedule_tick 直接 dispatch compiled actions,不额外再起一轮 Autopilot reasoner
  2. 落地三类 lane executor:
    • same_thread_prompt
    • new_thread_prompt
    • feishu_message
  3. 固化 turn-terminal gating:
    • 只对前台 mainline turn 生效
    • detach / subagent / review / detour / helper 全部跳过
  4. 固化 schedule_tick 执行模型:
    • daemon-owned direct-dispatch hidden run
    • 不依赖当前 surface 是否仍 attach

非目标

  1. 本单不实现 Autopilot.md compile prompt 或 validator。
  2. 本单不实现 command surface / status / registry persistence。
  3. 本单不做 /cronautocontinueautowhip 的切流或兼容收尾。
  4. 本单不把 bind to my view 混进 V1 runtime。

范围

  • turn_terminal hook 与 frontstage gating
  • schedule_tick scheduler integration
  • source materialization:
    • turn terminal state
    • turn final message
    • thread history recent/full
    • workspace binding / surface context
    • schedule context
  • turn_terminal one-off runtime decision envelope
  • schedule_tick direct dispatcher
  • three lane executors
  • recipient resolution for feishu_message

完成标准

  1. turn_terminal 只会在当前 frontstage mainline turn 命中时触发,不会误打到:
    • detached surface
    • subagent turn
    • fork/detour 临时会话
    • review 会话
    • internal helper thread
  2. schedule_tick 能按 frozen runner contract 直接 launch_turn 或投递消息,即使当前 surface 已 detach,且不会再额外跑一轮 runtime 推理。
  3. same_thread_prompt 能复用当前 thread 继续补发,而不偷走 thread selection 或破坏前台 queue 语义。
  4. new_thread_prompt 不污染当前前台 Claude child,会统一走 hidden helper / hidden headless run。
  5. feishu_message 能直接发 text / simple_card 到:
    • 当前 event surface
    • 或 workspace-bound surface
  6. turn_terminal runtime 输出只允许:
    • skip
    • 或一个 primary action

依赖

下游依赖

  • migration 子 issue 需要基于本单提供的真实 runtime 行为设计 /cronautocontinueautowhip 切流。

相关文档

  • docs/draft/autopilot-workspace-automation-design.md
  • docs/implemented/cron-bitable-scheduler-design.md
  • docs/draft/upstream-retryable-turn-autocontinue-design.md
  • docs/general/remote-surface-state-machine.md

涉及文件

  • internal/core/orchestrator/service_remote_turn_outcome.go
  • internal/core/orchestrator/service_autocontinue.go
  • internal/core/orchestrator/service_autowhip.go
  • internal/core/orchestrator/service_queue.go
  • internal/core/orchestrator/service_queue_binding.go
  • internal/core/orchestrator/service_temporary_session.go
  • internal/core/orchestrator/service_helpers_threads.go
  • internal/app/daemon/app_cron_scheduler.go
  • internal/app/daemon/app_cron_launch.go
  • internal/app/daemon/app_cron_runtime.go
  • internal/app/daemon/app_thread_history.go
  • internal/app/daemon/workspace_surface_context.go
  • internal/adapter/feishu/projector.go
  • internal/adapter/feishu/controller_gateway.go

已确认事实

  1. service_remote_turn_outcome.go 已经有稳定的 terminal cause 分类:
    • completed
    • user_interrupted
    • autocontinue_eligible_failure
    • startup_failed
    • nonretryable_failure
    • transport_lost
  2. service_autocontinue.go 已经证明:
    • 可以在前台 surface 上冻结 dispatch plan 后补发 prompt
    • detach / thread drift 等 gating 会清掉 runtime
  3. service_autowhip.go 已经证明:
    • completed turn 后可以继续补打一轮
    • 但当前 stop phrase / backoff / suppress-once 都是老状态机债,不适合直接带入新 runtime
  4. app_cron_runtime.go 已经证明:
    • daemon-owned hidden run 可以在 hello 后发 prompt.send(start_ephemeral + internal_helper)
    • 并在完成后统一 writeback
    • 这条骨架可以直接作为 schedule_tick -> launch_turn 的 substrate
  5. app_thread_history.go + claudesessionstore.HandleLocalCommand(...) 已经证明:
    • Codex / Claude 都能提供 thread history source
  6. workspace_surface_context.go 已经提供 workspace -> surface/chat 绑定线索。
  7. feishu/projector.go / controller_gateway.go 已经能直接执行:
    • OperationSendText
    • OperationSendCard

建议范围

  1. 先把 turn_terminal gating 和 source materialization contract 定死。
  2. 再把 schedule_tick 统一挂到 cron-style hidden direct-dispatch run 骨架。
  3. 最后实现三条 lane executor,并补齐:
    • current-thread safety
    • new-thread isolation
    • Feishu recipient resolution

执行决策

  • 是否拆分:否;本 child issue 自身作为 runtime / lane executor 单 worker 单元执行。
  • 当前执行单元:turn_terminal reasoner、schedule_tick direct dispatcher 与 lane executor。
  • verifier:需要;该单会改 turn 终态处理、hidden run 和 Feishu 投递路径。

当前阶段

  • blocked

当前执行点

  • 已完成:
    • #638 母单收敛出 event/source/lane 闭包。
    • 已确认现有 turn-terminal、cron hidden run、thread history 和 Feishu 投递几条资产可复用。
  • 当前 blocker:
    1. 需要 control-plane 子 issue 先冻结 registry / enable bits contract。
    2. 需要 compiler 子 issue 先冻结 compiled schema 与 frozen runner contract 字段。
  • 下一步:
    1. 依赖落稳后,从 turn_terminal gating 与 source materializer 开始。
    2. 再接 schedule_tick direct dispatcher 与 lane executor。

恢复步骤

  1. 先确认 control-plane 与 compiler 子 issue 的 registry/schema contract 已稳定。
  2. 再按顺序检查:
    • internal/core/orchestrator/service_remote_turn_outcome.go
    • internal/core/orchestrator/service_autocontinue.go
    • internal/core/orchestrator/service_autowhip.go
    • internal/app/daemon/app_cron_runtime.go
    • internal/app/daemon/app_thread_history.go
    • internal/adapter/feishu/projector.go
  3. 先做 gating / source / lane 三层切线,再进入实现。

实现参考

  • runtime 必须保持双路径:turn_terminal 是 one-off reasoner,schedule_tick 是 direct dispatcher,不要把两者混成一个会持续等待结果的二级 agent。
  • turn_terminal 只看当前 frontstage mainline;review/detour/helper 需要 fail-closed。
  • new_thread_prompt V1 一律走 hidden helper / hidden headless,不直接借当前前台 Claude child 开旁路线程。
  • feishu_message V1 只支持 textsimple_card,不要扩成任意 card DSL。

检查参考

  • go test ./internal/core/orchestrator ./internal/app/daemon ./internal/adapter/feishu
  • turn-terminal gating focused tests
  • schedule direct-dispatch hidden run / frozen runner contract tests
  • same-thread / new-thread / feishu lane executor tests
  • 复核 docs/general/remote-surface-state-machine.md 是否需要同步更新

收尾参考

  • 完成后结果必须回卷到 #638 母单。
  • 若 frontstage gating、hidden run 或 Feishu 投递合同变化,应同步 docs/draft/autopilot-workspace-automation-design.md

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:codexCodex protocol translation and wrapper integrationarea:daemonDaemon server, admin API, and runtime controlarea:feishuFeishu/Lark integration, gateway, projector, or previewarea:runtimeRuntime manager, process lifecycle, and persisted statearea:wrapperWrapper process, proxy handling, and child launch flowenhancementNew feature or requeststatus:blockedBlocked by an external dependency, upstream change, or awaited decision

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions