Skip to content

feat: add the message_family_chat tool behind fork-family-messages - #265

Merged
ibetitsmike merged 10 commits into
mainfrom
mike/chat-family-messages-1-tool
Nov 13, 2026
Merged

ibetitsmike merged 10 commits into
mainfrom
mike/chat-family-messages-1-tool

Conversation

@ibetitsmike

Copy link
Copy Markdown
Owner

Xum created this PR on behalf of @ibetitsmike.

Part of #247 (PR 1 of 4: server tool; next are list_family_chats, the tool card and the recipient header).

Adds the fork-family-messages experiment and the message_family_chat chat tool. A chat sends a text message by chat ID to any other chat with the same root: its parent, a sibling or another descendant. Delivery works like message_agent: an idle recipient starts a turn, a busy recipient gets the message before its next model call (steer), and no turn is interrupted. The message arrives as a user message in an <agent-message from_chat_id="..." from_title="..."> envelope that names the sender and says it comes from an agent, not from the user.

  • Each send records a chatd.chat_family_messages row (new chatdmig node) in the send transaction through forkAdmit. A sender may send at most 60 messages in the rolling hour, and the tool runs its calls serially so parallel calls in one step cannot pass the limit together.
  • Unknown chats and chats of another family get the same "not in this chat's family" error, so a chat cannot probe IDs outside its family. Archived chats, the sender itself, empty bodies and bodies over 16 KiB are refused.
  • Like message_agent, a message to a finished child counts against the family live-subagent limit.

Known limit: a parent blocked inside wait_agent gets a family message only after wait_agent returns.

The coderd/x/chatd/ARCHITECTURE.md change is one TODO for the author to describe the feature.

Adds the fork-family-messages experiment and the message_family_chat chat
tool. A chat sends a text message to any other chat with the same root (its
parent, a sibling or another descendant) by chat ID. Delivery follows
message_agent: an idle recipient starts a turn, a busy recipient gets the
message before its next model call, and no turn is interrupted. The message
arrives in an agent-message envelope with the sender chat ID and title.

Each send records a chatd.chat_family_messages row in the send transaction,
and a sender may send at most 60 messages in the rolling hour. Chats outside
the family, unknown chats, archived chats and the sender itself are refused.

Refs #247
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum posted this comment on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 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-13T11:16:03.154642Z d589b93 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: 24c507b784

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

Xum posted this comment on behalf of @ibetitsmike.

@codex review (head now includes a merge of main at 0896529; no PR changes)

@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: b9f2509259

ℹ️ 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_family_messages.go Resolved
Comment thread coderd/x/chatd/fork_tools.go Resolved
Comment thread coderd/x/chatd/fork_family_messages.go Resolved
Addresses the Codex review of #265:

- Escape <agent-message> wrapper tags (case and spacing variants) in the
  body and sender title, so a sender cannot close the envelope early.
- Record each message under the tool-call occurrence ID and return the
  recorded recipient on a replayed call, so a worker restart does not
  deliver the message twice.
- Drop the sender's rows older than the rate window in the send
  transaction, so the ledger stays bounded.
- Include message_family_chat in the Task alias of custom agent tool
  policies, so disallowing Task also blocks family messages.

Refs #247
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum posted this comment 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: ae6a9f37a4

ℹ️ 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_family_messages.go Resolved
Comment thread coderd/x/chatd/fork_family_messages.go Resolved
Comment thread coderd/x/chatd/fork_family_messages.go Resolved
Comment thread coderd/x/chatd/fork_tools.go Resolved
Comment thread coderd/x/chatd/fork_family_messages.go Resolved
Comment thread coderd/x/chatd/fork_family_messages.go Resolved
Addresses the second Codex review of #265:

- Return hook dispatch failures as tool execution errors, as spawn_agent
  does, so the sender fails closed.
- Refuse calls without a deterministic tool-call ID, which replay
  deduplication needs.
- Resolve the family root with subagentRootChatID, so first-level children
  without a root ID reach their parent and siblings.
- Index chat_family_messages.recipient_chat_id for the chat delete cascade.
- Keep the agent-message envelope around a user_prompt_submit hook's prompt
  override.
- Word the reply hint so it holds when the recipient lacks the tool.

Refs #247
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum posted this comment on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: d4a21e59f3

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

