Skip to content

feat: add chat hook dispatch storage and hook columns#27427

Open
ibetitsmike wants to merge 1 commit into
mainfrom
mike/chat-hooks/db
Open

feat: add chat hook dispatch storage and hook columns#27427
ibetitsmike wants to merge 1 commit into
mainfrom
mike/chat-hooks/db

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Stack Context

First PR of the chat lifecycle hooks stack (replaces the oversized #27275 split). This stack lets deployments register an external webhook that observes and steers agent chat lifecycles (session_start, user_prompt_submit, pre/post_tool_use, stop, pre/post_compact, subagent spawn).

Stack: #27427 (this) -> #27401 (dispatch backend) -> #27428 (chatstate transitions) -> #27429 (chatd wiring) -> #27430 (API + UI).

What

  • Migration 000551: chat_hook_dispatches table (dispatch audit keyed by JWT jti) plus chats.hook_allowed_tools, chat_messages.turn_id, and chat_queued_messages.{turn_id,hook_prefix,hook_allowed_tools} columns.
  • sqlc queries for dispatch insert/finalize/replay, hook policy updates, and message content rewrite (refreshes search_tsv).
  • dbauthz policies + tests for the new querier methods, dbgen seeding, dbpurge retention (90 days, batched), audit table entry.
  • Minimal zero-value struct literals in chatstate so exhaustruct passes; behavior is unchanged (zero UUIDs map to NULL in the insert queries).

Why

Landing the schema first pins the migration number (no more renumber churn against main) and keeps the behavioral PRs above it review-focused. All columns and queries stay inert until #27429 wires dispatch.

Note for dev DBs that migrated the old branch-local 000551/000552: repair schema_migrations.version and _develop.applied_migrations, or use --db-reset.

This PR was prepared by Mux (AI agent) on Mike's behalf.

@github-actions

Copy link
Copy Markdown

Docs preview

Check 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.

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

ℹ️ 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/database/queries/chats.sql
Adds the chat_hook_dispatches table, hook_allowed_tools and turn_id
columns, sqlc queries, dbauthz policies, dbpurge retention, and the
audit table entry for the upcoming chat lifecycle hooks feature.
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@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: 5f61ea5544

ℹ️ 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/database/queries/chathooks.sql
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 5f61ea5544

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

DROP VIEW IF EXISTS chats_expanded;

ALTER TABLE chats ADD COLUMN hook_allowed_tools jsonb;
ALTER TABLE chat_messages ADD COLUMN turn_id uuid;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a new identifier on chat_messages? Is snapshot_version / history_version not sufficient? Would a monotonically incrementing integer be more efficient w.r.t storage versus a UUID?

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.

2 participants