Skip to content

feat(teams): delete unused teams and restore their memberships - #1379

Closed
vsrikar08 wants to merge 30 commits into
fix/1367-shared-read-fencefrom
feat/1291-team-recovery
Closed

vsrikar08 wants to merge 30 commits into
fix/1367-shared-read-fencefrom
feat/1291-team-recovery

Conversation

@vsrikar08

@vsrikar08 vsrikar08 commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

What changed

Teams could be created and edited, but could not be safely deleted or recovered. Administrators can now delete an unreferenced team and restore it from Deleted teams, retaining its identity and recorded memberships. A patch or connection reference blocks deletion, including retained patches; no audience silently becomes Company.

Part of #1291 / #1192; keep #1291 open until merged. Stacked on fix/1367-shared-read-fence (22e2de09), preserving test/1192-teams-integration. UI option A and the deletion policy were approved by Srikar. No merge or deployment.

flowchart LR
  A[Administrator] --> T[Companies: lock team exclusively]
  T --> R[Hosting: patch and connection reference readers]
  R -->|Referenced| B[Refuse deletion]
  R -->|Unused| D[Soft delete, retain memberships, record actor]
  D --> U[Deleted teams: restore same identity]
  W[Audience writers: shared team locks] --> T
Loading

Look at

The real-server journey in TeamAccess.test.ts publishes to Design + Engineering, checks patch and connection deletion guards, removes references deliberately, deletes/restores Design and refuses a new publish to the deleted team. Another case races first publication against deletion; the existing stream journey exercises the real member adapter, revocation and restoration. These three server tests pass.

The Companies lifecycle case verifies retained memberships, non-revival of explicitly removed memberships, member refusal, and fail-closed missing assembly. The upgrade case preserves existing team identities, memberships and attribution. The selected active/deleted pages were inspected locally: HTTP 200, no browser errors. All data was synthetic in a new throwaway instance.

How it was verified

Latest assembled head: 0e01b1c357ee8a726e30f224671c32cf16b311dc. It contains every current head of #1355, #1356, #1357, #1358, #1360, #1362, #1363, #1364 and #1378 as ancestors. #1356's existing Teams service/batch/inactive-removal changes were integrated with later visibility, explicit membership and team recovery. #1360's own-table subscription cleanup is retained; #1378's shared-source membership fence remains. Guest title and SDK patch-ID fixes are present from their owning PRs. Released migration 36 and unshipped access migrations 37–41 are preserved.

Code checks at 19e603f (final head adds two documentation sentences) passed: all 24 workspace typecheck tasks, 74 focused tests in eight suites, formatting, lint and whitespace checks. The focused command covers Teams, Audiences, GuestGrants, SdkApi, real-server TeamAccess and Guests, company migrations and QuerySubscriptions.

Broad verification is not green: the full command ran through every stage while integration was being finalized. Format, lint, synthesis, Postgres concurrency (28 tests), packed install and tier-2 smoke passed. Node: 3,200 passed / 63 failed / 18 skipped. Bun: 2,905 passed / 55 failed / 15 skipped. The early typecheck failure was fixed and the complete latest-head typecheck passes. CLI smoke failed on Mac shortcut text (Ctrl+K expected, ⌘ K rendered); browser stopped after a hotkey case failed (6 passed, 109 not run). Other failures include Linux /proc fleet assumptions and CLI/dev/timeouts; they have not all been adjudicated as infrastructure flakes. These results do not establish complete-feature readiness.

Brightline and independent acceptance remain unverified on this head. Srikar explicitly took over the complete synthetic Brightline journey. The isolated instance created during setup was stopped. Earlier screenshots, films and acceptance below apply to their recorded historical commits, not this assembled head. No merge or deployment.

Release impact

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

No user configuration or CLI change.

  • What does a revert leave behind? Migration 40, retained team rows, lifecycle audit records and deletion timestamps. Memberships are retained.
  • Does the release before it still work with that? No: older code ignores team deletion timestamps; the complete audience/role stack also has a one-way boundary. One-way: fix forward. Do not roll back past this stack once it has written new roles/audiences or deleted teams.

Model: GPT-6. Harness: Codex.

Flow team-recovery, as Ada Park (super_admin)

