feat(teams): auto-notify leader LLM on task completion (closes #4, compat with #6)#7
Open
RensTillmann wants to merge 2 commits intotmustier:mainfrom
Open
Conversation
added 2 commits
March 6, 2026 05:38
Closes tmustier#4. Compatible with PR tmustier#6 (onDm callback). Three notification layers: 1. Per-task: pi.sendMessage() injects completion info into leader context (triggerTurn: false) so it accumulates without interruption 2. Batch-complete: pi.sendUserMessage() wakes the idle leader when ALL tasks from a delegate() call finish 3. DMs (PR tmustier#6 compat): onDm callback with 50ms debounce batching, delivered via pi.sendMessage() with triggerTurn: true DelegationTracker class tracks task ID batches from delegate calls. Cleared on session_switch. Batches pruned after notification.
The original DelegationTracker.checkCompleted() polled listTasks() on every inbox cycle, which raced — it could see stale task statuses and fire false-positive batch-complete notifications immediately after delegation. Replaced with event-driven markCompleted(taskId): only marks a task done when an idle_notification with completedTaskId is actually received. No more filesystem polling for task status. Also: batch completions are collected across all messages in one poll cycle and deduplicated before firing notifications.
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.
Problem
When teammates complete tasks,
leader-inbox.tscallsctx.ui.notify()which only shows a UI toast. The leader LLM never receives a message in its conversation, so it goes stale after delegating — the human has to manually poke it to check progress.This is exactly the problem described in #4.
Solution
Three notification layers, each serving a different purpose:
1. Per-task completion (
onTaskCompletedcallback)When a worker completes a task, inject the completion info into the leader's conversation via
pi.sendMessage()withtriggerTurn: false. This adds context without interrupting an active turn — the leader sees it on its next response.2. Batch-complete auto-wake (
DelegationTracker)When ALL tasks from a single
delegate()call reach "completed", firepi.sendUserMessage()which triggers a new LLM turn. This wakes the idle leader to review results and continue orchestrating.DelegationTrackerclass tracks task ID batches from eachdelegate()callcheckCompleted()polls task statuses (called every 700ms in the inbox loop)sendUserMessagedirect) and streaming (deliverAs: "followUp") statesctx.ui.notify()if sendUserMessage throwssession_switch, pruned after notification3. DM delivery (PR #6 compat)
Includes the
onDmcallback pattern from #6 so both PRs can coexist. DMs are batched with a 50ms debounce and flushed viapi.sendMessage()withtriggerTurn: true.Files changed
leader-inbox.tsDelegationTrackerclass,pi/onDm/onTaskCompleted/delegationTrackerparams, batch-complete check at endleader.tspollLeaderInboxleader-teams-tool.tsdelegateaction viadelegationTracker.addBatch()Compatibility with PR #6
This PR includes the same
onDmcallback approach from #6 (DM routing to leader LLM context with debounce batching). If #6 merges first, this PR's DM handling can be dropped — the rest (per-task + batch-complete) is additive.Before / After
Before: Leader delegates → workers complete → UI toast only → leader goes stale → human pokes
After: Leader delegates → workers complete → per-task info injected → all done →
sendUserMessageauto-wakes leader → leader reviews and continues