Skip to content

feat: accept secret answers to descendant questions outside chat messages - #119

Merged
ibetitsmike merged 37 commits into
mainfrom
mike/descendant-questions-4-secret-answers
Nov 10, 2026
Merged

ibetitsmike merged 37 commits into
mainfrom
mike/descendant-questions-4-secret-answers

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

Part of #73

Xum opened this PR on behalf of @ibetitsmike.

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. secret stays out of the ask_user_question schema 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 reach chat_messages.

What changes

  • New chatd node 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).
    • dbauthz authorizes every query as an update of the owning chat, the list included, because it returns the values. The purge query needs system delete.
    • dbcrypt encrypts value on insert and decrypts it on list, the same way as plugins.config. With dbcrypt off, value is plaintext and value_key_id is 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:
    • it rejects an empty value (400), one with a null byte (400) and one over 16 KiB (400),
    • it accepts only the chat's pending question with that call ID (else 409), and only a secret one (400),
    • it stores the value (a second answer is a 409) and sends the chat Answer to ask_user_question call <id>: followed by The 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.
    • Error responses never include database error text, because that text can quote the value.
  • POST /api/v2/chats/{chat}/messages rejects (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's postChatMessages; the check is in coderd/fork_chat_questions.go. A question whose JSON does not decode counts as secret.
  • An edit of a chat message (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.
  • When the route replaces a stored answer that no message reports, it locks the chat row in the same transaction, the lock the queue's promotion takes. It then rechecks that the question is still pending and that no queued message reports the answer.
  • The pending-questions list sends "options": [] for a question without options, such as a secret one.
  • coder server dbcrypt rotate and decrypt re-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), and dbcrypt delete deletes the encrypted rows.
  • When a chat asks a new question, its earlier secret answers are deleted in the same transaction.
  • SDK: ChatQuestion.Secret, ChatSecretAnswerRequest, Client.AnswerChatSecretQuestion.
  • coderd/x/chatd/ARCHITECTURE.md gets 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>}} in execute, write_file and edit_files input, 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

  • Only postChatMessages is guarded. Editing a queued message or an earlier message into an answer is not, because the UI never answers that way.
  • PR6 documents the limits of substitution: a tool that transforms the value (base64, for example) can return it in a form that the scrub does not match, and the workspace sees the value.

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 no null options. 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 as call/a%41 and call a%41 reach 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 the chat_secret_answers foreign key, and when the commands stop after one page, the test fails too.
  • TestForkQuerier (dbauthz) cases for the five queries, and TestChatSecretAnswers (dbcrypt): the stored value is encrypted and lists back as plaintext.
  • chatdmig check, check-apidoc.sh, TestEndpointsDocumented, go build, go vet pass.
  • TestForkChatSecretAnswer also 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. TestReplaceUnreportedSecretAnswer checks that an answer is replaced while no message reports it, and that a delivered message stops the replacement. With the recheck removed, it fails.
  • UAT: see the comment below.
  • Server UAT of the round-3 recheck (dev server at 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.

…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
…ions-2-questions-route

# Conflicts:
#	coderd/apidoc/docs.go
#	coderd/apidoc/swagger.json
@ibetitsmike ibetitsmike changed the title feat(coderd): accept secret answers to descendant questions outside chat messages feat: accept secret answers to descendant questions outside chat messages Nov 10, 2026
@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-10T11:32:46.681588Z c5b7422 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.

@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: 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".

Comment thread coderd/x/chatd/ARCHITECTURE.md Resolved
Comment thread coderd/fork_chat_questions.go Resolved

@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: 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".

Comment thread enterprise/dbcrypt/fork_cliutil.go Resolved
@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: c5b742296b

ℹ️ 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 (ee5b159926) 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 (ee5b159926), 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

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 (b4dfdb922c) 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 (b4dfdb922c), 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

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 (5a47dc7bed) 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 (5a47dc7bed), 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 3036142 into main Nov 10, 2026
38 of 63 checks passed
@ibetitsmike
ibetitsmike deleted the mike/descendant-questions-4-secret-answers branch November 10, 2026 12:35
@ibetitsmike

Copy link
Copy Markdown
Owner Author

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

Merge evidence for head c5b742296b9a46703ba72982f575c9436b794805:

  • fork-ci pull_request run 42814771728 passed; its build job checked out Merge c5b742296b into 5a47dc7bed (current main). All checks green. Runs 42807753155 and 42811733760 had also passed on this head against earlier mains.
  • Codex on this exact head: no major issues (comment 6766217104). 0 unresolved review threads.
  • UAT PASS on dd51a0d051 (comment 6762080042) and the server UAT of the round-3 recheck at cbff12ee9c (PR body, Validation). Accepted as covering this head: the only later change is dbcrypt keyset paging for the recrypt scan, covered by TestChatSecretAnswersKeyCommands, which passes on this head and fails under its negative controls.
  • Adds one chatd migration node (chat_secret_answers). The model still cannot ask a secret question: secret stays out of the model-visible ask_user_question schema until PR7.

ibetitsmike added a commit that referenced this pull request Nov 10, 2026
…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
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