After is 373d0c1 (feat/1291-team-recovery), on the team scenario, from pnpm dev film.

  • After: finished in 8.9s
after.mp4

CI migration repair

The released-terms upgrade test failed with the same ledger mismatch as CI before the fix and now passes while preserving a recorded acceptance and migrating the existing admin to super admin. All 24 migration/team/server tests pass; test typecheck, lint and formatting pass. Only the canonical landed migration record was brought forward; unrelated main UI changes were not merged. Throwaway databases created with the old unshipped migration history need reset. CI is rerunning on the pushed fix; its result is pending.

@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 commented Nov 10, 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-11T08:14:02.722920Z 0e01b1c 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:docs Touches the docs area area:integrations Company connections and integration implementations area:ui Portal and first-party browser pages, shared rendering and styles size:m 100-500 changed lines labels 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: cf56243ecd

ℹ️ 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 packages/companies/src/TeamsPage.ts Resolved

@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: 373d0c120b

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

: "";
const confirm =
editable && confirmation === "delete"
? `<section><h2>Delete ${escapeHtml(selected.name)}?</h2><p>Its memberships will be kept for restoration. Patches and connections must no longer reference it.</p><form method="post" action="${escapeAttribute(`${base}delete${query}`)}"><a class="btn" href="${escapeAttribute(address(selected.id))}">Cancel</a><button class="btn btn-danger" type="submit">Delete team</button></form></section>`

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 Use the shared confirmation components for team lifecycle forms

When an administrator opens either delete or restore confirmation, the new markup omits confirmation-form, confirmation-consequence, and confirmation-actions, contrary to the applicable .agents/skills/ui-consistency/SKILL.md confirmation-form contract. Consequently, these controls bypass the shared action spacing and responsive wrapping defined in packages/core/src/html.ts. Apply the shared confirmation classes and group submit/cancel controls in confirmation-actions, as the existing Company and Machines confirmations do.

AGENTS.md reference: AGENTS.md:L85-L85

Useful? React with 👍 / 👎.

@vsrikar08

Copy link
Copy Markdown
Collaborator Author

Acceptance: FAIL

Checked 373d0c12 (base 22e2de09) on a fresh synthetic Patchy Dev instance, by GPT-6 in Codex. The new deletion/recovery behavior passes the checks below. The complete #1291 integration/release-readiness contract is not yet satisfied.

Done means

  • Team deletion/recovery policy: passed. The latest-head real-server and rendering suites pass 5/5 tests. They cover patch/connection reference guards, retained patch references, deleted-target publication refusal, restoration, a publication/deletion race, current membership stream revocation/restoration and escaped confirmation targets.
  • Independent connection concurrency probe: passed. Eight repetitions raced the real ConnectionStore.setAudience against Teams.setDeleted. Both never succeeded together; no connection grant pointed at a deleted team; the loser was refused with InvalidConnectionAudience or TeamInUse. This temporary probe was restored after execution.
  • Membership preservation and upgrade: passed locally. An independent earlier run passed 34/34 tests across Companies lifecycle, Companies migrations, AuthPages and real-server TeamAccess at cf56243e. Production code is unchanged between that commit and this head; the head adds rendering tests and corrects docs.
  • Complete assembled implementation/full journey: not satisfied. The PR explicitly retains feat(teams): manage multiple teams and memberships #1285's blocker because feat(teams): manage durable company teams and memberships #1356's latest reviewed refactor is absent from the assembled base. This run does not establish one complete Design/Engineering journey combining owner recovery, connections, shared sources, guest/public preservation and every CLI/MCP/cache surface.
  • Required verification: not satisfied. Author's full Node verification is non-green (reported 3187 passed / 72 failed); it is not a release acceptance pass. I did not reproduce or classify every broad failure.
  • Current docs/policy: passed for this change's scope. Latest head corrects stale role-storage/rollback guidance and describes reversible unreferenced-team deletion.

Golden journeys

  • Browser create → delete → Deleted teams → restore: passed on the latest-head throwaway instance. Desktop and 390px screenshots inspected; no browser errors.
  • Ordinary member GET of Deleted teams and direct POST delete/restore: passed, each returns 403.
  • Multi-team publication and real member stream removal/restoration: passed in the real-server suite.
