Skip to content

feat(chatd): wake wait_agent on the child's state channel - #333

Merged
ibetitsmike merged 7 commits into
mainfrom
mike/issue-300-wait-wake
Nov 15, 2026
Merged

ibetitsmike merged 7 commits into
mainfrom
mike/issue-300-wait-wake

Conversation

@ibetitsmike

Copy link
Copy Markdown
Owner

Coder Agents opened this PR on behalf of @ibetitsmike.

Top of a two PR stack for #300. It is based on #332 (mike/issue-300-answered-state), which stores the answered state. Merge #332 first; this PR then needs a retarget to main so fork-ci runs on it.

What changed

  • descendantQuestionPollInterval (2 s) is gone. awaitDescendantAnswer subscribes to ChatStateUpdateChannel(childID) before its first read, then reads the question again on each notification. Every event that retires a question commits through the child's state machine, which publishes on that channel after commit (feat(chatd): store the answered state of descendant questions #332 sets answered_at inside that transaction).
  • A fallback tick of subagentAwaitFallbackPoll (5 s) covers a lost notification and a new question, which commits outside the state machine. If the subscription fails, the wait falls back to subagentAwaitPollInterval, as awaitSubagentCompletion does.
  • The removed pendingDescendantQuestion helper had no caller left.
  • coderd/x/chatd/ARCHITECTURE.md describes the wake.

Tests

All run locally with flock ~/.fork-go.lock:

  • go test ./coderd/x/chatd/ -run TestDescendantQuestion -v: pass.
    • TestDescendantQuestionWaitAgent answers through Server.SendMessage. The call wakes with no clock advance: the child wait timer starts with the full 10 s.
    • New TestDescendantQuestionWaitReads counts GetPendingChatDescendantQuestion calls through dbmetrics over 60 s of mock time on an unanswered question. Logged result: question reads in 60s: 13 (the initial read, one per 5 s fallback tick, and the read after the short wait for the child). It asserts at most 13.
  • go test ./coderd/x/chatd/... -count=1: pass.
  • golangci-lint run --fix=false ./coderd/x/chatd/: no finding on changed lines. New-code config: 0 issues.

Not verified

Closes #300.

chat_descendant_questions now stores the family root and whether the
question is answered. The chatstate message insert marks the question
answered in the same transaction as the user message that answers or
retires it: a visible user message, the secret answer message, or a
compressed context boundary. A new question clears the state.

Reads of the pending question and the questions endpoint no longer scan
chat_messages. The chatdmig node backfills root_chat_id from the family
root and marks rows that the old rule treats as answered with
answered_by = 'migrated'. Pending rows stay pending.

Part of #300.
wait_agent on a child with a pending question no longer polls every two
seconds. It subscribes to the child's state channel before the first
read and reads the question again on each notification. Every event that
retires the question commits through the child's state machine, which
publishes on that channel. A 5 second fallback tick covers a lost
notification.

Closes #300.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 14, 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-15T12:36:45.065021Z ebf7a71 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.

Require answered_by on an answered row; a NULL passed the CHECK. Label
a prefixed answer to a question that is not secret as message, so
secret_answer means a secret question. Index root_chat_id fully, so the
cascade from a deleted chat can use it. Say in ARCHITECTURE.md that the
chatstate insert writes this table through a fork hook. Cover deleted,
compressed and secret rows in the backfill test.
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@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: 8e94182c0e

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

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

The ARCHITECTURE.md text is required by acceptance criterion 7 of #300 (final text, no TODOs); see the answered thread.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 8e94182c0e

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

Coder Agents acted on behalf of @ibetitsmike.

Merged the updated bottom branch, which now contains origin/main 9308bf6 (#330). @codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: ee9be5d2ac

ℹ️ 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/issue-300-answered-state to main November 14, 2026 18:06
…-state-opus-80f083c4

# Conflicts:
#	coderd/database/forkdb/chat_descendant_questions_test.go
#	coderd/database/forkdb/models.go
#	coderd/database/migrations/chatdmig/nodes/01a1da95-80da-7dd4-a368-4b8bf0e1f65f_chat_descendant_questions_answered.up.sql
#	coderd/x/chatd/fork_descendant_questions_internal_test.go
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

Retargeted to main after #332 merged (5f049c1) and merged main in (ebf7a71, no conflicts left; the diff against main is the 4 files of this PR). Tests run on this head: go test -run "TestDescendantQuestion|Subagent" ./coderd/x/chatd (59 pass), ./coderd/database/forkdb/, ./coderd/x/chatd/chatstate/, ./coderd/database/migrations/chatdmig/..., -run "Question|Secret" ./coderd/ all ok.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: ebf7a718f9

ℹ️ 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 3f37f49 into main Nov 15, 2026
9 checks passed
@ibetitsmike
ibetitsmike deleted the mike/issue-300-wait-wake branch November 15, 2026 12:51
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

Merged as 3f37f49 (squash, --match-head-commit).

Gates on head ebf7a71, with main at 5f049c1 (live on the server at merge time):

  • Every check run on the head passed. fork-ci run 43714549369 ran on this exact head and passed.
  • Codex receipt on the head: feat(chatd): wake wait_agent on the child's state channel #333 (comment) ("Didn't find any major issues", Reviewed commit: ebf7a718f9).
  • Review threads: 0 unresolved (the one ARCHITECTURE.md thread is resolved).
  • Behind main: 0.
  • Opus review, read-only, on the exact head: mergeable, no P1 or P2. Nits not acted on: an extra subscribe per wait_agent call on a direct child, a 200 ms fallback poll when the subscribe fails, a doc comment on awaitDescendantAnswer about a stale pending, and test gaps listed below.

Tests run on this head:

  • go test -count=1 -v -run 'TestDescendantQuestion' ./coderd/x/chatd/: 6 of 6 pass.
  • Earlier, on the same merge commit: 59 tests in ./coderd/x/chatd plus the forkdb, chatstate, chatdmig and coderd Question/Secret tests pass.
  • Negative control: forcing notifyCh = nil in awaitDescendantAnswer, so the wait gets no pubsub wake, makes TestDescendantQuestionWaitAgent fail (timeout at 25 s). Restored, it passes.

Not exercised: the subscribe-failure fallback path, a wake that does not retire the question (a plain message to a secret-question child), and the secret answer route waking a waiting wait_agent. Not run on a live server.

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.

chatd: descendant questions are polled every 2 s through a JSONB scan; store the answered state

1 participant