Skip to content

feat(teams): manage durable company teams and memberships - #1356

Closed
vsrikar08 wants to merge 13 commits into
feat/1284-company-rolesfrom
feat/1285-durable-teams
Closed

vsrikar08 wants to merge 13 commits into
feat/1284-company-rolesfrom
feat/1285-durable-teams

Conversation

@vsrikar08

@vsrikar08 vsrikar08 commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

What changed

Adds durable company teams, memberships, and attributable history. Admins can create and rename teams and edit memberships; ordinary members remain read-only.

Addresses Allison’s review with one Teams Effect service, batch membership reads, removal of inactive people, and one directory revision/wake per effective batch. Individual history remains; the unused changes reader is deferred to #1291. Admin-removal restrictions remain intact.

Closes #1285

Look at

  • Brightline now seeds Design and Engineering and Robin as a regular admin. Teams shows inactive roster entries for removal and uses the existing section heading style. Company settings redirects to People instead of repeating sidebar navigation.
  • Teams.test.ts covers atomic failure, duplicate/no-op batches, one revision per batch, individual attribution, inactive removal and current authority. The PostgreSQL-only concurrency/NOTIFY tests were removed.

How it was verified

39 focused tests passed across Teams, CompanyPage and scenario loading. The Companies package and test-program Effect typechecks passed using the installed checker directly. Full pnpm verify was not completed: local pnpm is 11.5.0 while the checkout requires 12.9.1.

The existing fixes at c7b29b7 are now integrated into assembled #1379 at 0e01b1c, preserving later permissions, lifecycle work and migration IDs 36–41. All 24 workspace typecheck tasks and 74 focused integration tests pass there. Complete-stack broad verification remains non-green, and Srikar is running the Brightline journey. This is not ready-to-merge evidence for the full feature.

Release impact

  • Breaking — requires action from anyone already running this
  • Not breaking — no action required

Part of the one-way roles/audiences stack; land together after stack verification.

  • What does a revert leave behind? Team, membership and history tables; the stack also writes super-admin roles and team audiences.
  • Does the release before it still work with that? Not across the complete stack. Follow the stack’s one-way release disposition.

Model: GPT-6.1 Codex; harness: Codex.

@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-10T03:13:31.922437Z c7b29b7 New commits
ℹ️ 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.

@github-actions github-actions Bot added area:server Touches the server area area:core Touches the core area area:docs Touches the docs area area:ui Portal and first-party browser pages, shared rendering and styles size:l 501-1,000 changed lines labels Nov 9, 2026

@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: 9398d7a80c

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

)
} satisfies Teams["Service"];
});
export const layer = Layer.effect(Teams, make);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep team operations as a module until a second consumer exists

The new service and layer have only one production consumer: TeamsPage.handle. Repository-wide search finds that AuthPages only provides the layer; the remaining consumers are tests. The authoritative Effect service review spec explicitly prohibits introducing a service or layer before a second consumer exists. Keep these operations in an ordinary Companies-owned module until the planned audience consumers actually land, avoiding the additional service construction and route-level provisioning in this change.

AGENTS.md reference: AGENTS.md:L97-L97

Useful? React with 👍 / 👎.

@allisonmahmood

Copy link
Copy Markdown
Owner

Review of #1356 (teams). Allison's review, posted by Fermy (his agent). Line numbers are at 93f76cd2. It's a static review; nothing was run. Stack-wide points are explained in the stack review on #1192.

The tables are right: teams, members (with composite foreign keys) and change history. Edits serialize under the company lock, and no-op edits don't advance anything. What needs work is the module's shape and a few edge cases.

Stack-wide

This PR

  • Should-fix: Teams should be a service.
    • Teams is a set of free functions that need SqlClient, and it has many consumers: the Companies pages, Patches, Integrations and Portal.
    • That is why the stack ends up with about 20 Effect.provideService(SqlClient.SqlClient, sql) calls and a dozen RoleForbidden catch arms; internal calls run into Teams.list's viewer check.
    • Make it a Context.Service with make and layer, like Users. Expose one batch call, memberships(companyId, userIds), and keep the viewer check on page-facing calls only.
    • Teams.ts also repeats Effect.flatMap(SqlClient.SqlClient, (sql) => …) nine times.
  • Should-fix: there's no way to remove a deactivated person from a team.
    • Teams.ts:205 refuses inactive targets with UserNotFound, and rosters hide them. Reactivation then restores every membership.
    • To keep someone out of Finance, an admin has to reactivate them first, which gives them access in the meantime.
    • Allow removing inactive members.
  • Should-fix: advance the revision once per batch.
    • setMemberships advances the directory revision and sends a pg_notify once per person (Teams.ts:215).
    • This also removes a plausible deadlock. Each pass locks companies_directory and then foreign-key-checks the next user row. Meanwhile Users.refresh, on an email change at sign-in, holds that user row FOR UPDATE while its trigger waits for companies_directory.
    • History rows can take a timestamp or a serial id instead of the directory revision.
  • Nit (UI consistency):
    • TeamsPage.ts:61 uses tabs to move between pages (Company, People, Teams). The spec keeps tabs for narrowing a single list.
    • /settings/company (AuthPages.ts:293) is a two-link hub that repeats the sidebar.
    • The team heading is a bare <h2> rather than section-heading.
  • Nit: no dev scenario seeds a regular admin or a team. Without hand-written SQL, pnpm dev up, dev shot and acceptance can't show three roles or any teams. Add both to one scenario.

Tests

  • Drop:
    • "publishes … only after outer commit, never for rollback". It tests PostgreSQL's transactional NOTIFY. Keep its "a no-op doesn't advance the revision" assertion in the batch test.
    • "serializes concurrent membership edits". It tests ON CONFLICT DO NOTHING.
  • Trim: the copy assertions in CompanyPage.test.ts "keeps rejected team names…".
  • Keep: "rejects member self-assignment, foreign teams/people…".

@vsrikar08 vsrikar08 added the one-way Rolling production back past this PR would break the release before it label Nov 10, 2026

@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: c7b29b7d7b

ℹ️ 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 on lines +50 to +52
target.role !== "super_admin" &&
(actor.role === "super_admin" ||
(actor.role === "admin" && (target.role === "member" || actor.id === target.id)));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Allow super admins to leave teams they have joined

When a super admin joins a team, this predicate prevents anyone—including that person or another super admin—from removing their membership. setMemberships permits the addition but rejects its reversal, and the roster hides the Remove control using the same predicate. The only workaround is to demote the person first, which is unavailable for the company's sole active super admin. Allow an authorized super admin to remove these memberships without changing company roles. This also restores the documented ability to manage their own team memberships.

AGENTS.md reference: AGENTS.md:L80-L80

Useful? React with 👍 / 👎.

@github-actions github-actions Bot added area:ci CI, shared testing infrastructure, development scripts and tooling size:xl Over 1,000 changed lines; review in multiple passes and removed size:l 501-1,000 changed lines labels Nov 10, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner

Superseded by #1416 (the rollback bridge) and #1417 (teams), which carry this work forward under Allison's decisions on #1192 (#1192 (comment)). Closing without merging; Srikar is co-author there. Posted by Fermy (Allison's agent).

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

Labels

area:ci CI, shared testing infrastructure, development scripts and tooling area:core Touches the core area area:docs Touches the docs area area:server Touches the server area area:ui Portal and first-party browser pages, shared rendering and styles one-way Rolling production back past this PR would break the release before it size:xl Over 1,000 changed lines; review in multiple passes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants