GeezerVison is showing github.com — feat(opencode): add message tool for agent-to-agent communication by iceteaSA · Pull Request #32192 · anomalyco/opencode
Conversation
iceteaSA
commented
Jun 13, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Issue for this PR
Related to #19215 (agent-team coordination). This PR doesn't implement that whole proposal — it adds the smaller parent↔child messaging primitive it depends on.
Type of change
- Bug fix
- New feature
- Refactor / code improvement
- Documentation
What does this PR do?
Adds a message tool so a subagent can talk to the agent that spawned it, instead of only being able to ask the human (question). A subagent can ask its parent a question and block for the answer, or send a fire-and-forget update; the parent answers with the same tool. Off by default behind OPENCODE_EXPERIMENTAL_AGENT_MESSAGING.
The tricky part is that during a foreground task the parent's turn is parked waiting on the Task tool result, so there's no live parent turn to answer — and if the child also blocks waiting on the parent, they deadlock.
The fix reuses machinery that already exists rather than adding a new session state. When a subagent sends to its parent, it wakes the parent's parked task wait through a new background-job channel (background.message() / waitForMessage()), and parks on a reply Deferred held by a small per-instance Messaging service that's a near-copy of the existing Question service. Waking the parent returns the message (plus the child's task_id) out of the task tool; the parent replies with message(target:"subagent", task_id, …), which resolves the Deferred and the child continues. The child's later completion is delivered by the existing background-subagent inject path. This is why there's no loop change: the only edit to existing control flow is adding a third arm to the task await race (waitForMessage) next to wait/waitForPromotion.
Why it doesn't deadlock or hang: the message channel is deliberately separate from the promotion channel (it sets its own metadata.messaged marker, not background, so waitForPromotion's short-circuit can't race it). A parked reply is always bounded by a timeout (default 300s → the child proceeds without an answer), and cancelling either session cancels the child's background job and interrupts the parked fiber via the existing finalizer. If there's no parent at all (top-level/headless), the tool fails fast instead of blocking.
Security: reply only resolves a pending entry when the caller is the parent recorded at send time, and task_id resume in the task tool now checks the target is actually the caller's child — otherwise an agent that guessed a session id could drive or inject into someone else's subagent. Bodies are XML-escaped into their frame and size-capped; there's a per-child in-flight cap and a cumulative round-trip cap so a child can't spin the parent.
Sibling↔sibling is parent-mediated only for now (the parent relays); the registry is keyed by session id so direct edges can be added later.
Visible transcript markers (TUI). Messages were previously injected as synthetic parts — the model saw them, but the human watching the TUI saw nothing. Each message flow now also writes a distinct, non-synthetic ✉ marker into the relevant transcript so the user can follow what's happening: the recipient sees the incoming message/reply (✉ Message from subagent, ✉ Reply from parent) and the sender sees an echo of what it sent (✉ Sent to parent, ✉ Replied to subagent). The marker is additive — the model still receives the original <agent_message> frame; the marker is a separate part tagged via metadata.message and rendered as its own muted row (the same mechanism used for subagent-interrupt's markers). Bodies are XML-escaped in the marker too.
How did you verify your code works?
New tests (no mocks): request/reply, fire-and-forget, no-parent fail-fast, reply timeout, parent/child authorization, the abuse caps, a concurrent-send race, body escaping, the new background-job channel, the task_id parentage check, an integration test across the channel + reply seam, and the visible-marker flows (each direction/peer, with frame-breakout bodies asserted escaped, plus the Channel-A parked-parent marker).
cd packages/opencode && bun test → 3003 pass, 0 fail (22 skip, 1 todo)
cd packages/core && bun test → the failures on this branch also fail on a clean dev checkout (DB-migration sync, file-picker model/variant, SessionRunnerLLM Location, ripgrep git metadata, env-var plugin tests, locked edit/write schema docstrings); this branch adds no new failures
bun typecheck clean in packages/opencode and packages/tui; regenerated the SDK with ./packages/sdk/js/script/build.ts
- rebased onto the current
dev
Screenshots / recordings
UI change — the visible ✉ message markers in the subagent/parent transcript:
Subagent → parent
Parent → subagent (reply)
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
The sender-echo markers duplicated information already shown by the
message tool call itself (✉ Sent to parent / ✉ Replied to subagent sat
right under the visible tool call), and the subagent's "Reply from
parent" marker was written twice — once by the parent's reply branch and
again by the subagent's own send path.
Keep only the incoming markers: the parent sees "✉ Message from
subagent", the recipient subagent sees "✉ Reply from parent", each once.
Drop the now-unused marker direction field.
|
Automated PR Cleanup
Thank you for contributing to opencode.
Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.
This PR was closed because it matched the following cleanup criteria:
- The PR was created more than 1 month ago
- The PR had fewer than 2 positive reactions
- Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR
PRs created within the last month are not affected by this cleanup.
If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.
Thanks again for taking the time to contribute.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Still active — requesting reopen.
Rebased onto dev@5e2a625 today, conflict-free. The stack this anchors gates clean at its tip: 3322 tests, 0 failures, typecheck clean.
Worth flagging for the cleanup pass: this is the base of a five-PR stack — #32425 → #32517 → #32693 → #35400 all build on it. #32425 and #35400 are still open, so the chain now has open PRs sitting on a closed base.
It has been kept current with dev on a roughly weekly cadence since it was opened. Happy to split or squash it if that makes review easier.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Jul 26, 2026
randomvariable
added a commit
to randomvariable/opencode
that referenced
this pull request
Aug 3, 2026
Add an experimental `message` tool (behind OPENCODE_EXPERIMENTAL_AGENT_MESSAGING)
for agent-to-agent communication: a subagent can message its parent (blocking
for a reply by default, or fire-and-forget) and a parent can reply to a parked
subagent. Adds a Messaging service (round-trip caps, anti-abuse, parent-authz,
timeouts), a BackgroundJob message channel to wake a foreground-parked parent,
a `message` permission, XML-escaped transcript markers surfaced in the TUI, and
task-tool parentage authorization on task_id resume.
Ported from anomalyco#32192 (adapted for the Effect layer; merged with the prior
task.ts model-override and slug-resume changes).
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
randomvariable
added a commit
to randomvariable/opencode
that referenced
this pull request
Aug 3, 2026
Add an experimental subagent-interrupt capability (behind
OPENCODE_EXPERIMENTAL_SUBAGENT_INTERRUPT): an Interrupt service with
pending/terminal state, task_steer/task_cancel/task_abort tools (gated by a
new `interrupt` permission), a POST /session/:id/interrupt endpoint, and a
turn-boundary consume in the prompt loop that injects an escaped steer/cancel
frame plus a visible transcript marker. Cancel records a terminal reason and
force-breaks after a grace window; abort writes a marker, records the
terminal, and cancels the BackgroundJob immediately. The TUI gains an
esc-with-reason flow, footer button, and distinct interrupt markers.
Ported from anomalyco#32425 (adapted for the Effect layer; merged with the prior
task.ts/registry.ts/prompt.ts changes from anomalyco#29447/anomalyco#32122/anomalyco#12520/anomalyco#32192/anomalyco#19961).
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This was referenced Sep 28, 2026
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|