Active team Deleted team Restored, phone
Active team Deleted team Restored team on phone

Rollback answers: Match the changed schema and code, and one-way is present. Older code ignores deletion timestamps, so rollback is unsafe after deletion; fix forward. CI's failed rollback rehearsal is an external baseline blocker: its job says the live commit is uncertain because Deploy run #43 is waiting. It does not demonstrate a lifecycle migration failure.

Not run / limits

  • Independent full workspace verification, live Clerk/mail, full public/guest/CLI/MCP/file/cache matrix and all golden journeys.
  • Full release upgrade/rollback rehearsal against a pinned live baseline; CI could not select one.
  • First local evidence attempts collided during CLI artifact staging; their ENOENT/health-timeout runs are not counted as behavioral passes. The sequential reruns and latest-head browser flow above completed successfully.

No new lifecycle defect was found. This FAIL is the outstanding assembled-feature acceptance gate, not a claim that team deletion/recovery is broken. Keep #1291 open and do not call the stack ready to merge or release.

@github-actions github-actions Bot added size:l 501-1,000 changed lines and removed size:m 100-500 changed lines labels Nov 11, 2026
@github-actions github-actions Bot added area:ci CI, shared testing infrastructure, development scripts and tooling area:cli Touches the cli area area:primitives Patch tables and files size:xl Over 1,000 changed lines; review in multiple passes and removed size:l 501-1,000 changed lines labels Nov 11, 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: 68b300b23a

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

const people = (yield* users.list(ref.companyId)).filter(
(person) => person.deactivatedAt === null
);
const people = yield* users.list(ref.companyId);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Exclude inactive people from the add-members picker

When a company has deactivated people who are not already on the selected team, removing this filter makes them selectable in “Add people,” because candidates includes every person without a recorded membership. However, Teams.setMemberships rejects inactive additions with UserNotFound and rolls back the entire submission, including any active people selected alongside them. Keep inactive people available for displaying and removing recorded memberships, but filter the add-members candidates to active people.

Useful? React with 👍 / 👎.

@vsrikar08

Copy link
Copy Markdown
Collaborator Author

Allison review reconciliation at 0e01b1c357ee8a726e30f224671c32cf16b311dc (existing stack only; no merge or deploy).

Each apparent gap was checked against the owning branch and assembled source before deciding whether it needed code. Later #1192 A–D decisions take precedence. #1359 and #1361 are issues, not PRs. All conversation comments, submitted reviews and inline comments were refreshed; Allison has no review-body/inline comments on this set, and no direct comments on #1378/#1379.

