Repository navigation
feat: accept secret answers to descendant questions outside chat messages - #119
Conversation
…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
…ndant-questions-2-questions-route
…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
…family question list
…ions-2-questions-route # Conflicts: # coderd/apidoc/docs.go # coderd/apidoc/swagger.json
…ions-4-secret-answers
|
@codex review
|
Codex Review Summary: ✅ CompletedThis 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. |
…hitecture document
|
@codex review
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dd51a0d051
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 50ca4d03fc
ℹ️ 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". |
Closing and reopening only to make GitHub recompute the merge ref against current main ( |
The merge ref now points at current main ( |
Closing and reopening only to make GitHub recompute the merge ref against current main ( |
The merge ref now points at current main ( |
Closing and reopening only to make GitHub recompute the merge ref against current main ( |
The merge ref now points at current main ( |
Merge evidence for head
|
…n the pstack adapter (#145) * docs: re-pin pstack adapter citations after #119 * docs: map agent definition warnings in the context popup * docs: map worktree removal on archive in the pstack adapter * docs: bump the pstack adapter check to 77b2073 * docs: cover automatic archives and submodule commits in worktree cleanup * docs: cover reflog-only commits in worktree cleanup
Part of #73
This is the first of four PRs for secret answers to descendant questions (R8.3). A descendant chat can ask the user for a value it must not see in its history, such as a token. The user answers through a new route, and the value is stored outside
chat_messages. The asking chat gets an ordinary user message that says only that the user answered.The model cannot ask a secret question yet.
secretstays out of theask_user_questionschema that the model sees until the masked input ships (PR7). This PR adds the storage, the route and the server-side guard, so every commit on main keeps this rule: no secret answer can reachchat_messages.What changes
chat_secret_answers(chat_id,tool_call_id,value,value_key_id,created_at). The key is(chat_id, tool_call_id), and rows go when the chat is deleted (FK cascade). Fork queries insert, list by chat, delete one, delete by chat, and delete rows older than a time (for the 24 h purge in PR5).valueon insert and decrypts it on list, the same way asplugins.config. With dbcrypt off,valueis plaintext andvalue_key_idis NULL.POST /api/v2/chats/fork/{chat}/questions/secret-answer(fork-nested-subagents), body{"tool_call_id": "...", "value": "..."}, 204 on success. The ID goes in the body because coderd routes on the unescaped path, where an ID with a/would not match. It uses the same check as sending a message to that chat: chat owner, update access, not archived. Then:Answer to ask_user_question call <id>:followed byThe user gave a secret answer.If that send fails, it deletes the value so that the user can answer again. If the chat is busy, the message is queued; if the owner deletes that queued message, a new answer replaces the stored one and is reported again.POST /api/v2/chats/{chat}/messagesrejects (409) every message to a child chat while the chat's pending question is secret, because any user message answers the pending question. This is one call in upstream'spostChatMessages; the check is incoderd/fork_chat_questions.go. A question whose JSON does not decode counts as secret.PATCH /api/v2/chats/{chat}/messages/{message}) and an edit of a queued message's content (PATCH /api/v2/chats/{chat}/queue/{queued_message}) get the same 409, because an edit can carry the value too."options": []for a question without options, such as a secret one.coder server dbcrypt rotateanddecryptre-encrypt or decrypt these rows in pages of 100 before they revoke keys (a row deleted or answered again after its page was read is left as it is), anddbcrypt deletedeletes the encrypted rows.ChatQuestion.Secret,ChatSecretAnswerRequest,Client.AnswerChatSecretQuestion.coderd/x/chatd/ARCHITECTURE.mdgets a TODO for the new table; the document's owner writes the text.How it differs from the PRD
The PRD says the answer is delivered to the agent once. In this design, the model never receives the value. The model writes
{{secret:<call_id>}}inexecute,write_fileandedit_filesinput, and PR6 substitutes the value on every use until the chat asks again, the chat is deleted, or 24 h pass. Every tool response of that chat has the exact value replaced by the placeholder. The lead approved this as a product call.Limits
postChatMessagesis guarded. Editing a queued message or an earlier message into an answer is not, because the UI never answers that way.Validation
TestForkChatSecretAnswer(coderd, Postgres): the normal answer path is rejected for a secret question, with or without the answer prefix, and is still accepted for a normal one. The list sends nonulloptions. The route rejects a wrong call ID, an empty value, a value with a null byte (without the check, Postgres fails it with a 500), a non-secret question, another user and a second answer. A busy chat queues the report, a second answer gets a 409, and after the owner deletes the queued message, a new answer is stored and reported again (with the queue check removed, the retry fails with a 409). Tool call IDs such ascall/a%41andcall a%41reach the stored question unchanged. After a good answer the row holds the value, no message of the chat contains it, and the chat has the "secret answer" user message. With the guard call removed, the test fails at the first check.TestDescendantQuestionToolRecordsQuestion: a new question drops earlier secret answers.TestChatSecretAnswersKeyCommands(dbcrypt): rotate re-encrypts 101 answers (more than one page), decrypt leaves them plaintext, and delete removes only the encrypted ones. With the rotate hook removed, revoking the old key fails on thechat_secret_answersforeign key, and when the commands stop after one page, the test fails too.TestForkQuerier(dbauthz) cases for the five queries, andTestChatSecretAnswers(dbcrypt): the stored value is encrypted and lists back as plaintext.chatdmig check,check-apidoc.sh,TestEndpointsDocumented,go build,go vetpass.TestForkChatSecretAnsweralso puts the value in a message edit and in a queued message's content edit, and checks that each is refused. With either guard removed, the test fails.TestReplaceUnreportedSecretAnswerchecks that an answer is replaced while no message reports it, and that a delivered message stops the replacement. With the recheck removed, it fails.cbff12ee9c, no model turns): a waiting child had a secret question staged in SQL. The route listed it as secret. A normal message got 409. An answer for another call got 409. The valid answer got 204 and delivered a message that names the placeholder but not the value. A second answer got 409 and the first value stayed. Nothing was queued. The value appeared in no chat message, no database dump line and no server log line.