Skip to content

feat(coderd): let descendant chats ask the user blocking questions behind fork-nested-subagents - #86

Merged
ibetitsmike merged 9 commits into
mainfrom
mike/descendant-questions-1-chatd-tool
Nov 10, 2026
Merged

ibetitsmike merged 9 commits into
mainfrom
mike/descendant-questions-1-chatd-tool

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

Part of #73

Xum opened this PR on behalf of @ibetitsmike.

With fork-nested-subagents on, a delegated chat that is not an explore subagent gets a blocking ask_user_question. Its question is meant for the user, not the parent agent. When the experiment is off, the tool list and the stop list match upstream.

What changes

  • New chatd node chat_descendant_questions (one row per chat, chat_id primary key, cascades on chat delete) with the forkdb queries UpsertChatDescendantQuestion and GetPendingChatDescendantQuestion. A question is pending until the chat gets a non-deleted user message newer than the question. Model-only user rows, such as lifecycle hook context, do not count.
  • fork_descendant_questions.go wraps upstream's ask_user_question so that it also records the question. forkStopAfterTools adds the tool to the stop list, so the call ends the child's turn. The child's next user message is the answer.
  • wait_agent on a child with an unanswered question returns needs_input: true, the questions, and a note. If the question is already pending when wait_agent is called, it waits (until its timeout) for the answer and the child's report.
  • The only change to upstream code is one line in turn_environment.go (the StopAfterTools hook). The rest is wired through appendForkTools.
  • ARCHITECTURE.md gets two TODO lines only; the author writes the prose.

Root-chat UI and the family questions endpoint come in later PRs of #73.

Known behavior

  • Plan-mode subagent turns do not get the tool, because upstream builtinPlanToolAllowed allows ask_user_question only for root chats.
  • The PR has about 733 hand-written lines (about 324 of production code and SQL, about 404 of tests). That is over the 500-line target.

Validation

  • go build ./coderd/... ./enterprise/cmd/coder, go vet, chatdmig check, and the forkdb generate.sh drift check: all pass.
  • go test ./coderd/x/chatd/..., ./coderd/database/forkdb/..., ./coderd/database/dbmetrics/... and dbauthz -run TestForkQuerier (Postgres in Colima): all pass.
  • I negative-controlled every new test: each one fails when the behavior it covers is broken (15 breaks).
  • I ran remote UAT round 1 on a dev build of b7a61f7, with the experiment on and off, and it passed. The follow-up commits change only tests and merge main.

…hind fork-nested-subagents

A delegated chat that is not an explore subagent gets a blocking
ask_user_question tool. The call records the question in the new
chatd.chat_descendant_questions table and ends the turn; the answer is the
next user message. The parent's wait_agent reports needs_input while the
child's question is unanswered and, when called while it is pending, waits
for the answer before it waits for the child.
…c and cover the late question

TestDescendantQuestionEndsTurn raced the child's turn against the root's wait_agent call: when the question was already pending, wait_agent waited the default five minutes and the test hit its deadline (about 1 in 3 to 1 in 15 runs). The root's wait_agent now starts once the question is pending, with a 1 second timeout.

TestDescendantQuestionWaitAgent now also covers a question the child asks while the parent waits on it, which only the racy end-to-end path exercised. TestAppendForkTools now includes wait_agent, so wrapping it with the experiment off fails.
…ions-1-chatd-tool

# Conflicts:
#	coderd/database/forkdb/forkdbmock/forkdbmock.go
#	coderd/database/forkdb/querier.go
#	coderd/database/forkdb/sqlc.yaml
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum posted this on behalf of @ibetitsmike.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T04:02:09.487248Z a81edc7 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bca159a339

ℹ️ 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".

Comment thread coderd/x/chatd/ARCHITECTURE.md Resolved
…tions

wait_agent now always runs the wrapped tool, so include_tool_calls and its
validation apply while a question is pending, a question asked before an
inner timeout is reported, and a failed question lookup is an error.
Model-only user rows from lifecycle hooks no longer answer a question.
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum posted this on behalf of @ibetitsmike.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 9d8f4a30bb

ℹ️ 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".

…ions-1-chatd-tool

# Conflicts:
#	coderd/database/forkdb/sqlc.yaml
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum posted this comment on behalf of @ibetitsmike.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: f508e342aa

ℹ️ 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".

…ions-1-chatd-tool

# Conflicts:
#	coderd/x/chatd/fork_tools.go
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum posted this comment on behalf of @ibetitsmike.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 01f9c60dbf

ℹ️ 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".

Comment thread coderd/x/chatd/fork_tools.go Resolved
…ions-1-chatd-tool

# Conflicts:
#	coderd/database/dbauthz/fork_forkdb_test.go
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum posted this comment on behalf of @ibetitsmike.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1ca1464aba