Review area Classification before integration Result at assembled head
#1355 direct super_admin storage, installed-CLI identity compatibility, invite actor locking/revoke authority, role labels, seed/order, meaningful concurrency tests Already present on #1355 Retained. Terms migration 36 preserved; access-stack migrations 37–41 remain in order. Lower standalone branch numbers are not the assembled migration ledger.
#1356 Teams service, batch memberships, inactive removal/rosters, once-per-batch authority/wake with per-person history, removal of unused changes reader and PostgreSQL-only tests Needs propagation from c7b29b7 Existing implementation integrated, with newer explicit super-admin membership, protected admin removal, member visibility, history and deletion/restoration retained. No parallel Teams implementation.
#1356 page-navigation/settings/heading cleanup, regular-admin/team scenario, concise validation tests Needs propagation from c7b29b7 Integrated, retaining the later active/deleted list tabs and recovery controls.
#1357 canonical scope/team rows and named guest grants; removed pool/activation/redundant revisions; guest history/eligibility/actor stamps and migration preservation Already present Retained. Later B/D govern: no all-guests audience or mandatory audience question.
#1357 guest details Ordinary-member fix already present; management-only super-admin title exception genuinely missing at bb7c7fc Fixed in owning #1357 and integrated. Protected title is null and rendered as Restricted patch; oversight retains grant counts/state. Removal confirmation handles null titles.
#1357 removed-owner recovery code, legacy Company commands preserving teams, readership labels, inactive-owner repair, stable error codes, hidden-team preservation, default-path coverage, one public Save button, hidden source lifecycle filtering Already present Retained.
#1358 lifecycle lock-order/read-only fix, bounded management metadata, content-only descriptions, safe rollback receipt, tagged card branch, one management query/card, scoped owner history, no duplicate All card, decoded/reused roles and recovery tests Already present Retained under later A, which keeps management-only oversight.
#1360 own-table subscription cleanup Needs propagation from e542116; had regressed downstream Restored. SubscriptionReads matches e542116 apart from one explanatory comment. Real directory/shared-source membership dependencies, stream admission/wakes and #1378 pre-execution fencing remain.
#1360 invocation-local reauthorization reuse, shared browser/MCP admission, MCP retirement parity, real server revoke/reconnect/restore test, lifecycle-only revision fence Already present Retained and exercised by focused tests.
SDK patch-ID probe called out on #1360, owned by #1363 Genuinely missing at ee34bbb/bb7c7fc9; shared-schema viewer checks were already implemented Fixed in #1363 using required-viewer findForViewer, with restricted/missing/entitled generation coverage; integrated without duplicating shared-schema checks.
#1362 later A: recorded super-admin joins, protected removals, team/roster visibility, hidden-team preservation and scoped owner history; test trimming Already present Retained when integrating #1356. No derived automatic memberships. User-retained protection against removing other admins is intentional.
#1363 viewer-required shared table/store/file/schema admission, hidden dependant counts, narrowing-only acknowledgement and stale-warning protection, nonlocking GET refusal, keep-source-recheck test Already present Retained. Query-count instrumentation additionally removed from assembled Audiences tests.
#1364 later C: owner build entitlement at publish/call/queue, admitted reader use, Block guests, filtered discovery/SDK/logs/Used by, meaningful errors, removed dead connection fencing/warnings, own-property guard, skill mirror/hash, test trimming Already present on #1364 Retained; its latest a67765f is now an ancestor too, including the terms-preservation migration test. Duplicate connectionRecheck parameter annotations removed while retaining the export annotation required by declaration generation.
Stale guest-pool, automatic-membership, per-caller connection, connection-revision, activation and ask-policy documentation Needs propagation for corrected #1364 prose; genuinely missing corrections elsewhere Product/glossaries/CLI README and #1192 reconciled. Two additional future-work sentences corrected after checking all branches.
#1379 guarded unused-team deletion/restoration, reference locks, stable identity and membership restoration Already present Preserved; no silent widening and no resurrection of explicitly removed memberships.

Retained alternatives / literal engineering-request limits:

  • Audiences still has several loader/adaptor shapes and SqlClient-provision wrappers. Its pure admits predicate and Companies-owned batch facts are shared, and Teams is now the existing Effect service. The broader audience-interface simplification is partial, not a newly proven authorization defect; no additional service/policy architecture was introduced.
  • Company-wide writer locks still exist. The concrete invitation bottleneck and lifecycle lock-upgrade deadlock were fixed; the broader suggested conversion to involved-user locks was not implemented. Existing lock ordering was preserved rather than changing all writer concurrency during integration.
  • SharingChange retains its mutually exclusive legacy scope/audience union for type safety; stable audience refusals use distinct semantic tagged errors under repo conventions. These are alternative interface/error shapes, not missing refusal behavior.
  • The existing single publish force flag still acknowledges both dependency refusals. No new consent model was chosen. An explicit-Company packed-install case remains; default publication is exercised elsewhere, including the scenario and focused tests.

Verification:

  • All 24 workspace typecheck tasks and 74 tests across Teams, Audiences, GuestGrants, SdkApi, TeamAccess, Guests, company migrations and QuerySubscriptions pass at 19e603f. Final HEAD adds only two documentation wording changes; formatting/lint/whitespace checks pass.
  • Full verification completed every stage during integration: format/lint/synth, Postgres concurrency (28 tests), packed install and tier-2 smoke passed. Node 3,200 passed / 63 failed / 18 skipped; Bun 2,905 passed / 55 failed / 15 skipped. The early typecheck error was corrected and full workspace typecheck rerun successfully. CLI smoke failed on Mac shortcut wording; browser stopped on a hotkey assertion (6 passed, 109 not run). Other failures include Linux /proc fleet assumptions and CLI/dev/timeouts; not all are classified as infrastructure flakes. Do not treat this as green required verification.
  • Srikar explicitly took over the complete synthetic Brightline journey. It is unverified here. Latest-head independent complete-feature acceptance is also not established. The isolated setup instance was stopped; existing daily-driver instances were left alone.

