Repository navigation
fix(coderd/x/chatd): deliver a replayed message_agent message once - #282
Conversation
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8a698decdd
ℹ️ 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".
|
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Added organization scope to the replay records in 2487f77. @codex review |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
$> Coder Agents acted on behalf of @ibetitsmike.\n\nMerged main 5c34d7e (#280) with a merge commit, which was clean. A follow-up docs commit lists |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5efe64e722
ℹ️ 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".
…ded the message_agent call
|
$> Coder Agents acted on behalf of @ibetitsmike.\n\nPushed 314f266. It fixes the concurrent replay insert: on a failed send, the wrapper reads the record again and returns the recipient. A new test covers this. I answered the organization index finding: the index layout matches |
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Merged as 94caf1e (squash, Gates on head 314f266:
Not exercised: the new chatdmig node applying on the deployed server, and a real restart during a live message_agent batch. The same race in message_family_chat is filed as #287. |
Part of #252
Problem
When chatd stops in the middle of a tool batch, the next worker runs the whole batch again with the same tool call IDs. A
message_agentcall that had already delivered its message in that batch delivers it again, so the child gets the same message twice. The restart probe from #252 reproduced this onmain: the child received its NOTE twice.Fix
Behind
fork-nested-subagents, which owns the nested subagent tools:chatd.chat_subagent_messages(migration node01a1d6ec).idis the tool call ID, withorganization_id(copied from the sender chat, as inchat_family_messages),sender_chat_id,recipient_chat_idandcreated_at. Rows cascade on delete of either chat and of the organization.fork_message_agent_replay.gowrapsmessage_agent. A call with a tool call ID first looks up its row by(id, organization, sender). When the row exists, the call returns the recipient and sends nothing. Otherwise it runs the tool with the call ID in its context. When that send fails, the wrapper reads the row again and returns the recipient if another run of the same call recorded it meanwhile, for example a run that a takeover left going. The losing send rolls back on the primary key, so the message goes out once.sendSubagentMessagepasses aforkAdmithook. For a send from the wrapper, the hook inserts the row in the sameSendMessagetransaction that delivers the message, and deletes the sender's rows in its organization that are 24 hours old or older. Workflow steps call the same function without the context key and record nothing.ARCHITECTURE.mdlists the table and describes the mechanism next to the family message dedupe. The at least once paragraph listsmessage_agentandmessage_family_chatas replay safe.Tests
flock ~/.fork-go.lock go test ./coderd/x/chatd -run 'TestForkMessageAgentReplay$' -count=1: ok. With the wrapper line infork_tools.goremoved it fails withexpected: 1, actual: 2("a replay does not send again").flock ~/.fork-go.lock go test ./coderd/x/chatd -run '^TestForkMessageAgentReplay' -count=1 -v: both tests pass.TestForkMessageAgentReplayConcurrentRunrecords the call just before the real send runs. With the re-read disabled it fails with the duplicate key tool error.flock ~/.fork-go.lock go test ./coderd/x/chatd -run '(?i)(messageagent|message_agent|familymessage|subagent|family|spawn|archive)' -count=1 -v: ok, 156 top-level tests passed, none failed or skipped, includingTestChatFamilySurvivesRestart. The regex is grouped because Go splits-runon top-level|, so an ungrouped(?i)covers only the first alternative (fork-ci: Chat API tests step skips skill, MCP and plugin tests #286).flock ~/.fork-go.lock go test ./coderd/database/forkdb/... -count=1: ok, including the newTestChatSubagentMessagesagainst Postgres.flock ~/.fork-go.lock go test ./coderd/database/dbauthz -run TestForkQuerier -count=1: ok.flock ~/.fork-go.lock go test ./coderd/database/migrations/chatdmig/... -count=1: ok.flock ~/.fork-go.lock go test ./coderd/x/chatd -run '(?i)message|subagent|family|secret|workflow' -count=1: ok before the main merge. This ungrouped regex ran only part of the matching tests; the grouped run above is the full set.TestChatFamilyRestartReplaysMessageAgentOncecopied in temporarily,go test ./coderd/x/chatd -run 'TestChatFamilyRestartReplaysMessageAgentOnce$|TestChatFamilySurvivesRestart$' -count=2: ok. The probe is not committed here; it joins the harness from test(coderd/x/chatd): prove a busy chat family survives a chatd restart #279 once this lands.golangci-lint run --fix=falseon the changed packages: no findings in the changed files.Not covered
message_agentcalls without a tool call ID run as before. chatd always sets one for model tool calls.message_family_chathas the same check then insert pattern without the re-read, so a concurrent run of a family message reports a failure after the other run delivered it. That code is outside this PR.