ℹ️ 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".

@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum posted this comment on behalf of @ibetitsmike.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 97834de11f

ℹ️ 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".

@ibetitsmike

Copy link
Copy Markdown
Owner Author

Focused UAT on 97834de11f

Dev build v2.0.0-devel+97834de11 with CODER_EXPERIMENTS=fork-nested-subagents, run in a disposable workspace. The chat model was GLM-5.3-Flash on oMLX. I checked the results in the dev instance database and API, not in the model's prose.

S7: normal depth-1 flow. Result: pass.

Time (UTC) Event
03:47:23.291 The child (asker) calls ask_user_question. The question row is stored as call_e613bf0c, and the child's turn ends (waiting).
03:47:29.191 The root calls wait_agent once (timeout_seconds: 900). The call stays blocked while the question is pending.
03:51:56.661 The answer is posted to the child chat (POST /api/v2/chats/<child>/messages, HTTP 200).
03:52:00.786 The child replies CHOSEN=Blue.
03:52:00.813 The root's wait_agent returns 27 ms later with report CHOSEN=Blue, status waiting and no needs_input.
03:52:10.912 The root replies ROOT_SAW=CHOSEN=Blue.

The UAT driver's first answer POST had no body (a script bug), so the answer went out about four minutes later than planned. The single wait call stayed blocked on the pending question for that whole time.

S8: replaced question. Result: pass. I staged this case in the database because a model can't reliably hit a 2-second window.

Time (UTC) Event
03:53:06.232 The child asks call_5e38787a. The root's first wait_agent returns needs_input.
03:53:19.533 The root's second wait_agent starts (timeout_seconds: 900).
03:53:33.025 The question row is replaced (tool_call_id staged-replacement, with a new "Size" question).
03:53:33.574 wait_agent returns 0.55 s later, within one poll, with needs_input: true and the Size question. Before the fix, it would have waited until the 900 s timeout.

Both chats were archived afterwards, the dev server was stopped, and the temporary model key was revoked.

Xum posted this comment on behalf of @ibetitsmike.

…ions-1-chatd-tool

# Conflicts:
#	coderd/database/dbauthz/fork_forkdb.go
#	coderd/database/dbmetrics/fork_forkdb.go
#	coderd/database/forkdb/sqlc.yaml
#	coderd/x/chatd/ARCHITECTURE.md
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum posted this comment on behalf of @ibetitsmike.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: a81edc7fdc

ℹ️ 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".

@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum (AI agent) closed and reopened this on behalf of @ibetitsmike.

Closing and reopening only to make GitHub recompute the merge ref against current main (26c1e0271e) and run fork-ci on it. The head is unchanged.

@ibetitsmike ibetitsmike reopened this Nov 10, 2026
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum (AI agent) closed and reopened this again on behalf of @ibetitsmike.

The merge ref now points at current main (26c1e0271e), but the run started by the first reopen was queued against the old merge ref. This second reopen starts fork-ci on the recomputed merge. The head is unchanged.

@ibetitsmike ibetitsmike reopened this Nov 10, 2026
@ibetitsmike
ibetitsmike merged commit 96d44ec into main Nov 10, 2026
20 of 27 checks passed
@ibetitsmike
ibetitsmike deleted the mike/descendant-questions-1-chatd-tool branch November 10, 2026 05:54
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum (AI agent) merged this on behalf of @ibetitsmike.

Merge evidence for head a81edc7fdc7ae810dc2060a193a139e9d0e92df8:

  • fork-ci pull_request run 42763369613 passed; its build job checked out Merge a81edc7fdc into 26c1e0271e (current main). All checks green. Run 42752829310 had also passed on this head.
  • Codex round 7 on this exact head: no major issues (comment 6758623190). The two P2s on 1ca1464 (a replaced question during wait_agent, and a question left pending after clearing the chat) were fixed with tests that fail when the fix is reverted; earlier dropped findings were replied to and resolved. 0 unresolved review threads. Merge state CLEAN.
  • The main merges (c43627a, 0298da5) kept both sides in registration files, generated code and the owner TODO lines in coderd/x/chatd/ARCHITECTURE.md; fork_descendant_questions.go and chat_descendant_questions.sql are identical to 97834de.
  • Focused UAT PASS at 97834de (comment 6758533112): in the normal depth-1 flow the root's single wait_agent stayed blocked while the question was pending and returned 27 ms after the answer was posted to the child, with the answer threaded through. With a replacement question staged in the database, the waiting wait_agent returned needs_input for the new question 0.55 s later, within one poll. After /clear the pending question is retired. No server errors beyond the NATS cluster-host notice. UAT round 1 at b7a61f7 covered the original flow.
  • The only change to coderd/x/chatd/ARCHITECTURE.md is owner TODO lines.

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.

1 participant