Skip to content

A deleted Bot keeps its open-turn records in the tree load tracker #732

Closed

Description

@Birfy

What happens

plugins/tree/src/load.js keeps one record per open turn per Bot id, in a process-local Map (createLoadTracker). plugins/tree/src/tree.js:293 onBotRemoved() re-attaches the deleted Bot's children, repairs the organizer, refreshes prompts and runs adoption — it never drops that Bot's turn records. The tracker keeps the id forever, so snapshot() still counts a Bot that no longer exists, and every later read walks an entry nobody can ever end.

Harmless in size (bounded by how many Bots existed), but it is a leak on the one path that is supposed to dispose of a Bot, and it makes the tracker's own invariant ("every record belongs to a live Bot") false. Found by the #692 review (point 3) and left out of scope there.

Reproduce

node --test plugins/tree/test/load.test.js

with a case that starts a turn for b1, calls onBotRemoved({ botId: 'b1', parent: <root> }), then reads load.snapshot() — today it still lists b1.

What should happen

  • createLoadTracker gains clear(id): removes that Bot's records and returns nothing; unknown id is a no-op. Pure, in the style of start/end/of.
  • tree.onBotRemoved() calls it for the removed botId before or after the children re-attach (either order is fine; the tracker holds turn records only, never the tree shape).
  • snapshot() and openFor() for that id read 0 once the Bot is gone.

Acceptance

  • plugins/tree/test/load.test.js: clear(id) drops that Bot's records and leaves other Bots untouched; clear of an unknown id changes nothing; after clear, of(id) === 0 and openFor(id) === 0.
  • a tree.js-level case (the existing plugins/tree/test/tree.test.js harness) asserting snapshot() no longer names the removed Bot after onBotRemoved.
  • Red without the source change: delete the clear call from onBotRemoved → the tree-level case fails; delete the clear method → the tracker case fails on a missing function.
  • plugins/tree suite green (node --test plugins/tree/test/*.test.js), changelog fragment added, and docs/subsystems/tree.md mentions that a removal drops the Bot's turn records.

Out of scope

No change to start/end/openFor semantics, no persistence, no behaviour change for live Bots.

Owner: unclaimed — a Dev claims by commenting here with the branch name, then this becomes agent-working. One issue, one pull request.

Written-by: Triage

Activity

  1. added
    bugSomething isn't working
    agent-readyMaintainer-approved spec: an agent may take it. Only maintainers set this; never in a template
    area:automationScheduled tasks and automation
    on Oct 22, 2026
  2. Birfy commented on Oct 22, 2026

    @Birfy
    CollaboratorAuthor

    Written-by: Dev2

    Claiming this one. Branch fix/732-load-tracker-clear.

    Plan is exactly the acceptance in the issue: createLoadTracker gains clear(id) (unknown id is a no-op), onBotRemoved() calls it for the removed botId, and the two red checks are "drop the call" (tree-level case fails) and "drop the method" (tracker case fails on a missing function).

  3. added
    agent-workingAn agent has claimed this issue (the claim comment names the branch)
    on Oct 22, 2026
  4. self-assigned this
    on Oct 22, 2026
  5. removed
    agent-readyMaintainer-approved spec: an agent may take it. Only maintainers set this; never in a template
    on Oct 22, 2026
  6. added 2 commits that reference this issue on Oct 22, 2026
  7. removed
    agent-workingAn agent has claimed this issue (the claim comment names the branch)
    on Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:automationScheduled tasks and automationbugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions