feat: wire chat lifecycle hooks into chatd#27429
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 953ead293d
ℹ️ 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".
9fefafe to
e0b7344
Compare
953ead2 to
bbc1484
Compare
|
@codex review |
e0b7344 to
a05cf3c
Compare
bbc1484 to
d0f7244
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d0f7244efd
ℹ️ 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".
a05cf3c to
841eefb
Compare
d0f7244 to
5250a86
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5250a861a5
ℹ️ 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".
5250a86 to
e62369a
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e62369a8af
ℹ️ 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".
841eefb to
e08f7af
Compare
e62369a to
d835b06
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d835b06b87
ℹ️ 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".
d835b06 to
a3855c0
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a3855c04aa
ℹ️ 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".
e08f7af to
c6e5dff
Compare
a3855c0 to
08fb016
Compare
Docs previewCheck off each page once it's been reviewed. If a page changes in a later push, its checkbox clears automatically so it gets a fresh look. Pages not yet wired into the docs navigation aren't listed here. |
|
@codex review |
c6e5dff to
bc056cc
Compare
08fb016 to
8e776d7
Compare
|
@codex review |
bc056cc to
af39f14
Compare
8e776d7 to
cb5540c
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cb5540c9e0
ℹ️ 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".
af39f14 to
f9b2900
Compare
cb5540c to
4c02cf5
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4c02cf59e8
ℹ️ 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".
4c02cf5 to
265d881
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! 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". |
Dispatches session_start, user_prompt_submit, pre/post_tool_use, stop, pre/post_compact, and subagent spawn hooks from chatd, applies hook responses (prompt overrides, prefix notices, allowed-tools narrowing, stop nudges, compaction summary hints), persists dispatch effects transactionally with each step, and injects the dispatcher from coderd based on the new deployment configuration (hook URL, secret, timeout, experiment) documented in the admin setup doc.
f9b2900 to
4e9961b
Compare
265d881 to
8f4a766
Compare
|
@codex 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". |

Stack Context
Chat lifecycle hooks stack: #27427 (DB schema) -> #27401 (dispatch backend) -> #27428 (chatstate transitions) -> #27429 (this) -> #27430 (API + UI).
This is intentionally one PR: response application, allowed-tools narrowing, and the generation commit path are shared between lifecycle and tool/prompt hooks, so splitting them would force an artificial intermediate rewrite of
commitGenerationStep.What
Grouped by area:
Lifecycle engine (
hooks.go,generation.go,options.go)session_starton startup/resume/clear (once per process viasessionStartTracker),stopwith one nudge-continue per turn (stopNudgeTracker),pre_compact/post_compactaround compaction with summary hints (chatloop.SummaryHint).FinishErrorin the same transaction.Tool and prompt hooks (
hooks.go,chatd.go,generation_preparer.go)pre_tool_usepreflight for model-issued, pending-dynamic, and local tool calls: allow/deny/input-override decisions, duplicate tool-use ID rejection, denied results synthesized without execution.post_tool_useafter execution with tool responses.user_prompt_submiton send/edit/queued promotion: prompt overrides, deny with the hook reason (UserPromptDeniedError.Error()carries the hook's user message so non-HTTP callers such as subagent tools surface it too), queue-time deferral of hook effects, and title recomputation after overrides so redacted prompts never leak into titles.HTTP error mapping (
coderd/exp_chats.go)UserPromptDeniedErrorto 403 with the hook's user message, and dispatch failures to a 502ChatHookDispatchFailedResponsecarryingkind: hook_dispatch_failed.Subagent hooks (
subagent.go):user_prompt_submitfor child chat creation, fallback titles when hooks rewrite prompts, and spawn-tool dispatch failures propagate as errors (fail closed) instead of degrading into tool responses.File links after overrides (
coderd/exp_chats.go): create/send/edit link only file IDs still present in the persisted or queued content, so attachments dropped by a prompt override are never linked to the chat.Deployment config and wiring (
codersdk/deployment.go,coderd/coderd.go)--ai-chat-hook-url/secret/timeout/enabledbehind theagent-lifecycle-hooksexperiment, consumed here by the dispatcher construction incoderd.go(experiment gate warning included).docs/admin/setup/chat-lifecycle-hooks.md) plus generated CLI/API/type artifacts.ARCHITECTURE.mddocuments the hook flow and invariants.Why
This is the behavioral core of the feature: every hook event chatd emits, every response effect it honors, and the client-facing error semantics. The deployment configuration lives here rather than in #27401 so the options ship in the same PR as the code that reads them. Most of the diff is tests (dispatch ordering, deny/override matrices, compaction, stop nudges, subagent spawn, endpoint error mapping).