Skip to content

fix(coderd/x/chatd): keep secret answers out of shell code, media and fragments - #136

Merged
ibetitsmike merged 94 commits into
mainfrom
mike/descendant-questions-6b-secret-hardening
Nov 10, 2026
Merged

ibetitsmike merged 94 commits into
mainfrom
mike/descendant-questions-6b-secret-hardening

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 PR hardens the secret answer substitution of #126. Codex found twenty-four ways a secret answer could still reach the model, run as shell code, or be answered without the value. This PR fixes twenty-three of them before PR7 turns the secret flag on, and Limits explains the one left. The flag stays off here too, so no chat can have a secret question yet. Tests turn it on.

Threat model

The scrub protects against accidental exposure. A tool prints or shows the value, and the model would otherwise see it. The scrub does not protect against a model that deliberately transforms the value, for example with base64, before a tool prints it. The workspace sees the value, so a transformed value is out of scope.

What changes

  • Computer-use chats (feat(coderd): give descendant tools secret answers without showing them to the model #126 thread 4523688886): their screenshots go to the model through the provider runner, which the secret wrapper does not wrap. ask_user_question in a computer-use chat now leaves the secret property out of its schema, and it refuses a secret question with "a computer-use chat cannot ask secret questions".
  • Truncated output (4523688898): a tool that caps its output can cut a value, so the whole value no longer matches. After it replaces whole values, the scrub now also replaces each run of text that starts like a value for at least 8 bytes, or ends like it. 8 bytes is the floor that the route already enforces for a value. A shorter run stays. This can replace ordinary text that starts like a secret, which is the safe side. Until the scrub ends, each replacement is a marker with a null byte, which the route refuses in a value, so no later pass cuts a placeholder that an earlier pass wrote (fix(coderd/x/chatd): keep secret answers out of shell code, media and fragments #136 thread 4524578906).
  • ASCII-escaped JSON (feat(coderd): give descendant tools secret answers without showing them to the model #126 thread 4524361234): Python's default json.dumps writes each non-ASCII character as a \u escape, so a value with ä matched none of the scrub forms. The scrub now also matches the ASCII-only JSON forms, with a surrogate pair for a character outside the Basic Multilingual Plane. Every JSON form, ASCII-only or not, is matched in lowercase and uppercase hex, so an encoder that writes \u003C for < or \^[ for an escape character is covered too (fix(coderd/x/chatd): keep secret answers out of shell code, media and fragments #136 thread 4524960974). Each JSON form also has a variant with / written as \/, as PHP's default json_encode writes it (fix(coderd/x/chatd): keep secret answers out of shell code, media and fragments #136 thread 4524578928). The scrub also matches the value as Bash writes it in $'...' for a word with a control character, as set -x does, with non-ASCII characters kept or in octal (fix(coderd/x/chatd): keep secret answers out of shell code, media and fragments #136 thread 4524816627). It also matches the value as Go's %q and %+q write it, with a control character as \x01, as an agent error that quotes a path does (fix(coderd/x/chatd): keep secret answers out of shell code, media and fragments #136 thread 4525118082). It also matches the value as Bash's printf %q writes a word with shell characters, each with a backslash before it, and as declare -p writes it in "..." (fix(coderd/x/chatd): keep secret answers out of shell code, media and fragments #136 thread 4527514286).
  • Media results (4523933068): a wrapped tool that returns an image or a document while the chat holds secret answers now returns only its text, plus "The media output and attachments of this tool are withheld while this chat holds secret answers." The scrub cannot look inside the bytes.
  • Attachments (fix(coderd/x/chatd): keep secret answers out of shell code, media and fragments #136 thread 4524238875): attach_file and propose_plan return a text result whose metadata names a stored file, and the next prompt resolves that file's bytes for the model. While the chat holds secret answers, the wrapper now drops attachment metadata from every result, text results included, and adds the same note.
  • Shell injection in execute (4523933071): feat(coderd): give descendant tools secret answers without showing them to the model #126 put the value into the command string, so the shell parsed it as code. A ' broke the quoting, and $(...) or a backtick ran a command. The wrapper now starts the command with CODER_SECRET_ANSWER_<n>='<value>'; , where the value is single-quoted and each ' is written as '\''. Each placeholder becomes an expansion of that variable, chosen for the quotes around it: "${CODER_SECRET_ANSWER_<n>}" outside quotes, ${...} inside double quotes, and '"${...}"' inside single quotes. The quote scan skips backslash escapes but does not follow command substitutions or here-documents. A wrong guess there only splits the value into words or keeps the expansion as text. In no case does the shell run the value as a command. Bash still expands the subscripts of an array reference when it evaluates a variable as arithmetic, so execute refuses a placeholder whose value has a $ or a backtick after a [ (fix(coderd/x/chatd): keep secret answers out of shell code, media and fragments #136 thread 4524460000). The error tells the model to write the value to a file with write_file. The wrapper adds underscores to the variable name until the command does not contain it, so the command cannot assign or unset it (4524460010). Placeholders in the other execute parameters, such as workdir, get the JSON-escaped value, as for other tools (4524459992). They get it before the command gets the assignments, and nothing scans the command again, so a value that holds its own placeholder is in the command once, quoted (4524578900). The variable is not exported. The scrub also matches the single-quoted form, so the assignment never shows in tool output, for example in ps.
  • Parent answers (4523688908): the wait_agent note for a secret question no longer offers message_agent. forkValidateSubagentResume, which message_agent and wake-ups call before and inside the send transaction, now refuses a send to a child whose pending question is secret. Such a message would answer the question without the value. The refusal also applies to wake-ups, so a wake-up of such a child fails with that error instead of answering the question.
  • Queued messages (fix(coderd/x/chatd): keep secret answers out of shell code, media and fragments #136 thread 4524238884): a message queued while the child still runs would be promoted at the end of the turn, after the secret question, and would answer it. A secret question is now refused while the child's queue holds messages, with a note to end the turn, read them, and ask again. The check runs in the transaction that records the question, under the chat row lock that SendMessage takes before its own check, so no send can reach the queue in between. An ordinary question now takes the same lock, and it is refused while the report of an answer to the pending secret question waits in the queue. The end of the turn would deliver that report as the answer to the ordinary question (fix(coderd/x/chatd): keep secret answers out of shell code, media and fragments #136 thread 4527514295).
  • Chat API messages and edits (fix(coderd/x/chatd): keep secret answers out of shell code, media and fragments #136 threads 4524816616 and 4524960967): the chat API refuses a message or an edit to a chat with a secret question before it calls SendMessage or EditMessage, so a question recorded in between would be answered by the message. Both now refuse, in their transaction, every message to a descendant chat whose pending question is secret, with chatd.ErrSecretQuestionPending, which the chat API returns as the same 409. Only the message that reports a stored answer passes, and it marks its context with chatd.WithSecretAnswerReport.
  • Late answer reports (fix(coderd/x/chatd): keep secret answers out of shell code, media and fragments #136 thread 4524960980): two overlapping answers to one question could let the second one report its answer after the child had asked a new secret question, which would answer the new question without its value. chatd.WithSecretAnswerReport now carries the tool call ID, and the report passes only while that question is pending and its answer is stored. Otherwise SendMessage returns chatd.ErrSecretAnswerNotPending, and the answer route returns 409. The answer route also stores the answer in the transaction that checks its question under the chat row lock, so it refuses an answer to a question that is no longer pending with 409 instead of storing it, where the child could still use its placeholder (fix(coderd/x/chatd): keep secret answers out of shell code, media and fragments #136 thread 4527514274).

The two other #126 threads need no code. The 8 byte floor (4523933077) is a recorded product call, and a clear recovers. The options schema (4523688921) stays as it is, because provider tool schemas don't reliably support if/then, and upstream's error names the missing options on the next step.

Limits

Bash evaluates a variable again in a few places where the command puts it, and there a command substitution in the value runs. Arithmetic is the only such place that execute refuses. An associative array subscript in a builtin such as unset or declare, and indirect expansion, are not refused (#136 thread 4524578916). Ordinary use of the placeholder never puts the value there, so these places are outside the accidental-exposure threat model. Refusing every value with $ or a backtick would block common generated passwords and push the model to write_file, which leaves the value on disk.

With the flag off

Nothing can create a secret question or a secret answer, so none of the new paths run except one read. Each message or edit to a descendant chat now reads the chat's pending question in its transaction, an indexed read by chat_id, and finds no secret question.

Validation

  • TestSubstituteExecuteSecretAnswers runs the rewritten command under sh -c. The value holds ', ", ;, |echo INJECTED, &, *, a newline and a backslash. The command uses the placeholder bare, in double quotes and in single quotes, and printf prints the value unchanged in all three. Negative controls: with the value spliced into the command as before, the test fails. With every placeholder expanded as "${...}", the single-quoted case fails. The test also covers a placeholder in workdir, a command that assigns and unsets the variable names, and a value that runs code in $(( )). It also runs a value that holds its own placeholder and a quote that would end the assignment, and it checks that a value with $ or a backtick after [ is refused. With the workdir substitution removed, the variable name fixed, the command scanned again, or the arithmetic refusal removed, it fails.
  • TestScrubSecretAnswers covers a cut-off prefix, a cut-off suffix, a 7 byte run that stays, the single-quoted form, the ASCII-escaped JSON forms of a value with ä and an emoji, uppercase hex escapes of < and of a control character, an escaped /, a value that starts like its placeholder, both $'...' forms of a value with control characters, the Go %q and %+q forms of a value with a control character and ä, and the printf %q and declare -p forms of values with a space, $ and ~. Where bash exists, it also scrubs a real set -x trace and real printf %q and declare -p output. With the fragment scrub, the ASCII forms, the uppercase forms, the Go quoted forms, the escaped / forms, the $'...' forms, the backslash forms, the escaped ~ forms or the markers removed, it fails.
  • TestSecretAnswerTools covers the withheld media, withheld attachment metadata, and the variable assignment in a wrapped execute. With the media check or the attachment check removed, it fails.
  • TestDescendantSecretQuestion covers the computer-use refusal, the refusal while a message is queued, and the refusal of an ordinary question while the report of a secret answer is queued. With the queue check or the report check removed, it fails. TestSecretQuestionRefusesSubagentMessage covers the refused message_agent message, the refused SendMessage and EditMessage without the report mark, a report without a stored answer, the report that passes, a late report after a newer secret question, and an allowed answer to an ordinary question. TestDescendantQuestionWaitAgent checks both notes. Each fails with its check removed.
  • TestStoreSecretAnswer covers a refused answer to an earlier question, a first answer, a replaced unreported answer, and a refused answer after the report is delivered. With the question check removed, it fails.
  • gofmt and go vet pass.

…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.
@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: 6dee42d542

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

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: fbc5d4bbaf

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

Base automatically changed from mike/descendant-questions-6-secret-substitution to main November 10, 2026 16:11
…ions-6b-secret-hardening

# Conflicts:
#	coderd/x/chatd/fork_descendant_questions.go
#	coderd/x/chatd/fork_secret_answers.go
#	coderd/x/chatd/fork_secret_answers_internal_test.go
#	coderd/x/chatd/fork_secret_answers_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: 1f12d2726f

ℹ️ 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_subagents.go Resolved
Comment thread coderd/x/chatd/fork_secret_answers.go Resolved
…backslash forms

Store a secret answer in the transaction that checks its question under the
chat row lock, refuse an ordinary question that would replace a secret one
whose answer report is queued, and scrub the forms that Bash's printf %q and
declare -p write.
@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

if err := ftx.DeleteChatSecretAnswer(ctx, forkdb.DeleteChatSecretAnswerParams{ChatID: arg.ChatID, ToolCallID: arg.ToolCallID}); err != nil {
return err
}
reportQueued = queued
return ftx.InsertChatSecretAnswer(ctx, arg)

P2 Badge Serialize concurrent secret answer submissions

When two requests answer the same pending secret question concurrently, the second can enter this delete-and-reinsert path after the first stores value A but before it sends its report, replacing A with B. The first request's subsequent WithSecretAnswerReport send validates only that some answer exists for the call ID, so it can resume the child using B and return 204, while the request that actually supplied B can then receive 409 because the question is no longer pending. Preserve an identity for the in-flight answer or serialize storing and reporting so one submission cannot silently report another submission's value.

ℹ️ 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 5845643171 (concurrent secret answer submissions, P2): dropped. It needs two concurrent answers from the user to the same question, and the stored value is still one that the user gave for that question, so nothing reaches the model or runs as code.

Xum posted this comment on behalf of @ibetitsmike.

@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 (5f6b636911) 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 (5f6b636911), 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 af6e275 into main Nov 10, 2026
27 of 35 checks passed
@ibetitsmike

Copy link
Copy Markdown
Owner Author

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

Merge evidence for head 8f3752a9cab1c663548830d576d5aea3fc120bf7:

  • fork-ci pull_request run 42863328937 passed on attempt 2; its build job checked out Merge 8f3752a9ca into 5f6b636911 (current main). Attempt 1 failed only TestRunnerManager_HeartbeatDoesNotReviveStaleLease, the known flake test(coderd/x/chatd): fix flaky TestRunnerManager_HeartbeatDoesNotReviveStaleLease #61, so I re-ran the failed job. Run 42856903500 had also passed on this head against df22c722f3. All checks green.
  • Codex on this exact head (review 5845643171): one P2 (two concurrent user answers to the same secret question) dropped with a reply, because the stored value is still one the user gave for that question and nothing reaches the model or runs as code. 0 of 18 review threads unresolved.
  • UAT: the feat(coderd): give descendant tools secret answers without showing them to the model #126 light UAT on the local deployment stands, since the secret question schema stays off until PR7; normal descendant question round trips passed on the daily server at df22c722f3. This head's fixes are covered by targeted tests and 4 negative controls. The full secret UAT runs on PR7.
  • No migration.

@ibetitsmike
ibetitsmike deleted the mike/descendant-questions-6b-secret-hardening branch November 10, 2026 18:16
ibetitsmike added a commit that referenced this pull request Nov 10, 2026
…space stop in the pstack adapter (#154)

* docs: map notify_user and the daily wake-up limits in the pstack adapter

* docs: check the pstack adapter against main at d1bb658

* docs: re-pin pstack adapter cites that #115 and #136 moved

* docs: re-pin pstack adapter cites that #136 moved

* docs: say that a root archive stops the workspaces of workspace subagents

* docs: re-pin pstack adapter cites that #147 moved

* docs: qualify the wake-up limits, pause notices, inbox, and workspace autostop

* docs: condition the archive cleanup of isolated subagents on the experiment

* docs(docs/fork): qualify notification limits and the archive workspace stop

* docs(docs/fork): qualify notify_user availability, limit, and silent drops
ibetitsmike added a commit that referenced this pull request Nov 10, 2026
* feat(coderd): let descendant chats ask the user blocking questions behind 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.

* test(coderd/x/chatd): make the descendant question tests deterministic 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.

* feat(coderd/database): list a chat family's pending descendant questions

Adds the forkdb query ListPendingChatDescendantQuestionsByRoot with its
dbauthz (read access to the root chat) and dbmetrics wrappers.

* feat: add GET /api/v2/chats/fork/{chat}/questions

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.

* fix(coderd): keep wait_agent options and timeouts for descendant questions

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.

* test(coderd): cover skipping an undecodable descendant question

* fix(coderd/database/forkdb): ignore model-only user rows in the family question list

* feat(site/src): show descendant chat questions on the root chat page

* fix(site/src/api): keep the descendant questions fetcher module-private

* fix(coderd): end the question wait on a replaced question and retire it on clear

* fix(site/src/pages/AgentsPage/components): name the descendant question dock by its header

* fix(coderd/database/forkdb): retire a cleared chat's question in the family question list

* refactor(site/src/api): move the descendant question query options to api/queries

* wip: chat_secret_answers storage (node, queries, dbauthz, dbmetrics, dbcrypt)

* chore(coderd/database/forkdb): generate chat_secret_answers queries

* feat(coderd): accept secret answers to descendant questions outside chat messages

* docs(coderd/x/chatd): leave a TODO for chat_secret_answers in the architecture document

* fix(site/src): handle load errors, focus and stale answers in the descendant question dock

* fix(enterprise/dbcrypt): encrypt, decrypt and delete chat secret answers in key commands

* fix(coderd): drop the pending secret answer with a detached context

* fix(site/src/pages/AgentsPage/components): show a failed poll next to cached descendant questions

* fix(coderd): refuse every message while a secret question is pending

Also send an empty options array for questions without options, and match the secret-answer route ID to its summary.

* fix(enterprise/dbcrypt): page chat secret answers in key commands

* fix(site/src/pages/AgentsPage/components): disable descendant answers while the chat cannot take a turn

* feat(coderd): expire chat secret answers after 24 hours

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

* fix: reject null bytes in secret answers and skip re-answered ones in key rotation

* fix(site/src): refresh the descendant chat's caches after the dock answers

* test(site/src/pages/AgentsPage/components): keep the seeded child chat cached in the dock test

* fix(coderd): let a secret answer be given again after its queued message is deleted

* fix(coderd/database): batch the secret answer purge on the database clock and record it

The purge now deletes at most 1000 expired answers per tick, measures the
24 hour TTL with now() like GetChatSecretAnswersByChatID, and adds the
purged count to the dbpurge log line and records_purged metric.

* test(site/src/pages/AgentsPage/components): name the dock story fixture variants

* fix(coderd): keep tool methods through the secret wrapper and reject short secret answers

Turn setup reads a descendant chat's secret answers once and wraps the
tools only when the chat has some. The wrapper forwards the optional
methods the chat loop asserts. The secret answer route rejects values
under 8 bytes, which the output scrub would match in ordinary text.

* fix(coderd): unescape the tool call ID of the secret answer route

* test(site/src/pages/AgentsPage/AgentChatPage): pin a subagent answer from a running root chat

* feat(coderd/x/chatd): offer secret questions to descendant chats

* feat(site/src): take secret answers to descendant questions in a masked field

* style(coderd/x/chatd): gofmt the secret answer test tool

* fix(coderd): send the tool call ID of a secret answer in the request body

* fix(site/src): send the secret answer's tool call ID in the request body

* fix: keep a concurrent secret answer when an undelivered one is deleted

InsertChatSecretAnswer returns the row's created_at, and the cleanup after a
failed send deletes the answer only while that created_at still matches. A
request that replaced the row inserted it later, so its answer stays.

* fix(coderd): regenerate the secret answer queries and update the purge test for the insert's created_at

* fix(coderd/x/chatd): update secret answer tests for the insert's created_at

* fix(coderd/database): restore the time imports the merged secret answer insert needs

* test(site/src): expect the disabled answer field on a secret question's card

* fix: keep an in-flight secret answer and accept messages with the experiment off

A failed send no longer deletes the answer: the question stays pending, and
the next answer replaces the unreported one in one transaction. This drops
the created_at check that only guarded that delete. The guard on the normal
answer path applies only with fork-nested-subagents on, because the secret
answer route is gone without it.

* fix(coderd/database): drop the created_at fixups that the secret answer insert no longer needs

* fix(coderd/x/chatd): drop the created_at fixups that the secret answer insert no longer needs

* fix(coderd): keep a secret question pending past a promoted queued message

Only the secret answer's own message, or a context boundary, retires a secret question. A message the user queued before the question no longer answers it when the end of the turn promotes it.

* fix(coderd): replace a secret answer past its TTL while its message is queued

* fix(coderd): refuse secret edits and serialize the secret answer replacement

Edits of a chat message or of a queued message's content now get the same refusal as a new message while a secret question is pending. Replacing an unreported answer now locks the chat row and rechecks, in the same transaction, that no queued or delivered message reports the answer.

* fix(coderd/x/chatd): keep secret answers out of shell code, media and fragments

Refuse secret questions in computer-use chats, scrub cut-off prefixes and
suffixes of a value, withhold media from wrapped tools while answers are
active, give execute the value through a shell variable the wrapper
assigns, and refuse internal messages to a child whose pending question is
secret.

* fix(coderd/x/chatd): restore the JSON escaping helpers of the secret scrub

* perf(enterprise/dbcrypt): page chat secret answers by key during recrypt

* fix(coderd/x/chatd): withhold attachments and refuse queued secret questions

A tool result that attaches a file while the chat holds secret answers
now drops the attachment metadata, because the next prompt resolves the
file bytes for the model. A secret question is now refused while
messages wait in the queue of the chat: the end of the turn would deliver
them after the question and answer it without the value. The check holds
the chat row lock that SendMessage takes before it refuses messages to a
chat with a pending secret question.

* fix(coderd/x/chatd): show the queued secret question refusal without the transaction prefix

* fix(coderd): reuse the queued report when an expired secret answer is 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.

* fix(coderd/x/chatd): scrub secret answers that a JSON encoder escaped to ASCII

Python's default json.dumps writes each non-ASCII character as a \u
escape, so a value with such a character matched none of the scrub forms.
The scrub now also matches the ASCII-only JSON forms, with lowercase and
uppercase hex.

* fix(coderd/x/chatd): substitute execute workdir and isolate secret shell variables

A placeholder in an execute parameter other than command, such as
workdir, now gets the value as JSON, as in other tools. The variable the
wrapper assigns gets underscores added until the command does not name
it, so the command cannot assign or unset it. A value in which a $ or a
backtick follows a [ is refused for execute, because Bash runs the
subscripts of such a value as code where it evaluates the variable as
arithmetic.

* fix(coderd/x/chatd): refuse shell-evaluable values and protect scrub placeholders

execute now refuses a secret value with $ or a backtick, since Bash
evaluates a variable again in arithmetic and array subscripts. The other
execute parameters get their values before the command holds the
assignments, so a value holding its own placeholder is substituted once.
The scrub writes null-byte markers until the end, so a fragment pass cannot
cut a placeholder, and it matches JSON forms with an escaped solidus.

* fix(coderd/x/chatd): narrow the execute refusal back to arithmetic-unsafe values

execute again refuses only a value with $ or a backtick after a [, which
Bash runs where it evaluates a variable as arithmetic. Refusing every $
blocked common generated passwords. Other re-evaluating contexts are ones
the command picks, outside the accidental-exposure threat model.

* fix(coderd): recheck secret questions on every send and scrub Bash ANSI-C quoting

SendMessage now refuses any message to a chat whose pending question is
secret inside its transaction, not only message_agent sends, because the
chat API checks before the question can be recorded. Only the message that
reports a stored answer passes. The scrub also matches the $'...' form in
which Bash writes a word with a control character, as set -x does.

* test(coderd/x/chatd): mark the secret answer report in TestSecretAnswerReachesToolsNotModel

* fix(coderd): recheck secret questions on edits and bind answer reports to their question

Codex round 6 on #136: EditMessage rechecks the pending secret question
under the chat lock, the answer report carries its tool call ID and passes
only while that question is pending with a stored answer, and the scrub
covers uppercase hex in JSON escapes of ASCII characters.

* test(coderd/x/chatd): drop the busy behavior argument main removed from sendSubagentMessage

* test(coderd/x/chatd): cover a late answer report after a newer secret question

* fix(coderd/x/chatd): scrub secret answers as Go's %q and %+q quote them

* fix(site/src/pages/AgentsPage/components): keep password managers off the secret answer field

* fix: address Codex review of secret questions

The tool row reads secrecy from the result too, the dock renders the
secret prompt as Markdown and keeps focus after a secret answer, and
ordinary questions keep options required in the tool schema.

* chore(site/src/pages/AgentsPage/components): format secret question changes

* fix(coderd/x/chatd): let only secret questions leave out options in the schema

* fix: keep secret questions answered and let the user decline them

Keep the secret answers of earlier questions until their TTL so tool output
that shows a persisted value stays scrubbed. A deleted answer report still
retires its secret question, so an edit cannot revive it. The user can
decline a secret question, such as for a value too short to hide, which
retires it without a value.

* test(site/src/pages/AgentsPage/components): cover the sent secret answer state and name fixtures with mock

* chore(site/src/pages/AgentsPage/components): format secret question tests and drop a duplicate comment

* fix(coderd): drop a declined question's stored answer and keep secret answer reports through prompt overrides

* chore(coderd/apidoc): describe declined secret answers

* fix(coderd): refuse to decline a secret question whose answer report is queued

* fix(site/src/pages/AgentsPage/components): clear stale secret answer errors and explain a disabled secret form

* chore(site/src/pages/AgentsPage/components): format the secret answer submitting story

* test(coderd): check the queued decline refusal under the chat lock

The coderd test raced a promotion of the queued report, so either 409
satisfied it. The chatd test queues the report itself.

* fix(site/src/pages/AgentsPage/components): tie secret answer errors to the field and explain secret questions in descendant chats

* test(site/src/pages/AgentsPage/components/ChatElements/tools): leave the secret question story to the visual capture
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