🤖 refactor: unify agent tree message dispatch behind one relation pipeline - #4024
Conversation
Salvaged from the timed-out implement round: relation-parameterized sendTreeMessage pipeline with thin public wrappers, family envelope construction moved into AgentPeerMessageBroker.prepareFamilyMessage, unified budget reservation/refund mechanics with per-route policy.
This comment has been minimized.
This comment has been minimized.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: febac31226
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
This comment has been minimized.
This comment has been minimized.
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Summary
Unifies the four agent-tree message dispatch paths in
taskService.ts(descendant guidance, peer/ancestortask_send_message, and the parent/sibling RLM family-message routes) behind one relation-parameterizedsendTreeMessagepipeline. The four public methods keep their exact signatures, result/error shapes, and delivery semantics; they are now thin wrappers that build a relation spec and enter the shared pipeline.Background
Card 3 of the 2026-08-31 architecture review. PR #4010 centralized peer-messaging admission invariants (throttles, budgets, envelope prep) in
agentPeerMessageBroker.ts, but the four dispatch paths still each reimplemented the same ritual: validate topology, admission refusals, envelope/payload construction, budget reservation, delivery lock, dispatch, refund accounting. The same char-cap, budget, envelope, and lock logic appeared up to four times with only the relationship check differing (~1,150 lines).Implementation
sendTreeMessage(spec)pipeline owns the shared phase order (normalize/cap, topology, refusals, envelope, budget, lock, dispatch, refund accounting), parameterized by a relation-discriminated spec. Overloads keep each public route's result type exact.sendFamilyTreeMessagecore; their envelope/trigger construction moves intoAgentPeerMessageBroker.prepareFamilyMessagenext topreparePeerMessage, so one module owns every envelope format. Payload/trigger strings are byte-identical to before.reserveTreeMessageBudgetwithmarkPersisted/refundIfUnpersisted) while each route keeps its exact refund policy (refund only when nothing persisted; queued-then-cleared sends keep the charge).admissionStaleprobe, dedupe keys, correlation metadata, wake accounting) is preserved unchanged inside the peer leg.Net: -28 LOC across production and tests (+457/-485).
Validation
make static-checkgreen;make typecheckgreen.bun testontaskService.test.ts,agentPeerMessageBroker.test.ts,tools/task_list.test.ts,tests/ipc/tasks/persistentSubagentCompaction.test.ts: fail set identical to a clean-base run of the same suite (two pre-existing host-specific fails, no regressions).queued/turn-end) are never delivered after the turn ends. A controlled re-run of the identical scenario against base main0672c8f47reproduced it exactly, so it is a pre-existing defect in the queued-wake drain path, not introduced by this refactor; it deserves a separate fix.Risks
Intricate-logic refactor in the messaging hot path. Highest-severity regression classes would be: lost or duplicated peer wakes (budget/refund drift), envelope framing changes (security boundary), and descendant reactivation semantics. Mitigations: phase order and refund horizons preserved verbatim per route, envelope strings byte-identical, admission probes untouched, and the relation-parameterized tests assert through the public API with per-route error shapes.
Generated with
xum• Model:anthropic:claude-fable-5• Thinking:xhigh• Cost:$27.13