Every current requested PR head is an ancestor of assembled #1379. The stack is not declared ready to merge. No new issue/PR, PR merge, deployment, production/live-database change or daily-driver preview change.

Model: GPT-6; harness: Codex.

@vsrikar08

Copy link
Copy Markdown
Collaborator Author

Follow-up to the Allison review reconciliation at 0e01b1c3: the assembled Teams work now continues in #1404, at 9b2d0a7158d9758adfbe4a51a1fc6320831c0c5a. No PR has been merged or deployed as part of this work.

#1404 carries the existing access stack plus the approved Teams UI revamp, on an independent branch based on main. The original feat/1291-team-recovery branch is unchanged. Its large diff includes the unmerged backend, contracts, migrations and tests—not just the UI.

Area Result in #1404
Existing Teams/access stack Retains roles, recorded memberships, team-scoped patch and connection access, named guest grants, owner recovery, runtime/shared-source enforcement, CLI/MCP contracts and guarded team deletion/restoration. No automatic memberships or silent widening to Company.
Teams UI (#1403) Implements Srikar’s selected 03: card grid → team page direction: compact team cards with counts/avatar previews, responsive mobile links, searchable roster and people picker, and create/rename/remove/delete/restore dialogs. Uses the existing router and shared Patchy UI components; replaces the previous Teams presentation rather than retaining a parallel implementation.
Recovery UI Keeps management-only metadata separate from content access, reuses confirmation/sharing controls, filters eligible replacement owners, and retains owner-only self-join history and dependency/stale-action safeguards.
Cleanup Removes the obsolete confirmation URL alias and redundant directory rendering. Directory previews use batched reads. UI and backend reuse the membership-removal rule; publication and sharing reuse hidden-team preservation.
Review fixes Corrects remaining Super admin controls/copy, restores guest rows in People’s All tab, focuses team-operation refusals, preserves hidden team grants when republishing, and retains membership dependencies when resuming shared-source queries.
Main integration Incorporates main through b9dc456b, including shortcut preferences and controls. Keeps both the people and keyboard icons. Main’s migration 38 is retained; the unshipped team-stack migrations are now 39–43, with upgrade tests updated.
CI fixes Updates role/navigation expectations and removes a cross-test assumption exposed when the preceding publication/deletion race leaves another team active. Lifecycle assertions still verify deletion removes access and restoration restores it.

Verification and remaining limits:

  • Latest main integration: all 25 workspace typecheck tasks and 70 affected core/portal/serving/server tests pass.
  • Earlier focused verification passed 221 tests; the subsequent CI-fix suites passed 26 unit tests, 22 sidebar/switcher browser tests, and the 3 team server tests on Node 26. These are separate runs, not an additive test total.
  • The card directory and roster were checked visually on desktop/mobile with fresh synthetic scenario data; screenshots are in feat(teams): add team access and management UI #1404. Independent GPT-6.1 Sol UI review rated the selected implementation 9/10. A later scoped review found a missing mobile Guest label, which was fixed; this is not a latest-head complete-feature acceptance verdict.
  • A read-only codebase-design review found no second router or parallel Teams implementation. It did identify one small unresolved duplication: the new Company navigation entry redirects through /company to People, without a distinct Company page. No implementation changes were made during that review.
  • GitHub confirmed feat(teams): add team access and management UI #1404 mergeable after the latest main update and created CI run 43098779390. Its final result is not established here; ongoing polling was stopped at Srikar’s request. The preceding live Attio failure was a transport error in the informational probe check.
  • The existing one-way upgrade restriction remains: older role/audience decoders cannot read the new values. This summary does not declare the stack ready to merge or supersede the outstanding complete-feature acceptance requirement.

Model: GPT-6; harness: Codex. Independent UI review: GPT-6.1 Sol.

@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:cli Touches the cli area area:docs Touches the docs area area:integrations Company connections and integration implementations area:primitives Patch tables and files 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