Skip to content

feat(coderd/database): add the InsertChatSubagent fork query - #26

Merged
ibetitsmike merged 2 commits into
mainfrom
mike/fork-foundation-2-chat-subagent-insert
Nov 9, 2026
Merged

ibetitsmike merged 2 commits into
mainfrom
mike/fork-foundation-2-chat-subagent-insert

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

Part of #5

Xum opened this PR on behalf of @ibetitsmike.

Adds InsertChatSubagent, the first fork write query, so the subagent work can record a row in chat_subagents when it creates a child chat.

  • dbauthz authorizes it as an update of the owning chat (ActionUpdate on the chat), like InsertChatDebugRun.
  • dbmetrics times it; dbgen.ChatSubagent inserts a row for tests.
  • TestInsertChatSubagent writes every column, reads the row back, and checks that a second row for the same chat is a unique violation.
  • TestInTx/RollbackChatSubagent writes a chat and its subagent row in one forkdb.InTx transaction, rolls it back, and finds neither.

No user-visible behavior changes: nothing calls the new query yet.

Size: 185 added lines, about 130 hand-written

Generated: chat_subagents.sql.go, querier.go, forkdbmock/forkdbmock.go (55 lines). About 88 lines are tests.

Validation
  • go build ./coderd/..., go vet on the touched packages, git diff --check.
  • chatdmig check; chatdmig tests pass on Postgres.
  • generate.sh: no drift. git diff origin/main -- coderd/database/dump.sql coderd/database/queries.sql.go coderd/database/querier.go coderd/database/dbmock is empty.
  • go test ./coderd/database/forkdb/... ./coderd/database/dbauthz/ ./coderd/database/dbmetrics/ ./coderd/database/dbgen/ ./enterprise/dbcrypt/ on Postgres 17.
  • Negative controls: making forkdb.InTx build its fork store from the outer database instead of the transaction fails every TestInTx subtest; swapping worktree_path and branch in the insert fails TestInsertChatSubagent; authorizing with ActionRead fails TestForkQuerier/InsertChatSubagent.
  • Remote UAT: PASS on 56aabd9f12, the same change before the rebase onto main after feat: add chat plugins backed by a chatd fork node #2 merged.
Code diff between the UAT SHA and the head

git range-diff pairs no commits, because the tests changed. Comparing the added and removed lines of the non-test files (queries/chat_subagents.sql, chat_subagents.sql.go, querier.go, forkdbmock, and the fork_forkdb.go files of dbauthz, dbmetrics and dbgen) between 99317f60ee..56aabd9f12 and c479170b46..1356ff9633, the only differences are:

  • The InsertChatSubagent doc comment in dbauthz now ends "like InsertChatDebugRun".
  • dbgen/fork_forkdb.go and the policy import in dbauthz already exist on main from feat: add chat plugins backed by a chatd fork node #2, so the head adds only the function bodies.
  • Blank lines between functions moved with the insertion point.

The query SQL, the generated code, the authorization check and the dbmetrics wrapper are the same. Tests: the UAT SHA carried chatdmig equivalence tests and a TestInTx rewrite, which #2 replaced on main; the head adds TestInsertChatSubagent and TestInTx/RollbackChatSubagent instead.

Authorizes as an update of the owning chat, like InsertChatDebugRun.
Adds dbgen.ChatSubagent and a database test that a chat takes one
subagent row and reads it back.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 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-09T04:01:28.684740Z 1356ff9 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.

@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum posted this comment on behalf of @ibetitsmike.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 12b4d48cfd

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

…ogether

The W0a acceptance asks for a test that a rolled-back transaction which
wrote a chat and its chat_subagents row leaves neither.
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum posted this comment on behalf of @ibetitsmike.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 1356ff9633

ℹ️ 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 d4e1dfc into main Nov 9, 2026
9 checks passed
@ibetitsmike
ibetitsmike deleted the mike/fork-foundation-2-chat-subagent-insert branch November 9, 2026 04:19
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum (AI agent) merged this on behalf of @ibetitsmike as d4e1dfc (squash, head 1356ff9). Before merging, Xum checked fork-ci on the exact head, the clean Codex review on 1356ff9, 0 unresolved threads, the UAT pass with the UAT-to-head diff in the description, and that c479170 (#23) was deployed healthy first.

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