Skip to content

feat: add ACP subagent waiting and transcript streaming - #30560

Merged
hugodutka merged 1 commit into
hugodutka/acp-tools-apifrom
hugodutka/acp-subagents-tools
Oct 26, 2026
Merged

hugodutka merged 1 commit into
hugodutka/acp-tools-apifrom
hugodutka/acp-subagents-tools

Conversation

@hugodutka

@hugodutka hugodutka commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

Add acp_wait_agent to stream ACP transcripts, including reasoning and nested tool activity, to users while returning the subagent's text response to the parent model. Reconnect dropped streams from their transcript cursor, preserve running sessions on wait timeout or cancellation, and persist separate user-visible and model-visible results.

Depends on #31022.

Generated with Codex, carefully reviewed by Hugo.

@hugodutka
hugodutka added this pull request to stack #30559 October 9, 2026 16:17
@hugodutka
hugodutka force-pushed the hugodutka/acp-subagents-tools branch from 4af3b0a to 1d18df8 Compare October 9, 2026 16:49
@hugodutka
hugodutka marked this pull request as ready for review October 9, 2026 16:58
@hugodutka
hugodutka requested a review from mafredri October 9, 2026 16:58
@hugodutka
hugodutka force-pushed the hugodutka/acp-subagents-tools branch 2 times, most recently from 8af7bd8 to 435c9f1 Compare October 12, 2026 09:24
@hugodutka
hugodutka force-pushed the hugodutka/acp-subagents-tools branch from 435c9f1 to 5a703c3 Compare October 12, 2026 10:03
@hugodutka
hugodutka force-pushed the hugodutka/acp-subagents-tools branch from 5a703c3 to 795d915 Compare October 12, 2026 12:45
@hugodutka
hugodutka force-pushed the hugodutka/acp-subagents-tools branch from 795d915 to b3a7a9c Compare October 14, 2026 19:09
@hugodutka
hugodutka force-pushed the hugodutka/acp-subagents-tools branch from b3a7a9c to 7dcce90 Compare October 14, 2026 19:12
Comment thread coderd/x/chatd/acp.go
var errACPWorkspaceChanged = xerrors.New("ACP chat workspace changed")

func (p *Server) acpTools(ctx context.Context, opts rootChatToolsOptions) []fantasy.AgentTool {
if opts.isPlanModeTurn || opts.chat.ParentChatID.Valid || !p.experiments.Enabled(codersdk.ExperimentChatACPSubagents) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So plan mode cannot use acp sub-agents?

@hugodutka hugodutka Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. Seems reasonable to me.

Comment thread coderd/x/chatd/acp.go Resolved
Comment thread coderd/x/chatd/acp.go Resolved
Comment thread coderd/x/chatd/acp.go Resolved
Comment thread coderd/x/chatd/acp.go Resolved
info.Status, info.Error = workspacesdk.ACPSessionStatusError, waitErr.Error()
}
return o.waitResponse(session, info, &transcript, timedOut), nil
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is quite hard to follow and contains a lot of conditional logic which seems like they should be various named phases.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored it. Let me know if it reads better now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better, thanks.

Comment thread coderd/x/chatd/acp_wait.go Outdated
}

