Skip to content

feat(coderd): expire chat secret answers after 24 hours - #125

Merged
ibetitsmike merged 54 commits into
mainfrom
mike/descendant-questions-5-secret-answer-ttl
Nov 10, 2026
Merged

ibetitsmike merged 54 commits into
mainfrom
mike/descendant-questions-5-secret-answer-ttl

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 second of four PRs for secret answers to descendant questions (R8.3). It stacks on #119. A secret answer is now usable for 24 hours. After that, reads skip it, and dbpurge deletes it.

What changes

  • GetChatSecretAnswersByChatID returns only answers newer than 24 hours, so an answer expires on time even when the purge has not run yet.
  • dbpurge calls purgeForkInTx once per tick, inside its transaction. It deletes up to 1000 chat_secret_answers rows older than 24 hours with DeleteOldChatSecretAnswers, oldest first. The age is measured with PostgreSQL's now(), the same clock as created_at and the read filter.
  • A second answer replaces a stored answer that has expired while its message is still queued, so the user can answer again. It uses the same TTL-filtered read as the worker. The route then sends no second message: the queued one reports the new answer, so the child never gets a duplicate report.
  • The purged count goes to the purge's log line and to coderd_dbpurge_records_purged_total{record_type="chat_secret_answers"}. In upstream's dbpurge.go, the call, the log field and the metric line are the only changes. The fork code is in fork_dbpurge.go.
  • If the store has no fork queries, as with the mock stores in upstream's purge tests, the purge logs a warning and skips. The read filter still expires the answers.
  • created_at has no index. An answer lives at most 24 hours plus one 10 minute purge interval, and the next question of its chat deletes it, so the table stays small.
  • coderd/x/chatd/ARCHITECTURE.md: the chat_secret_answers TODO now mentions the expiry. The document's owner writes the text.

Validation

  • TestDeleteOldChatSecretAnswers (dbpurge, Postgres): a 25 hour old answer is deleted, a 23 hour old one is kept, and the counter shows 1. With the metric line removed, the test fails.
  • TestForkChatSecretAnswerExpired (coderd): a queued answer aged to 25 hours is replaced by a second answer, and the queue still holds exactly one report. Without the TTL check, the second answer gets a 409. With the second send restored, the queue holds two reports and the test fails.
  • TestPurge, TestMetrics, TestDBPurgeAuthorization and dbauthz TestForkQuerier pass. forkdb/generate.sh leaves no diff, and gofmt and go vet pass.
  • fork-ci runs only on PRs into main. This PR targets feat: accept secret answers to descendant questions outside chat messages #119's branch, so CI runs after feat: accept secret answers to descendant questions outside chat messages #119 merges and this PR moves to main.
  • Server UAT of the expiry (dev server at cbff12ee9c, fork-nested-subagents on, no model turns). I staged answers in SQL: two expired ones (25 h and 24 h 1 min old) and one fresh one (23 h). The dbpurge tick at 11:02Z deleted both expired rows and kept the fresh one. An answer aged past 24 h on a question that was pending again was replaced by a new answer (204, new value, fresh created_at). A database dump, chat_messages and the server log held none of the staged values.

…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-10T12:41:22.494835Z a696b95 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: 7308643f67

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

…acement

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.
…escendant-questions-5-secret-answer-ttl

# Conflicts:
#	coderd/fork_chat_questions.go
@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. Delightful!

Reviewed commit: 2fd2054403

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

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: b1b0aeca3e

ℹ️ 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/fork_chat_questions.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.
@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. What shall we delve into next?

Reviewed commit: 9ab5356a2f

ℹ️ 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-4-secret-answers to main November 10, 2026 12:35
…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
@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 (3036142c68) and run fork-ci on it. The head is unchanged.

@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum posted this comment on behalf of @ibetitsmike.

@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 (3036142c68), 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
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: a696b95118

ℹ️ 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
ibetitsmike merged commit ad10107 into main Nov 10, 2026
14 of 20 checks passed
@ibetitsmike
ibetitsmike deleted the mike/descendant-questions-5-secret-answer-ttl branch November 10, 2026 13:16
@ibetitsmike

Copy link
Copy Markdown
Owner Author

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

Merge evidence for head a696b951181606b84d1c432554f7b78290881e03:

  • fork-ci pull_request run 42817447192 passed; its build job checked out Merge a696b95118 into 3036142c68. Main has since gained only docs: map wake-ups and worktree binding in the pstack adapter #139 (1be1a17a96), which changes docs/fork/pstack-adapter.md only. All checks green.
  • Codex on this exact head: no major issues (comment 6767592000). 0 unresolved review threads.
  • Server UAT of the 24 hour expiry passed at cbff12ee9c (PR body, Validation). Accepted as covering this head: the later route change (no second report when a queued expired answer is replaced) is covered by TestForkChatSecretAnswerExpired with a failing negative control, and a696b95118 only merges main.
  • No migration. The ARCHITECTURE.md change only extends the owner TODO for chatd.chat_secret_answers.

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