Repository navigation
Conversation
…hooks chatd will run the user_prompt_submit hooks when a turn starts from a message that has prompt_hooks_pending set. This adds the queries that step needs. ResolveChatMessagePromptHooks clears the flag and either rewrites the content or soft-deletes the message. InsertChatMessages and InsertChatQueuedMessageWithCreator carry the flag, and UpdateChatQueuedMessageContent clears it because an edit runs the hooks on the new content. Both soft deletes clear the flag, so a deleted row never blocks the down migration. ClearChatMessagesPromptHooks serves a context reset. _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_
…solvePromptHooks A message keeps its prompt_hooks_pending flag when it moves from the queue into history, so chatd can run the hooks when the message starts a turn. ResolvePromptHooks is the transition that clears the flag and rewrites or soft-deletes the message. It runs from R0, R1 and R1P and does not change the status. A flagged row must be a user message visible to the user and the model, because chatd looks for flagged rows in the history the user sees. ClearContext clears the flags of the rows it hides, since those messages never start a turn. _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_
…flagged message When a generation step finds a message with prompt_hooks_pending set, it runs the user_prompt_submit hooks first, outside any transaction, and one short transaction applies the result and clears the flag. A rewrite replaces the content, a denial deletes the message and fails the chat with kind hook_denied in the same transaction, and a failure that is not a denial fails the chat and keeps the message. With hooks off the flag is cleared and the message stays as saved. If a worker dies before the transaction commits, the flag is still set and the next worker runs the hooks again. Nothing sets the flag yet, so no existing chat is affected. A manual title no longer sends a message that still waits for its hooks to a model. _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_
…utomations-prompt-hooks
…repeat a behavior The history query skips deleted rows, so a flagged message is never deleted. Each removed test is covered by a test that a mutant of the product code turns red alone.
…very prompt Reading the prompt query for the title and summary generators sent a flagged message to a model before its hooks ran. The query now skips it. Also drop the content version input and the context boundary skip that no path can reach, and describe the transition in the state diagram.
…utomations-prompt-hooks
…utomations-prompt-hooks
|
@codex review |
|
@codex security 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. |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
|
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". |
…s to a flagged message
…cks two tests repeat
|
@codex review |
|
@codex security review |
|
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". |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
…ssion share instead of copying it
…utomations-prompt-hooks
|
@codex review |
|
@codex security 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 Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
Why
Part of the Automations RFC (CODAGT-1135). An automation will publish a message into a chat on behalf of a webhook or a schedule. That message never goes through the HTTP send path, so its
user_prompt_submithooks do not run there. The RFC has chatd run them when the message starts a turn, keyed only on theprompt_hooks_pendingflag, so chatd needs no knowledge of automations.Stacked on #32067. Review only this diff. It merges after #32067.
This PR teaches chatd that one thing. Nothing sets the flag yet (the publish path is a later PR), so every chat behaves as before.
What changed
prompt_hooks_pendingset. With lifecycle hooks off it only clears the flag. Otherwise it dispatchesuser_prompt_submitoutside any transaction, then applies the result in one short transaction through a newResolvePromptHookstransition and ends the task. The history change starts the next task, as after a steer delivery.hook_deniedand the hook's user message, in the same transaction, so a crash cannot leave the message deleted and the chat running. Messages queued behind it stay queued.hook_dispatch_failed, like the other generation-time hooks. The hooks run again when the chat resumes. A worker that dies before the transaction commits, or loses its lease, leaves the flag set, so the next worker runs the hooks again.ClearContextclears it, so no stale flag blocks the down migration.GetChatMessagesForPromptByChatIDskips it, and so does the manual title path.Scope
automation_idor any automation, no experiment, no SDK fields.Tradeoffs
Blast radius
Every chat turn now scans its loaded history for the flag at every step. With the flag false the step is unchanged, and a test pins that a human message runs its hooks once, not again at turn start. The prompt query gains one
AND prompt_hooks_pending = falsefilter. The two soft-delete queries andClearContextalso clear the flag. While nothing sets the flag, those writes change no row.Live check
Built
./enterprise/cmd/coder, rancoder serverwithagent-lifecycle-hooks, the stockscripts/agenthooks-server(and a throwaway denying consumer) and a fake OpenAI server, and set the flag by SQL: allow, rewrite, denial (chat errorhook_denied, the model got no request), a human turn with the flag false (one hook call), and hooks off (flag cleared, no hook call) all behaved as above.ARCHITECTURE.md prose was drafted by an agent at the user's request; the user will review it.
Generated with
xum• Model:anthropic:claude-sonnet-5-5• Thinking:xhigh