Skip to content

pstack W0a: forkdb foundation #5

Closed

Description

@ibetitsmike

Xum created this issue on behalf of @ibetitsmike.

Part of #4.

Workspace brief from the pstack parity plan (local plan page "Running pstack on the Coder Agents Fork"; the PRD is local to Mike's Mac and not reproduced here). Claim numbers such as 1.3 or shared.2 refer to the plan page.

This issue is W0a: items 1 to 4 of the W0 brief below, on mike/fork-foundation. Item 5 is W0b.

W0 · Foundation (runs as W0a and W0b)

W0a builds items 1 to 4 on mike/fork-foundation. W0b brings the upstream stacks (item 5) on mike/fork-upstream-stacks. They run in parallel.

Task. Build the fork base that every feature workspace uses, then stop.

Background. The fork keeps Coder Agents tables in a chatd schema with graph-ordered nodes (coderd/database/migrations/chatdmig/README.md). The README reserves coderd/database/forkdb for fork queries; fork main does not have the package yet (README.md:192-195).

Scope (W0a, stack of about 5 PRs).

  1. forkdb package, taken from PR feat: add chat plugins backed by a chatd fork node #2: sqlc.yaml that reads ../dump.sql and then the nodes in graph order, a generate target, a Store interface, and an authz wrapper that loads the owning chat through dbauthz first. A test fails when a forkdb method has no authz check.
    • Transaction accessor: fork files in coderd/database, dbauthz and dbmetrics that unwrap a database.Store (also the one InTx passes) to its DBTX, so forkdb.New(tx) joins the upstream transaction. Callers: child creation (chatstate.CreateChatWithID, subagent_operations.go:465), Admit (agentadmission.go:28), wake-up claims, archive cleanup.
  2. First node chat_subagents (plan shared.1): chat_id, agent_type, depth, isolation, worktree_path, branch, workspace_id. No backfill: a chat with no row is a legacy shared child of its built-in type.
  3. Hooks: p.appendForkTools(...) after turn_environment.go:737; registerForkChatRoutes in coderd/chat_routes.go:17; a fork renderer spread in toolRenderers (Tool.tsx:1178); one composer slot; codersdk/fork_experiments.go with init() that appends to ExperimentsKnown (deployment.go:5562).
  4. fork-ci jobs: forkdb generate drift, go test ./agent/agentcontext/... ./agent/agentgit/..., site tsc and vitest for src/pages/AgentsPage. Current jobs are only graph, schema, chat-tests, build.

Scope (W0b, 3 PRs).

  1. Upstream stacks (plan shared.5, decision upstream = merge): one PR per stack that merges the stack's top branch from coder/coder into fork main, as upstream wrote it. The PR description lists the upstream PRs and head SHAs it contains.

Starting points. chatdmig/README.md, chatdmig/graph.go, coderd/database/migrations/fork_chatd.go, coderd/database/dbauthz/dbauthz.go:6513, coderd/coderd.go:2656 (ReadExperiments), .github/workflows/fork-ci.yaml.

Acceptance.

  • chatdmig check passes and lists the new node after the adopt node.
  • sqlc parses the node files (-- requires: headers are comments) and forkdb generation is clean in CI.
  • With every fork experiment off, a test shows appendForkTools returns the tool list unchanged and fork routes return 404.
  • git diff main -- coderd/database/dump.sql coderd/database/queries.sql.go coderd/database/querier.go coderd/database/dbmock is empty.
  • A test rolls back a transaction that wrote both a chat and its chat_subagents row and finds neither.
  • Each stack merge PR passes fork-ci and is merged with a merge commit, like sync PRs (chatdmig/README.md:208), so later merges of the same branch bring only new commits. chatdmig check lists the routed 000640 node.

Deliverables. Merged PR stack; a short "how to add a fork table and query" section appended to chatdmig/README.md.

Constraints. No fork feature behavior; item 5 brings upstream code as upstream wrote it. Keep every hook to one line or one call in the upstream file.


Rules for every workspace

Topic Rule
Runner One Xum workspace per brief (W0 runs as W0a and W0b), started from fork main at its wave start. Every implementation runs implement-flow with the workstream issue as its input and the brief as the plan.
Branches mike/<topic> for the workspace; stacked PR branches mike/<topic>-<n>-<slug>. Local name equals remote name. Never push to main.
PR size 500 changed lines at most per PR, generated code excepted (reviewer-friendly-pr). Stack with gh stack; the extension is not installed on the Mac today (gh extension install github/gh-stack), else use explicit-base PRs.
Schema Fork tables are chatd graph nodes: go run ./coderd/database/migrations/chatdmig/cmd/chatdmig new <name> -requires <node or upstream:name>. Never edit a node that ran. No edits to dump.sql, queries.sql.go, querier.go, dbmock or numbered migrations.
Queries coderd/database/forkdb only (created by W0). Every method goes through the forkdb authz wrapper. A forkdb write that belongs with an upstream write runs in the same transaction, through the W0 accessor (database.Store exposes only InTx, coderd/database/db.go:22-31).
Authorization Chat-owned rows authorize through the owning chat (dbauthz.go:6513-6522 pattern). Agent and plugin rows reuse the skill RBAC objects. No new RBAC resources, no new API key scopes. Tools run as the chatd subject, which can read and update every chat (dbauthz.go:807-817): a tool that touches a chat other than its own runs as the owner (asOwner, chattool/listtemplates.go:437-443).
Upstream files One hook line per hot file (plan shared.2). Logic lives in new fork files. Hot files: turn_environment.go, chatd.go, subagent*.go, codersdk/chats.go, deployment.go, dbauthz.go, chat_routes.go, AgentChatInput, AgentChatPageView.
Open upstream PRs If a workspace needs an open coder/coder PR, W0 or W7 merges its branch into the fork with a merge commit. Its migrations go through chatdmig route into the chatd schema. Sync conflicts are solved later (Mike, 2026-11-08).
Flags Each feature is behind its fork-* experiment in codersdk/fork_experiments.go. With the flag off, tool lists, routes and UI match upstream.
API Swagger annotations on new public endpoints. Audited types update enterprise/audit/table.go.
chatd docs coderd/x/chatd/ARCHITECTURE.md gets TODO lines only. Mike writes the text.
Validation Go suites run in Colima: a postgres:17 container, plus golang:<go.mod version>-bookworm --network container:<pg> with volumes coder-gen-gomod and coder-gen-gocache and postgresql-client-17 from PGDG. chatdmig tests use CHATDMIG_TEST_DATABASE_URL='postgres://[email protected]:5432/postgres?sslmode=disable'. Never create a postgres role on the live Postgres. Frontend: site/AGENTS.md commands plus frontend-deep-review for any site/ diff.
Review implement-flow ends with codex-review-loop; Codex is installed (2026-11-08). If @codex review gets no reply within 30 minutes, tell the lead and run code-quality-review with Opus until Codex answers. Mike (2026-11-09): fix real defects in the PR's own change; drop scope creep and defensive bikeshedding with a one-line reply and a resolved thread, no follow-up issue. Upstream is only a sync source: never report or file anything upstream.
UAT coder-agents-uat through Coder MCP on the local deployment (http://127.0.0.1:3000, templates devcontainer or docker, RUNBOOK "Running a branch in a dev container workspace"). The remote agent runs scripts/develop.sh for the branch inside its workspace (plan decision uat). Never coder-local use a branch build: that replaces Mike's daily server.
Ready When a PR meets the merge bar, send the lead (task_send_message to 8ac7791132) READY #<pr> <head sha> with the CI, Codex, UAT and open-thread evidence, then wait. Never merge yourself.
Merge The lead merges (Mike, 2026-11-08). Merge bar: green fork-ci on the exact head, a clean Codex verdict, or Codex findings that were all fixed or dropped under the scope rule (the lead confirms each drop), no unresolved threads, UAT PASS on the head or on a SHA whose later commits only answer review, and a lead review of the diff against the brief. Squash, except sync and upstream stack PRs, which take a merge commit. A merge to fork main deploys Mike's daily server through autodeploy within about 5 minutes plus a drain of up to 30 minutes, so the lead merges one PR at a time and waits until Fork ops reports the deploy healthy. Experiments stay off on that server until Mike enables them.
Follow-ups A defect in merged code or on the daily server becomes an issue in ibetitsmike/coder with label followup. Fork ops triages it; an accepted one gets its own workspace running implement-flow.

Activity

  1. added
    pstack-parity
    on Nov 8, 2026
  2. ibetitsmike commented on Nov 8, 2026

    @ibetitsmike
    OwnerAuthor

    Xum wrote this comment on behalf of @ibetitsmike.

    Notes from the PR #2 author (head 7bff5a104a, forkdb landed in commit 35a62a01e7), to verify while splitting forkdb out:

    • Plugin-specific, leave out: forkdb/apikeyscopes.go (plugin API key scopes and ValidAPIKeyScope, used by coderd/apikey/apikey.go), forkdb/queries/plugins.sql and plugins.sql.go, forkdb/modelmethods.go (plugin RBAC objects), the chatdmig plugins node, and enterprise/dbcrypt/fork_forkdb.go (it overrides 6 plugin config queries; a generic version would only embed forkdb.Store).
    • Generic but coupled to plugin code, adapt them: dbauthz/fork_forkdb.go (the forkQuerier checks are per query), dbauthz/fork_forkdb_test.go plus a 4-line skip of ForkUnwrap/ForkWrap in upstream TestDBAuthzRecursive, scripts/check-scopes/fork.go (reads ALTER TYPE api_key_scope ADD VALUE from chatdmig nodes), and forkdb_test.go (TestSQLCSchemaOrder, TestFrom and TestInTx are generic, TestAPIKeyScopeValues is not).
    • sqlc generation fails when no queries file has a query, so the first PR needs a real query (the chat_subagents node) or a placeholder.
    • PR feat: add chat plugins backed by a chatd fork node #2 will rebase onto this work once it is on main.
  3. ibetitsmike commented on Nov 9, 2026

    @ibetitsmike
    OwnerAuthor

    Xum posted this on behalf of @ibetitsmike.

    W0a status: opened #25 (PR 1 of the foundation stack: forkdb package, chat_subagents node, GetChatSubagentByChatID, fork-ci drift job) at 99317f60ee. Remote UAT PASS on c4802d3262; later commits change tests only. Codex review requested.

  4. ibetitsmike commented on Nov 9, 2026

    @ibetitsmike
    OwnerAuthor

    Xum posted this on behalf of @ibetitsmike.

    W0a status: #25 is READY at 99317f60ee: fork-ci green on the head, Codex reviewed (3 findings dropped under the scope rule, threads resolved), UAT PASS on c4802d3262 with test-only commits after it. Waiting for the lead to merge.

  5. ibetitsmike commented on Nov 9, 2026

    @ibetitsmike
    OwnerAuthor

    W0a status: PR 2 of the stack is open as #26 (InsertChatSubagent, head 12b4d48cfd), rebased onto main after #2 merged. Codex review requested; PR 3 (Go hooks) is committed locally and follows once #26 is READY.

    Xum posted this comment on behalf of @ibetitsmike.

  6. ibetitsmike commented on Nov 9, 2026

    @ibetitsmike
    OwnerAuthor

    W0a status: PR 3 of the stack is open as #27 (fork hooks for chat tools, chat routes and experiments, head 40a073c935). It is based on main and independent of #26. Codex review requested.

    Xum posted this comment on behalf of @ibetitsmike.

  7. ibetitsmike commented on Nov 9, 2026

    @ibetitsmike
    OwnerAuthor

    W0a status: #26 is READY for the lead at 1356ff9633 (fork-ci green, Codex clean). #27 has a clean Codex verdict at bc6508af5b and is in UAT. #28 (fork-ci jobs and the README how-to) is open and merges after #27. The frontend hooks PR is in implementation.

    Xum posted this comment on behalf of @ibetitsmike.

  8. ibetitsmike commented on Nov 9, 2026

    @ibetitsmike
    OwnerAuthor

    W0a status: opened #30 (frontend hooks: forkToolRenderers spread in Tool.tsx, ForkComposerSlot in AgentChatInput.tsx). #26 is merged. In #27, UAT found that anonymous /chats/fork/* returned 404 instead of 401; that is fixed in fc9fb28 and UAT round 2 is running. #28 is Codex clean and waits on #27.

    Xum posted this comment on behalf of @ibetitsmike.

  9. ibetitsmike commented on Nov 9, 2026

    @ibetitsmike
    OwnerAuthor

    W0a status: #25, #26, #27 and #28 are merged. #30 (frontend hooks) is READY at 133bfc6: fork-ci green including the new site job, Codex clean, UAT passed with the UI identical to main. Open item for @ibetitsmike: two TODO(ibetitsmike) comments in coderd/x/chatd/ARCHITECTURE.md (the /chats/fork mount and appendForkTools).

    Xum posted this comment on behalf of @ibetitsmike.

  10. ibetitsmike commented on Nov 9, 2026

    @ibetitsmike
    OwnerAuthor

    W0a final status: the foundation stack is merged.

    Every PR merged with green fork-ci on its exact head, a clean Codex review, no unresolved threads, and UAT (N/A for the CI-only #28). Open item for @ibetitsmike: two TODO(ibetitsmike) comments in coderd/x/chatd/ARCHITECTURE.md (the /chats/fork mount and appendForkTools).

    Xum posted this comment on behalf of @ibetitsmike.

  11. ibetitsmike commented on Nov 15, 2026

    @ibetitsmike
    OwnerAuthor

    Coder Agents acted on behalf of @ibetitsmike.

    Closing as done, per Mike's decision on #219 (2026-11-15). Every PR this issue lists is merged; evidence: #4 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pstack-parity

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions