Skip to content

feat: add organization scoping to chats#23827

Merged
johnstcn merged 52 commits into
mainfrom
cian/chat-org-scoping
Apr 13, 2026
Merged

feat: add organization scoping to chats#23827
johnstcn merged 52 commits into
mainfrom
cian/chat-org-scoping

Conversation

@johnstcn

@johnstcn johnstcn commented Mar 30, 2026

Copy link
Copy Markdown
Member

Fixes coder/internal#1436

Chats were user-scoped only (owner_id). This adds organization_id to align with the site → org → user RBAC convention.

Changes

  • Migration 000466 adds organization_id NOT NULL to chats with 3-tier backfill (workspace org → user org membership → default org)
  • Chat.RBACObject() includes .InOrg(), ConfigChats() uses NoACLConverter()
  • CreateChatRequest requires organization_id, handler validates membership and rejects cross-org workspace binding
  • create_workspace tool validates template org matches chat org before calling CreateFn
  • Frontend AgentCreateForm uses controlled OrganizationAutocomplete (auto-selects for single-org users)
  • chatd.CreateOptions and subagent creation propagate org ID
  • All tests updated for org-scoped chat resources
  • Docs updated with organization_id in chats-api.md
Implementation plan & decision log

Key design decisions

  1. Org required at creation time — chats start with no workspace (bound later during chat loop), so we can't derive org from workspace at creation. Caller must provide organization_id.
  2. Cross-org validation — when a workspace is bound to a chat, we validate workspace.organization_id == chat.organization_id to prevent mismatches. The create_workspace tool also validates template org before calling CreateFn.
  3. Backfill strategy — primary path joins workspaces table (all workspaces have org). Fallbacks for deleted workspaces: user's oldest org membership (ORDER BY created_at ASC), then default org.
  4. Frontend — controlled OrganizationAutocomplete component (refactor(site): convert OrganizationAutocomplete to fully controlled component #24211). Auto-selects first org, dropdown for multi-org.
  5. RBAC modelResourceChat stays in OrgMemberPermissions (not excluded). The Member level in Rego is owner-scoped (subject.id == object.owner), so org members can only CRUD their own chats — same as workspaces. agents-access role gates chat creation at the handler level.
  6. Pre-check shapepostChats uses ResourceChat.WithOwner() without .InOrg() for the agents-access role gate (intentional belt-and-suspenders).

Scope boundaries

  • Only chats table gets organization_id. Child tables (messages, queued messages, diff statuses) inherit through FK.
  • chat_providers and chat_model_configs remain deployment-wide.
  • Chat is not auditable — no enterprise/audit/table.go changes.

🤖 Written by a Coder Agent. Will be reviewed by a human.

@johnstcn johnstcn changed the title [DNM] feat: add organization scoping to chats feat: add organization scoping to chats Mar 30, 2026
Chats were previously user-scoped only (owner_id). This adds
organization_id to the chats table so they align with the
existing site → org → user RBAC convention.

Key changes:
- Migration adds organization_id NOT NULL to chats with 3-tier
  backfill (workspace org → user's org membership → default org)
- RBAC: Chat.RBACObject() now includes .InOrg(), ChatConverter
  uses organizationOwnerMatcher(), org admins gain chat access
- API: CreateChatRequest requires organization_id, validates
  membership, rejects cross-org workspace binding
- Frontend: AgentCreateForm gets OrganizationAutocomplete picker
  (auto-selects for single-org users)
- chatd: CreateOptions and subagent creation propagate org ID
- All tests updated for org-scoped chat resources
The enterprise chatd test helpers (seedChatDependencies,
seedWaitingChat, seedRemoteRunningChat) now create an
organization and pass organization_id through to all
CreateOptions and InsertChatParams call sites.
Capture firstUser from coderdenttest.New and pass
firstUser.OrganizationID to all CreateChatRequest calls.
@johnstcn johnstcn force-pushed the cian/chat-org-scoping branch from 53722e0 to 8aec990 Compare March 30, 2026 22:48
Comment thread coderd/database/migrations/000467_chat_organization_id.up.sql
Comment thread coderd/database/queries/chats.sql Outdated
Fixes querier_test, chatprompt_test, chattool/startworkspace_test
and remaining chatd_test InsertChatParams that were missing the
new required organization_id field.
ChatConverter now uses organizationOwnerMatcher() instead of
the hardcoded empty string, so the expected SQL in compile
tests must reference organization_id :: text instead of ''.
Also renamed ChatOrgScopedNeverMatches to ChatOrgScopedMatches
since org-scoped queries now actually match.

@johnstcn johnstcn left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Self-review via deep-review skill (9 parallel reviewers). The compile_test P0 is already fixed in the latest push. Remaining items are test coverage gaps and a migration nit.

1 P1 (test coverage), 3 P2, 2 Obs, 2 Nits across 6 inline comments.

This review contains findings that may need attention before merge.

Comment thread coderd/exp_chats.go
Comment thread coderd/database/migrations/000467_chat_organization_id.up.sql
Comment thread coderd/rbac/roles_test.go
Comment thread coderd/database/migrations/000467_chat_organization_id.up.sql
Comment thread coderd/rbac/regosql/configs.go
Comment thread site/src/pages/AgentsPage/components/AgentCreateForm.tsx Outdated
- Add OrganizationID to all 51 CreateChatRequest callsites in
  exp_chats_test.go (CI blocker)
- Migration: add ORDER BY for deterministic backfill, add index
  on chats.organization_id
- Consolidate identical ChatConverter into NoACLConverter
- Fix stale 'not org-scoped' comment in querier_test.go
- Pre-select default org in AgentCreateForm picker
- Renumber migration 000457 -> 000458 (000457 now taken by
  chat_access_role on main)
- Merge RBAC test: agentsAccessUser goes to false set since it
  has no org role for org-scoped chats
- Merge exp_chats_test: keep agents-access member pattern from
  main, add OrganizationID
- Merge querier_test: keep agents-access role, add org member
…g test callsites

The great purge of 2026: 25 InsertChatParams and 2 CreateChatRequests
walk into a bar. The bartender says 'Where's your OrganizationID?'
They all get bounced by the FK constraint bouncer.

- db2sdk_test: TestChat_AllFieldsPopulated now populates all fields (shocking)
- dbauthz_test: InsertChat RBAC assertion includes .InOrg() (as it should)
- chatparam_test: TestChatParam/Found creates an actual org before inserting
- gitsync/worker_test: TestWorker gets its own org to play with
- exp_chats_test: 25 InsertChatParams + 1 CreateChatRequest get their papers
- mcp_test: CreateChatRequest finally declares its organizational allegiance
@johnstcn johnstcn force-pushed the cian/chat-org-scoping branch from 69fc07d to 1984d10 Compare March 31, 2026 11:41
…ast straggler

Two issues:
1. The UsageLimitExceeded test's InsertChatParams at line 510 was
   the world's best hide-and-seek champion — survived two rounds
   of grep due to a nearby OrganizationID in a different struct
   within the 15-line scan window.

2. OrgMemberPermissions excluded ResourceChat from the site-level
   member role but NOT from the org-level member permissions. With
   chats now org-scoped via .InOrg(), org members got implicit chat
   access through their member permissions — a privilege escalation
   that would make any security reviewer's eye twitch.
@johnstcn johnstcn force-pushed the cian/chat-org-scoping branch from 1984d10 to ba3c756 Compare March 31, 2026 11:53
The _ in 'user, _, model' was doing a fine job ignoring the org,
right up until CreateChat politely refused to exist without one.

@johnstcn johnstcn left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Round 2 deep review (6 parallel reviewers). Prior P2s for ORDER BY, index, and ChatConverter consolidation all verified fixed.

2 P2, 1 P3, 1 Obs across 4 inline comments. Overall this is in good shape — the RBAC model change is well-reasoned and the migration is solid.

review meme

Comment thread coderd/exp_chats.go
Comment thread coderd/rbac/roles_test.go Outdated
Comment thread site/src/pages/AgentsPage/components/AgentCreateForm.tsx
Comment thread coderd/rbac/authz.go
johnstcn added 2 commits April 1, 2026 17:04
Covers the primary user path: a regular org member accessing
their own org-scoped chat. Previously only owner and orgAdmin
were in the true list, leaving the most common access pattern
validated only by integration tests.
Three new subtests in TestPostChats covering the org validation
code paths that previously had zero direct test coverage:

- NilOrganizationID: uuid.Nil → 400
- NonMemberOrganization: wrong org → 403
- CrossOrgWorkspaceMismatch: workspace in org A, chat for org B → 400

johnstcn commented Apr 1, 2026

Copy link
Copy Markdown
Member Author

🤖 Design decisions noted from deep review round 2 (not actionable in this PR):

  • Org admin chat visibility: Intentional consequence of org scoping — org admins gain read/write on all chats in their org. This is consistent with other org-scoped resources (templates, workspaces). Worth calling out in release notes when this ships.

  • ON DELETE CASCADE on org FK: Deleting an org cascades to all its chats. Matches how other org-scoped FKs work (workspaces, templates). If chat data retention becomes a product requirement, revisit with ON DELETE RESTRICT.

  • create_workspace tool cross-org gap: The tool binds a workspace to a chat without validating cross-org consistency. This is pre-existing (the tool predates org scoping) and should be tracked as a follow-up.

  • Pre-check shape mismatch: The handler pre-check at line 396 authorizes ResourceChat.WithOwner() (no .InOrg()) while the DB insert checks the full org-scoped object. This is intentional belt-and-suspenders: the pre-check gates the agents-access feature, the DB layer enforces org-level authorization.

  • Backfill COALESCE edge case: All three branches can theoretically return NULL if no default org exists and the user has no org membership. In practice, Coder always has a default org. No action needed.

johnstcn added 4 commits April 9, 2026 13:28
… fix new callsites

Main added 202 commits including dynamic tools, system prompts,
chat files, recording, purge tests, and telemetry tests — all
with new InsertChatParams/CreateChatRequest/CreateOptions structs
that needed OrganizationID.
The RefreshesStaleStatusWithExternalAuth test was deleted on main in
7861fcf (inline diff resolution removed in favor of background
gitsync), but our merge conflict resolution accidentally brought it
back from the dead. Remove the zombie test and its orphaned imports.
TestChatMessageWithFiles/FilesLinkedOnSend and
TestPatchChatMessage/FilesLinkedOnEdit were missing OrganizationID
in their CreateChatRequest calls — stragglers from the main merge.
…pace creation

The create_workspace tool could silently bind a workspace from org A
to a chat scoped to org B. Now it looks up the template's org before
calling CreateFn and returns a tool error if they don't match.

Closes the cross-org gap noted in the deep review.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 55 out of 56 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread coderd/rbac/regosql/compile_test.go

@mafredri mafredri left a comment

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.

Panel re-review (round 4). 5 reviewers: Bisky, Mafuuu, Kurapika, Meruem, Zoro (wildcard). Netero first pass.

All R3 findings resolved. agents-access gates added to both promoteChatQueuedMessage and postChatToolResults. Em-dashes replaced. OrganizationID assertion added to child chat test. Clean fix commit with no scope drift.

Kurapika verified the full authorization model and found no additional security issues. Mafuuu traced the contract end-to-end and confirmed all entry points enforce the org constraint. Meruem verified no TOCTOU gaps in the org membership check (template org is immutable, membership revocation is caught by dbauthz).

Two convergent P3 findings: the new agents-access gates on promoteChatQueuedMessage (line 2143) and postChatToolResults (line 5869) have no corresponding tests. The identical pattern on postChatMessages does (line 4128). (Netero, Kurapika, Meruem)

Meruem notes ChatOwnerMe at compile_test.go:288 now tests a SQL clause (organization_id :: text = '') that can never match a row post-migration. The test validates compilation correctness but the compiled SQL is vestigial. Consider a comment noting this path is dead at the data level.

Bisky notes GetAuthorizedChats at querier_test.go:1355 only tests the negative case (cross-org admin sees 0 chats). No test confirms a same-org admin sees chats. The RBAC unit test covers the policy, but the SQL filter generator path is untested for the positive case.

"Five-line null check equivalent to newOrg?.id !== selectedOrg?.id. The five-line version obscures the intent without handling any edge case the one-liner misses." (Zoro)

Severity count: 2x P3 (missing gate tests), 3x P3 (frontend), 2x Nit. 3 dropped as P4.


site/src/pages/AgentsPage/AgentCreatePage.tsx:33

P3 Workspace dropdown shows workspaces from all organizations, not filtered by the selected org. (Mafuuu)

workspacesQuery uses workspaces({ q: "owner:me", limit: 0 }) which fetches every workspace the user owns across all orgs. When the user changes the org picker, handleWorkspaceChange(null) clears the selection but does not re-filter the options. A user can select Org A, pick a workspace from Org B, and submit. The server returns 400 but the error message requires org/workspace knowledge to diagnose.

Filter workspaceOptions by the selected org, or pass organizationId into the query.

🤖

coderd/rbac/roles.go:448

Nit Comment says "Without this role, members cannot create or interact with chats" but org members CAN read, update, and delete their own chats via OrgMemberPermissions (verified by OrgMemberWithoutAgentsAccessCanAccessOwnChats). (Meruem)

roles.go defines the RBAC model. A developer reading this comment would conclude agents-access is the sole gate for chat interaction, which is false at the RBAC layer. The handler-level gates are the actual enforcement for creation and inference.

🤖

🤖 This review was automatically generated with Coder Agents.

Comment thread coderd/exp_chats.go
Comment thread coderd/exp_chats.go
Comment thread site/src/pages/AgentsPage/components/AgentCreateForm.tsx Outdated
Comment thread site/src/pages/AgentsPage/components/AgentCreateForm.tsx Outdated
Comment thread site/src/pages/AgentsPage/components/AgentCreateForm.tsx Outdated
Backend:
- Add MemberWithoutAgentsAccess tests for promoteChatQueuedMessage and
  postChatToolResults handlers (both had gates but no test coverage)
- Add descriptive comments to templateAdmin and userAdmin role entries
  to match the style of neighboring roles in builtInRoles

Frontend (AgentCreateForm):
- Simplify orgChanged comparison to use optional chaining
- Replace window.confirm with ConfirmDialog for consistency and testability
- Filter workspace dropdown by selected organization (client-side)
- Add OrgChangeConfirmation story with play function assertions
@johnstcn

Copy link
Copy Markdown
Member Author

🤖

Addressed all 7 items from the review in 51d249c:

Backend (coderd/exp_chats_test.go):

  • Added MemberWithoutAgentsAccess subtests for both TestPromoteChatQueuedMessage and TestSubmitToolResults

Backend (coderd/rbac/roles.go):

  • Added descriptive comments to templateAdmin and userAdmin role entries to match neighboring style

Frontend (AgentCreateForm.tsx):

  • Simplified orgChanged to newOrg?.id !== selectedOrg?.id
  • Replaced window.confirm with ConfirmDialog (with new OrgChangeConfirmation story + play function)
  • Filtered workspace dropdown by selected org (client-side filtering with comment explaining rationale vs re-querying)
  • Kept [...organizations] spread — it is required because useDashboard().organizations is readonly Organization[] but OrganizationAutocomplete.options expects mutable Organization[]. Removing it causes TS4104. The proper fix would be updating the OrganizationAutocomplete prop type, but that is out of scope for this PR.

The comment claimed members cannot 'create or interact with chats'
without this role, but they CAN read/update/delete their own chats
via OrgMemberPermissions. The role gates creation and AI inference.
@johnstcn

Copy link
Copy Markdown
Member Author

🤖

Responding to the two top-level findings from the round 4 review:

AgentCreatePage.tsx:33 — Workspace dropdown unfiltered by org (Mafuuu P3)

Done. Added client-side filtering of workspaceOptions by selectedOrg.id inside AgentCreateForm. Went with client-side over re-querying to avoid extra loading/error states on org change — the dataset is small (owner:me) and limit: 0 guarantees completeness. Comment at the filter site explains this tradeoff and when to switch to server-side.

coderd/rbac/roles.go:448 — Misleading agentsAccess comment (Meruem Nit)

Fixed in 6694df9. The old comment said "members cannot create or interact with chats" — but members CAN read/update/delete their own chats via OrgMemberPermissions (confirmed by OrgMemberWithoutAgentsAccessCanAccessOwnChats). Updated to: "Without this role, members can still read, update, and delete their own chats via org membership, but cannot create chats or trigger AI inference."

Also added descriptive comments to the previously-uncommented templateAdmin and userAdmin entries to match the style of their neighbors.

# Conflicts:
#	site/src/pages/AgentsPage/components/AgentCreateForm.tsx

@mafredri mafredri left a comment

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.

Mostly minor stuff, so I feel confident to approve.

Comment thread coderd/x/chatd/chattool/createworkspace.go
Comment thread coderd/exp_chats.go Outdated
Comment thread coderd/exp_chats.go Outdated
Comment thread site/src/pages/AgentsPage/components/AgentCreateForm.tsx Outdated
Comment thread .gitignore Outdated
-e
# Agent planning documents (local working files).
docs/plans/
amend-review+self-review.zip

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.

😄

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

😅

johnstcn and others added 2 commits April 13, 2026 09:43
Three TestStartWorkspace subtests (InProgressBuild, FailedBuild,
StartTriggeredBuildFailure) were missing OrganizationID in their
InsertChatParams, causing FK constraint violations against PG.
Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>

Copy link
Copy Markdown
Contributor

Code Review Summary — PR #23827

ID Priority File Title
RRB001 P1 AgentCreateForm.tsx:191 Stale localStorage workspace ID survives org change on page reload
GTT001 P2 querier_test.go:1352 Missing test: org admin same-org chat visibility
GET001 P3 exp_chats.go:414 httpapi.Is404Error check on OrganizationMembers is dead code
GXC001 P3 active_chat_internal_test.go:39 Struct fields squashed onto single lines
GTB002 P3 exp_chats_test.go:674 Test assertions only check status codes, not error messages
PLUTO001 P3 AgentCreateForm.tsx:254 Ref-sync pattern could be replaced with useEffectEvent

Findings: 6 | P0: 0 | P1: 1 | P2: 1 | P3: 4

All findings are posted as inline annotations on the Pluto Code Review check run. This review is complete. Approval must be performed by a human.

Note

🤖 This comment was written by Coder Agent on behalf of Danielle Maywood

@mafredri mafredri left a comment

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.

Panel re-review (round 5). 5 reviewers: Bisky, Mafuuu, Kurapika, Meruem, Killua (wildcard). Netero first pass.

All R4 findings resolved. H8 (ChatOwnerMe vacuous SQL) and H10 (same-org admin test gap) closed by panel consensus: all 4 reviewers accepted the author's defenses. No performance concerns (Killua). Authorization chain verified correct across all 8 paths (Kurapika).

Three findings converge on error handling in the org membership validation.

list_templates returns templates from all organizations without org identifiers. The cross-org template guard tells the LLM "use list_templates to find templates in the correct organization," but the LLM receives the same unfiltered list with no way to distinguish orgs. In multi-org deployments this creates an inference loop. Aligns with @mafredri's question in #comment-3072017260. (Mafuuu P3, Meruem P3)

"The boundary between 'requires agents-access because it triggers inference' and 'does not require agents-access because it's metadata management' is a design decision worth pinning with tests on both sides. Right now only one side has a nail in it." (Bisky)

Severity count: 3x P3, 1x Nit.

🤖 This review was automatically generated with Coder Agents.

Comment thread coderd/exp_chats.go Outdated
Comment thread coderd/x/chatd/chattool/createworkspace.go
Comment thread coderd/exp_chats.go Outdated
Comment thread coderd/exp_chats_test.go
Frontend (AgentCreateForm.tsx):
- Validate localStorage workspace ID against initial org on mount,
  preventing stale cross-org workspace from being silently submitted

Backend (exp_chats.go):
- Remove dead Is404Error branch on OrganizationMembers (:many query)
- Remove redundant dbauthz.IsNotAuthorizedError check on workspace lookup

Backend (listtemplates.go, chatd.go):
- Filter list_templates by chat organization
- Include organization_id in template output for LLM context

Tests:
- Add same-org admin chat visibility test (positive case)
- Add positive-side agents-access boundary test (UpdateChat)
- Add error message assertions to NilOrganizationID/NonMemberOrganization
- Fix squashed struct fields in active_chat_internal_test
@johnstcn johnstcn merged commit 22062ec into main Apr 13, 2026
31 checks passed
@johnstcn johnstcn deleted the cian/chat-org-scoping branch April 13, 2026 11:31
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 13, 2026

Copy link
Copy Markdown
Contributor

[P2 warning] Persisted attachments lack org affinity

site/src/pages/AgentsPage/hooks/useFileAttachments.ts:19-31

PersistedAttachment records file metadata without org context. On reload, selectedOrg resets to organizations[0] but restored attachments may reference files uploaded to a different org. The in-session ConfirmDialog clears attachments on org change, but this doesn't survive reload.

Suggestion: Either store organizationId in the persisted attachment record and validate on restore, or clear persisted attachments when the org doesn't match on mount.

Found by react-robustness-bottom-up as owl.md

Note

This comment was written by Coder Agent on behalf of Danielle Maywood

Copy link
Copy Markdown
Contributor

[P3 suggestion] Fragile positional uuid.UUID parameter lists in test helpers

coderd/database/querier_test.go:10354

createChat takes 3 consecutive uuid.UUID params; createChildChat takes 5. Swapping any pair compiles silently.

Suggestion: Consider using a params struct or named arguments pattern to prevent silent swaps.

Found by go-design-bottom-up as eeyore.md

Note

This comment was written by Coder Agent on behalf of Danielle Maywood

Copy link
Copy Markdown
Contributor

[P2 suggestion] ListTemplates org-scoping filter is untested

coderd/x/chatd/chattool/listtemplates.go:27-60

The PR adds OrganizationID to ListTemplatesOptions and passes it to the DB filter, but no test sets this field. uuid.Nil is treated as "no filter" by the SQL, so existing tests never exercise org isolation.

Suggestion: Add a test that creates templates in two orgs and verifies ListTemplates with a specific OrganizationID only returns templates from that org.

Found by go-testing-top-down as buzz.md

Note

This comment was written by Coder Agent on behalf of Danielle Maywood

Copy link
Copy Markdown
Contributor

[P2 suggestion] Org picker uses raw organizations instead of permittedOrganizations()

site/src/pages/AgentsPage/components/AgentCreateForm.tsx:403-407

CreateTemplateForm and CreateUserForm both use permittedOrganizations() which filters by permission and includes stale-selection guards. AgentCreateForm uses raw useDashboard().organizations instead. Server-side RBAC prevents security issues, but the UX could show orgs the user can't actually create chats in.

Suggestion: Use permittedOrganizations("chat", "create") instead of raw organizations for the org picker.

Found by react-conventions as hades.md

Note

This comment was written by Coder Agent on behalf of Danielle Maywood

Copy link
Copy Markdown
Contributor

[P2 warning] Misleading comment claims filteredWorkspaces clears stale selection, but no code does

site/src/pages/AgentsPage/components/AgentCreateForm.tsx:194-197

The comment at line 195 says "It will be re-validated once the list arrives via filteredWorkspaces clearing the selection if stale" — but filteredWorkspaces is a read-only computed value that never calls setSelectedWorkspaceId. No reconciliation mechanism exists.

Suggestion: Either implement the reconciliation the comment describes, or correct the comment to reflect that the backend catches the mismatch with a 400 error and no client-side clearing happens.

Found by react-correctness-top-down as mulan.md (also independently confirmed by 4 other reviewers)

Note

This comment was written by Coder Agent on behalf of Danielle Maywood

Copy link
Copy Markdown
Contributor

[P3 suggestion] Stale comment on setupChatInfra

coderd/database/querier_test.go:10319

Comment says "Returns the store, user ID, and model config ID" but the function now returns four values (store, userID, modelConfigID, orgID).

Suggestion: Update the comment to mention the org ID.

Found by go-design-bottom-up as eeyore.md

Note

This comment was written by Coder Agent on behalf of Danielle Maywood

Copy link
Copy Markdown
Contributor

[P3 suggestion] Defensive guard silently skips org validation on uuid.Nil

coderd/x/chatd/chattool/createworkspace.go:149

The if options.DB != nil && options.OrganizationID != uuid.Nil guard silently skips the cross-org template check when OrganizationID is zero. Production is safe (CreateChat enforces non-nil), but silent bypasses are risky.

Suggestion: Consider logging or returning an error when OrganizationID is uuid.Nil instead of silently skipping validation.

Found by go-design-bottom-up as eeyore.md

Note

This comment was written by Coder Agent on behalf of Danielle Maywood

Copy link
Copy Markdown
Contributor

Code Review Summary (Round 2) — PR #23827

ID Priority File Title
RCT001 P2 AgentCreateForm.tsx:194 Misleading comment claims filteredWorkspaces clears stale selection
GTT002 P2 listtemplates.go:27-60 ListTemplates org-scoping filter is untested
RRB002 P2 useFileAttachments.ts:19 Persisted attachments lack org affinity
RXC001 P2 AgentCreateForm.tsx:403 Org picker uses raw organizations instead of permittedOrganizations()
GDB001 P3 querier_test.go:10319 Stale comment on setupChatInfra
GDB002 P3 querier_test.go:10354 Fragile positional uuid.UUID parameter lists in test helpers
GDB003 P3 createworkspace.go:149 Defensive guard silently skips org validation on uuid.Nil

Findings: 7 | P0: 0 | P1: 0 | P2: 4 | P3: 3

9 additional findings were filtered as re-reports of round 1 issues or duplicates. 1 finding (RDB002) was rejected by fact-checking.

This review is complete. Approval must be performed by a human.

Note

This comment was written by Coder Agent on behalf of Danielle Maywood

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add organization scope to chats and chat files

4 participants