WIP refactor(tower): rebase worktree before merge - #4074
Open
tpoisonooo wants to merge 8 commits into
Open
tpoisonooo wants to merge 8 commits into
tpoisonooo wants to merge 8 commits into
Conversation
🦋 Changeset detectedLatest commit: b1dc66c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
tpoisonooo
force-pushed
the
feat/tower-base-reanchor
branch
3 times, most recently
from
September 30, 2026 09:59
671a5b0 to
a30c33f
Compare
tpoisonooo
force-pushed
the
feat/tower-base-reanchor
branch
from
October 2, 2026 12:25
a30c33f to
ee93d81
Compare
added 6 commits
October 3, 2026 17:35
When .tower/comms is deleted while .tower/ survives (e.g. git clean), tower tools no longer hard-fail with not-initialized: - TowerStatus returns a state-lost report; never-initialized repos (no .tower/ at all) keep the existing not-initialized behavior - TowerSend/TowerComplete recover a minimal state (directory skeleton, empty missions/roster, recoveredAt marker, base taken from the current checkout branch) and keep delivering; a caller whose roster entry was lost is re-registered as a placeholder named after its agent id - TowerComplete degrades explicitly after a loss: the report is delivered to the tower as a completion-report-state-lost message and no mission is marked completed - TowerMerge/TowerRebase and every other locked mutation fail with an explicit state-lost error instead of silently running against an empty history - the recoveredAt marker is shown on the TowerStatus dashboard and in the status summary, reminding the tower to report the history loss to the user
Collaborator
Author
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requirement or Bug
背景与问题
Tower 目前的多 worker 编排主要依赖 prompt 约束和顺序执行,实际使用中暴露出四类问题:
热点文件冲突导致并行收益下降
多个 mission 同时修改
config.go等高频文件时,很容易在 merge/rebase 阶段集中发生冲突。冲突最终仍要串行处理,导致多个 worker 的实际交付速度接近线性。用户调整 worker 行为不够及时
Worker 主要通过下一次主动读取 inbox 获取新指令。用户中途调整需求时,消息可能要等 worker 当前任务结束后才会被处理。
切换 base 的约束过硬
/tower <base>同时受当前 checkout、已有 commit 和未完成 worktree 状态影响。只要仍有 mission 未完成,切换 base 就很容易产生冲突或被迫等待。机械编排过度依赖 LLM
状态判断、完成通知、review 路由、merge gate 和状态展示都由 prompt 指导 LLM 执行。规则容易在多处实现中漂移,也会增加上下文和 token 开销。
行为调整
热点文件允许并行开发,交付仍按序集成
多个 worker 可以并行修改同一个热点文件。Mission 仍然按照依赖关系或明确的 scope 规划交付顺序,但不再要求开发阶段完全串行等待。
合并前由 Tower 使用
TowerRebase将 mission branch 更新到当前 base:这样可以减少开发阶段的等待,同时保留集成阶段的确定性。
用户指令更快传递给 worker
TowerSend的消息仍会先持久化到 inbox。对于正在运行的 worker,消息会 steer 到当前 turn,在下一个步骤边界可见。正在执行的 tool call 不会被打断,避免工具调用中途失败或产生不完整状态。需要立即停止 worker 时,仍应使用显式的 stop/cancel 操作,而不是依赖普通消息。
支持存在未完成 worktree 时切换 base
/tower <base>支持在仍有 open missions 时 re-anchor base。系统会逐个 mission 返回:no-branch:branch 尚未创建;up-to-date:已经包含新 base;stale:需要先执行TowerRebase。只有 stale mission 需要 rebase,不再笼统要求所有 worktree 先完成。
边界仍然保留:base 必须是本地分支,最终 merge 仍要求主 checkout 位于记录的 base 上。
重构内容
这次重构的核心是:将机械协议从 prompt 驱动改为代码驱动,只把需要判断的工作留给 LLM。
统一 merge 判定
新增统一的 mission gate evaluator,供 Status、Merge 和 wake digest 共用,避免同一规则在多处实现中漂移。
代码现在统一检查:
clean + merge;hold、fix-then-merge是否阻断;Merge 使用固定 SHA 执行,避免检查完成后 branch 被继续移动。
确定性完成与通知
新增
TowerComplete(report):review-request;survey-summary;Review 提交后,代码也会自动将
review-result路由给正确的 owner/tower,不再要求 reviewer 手工发送通知或 resume 其他 Agent。加强消息与并发协议
/tower status不再启动 LLM/tower与/tower status改为通过 SDK 直接读取并本地渲染状态,不再向主 Agent 发送提示词。公共 SDK 只暴露该命令所需的最小状态文本接口,不把内部 mission、roster、review 和 gate 结构泄漏给客户端。
LLM 仍负责需要判断的工作:
兼容性说明
clean + hold和clean + fix-then-merge不再被视为 merge-ready。clean + merge且 branch tip 满足绑定条件的 review 才能批准合并。merged的旧路径不再可用;只有TowerMerge可以记录 merged。效果
/tower status不再消耗 LLM 请求;