Skip to content

feat(coderd): give descendant tools secret answers without showing them to the model - #126

Merged
ibetitsmike merged 74 commits into
mainfrom
mike/descendant-questions-6-secret-substitution
Nov 10, 2026
Merged

ibetitsmike merged 74 commits into
mainfrom
mike/descendant-questions-6-secret-substitution

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 third of four PRs for secret answers to descendant questions (R8.3). It stacks on #125, the 24 hour expiry. A descendant chat can now use a secret answer in its tools while the model still never sees the value. The model writes {{secret:<call_id>}} where the value belongs, and chatd puts the value in at run time.

The model still cannot ask a secret question. The secret flag in the ask_user_question schema stays off until the root chat page has a masked input (PR7). Tests turn it on.

What changes

  • At turn setup, withSecretAnswers reads the secret answers of a chat that can ask descendant questions. If the chat has any, it wraps every tool of the turn. An answer only arrives as the user message that starts a turn, so the answers hold for the whole turn. If the read fails, it wraps the tools anyway and each call reads the answers itself.
    • execute, write_file and edit_files get each placeholder in their input replaced by the value, escaped for a JSON string. The stored tool call keeps the placeholder.
    • spawn_agent, message_agent and every other tool keep the placeholder, because they pass their input to another model.
    • The content, metadata and error of every tool response have each value replaced by its placeholder. The scrub also matches each value in its JSON-escaped forms, and longer values go first.
    • Wrapped tools keep MCPServerConfigID and the optional methods the chat loop looks for: SerialToolCalls, HaltedToolCallError, ObserveStepToolCalls and ObserveStepToolResults.
  • The secret answer route from feat: accept secret answers to descendant questions outside chat messages #119 rejects values shorter than 8 bytes with a 400 that says to answer without the secret option. A short value would match ordinary text in tool output, which the scrub would then replace.
  • With the flag on, ask_user_question accepts one question with secret: true, a header, a question and no options. It records the question with the secret flag and tells the model which placeholder to write. The upstream tool would drop the flag, so the fork code handles that call.
  • The user message that reports a secret answer now also names the placeholder.
  • coderd/x/chatd/ARCHITECTURE.md gets a TODO for the substitution. The document's owner writes the text.

With the flag off

The flag is off in this PR, so the model can never ask a secret question. The secret answer route rejects a question that is not secret, so no chat has secret answers. Even so, some new code runs:

  • In a descendant chat (fork-nested-subagents on, the chat has a parent, not an explore subagent), turn setup reads the chat's secret answers once, an indexed read by chat_id. The read returns no rows, so no tool is wrapped and no tool call reads anything.
  • If that read fails, the turn logs a warning and wraps the tools. Each tool call then reads the answers, and if that read fails too, the tool returns "failed to read the secret answers of this chat; try again" and does not run.
  • Root chats and deployments without the experiment run no new code. The question and answer flow is unchanged. The new answer text is sent only from the secret route, which nothing can reach while the flag is off.

A LIGHT server UAT of normal descendant chats checks this (results below).

Limits

  • The workspace sees the value. A command can print it in a changed form, such as base64, that the scrub does not match, and the model then sees that form.
  • Scrubbing stops when the answer expires or the chat asks again. A value that already sits in a workspace file or process output can then show up in tool output. This follows the 24 hour TTL of feat(coderd): expire chat secret answers after 24 hours #125, and the lead approved it.
  • The value is substituted on every use until the chat asks again, the chat is deleted, or 24 hours pass. This differs from the PRD's "delivered once", and the lead approved it as a product call (see feat: accept secret answers to descendant questions outside chat messages #119).

