Repository navigation
refactor(coderd/x/chatd): move subagent operations out of tool closures - #28758
Conversation
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Another round soon, please! 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". |
4d7e41e to
5716497
Compare
|
@codex review
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5716497616
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
|
@codex review
|
|
Codex Review: Didn't find any major issues. Can't wait for the next one! 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". |
3edfd11 to
b414901
Compare
b414901 to
3331bf3
Compare
|
@codex review
|
|
Codex Review: Didn't find any major issues. Keep it up! 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". |
|
@codex review
|
|
Codex Review: Didn't find any major issues. Nice work! 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". |
ethanndickson
left a comment
There was a problem hiding this comment.
I like the goal. The 470-line subagentTools full of closures is hard to read. I'm less sure about the manager as the new layer, though. As written, it looks like the tool handlers turned into methods, not a layer that other code can use.
-
It takes the tool's input. The methods take the tool argument structs, so callers pass string chat IDs and the manager parses them:
func (m *subagentManager) Send(ctx context.Context, args messageAgentArgs) (database.Chat, bool, error) func (m *subagentManager) Await(ctx context.Context, args waitAgentArgs) (subagentAwaitResult, error)
Main's typed helpers
sendSubagentMessage(ctx, parentID, targetID, msg, busy)andinterruptSubagent(ctx, parentID, targetID)get folded into these. The only non-tool caller I could find is the Starlark workflow prototype (#31189), and it calls the typed*Serverhelpers directly:r.p.awaitSubagentCompletion(ctx, r.parent.ID, step.chatID, defaultSubagentWaitTimeout)
To use the manager, it would need a
currentChatclosure andwaitAgentArgs{ChatID: id.String()}. -
It builds the tool's output.
AwaitandListreturn structs with JSON tags.subagentManagerErrorexists only to tell the adapter whether to send a JSON error withtypeor a plain text error:if managerErr, ok := errors.AsType[*subagentManagerError](err); ok { return subagentErrorResponse(managerErr.err, managerErr.chat), nil } return fantasy.NewTextErrorResponse(err.Error()), nil
So parsing and output format both stay in the manager, and the adapters mostly call
json.Marshal.
Could the manager take typed inputs (parent and target chat IDs, a timeout, queue or interrupt) and return plain values (the chat, the report, recording info, a typed status error)? Then the tool adapters keep the parsing, defaults and JSON output, and sendSubagentMessage and interruptSubagent keep their typed signatures. #31189 looks like a real second caller, so it could help shape the API.
Generated by an agent on behalf of the user
|
@ethanndickson Thanks. Reshaped as you suggested in
Tool JSON, error text, names and schemas do not change. The PR description lists the mutants the adjusted tests catch.
|
|
@codex review
|
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. 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". |
|
@codex review
|
|
Codex Review: Didn't find any major issues. Can't wait for the next one! 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". |
Move the spawn_agent, list_subagent_models, wait_agent, message_agent, interrupt_agent, and list_agents logic out of the inline tool closures in subagent.go into a per-turn subagentManager in subagent_manager.go. The tools become thin adapters that marshal typed results. Child chat creation, the wait loop, report extraction, and the ancestor walk move to subagent_manager.go unchanged, including the archived-root refusal, database error returns, organization instructions, and title source handling main added since the original branch. Typed tool outputs marshal byte-identically to the previous map payloads.
The subagent manager took the tools' argument structs and built their JSON output. Its operations now take chat IDs, a timeout and a busy behavior and return plain values, and the tools in subagent.go parse arguments, apply defaults and build the JSON. - subagent_manager.go: drop subagentManager, subagentManagerError and the JSON result types. Restore main's sendSubagentMessage and interruptSubagent unchanged, and add awaitSubagent (desktop recording and a last status check before a timeout) and listSubagents. - subagent.go: each tool parses chat_id, applies the wait and list defaults, looks up the target chat so errors carry its type, and builds the JSON. spawnAgent validates the spawn_agent arguments. - Tests call the typed functions, or the tool where the behavior now lives in the adapter (the message_agent interrupted flag and list_agents paging). Tool names, descriptions, schemas, JSON output and error text do not change.
…t.go subagentLastError and subagentGenericErrorMessage build the last_error text that wait_agent returns to the parent model. Their only caller is subagentAwaitStatusErrorResult in the tool layer, so they belong in subagent.go, where main keeps them. The moved block is unchanged.
80bb0ce to
2deadd5
Compare
|
Rebased onto main @codex review
|
|
Codex Review: Didn't find any major issues. Swish! 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". |
…ations.go The file holds typed child chat operations, not a manager type. Rename the tests that used the manager name to match the functions they cover.
Moves the subagent tools' logic (
spawn_agent,wait_agent,message_agent,interrupt_agent,list_agents,list_subagent_models) out of large inline closures insubagent.go. Child chat operations become typed*Serverfunctions insubagent_operations.gothat other code can call, such as the workflow prototype in #31189. The tools become adapters that parse arguments, apply defaults and build the JSON.Changes
subagent_operations.go: operations take chat IDs, a timeout or a busy behavior and return plain values.awaitSubagentwrapsawaitSubagentCompletionwith the computer_use desktop recording and a last status check, and returns the chat, report and recording, a timeout, or a*subagentStatusError.sendSubagentMessageandinterruptSubagentare main's, unchanged.listSubagentsreturns unarchived children, most recently updated first. The helpers they call move from main unchanged.subagent.go: keeps main's model override resolution. Each tool parseschat_id, applies the wait timeout or list paging defaults, reads the target chat so errors carry itstype, and builds the JSON.spawnAgentvalidates thespawn_agentarguments.Behavior
No intended behavior change. Error strings, tool names, descriptions and schemas, hook fail-closed handling, the wait loop and recording lifetime match main.
wait_agentreads the target chat once more, for the recording decision.