Skip to content

Tree: smarter sub-Bot allocation (lead+children, reuse, deeper placement) maintained by auto-prune/merge #447

Closed

Description

@Birfy

Problem

The tree has no real placement logic. Every new Bot lands flat under whichever Bot created it, and in practice that is almost always Chief. Chief then fills up to maxChildren (8) with unrelated specialists. When the owner later asks for a coherent sub-team ("a dedicated team for the FlyBot repo: dev, test, maintenance, repo management"), there is no room and no way to restructure. Chief then works around the cap (see #446).

How placement works today (main at 753b7e9)

  • Always under the caller. create_child_bot(name, role_description) has no parent argument. The parent is always the calling Bot (tools.js, tree.js#L144-L161). Chief cannot create "FlyBot Lead" and then put Dev/Test under it in one step. It has to create the lead, then message the lead and hope the lead creates the right children.
  • Adoption is flat. Every pre-existing or UI-created Bot without tree fields becomes a direct child of Chief until the cap is reached. Any further ones stay outside the tree with only a log warning (tree.js#L85-L104).
  • No move/reparent. There is no tool or UI to move a Bot under another parent. Reparenting only happens when a Bot is deleted, and then its children go to the grandparent (onBotRemoved).
  • Reuse only looks one level deep. The coordinator prompt says to create a child "ONLY when no existing child fits (check list_children first)" (prompt.js#L26-L29). But list_children returns direct children only, and the prompt says "you cannot see deeper levels". The duplicate check also covers only sibling names (limits.js#L20). A "Tester" two levels down is invisible, so a second one gets created.
  • No balancing. No logic or prompt guidance tells Chief to group related Bots under a lead before it reaches the cap. The only rule when the cap is hit is "use the closest child".
  • Placement is not visible or confirmable. The owner finds out where a Bot went only from the sidebar afterwards. Non-tree Bots are also drawn under Chief (client.js#L308-L311), so the sidebar can be wrong as well.

Owner decision (2026-10-19 ~19:45 Asia/Shanghai)

Align allocation with #446's automatic prune/merge direction:

  • Allocation should produce a healthy tree (lead+children, reuse, deeper placement) that prune/merge can maintain.
  • Prune/merge (Tree: close create_bot maxChildren bypass; auto-prune/merge when over capacity or orphans exist #446) is the safety net when structure goes wrong (over capacity, orphans, misplaced bots).
  • Keep strong ideas from the prior proposal where they still fit; soften/drop "outside-tree bots stay outside forever / never auto-adopt" — orphans are candidates for automatic reparent/merge/prune.
  • Do not frame the design as a pure "ask owner when full" model.

Proposed behavior

  1. Reuse before create. Before creating, Chief checks existing Bots with a matching role across the whole tree, by name and role. Add a read-only find_bots(query) or tree_overview() tool for the root, giving name, role, parent and depth. If a match exists, reuse (or propose merge into) that Bot instead of creating a duplicate.
  2. Group by project or role. When a request names a project plus several roles, the default plan is a lead plus children: Chief → FlyBot Lead → {Dev, Test, Maintenance, Repo}, not four flat children of Chief. This costs one slot under Chief, not four — and matches what auto-prune/merge should restore toward when the tree has drifted flat.
  3. Placement-aware creation. Allow the root (and only ancestors) to create a Bot under a descendant it owns: create_child_bot(name, role_description, parent?), where parent must be the caller or one of its descendants. Limits and depth are checked at the target parent, and the existing per-parent lock still applies.
  4. Reparent / move as part of healthy structure (with Tree: close create_bot maxChildren bypass; auto-prune/merge when over capacity or orphans exist #446). Prefer automatic reparent/merge/prune when the tree is over capacity or orphans exist (Tree: close create_bot maxChildren bypass; auto-prune/merge when over capacity or orphans exist #446). A move_bot tool or sidebar "Move under…" remains useful for explicit owner-driven reshapes; model-proposed moves for large new plans can still use a plan card. Do not require owner confirmation for every safety-net reorganize that Tree: close create_bot maxChildren bypass; auto-prune/merge when over capacity or orphans exist #446 runs to restore caps.
  5. Balancing + safety net. When a parent is near the cap (e.g. ≥ 6/8), the coordinator prefers grouping related children under a lead rather than adding another flat child. When full or when orphans appear, Tree: close create_bot maxChildren bypass; auto-prune/merge when over capacity or orphans exist #446 auto-prune/merge runs — not "ask the owner / leave outside forever".
  6. Optional plan card for large creates. For a request that would create several new Bots (or a new lead subtree), Chief may show a short plan card (reuse / create / resulting paths) with Approve / Edit / Cancel. A single new leaf under a parent with room can proceed without a card, but the reply should still name the tree path. Plan cards are for forward allocation clarity, not the primary fix for an already-broken tree.

Recommendation: ship 1, 2, 3 and 6 as the allocation change, designed so the resulting trees stay maintainable by #446's auto-prune/merge. Implement move/reparent APIs so both explicit moves and automatic reorganization can share them. Drop any design that permanently parks orphans outside the tree.

Acceptance criteria

Related: child-cap bypass / auto-prune-merge #446, #6 (tree), #16 (who may create children), #56 (resource bounds).
Verified against main at 753b7e9.
Owner decision recorded 2026-10-19 ~19:45 Asia/Shanghai.

Activity

  1. self-assigned this
    on Oct 19, 2026
  2. added
    enhancementNew feature or request
    needs-humanThe agent loop stopped; a person must decide (reason in the last comment)
    area:automationScheduled tasks and automation
    agent-readyMaintainer-approved spec: an agent may take it. Only maintainers set this; never in a template
    and removed
    needs-humanThe agent loop stopped; a person must decide (reason in the last comment)
    on Oct 19, 2026
  3. changed the title [-]Tree: smarter sub-Bot allocation — reuse matching Bots, nest project teams under a lead, balance under the cap, confirmable placement plan[/-] [+]Tree: smarter sub-Bot allocation (lead+children, reuse, deeper placement) maintained by auto-prune/merge[/+] on Oct 19, 2026
  4. Birfy commented on Oct 19, 2026

    @Birfy
    CollaboratorAuthor

    Owner decision (2026-10-19 ~19:45 Asia/Shanghai):与 #446 新方向对齐——分配要产出可被自动 prune/merge 维护的健康树,而不是「满了就问 / 树外永不收养」模型。

    1. 保留并强化:全树 overview 以利 reuse;项目团队默认 lead + children;允许在 descendant 下创建;大创建前可选 plan card。
    2. 与 Tree: close create_bot maxChildren bypass; auto-prune/merge when over capacity or orphans exist #446 绑在一起:allocation 负责一次性放到合理位置;auto-prune/merge 是结构过载、孤儿、错位时的安全网。
    3. 放宽/取消:「树外 Bot 永远留在树外 / 永不自动收养」——孤儿应成为自动 reparent / merge / prune 的候选,而不是永久 outside。
    4. Move / balancing:可与 auto-reorganize 合并设计(系统可自动 consolidate;计划卡仍可用于大批量新建确认)。

    Issue body 的 Proposed behavior / Acceptance 已按此改写。已加 agent-ready,去掉 needs-human。

  5. added
    agent-workingAn agent has claimed this issue (the claim comment names the branch)
    on Oct 19, 2026
  6. Birfy commented on Oct 19, 2026

    @Birfy
    CollaboratorAuthor

    Claimed for development (2026-10-19 20:00 Asia/Shanghai). Branch fix/447-tree-smarter-allocation off main 753b7e9. Working in parallel this maintenance run.

  7. removed their assignment
    on Oct 19, 2026
  8. removed
    agent-workingAn agent has claimed this issue (the claim comment names the branch)
    on Oct 19, 2026
  9. Birfy commented on Oct 19, 2026

    @Birfy
    CollaboratorAuthor

    Releasing the claim (2026-10-19 20:57 Asia/Shanghai). The 20:00 run's worker stopped without changes, and #447 edits the same tree files as #446 (plugins/tree/src/tree.js, limits.js, prompt.js). Per the owner decision the allocation must build on #446's auto-prune/merge path, so #447 will be picked up right after #446's PR lands. Still agent-ready.

  10. Birfy commented on Oct 19, 2026

    @Birfy
    CollaboratorAuthor

    Owner decision (2026-10-19 Asia/Shanghai): recorded 21:27 on #446 (comment). In short: the tree organizes itself by role (role groups with a suitable existing lead, or a new lead with a clear role such as "FlyBot Lead"; no "least-loaded child" fallback), duplicates are merged and the old Bot archived (never deleted), a daily tidy archives long-idle leaf Bots after 30 days, every move / merge / archive is logged with one-click undo in the tree view, and big reorganizations run directly with a summary notice afterwards (no plan card for them).

    #447 builds on this: allocation (reuse before create, lead + children, create_child_bot(parent?), find_bots) should use the role-grouping and move / merge / undo primitives that the #446 rework (#448) adds, rather than its own. The optional plan card in "Proposed behavior" 6 stays for forward allocation only; automatic reorganization does not ask first.

  11. Birfy commented on Oct 19, 2026

    @Birfy
    CollaboratorAuthor

    Maintenance (2026-10-19 21:58 Asia/Shanghai): not claiming this run. #447 touches the same plugins/tree/ surface as open T3 #448 (awaiting-approval). Per owner rule (do not land overlapping T0/T1 work under an awaiting-approval PR; do not start parallel tree work), development waits until #448 merges. Spec already includes the owner decision recorded on #446.

  12. added
    agent-workingAn agent has claimed this issue (the claim comment names the branch)
    on Oct 19, 2026
  13. self-assigned this
    on Oct 19, 2026
  14. Birfy commented on Oct 19, 2026

    @Birfy
    CollaboratorAuthor

    Claimed for development (2026-10-19 23:06 Asia/Shanghai). #448 and #453 are on main (84a95a6), so the tree files are free. Branch fix/447-tree-allocation off 84a95a6. Allocation will reuse the role-grouping and move / merge / undo primitives from #448/#453.

  15. Birfy commented on Oct 19, 2026

    @Birfy
    CollaboratorAuthor

    Plan card deferred (2026-10-19 23:22 Asia/Shanghai). PR #454 ships Proposed behavior 1–5. The codebase has no chat card for a model-proposed plan with Approve / Edit / Cancel. The only approval cards are social's message holds, and the tree only has the sidebar reorg notice with Undo / Dismiss. A plan card would need a new chat slot, host endpoints and a way to resume the model's turn after the click, which is not small. Without the card, forward allocation goes ahead and its result names the tree paths. Automatic reorganization never asks first. The card can be a follow-up if it is still wanted after #454.

  16. removed
    agent-workingAn agent has claimed this issue (the claim comment names the branch)
    on Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

agent-readyMaintainer-approved spec: an agent may take it. Only maintainers set this; never in a templatearea:automationScheduled tasks and automationenhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions