Skip to content

fix(acp): forward subagent session events to ACP client#21801

Open
jasonmj wants to merge 4 commits intoanomalyco:devfrom
jasonmj:fix/acp-subagent-events
Open

fix(acp): forward subagent session events to ACP client#21801
jasonmj wants to merge 4 commits intoanomalyco:devfrom
jasonmj:fix/acp-subagent-events

Conversation

@jasonmj
Copy link
Copy Markdown

@jasonmj jasonmj commented Apr 10, 2026

Issue for this PR

Closes #21802

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

ACPSessionManager only tracks sessions explicitly created or loaded by the ACP client (session/new, session/load). When the Task tool spawns a subagent, it calls Session.create({ parentID: ... }) internally, producing a child session with its own ID that is never registered in the session manager.

In handleEvent(), all three event cases (permission.asked, message.part.updated, message.part.delta) call this.sessionManager.tryGet(sessionID) and return early if the result is undefined. This means every event from a subagent session is silently dropped — none of the subagent's tool calls, streamed text, or permission requests reach the ACP client.

The fix adds a resolveRootSession() method that, when a session ID is not directly tracked, walks the parentID chain via sdk.session.get() until it finds a known ACP-tracked ancestor. Events from child sessions are then forwarded to the ACP client attributed to the root session ID. A childToRootSession cache avoids repeated SDK calls for the same child session across multiple events.

How did you verify your code works?

Tested with the agent-shell Emacs ACP client. Before the fix, running a prompt that triggered the Task tool showed no subagent activity. After the fix, subagent tool calls, streamed text, and permission dialogs all appear in the parent session's buffer. TypeScript type-check passes with no errors.

Screenshots / recordings

N/A — CLI/protocol change with no UI.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Apr 10, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search, I found one potentially related PR:

Related PR:

The current PR (#21801) addresses a different aspect of the same broader issue: making subagent activity visible to ACP clients. PR #21111 handles session metadata updates while #21801 handles real-time event forwarding.

No exact duplicate PRs found.

@github-actions github-actions Bot removed needs:issue needs:compliance This means the issue will auto-close after 2 hours. labels Apr 10, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@jasonmj
Copy link
Copy Markdown
Author

jasonmj commented Apr 22, 2026

Not sure how I can move this forward, but I am keeping the PR up to date.

@feisuzhu
Copy link
Copy Markdown

Need this too

@jasonmj jasonmj force-pushed the fix/acp-subagent-events branch 3 times, most recently from 6b3ef56 to 4620720 Compare April 25, 2026 02:30
rekram1-node and others added 2 commits April 27, 2026 09:07
When a prompt is run through the Task tool, events arrive with a child
session ID that is not directly tracked by ACPSessionManager. Add
resolveRootSession() which walks the parentID chain via the SDK to find
the nearest ACP-tracked ancestor, caching results to avoid repeated
lookups. Replace all sessionManager.tryGet() calls in handleEvent with
resolveRootSession() so that tool call and message delta events from
sub-agent sessions are correctly forwarded to the ACP client.
@jasonmj jasonmj force-pushed the fix/acp-subagent-events branch from 4620720 to f917dc3 Compare April 27, 2026 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ACP clients cannot see subagent activity from Task tool

3 participants