Skip to content

feat(coderd): list a chat family's pending descendant questions - #114

Merged
ibetitsmike merged 18 commits into
mainfrom
mike/descendant-questions-2-questions-route
Nov 10, 2026
Merged

ibetitsmike merged 18 commits into
mainfrom
mike/descendant-questions-2-questions-route

Conversation

@ibetitsmike

Copy link
Copy Markdown
Owner

Part of #73

Xum opened this PR on behalf of @ibetitsmike.

With fork-nested-subagents on, GET /api/v2/chats/fork/{chat}/questions lists the unanswered ask_user_question calls of the descendants in a chat's family, oldest first. The root chat UI (next PR) uses it to show a "Question from " card and to send the answer to the asking child. With the experiment off, the route answers 403.

What changes

  • forkdb query ListPendingChatDescendantQuestionsByRoot: the pending questions of the unarchived descendants of a root chat, with the asking chat's title and parent. "Pending" uses the same rule as GetPendingChatDescendantQuestion from feat(coderd): let descendant chats ask the user blocking questions behind fork-nested-subagents #86: no non-deleted user message newer than the question. Model-only user rows do not count, and a context boundary such as a clear retires the question.
  • dbauthz authorizes the query through read access to the family's root chat. dbmetrics wraps it.
  • coderd/fork_chat_questions.go serves the route. Any chat of a family resolves to its root, so a child lists the same family as its root. The response is always a JSON array, never null. A row whose questions do not decode is logged and skipped, so it does not hide the family's other questions.
  • codersdk.ChatDescendantQuestion and Client.ChatDescendantQuestions, plus the regenerated swagger, API schema docs and typesGenerated.ts. The route is hidden from the generated API docs like the other fork chat routes.

The route serves any family the caller can read, including families started by API clients, not only UI chats.

Validation

  • go build, go vet, forkdb generate.sh drift check and .github/fork/check-apidoc.sh: all pass.
  • go test for ./coderd/database/forkdb/..., ./coderd/database/dbmetrics/..., ./coderd/x/chatd/..., dbauthz -run TestForkQuerier, ./coderd -run TestForkChat and ./coderd/coderdtest -run TestEndpointsDocumented (Postgres in Colima): all pass.
  • Each new test fails when the behavior it covers is broken: the archived, answered, model-only, cleared and family filters, the ordering, root resolution, the empty array, the decode skip, the root-chat authorization and the experiment gate.
  • UAT round 1 on a dev build of b34b83a passed. A real depth-2 grandchild asked a question and the route listed it with its parent. After the answer the route returned [], another user got 404, and with the experiment off the route answered 403. The later commits merge feat(coderd): let descendant chats ask the user blocking questions behind fork-nested-subagents #86 and add the model-only and cleared filters with their tests.

…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
Adds the forkdb query ListPendingChatDescendantQuestionsByRoot with its
dbauthz (read access to the root chat) and dbmetrics wrappers.
Lists the unanswered ask_user_question calls of the unarchived descendants
in a chat's family behind fork-nested-subagents, so the root chat UI and API
clients can answer them. Adds the codersdk types and client method and the
generated swagger, API docs and TypeScript types.
…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.
…ions-1-chatd-tool

# Conflicts:
#	coderd/database/forkdb/sqlc.yaml
…ions-1-chatd-tool

# Conflicts:
#	coderd/x/chatd/fork_tools.go
…ions-1-chatd-tool

# Conflicts:
#	coderd/database/dbauthz/fork_forkdb_test.go
…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
…ions-2-questions-route

# Conflicts:
#	coderd/database/dbauthz/fork_forkdb_test.go
#	coderd/database/forkdb/chat_descendant_questions.sql.go
#	coderd/database/forkdb/chat_descendant_questions_test.go
#	coderd/database/forkdb/queries/chat_descendant_questions.sql
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum posted this comment 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-10T06:46:38.383478Z ce5e021 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

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 8b0b2ebea2

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

UAT round 2 on 8b0b2ebea2 (PASS)

I ran this on a dev build (develop.sh) of v2.0.0-devel+8b0b2ebea in a dedicated UAT workspace. The model is a local GLM-5.3-Flash served through oMLX, and every chat is a real chat. Times are UTC on 2026-11-10.

Check Result
Q1: real depth-2 family. Root 75ea5894 spawns a coordinator 9ba8baec, which spawns asker 66b7d00b, and the asker calls ask_user_question The route on the root lists exactly 1 entry. It is the grandchild's entry: parent_chat_id = the coordinator, chat_title = asker, tool_call_id = call_a44a6808, which matches both the message and the DB row, and the questions decode with labels Red,Blue. The root itself is not listed. The route returns the same list when called on the coordinator and on the grandchild. (06:31:57)
Q2: answer Blue posted to the grandchild POST returns 200. Right after it, the route no longer lists the grandchild, and the grandchild replies CHOSEN=Blue. A fresh root with no descendants returns []. The 3 older PR1 families return [], so no family leaks into another.
Q6 (new, the cleared rule): a child asks, then POST /api/v2/chats/{child}/clear Before the clear, the child is listed with status waiting. The clear returns 200 and writes the boundary rows: a model-only user row 227 with compressed=t, then the assistant and tool rows. Afterwards the route drops the child, while its chat_descendant_questions row stays, because pending is derived. (06:31:12)
Q3: a second non-admin user, uatmember1794292412 with no roles The route returns 404 on the admin's root, coordinator and grandchild, the same as the upstream GET /chats/{id}. On the member's own empty root it returns [] with 200. Edge cases: an unknown UUID gets 404, a malformed ID 400, no token 401, POST 405, a trailing slash 404.
Q4: the same build restarted with CODER_EXPERIMENTS='' The route returns 403, and the message names fork-nested-subagents. With the experiment off, an unknown chat UUID also gets 403.

After the run I stopped the dev server and revoked the temporary oMLX sub-key.

Xum posted this comment on behalf of @ibetitsmike.

…ions-2-questions-route

# Conflicts:
#	coderd/apidoc/docs.go
#	coderd/apidoc/swagger.json
@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. Chef's kiss.

Reviewed commit: ce5e02182d

ℹ️ 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 (5decda1a92) 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 (5decda1a92), 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 ee693dd into main Nov 10, 2026
20 of 27 checks passed
@ibetitsmike
ibetitsmike deleted the mike/descendant-questions-2-questions-route branch November 10, 2026 07:17
@ibetitsmike

Copy link
Copy Markdown
Owner Author

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

Merge evidence for head ce5e02182dd950026372fd750d5babc7f68733b7:

  • fork-ci pull_request run 42772398930 passed; its build job checked out Merge ce5e02182d into 5decda1a92 (current main). All checks green. Run 42770424752 had also passed on this head.
  • Codex on this exact head: no major issues (comment 6760990193). 0 unresolved review threads.
  • UAT round 2 PASS on 8b0b2ebea2 (comment 6760810630): in a real depth-2 family the route listed only the grandchild's pending question, with the right parent, title, tool call ID and options, and returned the same list from any chat in the family. After the answer was posted the entry disappeared, and a cleared chat's question dropped out. A user without roles got 404 on another user's family, like GET /chats/{id}, and with the experiment off the route returned 403 naming fork-nested-subagents. The only difference between 8b0b2ebea2 and ce5e02182d is a merge of main whose only conflict resolution is the regenerated coderd/apidoc/docs.go and swagger.json; a merge that only regenerates files carries the UAT.

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