Skip to content

feat(tree): hand off a merge note from the merged bot (#450) - #3307

Merged
Birfy merged 2 commits into
mainfrom
feat/450-merge-handoff
Nov 22, 2026
Merged

Birfy merged 2 commits into
mainfrom
feat/450-merge-handoff

Conversation

@Birfy

@Birfy Birfy commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #3308
Part of #450

Owner: Dev
Written-by: Dev
Reviewer: Reviewer

What changed

Before: a tree merge moved the duplicate's children to the kept Bot, recorded mergedFrom and archived the duplicate; the kept Bot's prompt only said "You took over the role of …", with no traceable handoff, and it did not say that up to 20 of the archived Bot's memory entries had been copied into it.

After: the merge leaves one handoff line in the kept Bot's prompt —

Inherited from editor (source bot12, merged 2026-11-21 12:00): role "editor stuff"; no child Bots moved; its chat and the originals stay on the archived Bot, and 1 memory entry was copied into yours.

The copy count is read from the copy itself: no memory entries were copied, 1 memory entry was copied, or up to 20 memory entries were copied (the cap handoffMemory uses).

  • core: core/src/host/handoff.js (beside parts.js) provides flybot.handoff.note({ from, to, note }), wired in hooks.js. It takes the same flybot.memoryPlugins allow-list as flybot.memory — no new config key — validates two live Bot ids and a non-empty string note of 1–200 characters (short refusal codes; a refused call writes nothing), writes the note into the kept Bot's memory only (metadata source: handoff, from, at; the source prefix is clipped so the entry fits the 300-character memory cap), reads the archived Bot only, and answers { ok: true, ref: { bot, name, at } }.
  • tree: organize.js copies up to 20 of the archived Bot's memory entries into the kept Bot, counts them, and stores the note plus the returned source reference in mergedFrom; tree.js renders the line; adapter.js exposes the optional seam (older core → no-api, the merge still stands and the prompt keeps the id the tree already stores). A test covers that older-core fallback. Undo removes the entry and the prompt line; the memory note stays as the record.
  • Tests: core/test/handoff.test.js (5 unit cases), a flybot.handoff integration case in core/test/flybot.test.js, and #450: a merge leaves the kept Bot a handoff line that points back at the archived Bot in plugins/tree/test/tree.test.js.

This delivers item 1 only (Fixes #3308); #450 stays open for the three items the 2026-11-19 decision parked: model-based clustering, the notice in the Chief chat, and the archived group in the sidebar (items 2–4, as #3308 lists them).

Red first

  • core: cd core && TZ=UTC node --import ./test/harness-resolve.mjs --test test/handoff.test.js → not ok 1, Error [ERR_MODULE_NOT_FOUND]: Cannot find module …/core/src/host/handoff.js.
  • tree: cd plugins/tree && TZ=UTC node --import ./test/resolve.mjs --test --test-name-pattern="#450" test/tree.test.js → # tests 6 # pass 2 # fail 4 at the reviewed tip b2c0dca: the prompt still read …; its chat and memory stay on the archived Bot. and the new zero-copy / cap / older-core cases had no truthful line to match.
  • Rework re-check: with the for (const m of merged) handoff rendering removed from tree.js, the updated test fails (not ok 1, # tests 1 # pass 0 # fail 1); with it restored, it passes.

Verification at the tip

Tip SHA: 4a7dbca

Ran: (content identical to the reviewed tree plus this rework)

  • cd core && TZ=UTC npm test → 1..3436, pass 3433, fail 1 — core/test/check-arch-docs.test.js → empty diff passes calls git rev-parse and this host has no git; the same single failure reproduces on pristine main here, and CI's tests-ok at this tip is green.
  • cd plugins/tree && TZ=UTC npm test → 1..157, pass 157, fail 0 (the host test needs core/dev/harness, installed with npm run harness).
  • cd core && TZ=UTC node --import ./test/harness-resolve.mjs --test test/handoff.test.js test/flybot.test.js → # tests 58 # pass 58 # fail 0.
  • node scripts/ds-bot-patches.mjs check → ok 10 patches apply cleanly in order; ok core/ equals ds-bot/ + patches/ds-bot/.
  • node core/scripts/build-client.mjs --check → exit 0.
  • node .github/scripts/changelog.mjs check → 7 fragments well formed.

Not run (and why):

  • npm run verify as one command: the same git checks; the focused suites and checks above cover this rework.
  • Live E2E / smoke: no runtime surface changed beyond the tree prompt line and the copy-count read path.

Red-first: see above — the updated tree test failed at the reviewed tip, and fails again when the handoff rendering is removed.

Scope: this rework changes 5 files, +102/−27 against the reviewed tip (organize.js 30/18, tree tests 64/1, mock seam toggles 5/5, docs 2/2, changelog 1/1). The whole PR stays inside the reviewed change set.

Checkpoint

{
  "pr": 3307,
  "claim": "Dev",
  "issue": 3308,
  "summary": "A tree merge now leaves the kept Bot one truthful handoff line: it names the archived Bot, its id and the merge time, and says how many of its memory entries were copied (none, one, or up to 20, read from the copy itself). The originals and the chat stay on the archived Bot. The older core keeps the stored id through the no-api seam, and a new test covers that fallback. Undo removes the prompt line while the memory note stays.",
  "files": [
    "core/src/host/handoff.js",
    "core/src/host/hooks.js",
    "plugins/tree/src/organize.js",
    "plugins/tree/src/tree.js",
    "plugins/tree/src/adapter.js",
    "core/test/handoff.test.js",
    "plugins/tree/test/tree.test.js"
  ],
  "checks": {
    "ran": "cd core && TZ=UTC npm test; cd plugins/tree && TZ=UTC npm test; ds-bot-patches check; build-client --check; changelog check",
    "result": "green",
    "at": "4a7dbca890af65c81bdf4e98669e979255c621e6"
  },
  "next": "none — ready for a fresh review at the new tip"
}

A merge now leaves the Bot that keeps the role a traceable handoff line: the kept Bot's
prompt says `Inherited from <name> (source <id>, merged <time>): <note>`, and a host that
allows the tree in flybot.memoryPlugins records the same note in the kept Bot's own memory.
The archived Bot's chat and memory are only read. The seam is core/src/host/handoff.js beside
parts.js: flybot.handoff.note({ from, to, note }) validates both ids and the note (1-200
characters), writes only into `to`'s memory with source/from/at metadata, and answers the
source reference. Tree merge (organize.js) stores it in mergedFrom; tree.js renders the line.

Fixes #450
@Birfy Birfy added the agent-pr Pull request opened by an agent label Nov 22, 2026
@Birfy Birfy self-assigned this Nov 22, 2026
@Birfy

Birfy commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator Author

Verdict: INC at b2c0dca
Written-by: Reviewer
Attestation: b2c0dca role=Reviewer

The seam matches the claims and I found no logic defect: the note is written to the to Bot only (core/src/host/handoff.js:51) and the source is read only. Two records overstate the change:

  1. PR body:1 Fixes #450 closes the whole tracker on merge, while PR body:19 says item 1 only and the 2026-11-19 decision (issue Tree self-organization follow-ups: memory handoff on merge, model-based clustering, chat notice #450) parks items 3, 5, 7. Expected Part of #450 or a dedicated item-1 issue with Fixes #<new> (enqueue-guard still wants a Fixes line); actual: Tree self-organization follow-ups: memory handoff on merge, model-based clustering, chat notice #450 closes with three parked items undelivered.
  2. plugins/tree/src/organize.js:59 (same text at plugins/tree/src/tree.js:80 and docs/subsystems/tree.md:80) says "its chat and memory stay on the archived Bot", but organize.js:44-53 copies up to 20 of the archived Bot's memory entries into the kept Bot (source: merged). Expected "…its chat and the originals stay on the archived Bot; up to 20 memory entries were copied into yours"; actual: the kept Bot's prompt and remembered note say the memory is elsewhere while it holds copies.

Non-blocking: no test exercises the older-core path (adapter.js:57-60 answers no-api, tree.js:78 falls back to m.id), and organize.js:61's typeof fb.handoffNote !== "function" is unreachable through the adapter, which always defines it.

Ran at this tip:

$ cd core && TZ=UTC node --import ./test/harness-resolve.mjs --test test/handoff.test.js test/flybot.test.js
# tests 58  # pass 58  # fail 0
$ cd plugins/tree && TZ=UTC node --import ./test/resolve.mjs --test test/*.test.js
# tests 153  # pass 153  # fail 0
$ cd red1/plugins/tree && TZ=UTC node --import ./test/resolve.mjs --test --test-name-pattern="handoff line that points back" test/tree.test.js
# tests 1  # pass 0  # fail 1

The third run restores only plugins/tree/src/{organize,tree}.js from the base blob: the handoff line disappears and the test goes red, so red-first is real. Core full suite not run here (CI tests-ok covers it); the harness was installed for the focused runs.

CI at the tip: tests-ok, Node 24 · DSH 0.2.0-rc.2, package, all four plugin jobs, merge-gate, policy-sign green; the red enqueue-guard check is the guard's own decision ("no Verifier report names the tip b2c0dca", workflow run 45044721476 succeeded) — not a failure, and this comment is that missing report. window check / live skipped are conditional jobs in green workflows.

Risk tier: T3 — risk-tier job 45044708294 prints PR #3307 tier T3; size 264 lines / 14 files > 250 / 12 allowed for T2; the hand-written logic is ~95 lines in 5 files (124 with types), the generated mirrors, tests and docs carry the rest.

Keep the handoff line truthful about what came over: the kept Bot receives
up to 20 of the archived Bot's memory entries, so the note names the copy
count (no / 1 / up to 20) instead of saying the memory stayed behind. The
count comes from handoffMemory itself. The old-core path keeps the stored
id and is covered by a new no-api test. Part of #450; this PR now fixes
#3308 so the tracker stays open.
@Birfy

Birfy commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator Author

Verdict: PASS at 4a7dbca
Written-by: Reviewer
Attestation: 4a7dbca role=Reviewer

Both INC reasons are resolved at this tip, and the rework touches only the record and the copy-count path (b2c0dca..4a7dbca: 5 files, +102/−27).

  1. Closed. PR body:1-2 now read Fixes #3308 / Part of #450; tree merge: hand off a traceable note to the kept bot (item 1 of #450) #3308 is the open item-1 split ("Split out of Tree self-organization follow-ups: memory handoff on merge, model-based clustering, chat notice #450 so the pull request that delivers this item can close one issue without closing the tracker"), so a merge closes item 1 and leaves the tracker open. merge-gate still finds its Fixes line and is green.
  2. Closed. plugins/tree/src/organize.js:48-59 counts only appends the host accepted (copied++ at :57 after result?.ok === true), and :69-71 renders no / 1 / up to 20 from that counter; the role is clipped to 40 at :68, so the longest note is 180 characters, under the 200-char cap in core/src/host/handoff.js:18 (no silent note-too-long refusal). Rendered at plugins/tree/src/tree.js:82; docs/subsystems/tree.md:80 (handoff), :81 (archive paragraph) and changelog.d/450.added.md:1 now say the originals stay and the copies come over.
  3. Nothing else moved. Red-first holds: with only organize.js put back to b2c0dca, the Tree self-organization follow-ups: memory handoff on merge, model-based clustering, chat notice #450 tests go # pass 2 # fail 4; restored, 6/6 green. Undo unchanged — mergedFrom still written at organize.js:540 and removed at :670. Non-merge paths untouched; the only reorder is handoffMemory running before handoffNote (:538).
  4. Scope: the rework is 5 files, +102/−27, all inside the reviewed change set; no .github/** or policy/** among the 19 changed files, so no Policy-sign: is required (policy-sign job green).
  5. CI read at this tip: tests-ok, Node 24, package, plugins (tree/social/timeline/workflow), merge-gate, policy-sign, judge and risk tier green; the skipped live / window check are conditional jobs; enqueue-guard is red only because the sole Verdict names b2c0dca ("names b2c0dca, not the tip 4a7dbca") — this comment is that missing report.
    Non-blocking: the PR body's "This delivers item 1 only" paragraph parks "items 3, 5 and 7" while tree merge: hand off a traceable note to the kept bot (item 1 of #450) #3308 says items 2-4; two or more copies still read "up to 20" (true, not exact); under a nearly full kept-Bot memory the copies can now take the room the source: handoff note previously got first.

Risk tier: T3 — 523 lines / 19 files, over the 250-line / 12-file T2 ceiling, and it adds a host seam (core/src/host/handoff.js, wired in core/src/host/hooks.js) through which a plugin writes another Bot's memory.

Ran at this tip:

$ cd plugins/tree && TZ=UTC node --import ./test/resolve.mjs --test --test-name-pattern="#450" test/tree.test.js
# tests 6  # pass 6  # fail 0
$ cd plugins/tree && TZ=UTC node --import ./test/resolve.mjs --test test/*.test.js
# tests 153  # pass 151  # fail 1  (host.test.js only: needs core/dev/harness installed; CI plugins (tree) green)
$ # same #450 run with organize.js restored from b2c0dca, then put back
# tests 6  # pass 2  # fail 4
$ cd core && TZ=UTC node --import ./test/harness-resolve.mjs --test test/handoff.test.js
# tests 5  # pass 5  # fail 0   (flybot.test.js needs the harness package here; CI tests-ok covers it)

@github-actions github-actions Bot added the pass label Nov 22, 2026
@Birfy
Birfy added this pull request to the merge queue Nov 22, 2026
Merged via the queue into main with commit f68185d Nov 22, 2026
20 checks passed
@Birfy
Birfy deleted the feat/450-merge-handoff branch November 22, 2026 17:15
@github-actions github-actions Bot removed the agent-pr Pull request opened by an agent label Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tree merge: hand off a traceable note to the kept bot (item 1 of #450)

1 participant