Repository navigation
feat(companies): invite and manage company users - #150
Conversation
Astra reviewReviewed StandardsNo independent merge-blocking method or YAGNI findings. SpecBlocker — intent: resend gets stuck after a remote revoke succeeds but its response is lost
#146 asks for “resend as a second create.” Instead, every resend must first successfully revoke the previous Clerk invitation. Any revoke error returns early and retains that invitation's ID. If Clerk commits the revoke but the response is lost, the next click retries revoking an already-revoked invitation. Clerk only permits active, non-revoked invitations to be revoked. Subsequent resends therefore fail before creating another email; Patchy's invitation remains pending, but its Resend invite control cannot recover. Revoking the link in Clerk's dashboard produces the same mismatch. Smallest fix: make old-link cleanup idempotent for an already-revoked invitation and proceed to the replacement create, or use the specified second-create flow without making it depend on successful revocation. Keep a focused regression for the lost-response case. Evidence: an isolated reproduction over migrated Postgres, injecting the remote side effect followed by a transport failure through Summary: Standards: 0 blockers. Spec: 1 blocker — resend cannot recover from an already-revoked remote invitation. |
Code review: PR 150 vs #146Two-axis review of Intent vs #146#146 asked for one That is what landed. Routes, The one wording trap is reactivation. #146's tests/done-when say “reactivating restores both” (bearer 401 and the deactivated page). The domain contract is narrower: ADR-0007 “Reactivation restores membership access, not revoked machine tokens”, and the Companies glossary the PR updates. The implementation restores the browser, keeps old keys dead, and allows a fresh mint. The PR body records that reading. That is the parent spec, not a miss of intent. StandardsRefs: Hard
const company = Effect.fn("AuthPages.company")(function* (action: CompanyPage.Action) {
const viewer = yield* RequireSession.Viewer;
const session = yield* Session.Session;
const page: CompanyPage.Page = yield* CompanyPage.handle(viewer, action);
return page.redirect
? HttpServerResponse.redirect(page.redirect, {
status: 303,
headers: { "cache-control": "private, no-store" }
})
: pageResponse({ ...page, styles: CompanyPage.styles }, session);
});
Judgement
Duplicated Code: No other UI-consistency or Effect-service findings. Spec(a) Missing or partial. None. (b) Scope creep. None of product substance. Extra coverage (cross-company 404, Origin on POSTs, resend/revoke races) follows parent §7 CSRF and company-scoping, not new surfaces. (c) Implemented but wrong. None. Reactivation conflict (evaluated, not a defect). Also-checks. Removing yourself = deactivate self hidden for every viewer; last-admin demote is shown and refused on submit; last-admin self-deactivate is hidden and still 409 if POSTed. Concurrent demote exists in MethodThe method is the right small one: Auth still only answers who the caller is; Companies owns the tenant, the forms, and Clerk-as-mailman. Routes stay in Auth because that is where the first-party shell and CSRF already sit. The arrow stays Auth → Companies. /** Auth supplies the viewer; Companies owns the forms and their company-scoped actions. */
export const handle = Effect.fn("CompanyPage.handle")(function* (viewer: Viewer, action: Action) {
if (action.kind === "view") return yield* render(viewer);
if (viewer.role !== "admin") {
return yield* render(viewer, {
message: "Only an admin can manage this company.",
status: 403InviteMail belongs in Companies, not Auth: sessions are identity, invitations are membership. Server-rendered forms, 303, re-render with the reason is the same method as Join, which is the right deployed-stage surface. SPA/JSON would have been a second surface this ticket does not need. Authorization is enough: viewer is company-scoped, mutations key off Last-admin via company-row-then-user lock is the method. Hiding self-deactivate while still showing self-demote is the right product: demote is valid once another admin exists; deactivate-self is a footgun even then. Server still 409s a crafted last-admin POST. The one overfit is Clerk HTTP inside a Postgres transaction: // Hold the invite's row lock through delivery and commit. Consumption, revoke and
// resend cannot replace each other's Clerk id; interruption cannot roll back an
// invitation after the external request has already sent its email.
export const create = Effect.fn("Invitations.create")(function* (
input: Companies.InviteInput
) {
// ...
return yield* sql.withTransaction(
Effect.gen(function* () {
const invite = yield* companies.createInvite(input);
return yield* deliver(invite);
})
);
}, Effect.uninterruptible);They already accept Clerk/Patchy divergence on revoke failure, and YAGNIVerdict: mostly. Production is the small model. Weight is in the HTTP tests. Keep No groups, SSO, expiry, webhooks, retry queues, or generic mailer. The lockfile catalogs rewrite is pnpm noise from adding Cut if you want a smaller diff: the doubled lifecycle under Summary: Standards 1 hard + 2 judgement, worst is Reviewed with Grok 4.6 in the Grok Build harness; Standards, Spec, UI, Effect/surfaces, method, and YAGNI ran as separate sub-agents. |
|
Addressed both reviews in 1c30c19. Fixed
Kept, with reasons
Verification and readiness
|
|
|
@vsrikar08 Following up on your review after discussing it with Allison:
|
Astra review of 225975bReviewed only StandardsNo merge-blocking method or YAGNI findings against the repository's Effect/service and UI conventions. The change uses the existing clock, SQL transaction, and migration patterns without adding future-facing machinery. SpecNo merge-blocking intent findings. Clerk's default remains unchanged; local invitations are filtered from create-or-join and rejected on consumption at expiry. Successful resend renews the deadline, while expired invitations retain their admin resend/revoke controls. Product and domain documentation reflect the change. Verification: ran Summary: Standards: 0 blocking findings, worst: none. Spec: 0 blocking findings, worst: none. |
grok review of 225975bScoped to Spec for this commit is vsrikar08's item 3 (shorten Clerk expiry to 24h/7d) and Allison's 2026-09-06 reply: keep Clerk's documented 30-day default, and make Patchy's local invitation respect that expiry so create-or-join cannot accept after the emailed link is dead. Standards, Spec, UI, Effect/tests, surfaces, method, and YAGNI ran as separate sub-agents. StandardsNo hard Effect-service or UI-consistency findings.
Judgement — Mysterious Name / vocabulary clash ( Judgement — Duplicated Code: expiry is Judgement — Speculative Generality: SpecQuoted:
(a) Missing / partial. Core gap is closed: Partial on “so the two don't disagree.” Local (b) Not asked; inferred product. Expired rows keep the unique pending (c) Fragile, not wrong. A parallel 30-day constant is a reasonable reading of “Clerk's default,” not a strong guarantee they never disagree. Passing MethodThe method is the right small one. A stored Check sites are coherent:
Expired still occupying the unique slot is the unsurprising occupancy: one live row, resend or revoke. Freeing the slot on expiry would race a second invite.
Would change only if shipping again: freeze the backfill as YAGNIVerdict: mostly. Production is the small model. Cut if you want a smaller diff: the SurfacesWire, CLI, and seed did not apply ( Half-hit: create-or-join hides expired invites through Also untested, load-bearing: second invite while expired → No UI-consistency findings. Summary: Standards 0 hard + 3 judgement, worst is Reviewed with Grok 4.6 in the Grok Build harness; Standards, Spec, UI, Effect/tests, surfaces, method, and YAGNI ran as separate sub-agents. |
Review resolution — e64e93aReviewed both Astra review of 225975b and grok review of 225975b against the source and the pre-decided expiry design. Astra reported no blockers; Grok's actionable points were migration immutability and two coverage gaps. Fixed
Kept as is, with reasons
Verification
Merge readinessLatest PR head: CI run 34033492672 is successful on that head: test (22), test (24), lint (including format/typecheck), cli-smoke, and dependency-review all passed. The separate label check also passed. GitHub reports no configured required checks for this branch (and no effective base-branch rules); all configured checks were nevertheless verified green. PR is MERGEABLE / CLEAN, with no new review comments after the push and no inline review comments. No unresolved blockers. Ready to merge into the existing PR base; not merged. Implemented and verified with GPT-6 Astra in Oh My Pi. |
1d02ee9 to
266e5ce
Compare
Implement #146 with server-rendered company management, Clerk invitation delivery, and lifecycle coverage. Reactivation restores browser access while revoked machine tokens remain dead.
Handle Clerk already-revoked invitations as completed cleanup after a lost response. Restore sign-out on the company page, fix form recovery navigation, and remove duplicate lifecycle coverage.
e64e93a to
59dfead
Compare
Admins need one place to invite colleagues and manage their access. Members need to see who is in their company without management controls.
Adds
/companyusing the existing server-rendered shell and plain forms. Admins can invite, revoke, resend, change roles, deactivate and reactivate; members get the same read-only list. Clerk sends invitation mail while Patchy owns the invitation, including when delivery fails. The existing transactional last-admin and token-revocation rules protect access changes.Stacked on
auth/138-clerk-sign-in-create-company; this PR targets that branch and contains only the company-management change.Reactivation restores browser access and permits fresh machine tokens. Previously revoked keys stay revoked, matching the existing Users/glossary contract; #146's “restores both” wording should not imply reviving old credentials.
Closes #146.
Verification: 235 tests passed;
pnpm typecheck,pnpm lint, and packed CLI e2e passed. Live development Clerk/browser checks covered invite, resend, revoke, join, last-admin refusals, deactivation/reactivation, CLI access, and mobile layout. An initial unrelated ExpirySweep scheduling failure passed in isolation and on the full rerun. Standards and spec reviews found no implementation issues.Implemented with OpenAI GPT-6 Astra in the Oh My Pi harness.