Skip to content

feat: add forkdb for fork-only queries and the chat_subagents node - #25

Merged
ibetitsmike merged 5 commits into
mainfrom
mike/fork-foundation-1-forkdb
Nov 9, 2026
Merged

ibetitsmike merged 5 commits into
mainfrom
mike/fork-foundation-1-forkdb

Conversation

@ibetitsmike

Copy link
Copy Markdown
Owner

Part of #5

Xum opened this PR on behalf of @ibetitsmike.

Adds coderd/database/forkdb, the package for fork-only sqlc queries, so fork features can add tables and queries without touching dump.sql, queries.sql.go, querier.go or dbmock. The package, file names and APIs match draft PR #2, minus every plugin table, query, scope and route.

sqlc will not generate a package with zero queries, so this PR also adds the first fork table and one read query:

  • chatd graph node 01a1bd31-6117-7cbd-bb14-1a8ca7a596b3_chat_subagents creates chat_subagents (one row per tracked subagent chat; DDL from the plan, shared.1).
  • GetChatSubagentByChatID reads it. dbauthz authorizes it through the owning chat (ActionRead on the chat); dbmetrics times it; dbcrypt passes it through.

forkdb.From(db) unwraps the dbauthz, dbmetrics and dbcrypt wrappers to the raw store and wraps the fork querier back in the same order. forkdb.InTx runs fork and upstream queries in one transaction through the new ForkDBTX accessor.

CI: a new forkdb job in fork-ci fails when generate.sh output drifts from the committed code, and chat-tests now also runs ./enterprise/dbcrypt/....

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

Size: 822 added lines, about 666 hand-written

Generated: chat_subagents.sql.go, db.go, models.go, querier.go, forkdbmock/forkdbmock.go (156 lines). Of the rest, about 334 lines are tests. The wrappers, From and the tests that prove each wrapper unwraps only work together, so this stays one PR.

Validation
  • go build, go vet on the touched packages.
  • chatdmig check lists chat_subagents after the adopt node; chatdmig tests pass on Postgres.
  • generate.sh twice: 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/ ./coderd/database/forkdb/... ./coderd/database/dbauthz/ ./coderd/database/dbmetrics/ ./enterprise/dbcrypt/ on Postgres 17. Each new test fails when the behavior it covers is broken.
  • Remote UAT (dev server on a fresh database and on an upgraded fork main database): PASS on c4802d3262. The node applies once on upgrade, restarts apply nothing, user rows are unchanged, the table constraints behave as written, and /agents renders the same as on fork main. Later commits change tests only.

Add package forkdb, which runs fork-only queries generated by sqlc on the
connection or transaction of a database.Store and behind the dbauthz,
dbmetrics and dbcrypt wrappers. Add the first fork node, chat_subagents,
with one query, since sqlc refuses to generate with zero queries. Add a
fork-ci job that fails when forkdb generation drifts.
InTx had no test on this branch: PR #2's TestInTx needs plugin queries.
TestInTx checks that the fork queries run in the transaction of the
upstream queries and roll back with it.
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

@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-09T00:43:03.864789Z 99317f6 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.

@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: 99317f60ee

ℹ️ 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/dbauthz/fork_forkdb.go Resolved
@ibetitsmike
ibetitsmike merged commit b1f5f23 into main Nov 9, 2026
6 checks passed
@ibetitsmike
ibetitsmike deleted the mike/fork-foundation-1-forkdb branch November 9, 2026 01:00
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum (AI agent) merged this on behalf of @ibetitsmike after verifying the exact head 99317f6: fork-ci green (build, chat-tests, forkdb, graph, quiet, schema), 0 unresolved threads, and the three Codex findings dropped under the fork's scope rule. Merged as b1f5f23 after fork-main-33b0bb6ea9 deployed healthy.

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