Validation

  • TestSecretAnswerReachesToolsNotModel (chatd, Postgres, fake model): a child chat has a pending secret question and a stored answer, and gets the answer message. The model writes the placeholder in write_file, and the workspace gets the value. Then read_file returns the value, and the tool result shows the placeholder. The value is used with a quote and angle brackets, so its JSON escapings differ. No model request and no stored chat message contains the value in any of its forms.
  • TestSecretAnswerTools, TestSubstituteSecretAnswers, TestScrubSecretAnswers and TestDescendantSecretQuestion cover the wrapping, the forwarded methods, the escaping, the longest-first scrub and the secret question checks. A chat without answers and the root chat keep their tools unwrapped. With SerialToolCalls forwarding removed, TestSecretAnswerTools fails.
  • TestForkChatSecretAnswer covers the 8 byte floor.
  • gofmt and go vet pass.
  • fork-ci runs only on PRs into main. This PR targets the expiry PR's branch, so CI runs after the PRs below it merge.
  • LIGHT server UAT of normal descendant chats with the flag off (dev server at 5a8382e4b, oMLX GLM-5.3-Flash) passed. A root spawned a child that asked a Red/Blue question and got a normal answer. The child's tools ran through the secret wrapper unchanged, and the root saw CHOSEN=Red. With a secret answer staged for another call of the child, the flow was the same. The staged value appeared only in its chat_secret_answers row, and in no other table, no debug step and no server log line. A 5 byte secret answer got the 400 floor message.

…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
Also send an empty options array for questions without options, and match the secret-answer route ID to its summary.
@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-10T13:20:21.477569Z a38ee99 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: 29e887fbe7

ℹ️ 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_secret_answers.go Resolved
@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: db2ed04d29

ℹ️ 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_secret_answers.go Resolved
… replaced

An answer past its TTL can be replaced while the message that reports it
is still queued. The route now skips the send in that case, so the queued
message reports the new answer and no second report reaches the child
after the question is answered.
…e/descendant-questions-6-secret-substitution
@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: 308db86655

ℹ️ 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-5-secret-answer-ttl

# Conflicts:
#	coderd/database/dbauthz/fork_forkdb.go
#	coderd/database/dbauthz/fork_forkdb_test.go
#	coderd/database/dbmetrics/fork_forkdb.go
#	coderd/database/forkdb/chat_secret_answers.sql.go
#	coderd/database/forkdb/forkdbmock/forkdbmock.go
#	coderd/database/forkdb/querier.go
#	coderd/database/forkdb/queries/chat_secret_answers.sql
#	coderd/fork_chat_questions.go
#	coderd/fork_chat_questions_internal_test.go
#	coderd/fork_chat_questions_test.go
#	coderd/x/chatd/ARCHITECTURE.md
…e/descendant-questions-6-secret-substitution
Base automatically changed from mike/descendant-questions-5-secret-answer-ttl to main November 10, 2026 13:16
@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. 🚀

Reviewed commit: a38ee99870

ℹ️ 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 (e44a0a2f97) 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 (e44a0a2f97), 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 (976f8fce6d) 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 (976f8fce6d), 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 df22c72 into main Nov 10, 2026
41 of 52 checks passed
@ibetitsmike

Copy link
Copy Markdown
Owner Author

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

Merge evidence for head a38ee9987049c1d17e870fedd5fef80944669666:

  • fork-ci pull_request run 42844588407 passed; its build job checked out Merge a38ee99870 into 976f8fce6d (current main). Runs 42838383523 (against e44a0a2f97) and 42823136711 (against ad1010782c) had also passed on this head. All checks green.
  • Codex on this exact head: no major issues (comment 6768405377). 0 unresolved review threads.
  • UAT on the local deployment at 5a8382e (oMLX GLM) passed: a normal child question and answer went through the secret wrapper, a staged secret leaked nowhere outside chat_secret_answers, and the 8 byte floor returned 400. A light flag-off UAT of normal descendant chats also passed. The later commits are review fixes covered by the secret answer tests. The model still cannot ask secret questions until PR7 turns the schema flag on.
  • No migration.

@ibetitsmike
ibetitsmike deleted the mike/descendant-questions-6-secret-substitution branch November 10, 2026 16:11
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