Add organization_id (the sending chat's organization) to
chatd.chat_family_messages, filter the rate-limit, replay and prune
queries by it, and lead the sender index with it.

Refs #247
Replace the fork-family-messages TODO with the behavior of
message_family_chat and chatd.chat_family_messages after the
organization_id change.
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum commented 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: 532d35d69b

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

The ON DELETE CASCADE from chats looks up rows by sender_chat_id alone,
which an index leading with organization_id cannot serve.
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum commented on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: ac489971a4

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

…ages-1-tool

# Conflicts:
#	docs/reference/api/schemas.md
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum commented on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: d589b93cf3

ℹ️ 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 5ff45d4 into main Nov 13, 2026
9 checks passed
@ibetitsmike
ibetitsmike deleted the mike/chat-family-messages-1-tool branch November 13, 2026 11:29
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum merged this PR on behalf of @ibetitsmike.

Merged as 5ff45d43ee with a squash through gh stack merge. These checks passed on head d589b93cf3:

  • fork-ci run 43415145608 (9/9)
  • Codex: no major issues on d589b93cf3
  • 0 unresolved threads, branch up to date with main
  • UAT round 2 PASS on ac489971a4: 5/5 checks plus the organization check (64/64 rows carry the sender chat's organization_id)

The UAT carries over to the merged head. Normalized for index and hunk lines, its diff against main matches the tested diff except for the generated Experiment enum table in docs/reference/api/schemas.md, where chat-automations arrived from #271.

ibetitsmike added a commit that referenced this pull request Nov 13, 2026
…cture-fork-docs

# Conflicts:
#	coderd/x/chatd/ARCHITECTURE.md
ibetitsmike added a commit that referenced this pull request Nov 13, 2026
…ges (#266)

* feat: add the message_family_chat tool behind fork-family-messages

Adds the fork-family-messages experiment and the message_family_chat chat
tool. A chat sends a text message to any other chat with the same root (its
parent, a sibling or another descendant) by chat ID. Delivery follows
message_agent: an idle recipient starts a turn, a busy recipient gets the
message before its next model call, and no turn is interrupted. The message
arrives in an agent-message envelope with the sender chat ID and title.

Each send records a chatd.chat_family_messages row in the send transaction,
and a sender may send at most 60 messages in the rolling hour. Chats outside
the family, unknown chats, archived chats and the sender itself are refused.

Refs #247

* fix(coderd): harden message_family_chat delivery

Addresses the Codex review of #265:

- Escape <agent-message> wrapper tags (case and spacing variants) in the
  body and sender title, so a sender cannot close the envelope early.
- Record each message under the tool-call occurrence ID and return the
  recorded recipient on a replayed call, so a worker restart does not
  deliver the message twice.
- Drop the sender's rows older than the rate window in the send
  transaction, so the ledger stays bounded.
- Include message_family_chat in the Task alias of custom agent tool
  policies, so disallowing Task also blocks family messages.

Refs #247

* feat(coderd): add the list_family_chats tool behind fork-family-messages

With fork-family-messages on, every chat turn also gets list_family_chats.
It lists the unarchived chats of the caller's family (the same root), the
root first and then by creation time, so the model can find the chat IDs
that message_family_chat takes. Each entry has the chat ID, parent chat ID,
title, status and the caller's relation to the chat: self, parent, root,
child, sibling or other. At most 100 chats are listed, and truncated is set
when the family has more.

The new forkdb query ListChatFamilyMembers authorizes as a read of the root
chat. The Task tool alias of custom agents now includes list_family_chats.

Refs #247

* fix(coderd): close message_family_chat review gaps

Addresses the second Codex review of #265:

- Return hook dispatch failures as tool execution errors, as spawn_agent
  does, so the sender fails closed.
- Refuse calls without a deterministic tool-call ID, which replay
  deduplication needs.
- Resolve the family root with subagentRootChatID, so first-level children
  without a root ID reach their parent and siblings.
- Index chat_family_messages.recipient_chat_id for the chat delete cascade.
- Keep the agent-message envelope around a user_prompt_submit hook's prompt
  override.
- Word the reply hint so it holds when the recipient lacks the tool.

Refs #247

* fix(coderd/database/forkdb): keep the family list predicate indexable

Refs #247

* fix(coderd/x/chatd): keep list_family_chats within the tool-result budget

Stop listing once the entries reach 12 KiB, below chatloop's 16 KiB
smallest tool-result budget, and mark the list truncated. Add the
architecture TODO for list_family_chats.

Refs #247

* fix(coderd): scope chat_family_messages to an organization

Add organization_id (the sending chat's organization) to
chatd.chat_family_messages, filter the rate-limit, replay and prune
queries by it, and lead the sender index with it.

Refs #247

* docs(coderd/x/chatd): describe family messages in ARCHITECTURE.md

Replace the fork-family-messages TODO with the behavior of
message_family_chat and chatd.chat_family_messages after the
organization_id change.

* chore(coderd/database/forkdb): regenerate family message queries for organization_id

* fix(coderd): lead the family message index with sender_chat_id

The ON DELETE CASCADE from chats looks up rows by sender_chat_id alone,
which an index leading with organization_id cannot serve.
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