func (o acpToolOptions) waitReconnect(ctx context.Context) bool {
timer := o.clock.NewTimer(250*time.Millisecond, "acp-reconnect")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method name suggests something completely different, it's essentially a back-off but says it waits for connection to re-establish.

I also don't understand its purpose or why 250ms was selected. If we actually want this type of behavior, shouldn't we be using coder/retry or something? (Although, that one doesn't integrate with quartz which seems to be used here.)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed it and added a comment: the value is arbitrary. Yeah, no coder/retry here because it lacks support for quartz.

return harnesses
}

func acpSpawnProperties(harnesses []workspacesdk.ACPHarness) map[string]any {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels a bit off that the schema is spread all over the place. The tool is defined in one place, and properties elsewhere. Makes it harder to "see the whole", i.e. the entire schema for the tool.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored this file. Let me know if it's better now.

Comment thread coderd/x/chatd/acp_transcript.go Outdated
return false, false, xerrors.Errorf("decode ACP update: %w", err)
}
switch {
case update.UserMessageChunk != nil:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a bit too lax to me, for some reason we check header first, but then we accept any type of chunk, perhaps the client could even send two types of chunks and its first come, first served. Could lead to some weird issues rather than reporting a proper error state.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We check the header to drop anything other than a couple of message chunks we care about. We assume the stream is well-behaved: it comes from our own code in the workspace agent. We fully control the format and ordering here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd push back on "we fully control the format" slightly since the workspace agent is not a trusted boundary, there's nothing stopping a user from starting up their own workspace agent using the agents token, this could allow bypassing some kind of validation by sending a malformed payload. A strict enforcement is ideal in this case IMO.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Added enforcement.

Comment thread coderd/x/chatd/ARCHITECTURE.md Outdated

#### Generation goroutine

TODO: Document ACP subagent tools, native session identity, workspace-scoped session access, agent replacement within a workspace, live wait previews, and separate user/model wait results.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder to do.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got rid of the TODO. We don't need to document this in the architecture file.

@hugodutka
hugodutka force-pushed the hugodutka/acp-subagents-tools branch from 7dcce90 to 9ba61a6 Compare October 15, 2026 10:09
@hugodutka
hugodutka removed this pull request from stack #30559 October 15, 2026 10:16
@hugodutka
hugodutka added this pull request to stack #30832 October 15, 2026 10:17
@hugodutka
hugodutka force-pushed the hugodutka/acp-subagents-tools branch from 9ba61a6 to ea35b77 Compare October 15, 2026 11:04
@hugodutka
hugodutka removed this pull request from stack #30832 October 15, 2026 11:06
@hugodutka
hugodutka added this pull request to stack #30836 October 15, 2026 11:06
@hugodutka
hugodutka force-pushed the hugodutka/acp-subagents-tools branch from aeeb690 to f1c7abb Compare October 16, 2026 16:51
@hugodutka
hugodutka force-pushed the hugodutka/acp-subagents-tools branch 2 times, most recently from fee788c to fbcd892 Compare October 19, 2026 12:06
@hugodutka
hugodutka force-pushed the hugodutka/acp-subagents-tools branch from fbcd892 to a436d44 Compare October 19, 2026 12:58
@hugodutka
hugodutka force-pushed the hugodutka/acp-subagents-tools branch from a436d44 to 9280074 Compare October 19, 2026 13:40
@hugodutka
hugodutka removed this pull request from stack #30904 October 19, 2026 14:05
@hugodutka
hugodutka changed the base branch from hugodutka/acp-subagents-sessions to hugodutka/acp-tools-api October 19, 2026 14:05
@hugodutka
hugodutka added this pull request to stack #31024 October 19, 2026 14:05
@hugodutka
hugodutka force-pushed the hugodutka/acp-subagents-tools branch from 9280074 to 6dd0054 Compare October 19, 2026 16:35
@hugodutka
hugodutka force-pushed the hugodutka/acp-subagents-tools branch 4 times, most recently from 95d35d9 to fd39867 Compare October 20, 2026 15:23
@hugodutka
hugodutka force-pushed the hugodutka/acp-subagents-tools branch from fd39867 to 8afdd0d Compare October 20, 2026 15:58
@hugodutka
hugodutka force-pushed the hugodutka/acp-subagents-tools branch 2 times, most recently from 6aeafb5 to cbee9f2 Compare October 20, 2026 17:51
if args.TimeoutSeconds != nil {
timeout = time.Duration(*args.TimeoutSeconds) * time.Second
}
session, err := (acpSessionArgs{HarnessID: args.HarnessID, SessionID: args.SessionID, WorkingDirectory: args.WorkingDirectory}).sessionRef()

@mafredri mafredri Oct 23, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're just using acpWaitArgs values here, wouldn't it make sense for acpSessionArgs to be embedded in acpWaitArgs, and then we can just call args.sessionRef()?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The trouble is acpWaitArgs is generated by Fantasy. acpWaitArgs gets converted to the tool schema that the LLM model sees. I don't see how we could embed acpSessionArgs within it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants