Skip to content

feat(patches): recover owners who lose audience access - #1358

Closed
vsrikar08 wants to merge 15 commits into
feat/1286-patch-audiencesfrom
feat/1288-owner-recovery
Closed

vsrikar08 wants to merge 15 commits into
feat/1286-patch-audiencesfrom
feat/1288-owner-recovery

Conversation

@vsrikar08

@vsrikar08 vsrikar08 commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

What changed

An owner removed from a patch’s teams loses content access without losing a recovery route. Super admins manage every patch through bounded metadata; regular admins manage patches they can open. Neither ownership nor administration grants content access.

Closes #1288. Part of #1192. Stacked on #1357; the access-control stack must land together.

Look at

Allison’s review is addressed:

  • Deactivation/reactivation takes company authority before selected patch locks. Read-only management queries and guest lists take no write locks.
  • Confirmation forms consistently carry the expected owner ID, without field-presence checks.
  • Management-only access cannot edit descriptions. Sharing returns minimal metadata, rollback receipts use the permitted name, and content/management selection has an explicit discriminator.
  • Readable cards use their existing detail loader; management history reads only ownership/audience metadata, avoiding repeated source, dependant and version reads.
  • One management query supplies permitted metadata and canOpen, canManage, ownerCanOpen. It reuses the existing card, Settings and Versions renderers. Separate management-card/version methods and duplicate membership-facts queries are removed.
  • Owner history follows team visibility while retaining attributable records. All avoids duplicate cards, Needs attention retains inaccessible-owner recovery, and individual lookups distinguish names from IDs.
  • Companies supplies decoded role facts; reassignment reuses the resolved role and retains current-audience, expected-owner and target checks.

Super admins still explicitly join restricted teams to read content; ordinary CLI/MCP discovery remains audience-filtered.

How it was verified

At 80638018, against #1357 61da8e8f:

  • 120 tests passed across recovery, portal HTTP journeys, rendering and guest grants. Coverage includes forged description writes, hidden titles, stale read-only recovery forms, name/ID collisions, restoration without off sources, reassignment, membership restoration and scoped join history.
  • Both CLI smoke CI jobs pass on this head: Node 22, Node 26.
  • Full packed CLI smoke passes locally after aligning both audience assertions with the current schema and canonicalizing the macOS log-path check.
  • 24/24 workspace typecheck tasks, full lint and affected-file formatting pass. The full verification attempt also passed infrastructure synth, 28 Postgres concurrency tests and tier 2 smoke.
  • The earlier full pnpm verify attempt did not pass. Failures include execution-provider tests on macOS, GNU tar options unavailable on macOS, the install harness’s missing mise, and a browser hotkey timeout. No full-suite or acceptance pass is claimed.

Internal service/portal change; existing wire routes and CLI responses remain intact. No new migration, command, runtime activation or deployment. No dependent PR or combined testing branch was changed by this revision.

Release impact

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

Uses the stacked base’s existing schema and mutation routes.

  • What does a revert leave behind? Ownership, sharing and lifecycle changes in the base’s existing formats; no new persisted format.
  • Does the release before it still work with that? The immediate stacked base does. The complete access-control stack retains its separately documented one-way deployment boundary.

Model: GPT-6. 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-10T07:05:14.444325Z 8063801 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: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: 6e26917db6

ℹ️ 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/patches/src/Patches.ts Resolved
Comment thread packages/portal/src/PortalPages.ts Resolved
Comment thread packages/patches/src/Patches.ts Resolved
@vsrikar08

Copy link
Copy Markdown
Collaborator Author

Design review found four issues to fix:

  1. recoveryPost duplicates the existing lifecycle and sharing dispatchers. Its force/acknowledgement and guest-error handling already diverge. Reuse the existing action handlers with an authorized metadata view.
  2. Owner history filters only the first 100 company membership changes, hiding later relevant self-joins. Query relevant facts through Companies with correct pagination.
  3. The recovery membership link points to /company/teams; use the exported /settings/company/teams path.
  4. Single-patch views scan every company patch, with repeated per-owner/person eligibility queries under locks. Add a direct management lookup and batch eligibility reads.

Srikar authorized fixing all four. The fixes will stay on this stacked PR and preserve the separation between management metadata and content admission.

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

ℹ️ 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/portal/src/PortalPages.ts Resolved
@allisonmahmood

Copy link
Copy Markdown
Owner

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

The spec items are covered:

  • the stuck owner sees the problem;
  • Needs attention shows it to the admins who can fix it;
  • reassignment checks that the target can open the patch;
  • expected-owner guards stop stale actions;
  • publisher attribution survives.

The shape is too big, and it depends on #1361.

Waiting on Allison (A)

  • If feat(teams): protect admin memberships and restrict team visibility #1361 stands, every super admin is a member of every team. "Manages the patch but can't open it" then never happens for them, and the metadata-only oversight path is dead code. All of this goes:
    • lockOpenable's oversight flag;
    • managementCard and managementVersions;
    • the management branch of actionSelection;
    • recoveryPage's controls;
    • managementOwnerId on the Share dialog;
    • the seven "companyId" in selected.patch checks in PortalPages.ts (826, 828, 992, 1006, 1189, 1200, 1231).
  • If Allison keeps 11-03 decision 8 instead, the path is live and needs the oversight fix below.

This PR

  • Should-fix: deactivating or reactivating with patches selected can deadlock.
    • lockOpenable now takes companies FOR SHARE before the patch row (Patches.ts:1574).
    • The confirm step in UserLifecyclePage.ts:223-226 first retires or restores the person's patches: company FOR SHARE, then patch FOR UPDATE. In the same transaction, users.deactivate then asks for company FOR NO KEY UPDATE, which is a lock upgrade.
    • Meanwhile, an admin opening one of those patches through a management path (inventory, guest list, rollback, description, reassign) holds FOR SHARE and waits on the patch. Postgres aborts one of them with 40P01.
    • Fix: take the company lock first, in one mode.
    • Related: those read-only GETs now hold the patch FOR UPDATE and block publishes while they run.
  • Should-fix, if the oversight path stays: the metadata-only exception reaches everything.
    • manageable passes oversight: actor.admin to every caller (Patches.ts:1616), so the metadata-only exception reaches operations outside the role rules.
    • Description writes: a super admin who can't open the patch can POST the description action using the recovery page's hidden ids (PortalPages.ts:1050).
    • The title: the rollback receipt prints the title that the management card hides (:1070).
    • The full patch: manage() hands it to the guest-grant code.
    • The "companyId" in checks are also a security branch keyed on a missing field. They flip silently the day the card gains companyId. Use a tagged union.
  • Should-fix (size): this builds a second card stack.
    • It adds five service methods (management, managementCard, managementVersions, managementHistory, eligibleOwners), three types, and an 80-line recoveryPage (PortalPages.ts:363) that rebuilds the card.
    • Smallest shape: one management(companyId, userId) query that returns { canOpen, canManage, ownerCanOpen } per patch, and the existing card with its content sections left out when !canOpen.
  • Should-fix: owner history and team names.
    • Hidden team names show. managementHistory (Patches.ts:2612, rendered at PortalPages.ts:384 and :520) lists self-joins for every audience team. A member owner sees the names of teams that feat(teams): protect memberships and hide unrelated teams #1362 hides from them. Either filter by team visibility, or write the exception into product.md.
    • Super-admin access never shows. It is derived and never recorded, so product.md's "visible to affected owners" covers regular admins only (see A).
  • Nits:
    • On a super admin's All view, a patch they can open but its owner can't appears twice (PortalPages.ts:1534-1542).
    • management() scans the whole company on every All load and before every card.
  • Role storage (item 1):
    • reassign re-reads (role = 'admin' OR is_regular_admin) at Patches.ts:2913, after manageable has already resolved the role.
    • Rows that decide access aren't decoded through Schema at :1576, :1618 and :2589 (actors[0]!.role).
  • Company lock (item 4): see the deadlock above.

Tests

  • Keep: OwnerRecovery.test "recovers an inaccessible owner without admitting content…".
  • Drop: the oversight cases go with A.

@allisonmahmood

Copy link
Copy Markdown
Owner

Allison's decision on A (all four on #1192). Posted by Fermy (his agent).

11-03 decision 8 stands: super admins manage every patch but open only what its audience allows. The management view this PR builds stays live, so:

  • The oversight fix above is required. Limit the metadata-only exception to the management operations (owner, audience, sharing, reassign, retire). It shouldn't reach description writes, the rollback receipt or manage().
  • The size point still applies. One management query returning { canOpen, canManage, ownerCanOpen }, and the existing card without its content sections.
  • Owner history works as intended. With feat(teams): protect memberships and hide unrelated teams #1362's automatic membership gone, a super admin who adds themselves to a team leaves a real membership row, and managementHistory shows it to the owner.

@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: 244bc20e67

ℹ️ 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/portal/src/PortalPages.ts Resolved
@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: 2fa0b10d1e

ℹ️ 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/portal/src/PortalPages.ts Resolved
Comment thread packages/patches/src/Patches.ts Resolved
@vsrikar08
vsrikar08 force-pushed the feat/1288-owner-recovery branch from 0dea95c to 2fa0b10 Compare November 10, 2026 06:35
@github-actions github-actions Bot added size:xl Over 1,000 changed lines; review in multiple passes and removed size:l 501-1,000 changed lines labels Nov 10, 2026
@vsrikar08

Copy link
Copy Markdown
Collaborator Author

Addressed Allison’s review and the inline findings in c8dca0a8, on #1357 base 61da8e8f.

  • Lifecycle confirmation acquires company authority before patch locks; management GETs do not take write locks.
  • Oversight cannot write descriptions, disclose protected titles in rollback receipts, or return full patches through guest management. Content and management selection use explicit discriminators.
  • Management metadata/access flags come from one query; the existing card, Settings and Versions renderers are reused. Duplicate management-card/version methods and membership-facts queries are removed.
  • History intersects current granting teams with team visibility and retains the underlying audit records. All has no duplicate recovery cards; Needs attention retains the owner-access warning.
  • Name and ID lookups are distinct; stale recovery refusals suppress patch forms and overlays; management sharing loads the copy script.
  • Restore without off sources now reaches the existing confirmation submit form, rather than redirecting back to its management card. Dependency acknowledgements still use the existing flow.

Validation: 120 tests pass across recovery, portal HTTP journeys, rendering and guest grants; all 24 workspace typecheck tasks and full lint pass. Full verification was attempted and does not pass; its platform/execution, stale lower-stack CLI expectation, installation and browser failures are recorded in the PR body. No acceptance/merge-ready claim.

Updated #1288. Only #1358 was pushed; no dependent PR/testing branch, merge or deployment was changed by this session.

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

ℹ️ 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 +391 to +395
renderVersions({
card: { ...view.card, versions: view.versions },
viewer,
now: yield* Clock.currentTimeMillis
}) +

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 Carry the expected owner in management rollback forms

For a super admin viewing an inaccessible live patch with multiple versions, every rollback button rendered here submits without expectedOwnerUserId: versionsTable in render.ts includes only the patch ID, current version ID and requested version number. However, post rejects every management-only submission whose owner token does not match selected.owner.id, so these buttons always return a read-only 409 refusal without rolling back. Include the expected owner in management rollback forms, as the sharing and confirmation forms already do.

AGENTS.md reference: AGENTS.md:L79-L79

Useful? React with 👍 / 👎.

Comment on lines +1562 to +1564
}) +
management
.filter(

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 Include recovery records in attention navigation and counts

When the only patch needing attention is inaccessible to the super admin, appending its recovery entry after renderAllPatches leaves the attention navigation unaware of it. That renderer calculates tab visibility, counts and empty states solely from content-readable rows, so the normal All patches page hides the Needs attention tab entirely. Visiting ?show=attention directly then displays the recovery entry alongside a zero count and “Nothing needs your attention.” Include eligible management records in those calculations rather than only appending their markup afterward.

Useful? React with 👍 / 👎.

return yield* errorPage(404, "Patch not found", "The requested patch is unavailable.");
const patches = yield* Patches.Patches;
const selected = (yield* patches.read({ ...access, state: "all" })).find(
const selected = (yield* patches.read({ ...access, state: "all", patchRef: name })).find(

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 Resolve deleted patches by ID before loading their logs

For an owner or audience-admitted administrator opening a deleted patch during its retention window, the card still displays the Log tab, but this new patchRef: name makes that tab return 404. Patches.select resolves names only for rows whose deletedAt === null, even with state: "all"; the previous read-all-and-find path included deleted records. Resolve the exact name to its patch ID before reading, as the other updated card handlers do, or retain an all-state name lookup so retained logs remain accessible.

Useful? React with 👍 / 👎.

@github-actions github-actions Bot added the area:ci CI, shared testing infrastructure, development scripts and tooling label Nov 10, 2026
@vsrikar08

Copy link
Copy Markdown
Collaborator Author

Fixed the two design-review findings in 80638018:

  • Confirmation forms always carry the expected owner ID; no field-presence branch or duplicate reassignment field.
  • Readable cards use the existing card detail loader. Management-only viewers retain their permitted details; owner history reads ownership/audience metadata directly instead of invoking the full management path.

Corrected both stale packed-smoke audience assertions and normalized its expected log directory through realpath for macOS. The complete packed CLI real-server journey passes locally. Both CI smoke jobs now pass on this head: Node 22, Node 26.

120 focused tests, all 24 workspace typecheck tasks, lint, formatting and whitespace checks pass. Only #1358 changed; no other stacked PR/testing branch, merge or deployment.

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

ℹ️ 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 ref = { companyId: viewer.company.id, userId: id, actorId: viewer.user.id };
// Acquire the final administration lock before any selected patch locks.
if (choice === "keep" || choice === "confirm")
yield* Users.lockAdministrator(ref).pipe(Effect.catchTags({ RoleForbidden: Effect.die }));

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 Preserve the administrator recheck's permission refusal

If another administrator demotes or deactivates the acting administrator after the session viewer is loaded but before this company lock is acquired, lockAdministrator legitimately returns RoleForbidden. Converting that refusal to a defect bypasses this handler's existing RoleForbidden recovery, producing an internal server error instead of the intended 403 response for deactivation/reactivation submissions. Let the typed refusal propagate to the existing permission-error handler.

Useful? React with 👍 / 👎.

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