Repository navigation
feat: add ACP subagent waiting and transcript streaming - #30560
Conversation
4af3b0a to
1d18df8
Compare
8af7bd8 to
435c9f1
Compare
435c9f1 to
5a703c3
Compare
5a703c3 to
795d915
Compare
795d915 to
b3a7a9c
Compare
b3a7a9c to
7dcce90
Compare
| 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) { |
There was a problem hiding this comment.
So plan mode cannot use acp sub-agents?
There was a problem hiding this comment.
Yup. Seems reasonable to me.
| info.Status, info.Error = workspacesdk.ACPSessionStatusError, waitErr.Error() | ||
| } | ||
| return o.waitResponse(session, info, &transcript, timedOut), nil | ||
| } |
There was a problem hiding this comment.
This method is quite hard to follow and contains a lot of conditional logic which seems like they should be various named phases.
There was a problem hiding this comment.
I refactored it. Let me know if it reads better now.
| } | ||
|
|
||
| func (o acpToolOptions) waitReconnect(ctx context.Context) bool { | ||
| timer := o.clock.NewTimer(250*time.Millisecond, "acp-reconnect") |
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I refactored this file. Let me know if it's better now.
| return false, false, xerrors.Errorf("decode ACP update: %w", err) | ||
| } | ||
| switch { | ||
| case update.UserMessageChunk != nil: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Makes sense. Added enforcement.
|
|
||
| #### 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. |
There was a problem hiding this comment.
Got rid of the TODO. We don't need to document this in the architecture file.
7dcce90 to
9ba61a6
Compare
9ba61a6 to
ea35b77
Compare
aeeb690 to
f1c7abb
Compare
fee788c to
fbcd892
Compare
fbcd892 to
a436d44
Compare
a436d44 to
9280074
Compare
9280074 to
6dd0054
Compare
95d35d9 to
fd39867
Compare
fd39867 to
8afdd0d
Compare
6aeafb5 to
cbee9f2
Compare
| if args.TimeoutSeconds != nil { | ||
| timeout = time.Duration(*args.TimeoutSeconds) * time.Second | ||
| } | ||
| session, err := (acpSessionArgs{HarnessID: args.HarnessID, SessionID: args.SessionID, WorkingDirectory: args.WorkingDirectory}).sessionRef() |
There was a problem hiding this comment.
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()?
There was a problem hiding this comment.
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.
Add
acp_wait_agentto 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.