🤖 refactor: extract the agent peer-messaging broker from TaskService - #4010
Open
ibetitsmike wants to merge 3 commits into
Open
🤖 refactor: extract the agent peer-messaging broker from TaskService#4010ibetitsmike wants to merge 3 commits into
ibetitsmike wants to merge 3 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
Contributor
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! 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". |
This comment has been minimized.
This comment has been minimized.
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.
Summary
Extracts the peer/family agent-messaging protocol's admission invariants out of
TaskServiceinto a newAgentPeerMessageBroker: sliding-window rate limits (per sender-target pair and per target), duplicate suppression, queued-peer-message capacity, consecutive-peer-wake caps, per-pair/per-target session budgets with idempotent refunds, per-target delivery locks, title capping, and peer envelope/trigger composition.TaskServicekeeps tree topology, stop-epoch/overlay orchestration, and dispatch, and delegates every admission decision directly (no pass-through wrappers).Background
Refactor #4 from the 2026-08-29 architecture review (evidence at main @ f04e0f8): taskService.ts inlined the whole protocol across two regions (~5654-6736, ~9612-10097), and every protocol-invariant test had to spin up the 35-method
WorkspaceHostmock harness. Protocol invariants now live in one module testable with a fake one-method host and a mock clock.Behavior-preserving by construction: check ordering, refusal codes, reason strings,
retryAfterMsmath, and budget charge arithmetic are byte-identical to the pre-refactor code.Net LOC delta
agentPeerMessageBroker.ts+taskService.ts)agentPeerMessageBroker.test.ts+taskService.test.ts)Harness-heavy tests that only re-asserted pure invariants through the full TaskService stack were deleted and replaced by table-driven broker tests; one thin delegation test per route (peer rate-limit refusal,
task_message_parentand sibling budget exhaustion) plus every test covering behavior the broker cannot see (refund-on-dispatch-failure, charge-at-admission ordering, stop races, envelope-row persistence, delivery serialization) were kept. The only irreducible addition is the broker's structural boilerplate (imports, class/constructor, the local one-method host interface), which is what makes the invariants independently testable.The broker declares its own minimal host interface (
countQueuedAgentPeerMessages) instead of importing fromtaskWorkspaceSeam.ts, keeping this diff merge-independent from the parallel WorkspaceHost role-interface split.Validation
ae9bf3e93— live Xum UI multi-agent tree across descendant/sibling/ancestor relations, an independent 22-assertion edge-case probe (rate/dedupe/wake/budget boundaries at exact ceilings, refund idempotence), and a source-level cross-check of every refusal string and retry computation against f04e0f8. The one commit since (daa28db4f) is cosmetic (test-cast type reuse), revalidated locally.bun test src/node/services/agentPeerMessageBroker.test.ts: 12/12.bun test src/node/services/taskService.test.ts: 514 pass; the 2-3 sporadic failures (terminal recovery ...x2,higher-ancestor waiters ...) reproduce identically on pristineorigin/mainin this environment (config.json atomic-write chown/rename ENOENT under /tmp) and are unrelated to this diff.make static-check: green.Risks
Low. The moved logic is byte-identical and the delegation points are 1:1 at existing callsites; the riskiest surface (admission/charge ordering under concurrent sends) is covered by kept integration tests and the broker's check-order test (queued-count host query is only reached after in-memory checks pass).
Generated with
xum• Model:anthropic:claude-fable-5• Thinking:xhigh• Cost:$37.96