Skip to content

feat(access): recheck audiences across runtime and agent calls - #1360

Closed
vsrikar08 wants to merge 12 commits into
feat/1288-owner-recoveryfrom
feat/1287-audience-enforcement
Closed

vsrikar08 wants to merge 12 commits into
feat/1288-owner-recoveryfrom
feat/1287-audience-enforcement

Conversation

@vsrikar08

@vsrikar08 vsrikar08 commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

What changed

Loaded patches and cached agent tools could retain access after audience removal. Runtime and MCP now use the same targeted Patches admission check for protected work, including owned-resource callbacks and nested calls. Retired patches refuse callbacks consistently.

Closes #1287. Part of #1192. Stacked on #1358; these PRs remain unmerged and land together.

Allison's review is addressed: member callbacks reuse invocation-local authorization while patch lifecycle and company membership authority remain unchanged. Credential checks remain active; guest callbacks retain fresh current-version and connection checks. Live queries no longer depend on the member directory unless they read it. Existing document checks, membership wakes and delivery fences retain revocation protection. Patch fences consume #1357's numeric lifecycle revision directly, with no audience sum or activation switch.

Work admitted before removal commits may finish, including atomic mutations. Subsequent admission refuses access; delivered bytes and committed work are not retracted. Restoration permits fresh admission. Failed authority reads fail closed.

Look at

  • apps/server/src/TeamAccess.test.ts uses the full HTTP server, stored team memberships and the actual admission adapter. Removing the reader's only granting membership closes a subscribed stream, refuses the next table broker call and reconnect; restoration permits broker access and a fresh stream.
  • packages/mcp/src/Calls.test.ts checks callback retirement/restoration. Against the old adapter, the new assertion failed with ['admin', 'admin', 'admin']; the fixed adapter passes with ['admin', 'access_denied', 'admin'].
  • Reauthorization.test.ts covers unchanged-authority reuse, revocation, restoration, failed reads and authority changes during authorization. Existing callback, nested admission, guest, directory and subscription coverage remains.

How it was verified

  • Formatting, lint, workspace/test typechecking (24 tasks) and infrastructure synthesis passed.
  • All 15 affected suites pass across focused runs. The final combined run passed 64/65 tests; the workerd query suite then passed all 3 tests in isolation after its first-snapshot failure under concurrent verification. The full-server guest suite also passed.
  • Full pnpm verify was attempted, then stopped after broad fleet/provider, Linux /proc-on-macOS, CLI and source-copy failures. Full acceptance is not claimed; CI is running on the pushed head.

Surface review: no new wire/CLI contract, migration, skill surface or UI. Product/domain docs record authority and in-flight rules. Genuine directory dependencies and concurrent snapshot fencing remain. SDK generation, guest-detail and connection-page fixes stay outside this PR. Per Srikar's latest instruction, no dependent PR or combined testing branch was changed.

Release impact

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

Internal enforcement; no new client contract or stored format in this PR.

  • What does a revert leave behind? No new data format. It removes audience enforcement and must not be released independently of the complete access stack.
  • Does the release before it still work with that? This PR adds no incompatible data. The assembled stack inherits its lower PRs' one-way release constraints; do not roll back only its enforcement.

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:16:59.151464Z e542116 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:primitives Patch tables and files size:m 100-500 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: 7486748b47

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

Copy link
Copy Markdown
Owner

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

The coverage is complete. At the stack head, all of these check the current audience on every request:

  • portal lists and cards;
  • API list, detail, inventory and log;
  • repo pull;
  • direct, alias, numbered-version and raw URLs;
  • MCP find, open, read and change;
  • the tier 1 broker and files;
  • tier 2 admission, nested calls and callbacks;
  • stream open and reconnect;
  • every live delivery.

Team-membership, role and audience changes all advance a revision the fence watches. Nothing trusts a page load, credential or loaded version for content.

Two places are still open:

The diff is small because #1357 already put the decision into the shared reads. What's wrong is how often it checks, and that two adapters implement one decision.

This PR

  • Should-fix (performance): every subscription now depends on members:<company>.
    • Where: QuerySubscriptions.ts:72-74,100-107, SubscriptionReads.ts and RuntimeStream.ts:819.
    • The directory revision moves on any of these: a name or email change (including the claim refresh at sign-in), a role change, a deactivation, a team edit or a guest change. Each one re-runs every live query in the company. A change that commits mid-read fails that read with a retryable error frame.
    • Every delivery already runs the document check against the current audience, and the members: wake already closes revoked streams. Drop the per-subscription members: dependency.
  • Should-fix (performance): every callback reauthorizes.
    • CallbackGateway.ts:338 now reauthorizes every callback, not only viewer-authority ops. It also leaves a bare { … } block where the if used to be.
    • A handler that makes 50 table reads now does 50 viewer, patch and membership lookups.
    • Invocation.ts:277 repeats the admission Runtime has just done for a browser server.call.
    • Recheck callbacks only when the authority revision has moved.
  • Should-fix: two adapters for one decision.
    • The browser adapter (Server.ts:188-202) builds patches.find plus Audiences.canOpen by hand and re-provides SqlClient and Activation. Patches.find(id, …, viewer) already does that.
    • The MCP recheck (Calls.ts:279) builds a whole portalCard per callback, with every version plus off-sources; that is fix(access): protect patch metadata and simplify agent checks #1367's MCP item. It also reads with state "all", so MCP callbacks keep running on a retired patch while browser callbacks are refused.
    • Use one adapter for both.
  • Should-fix (test gap): nothing runs the real member check with a team audience.
    • The "stale loaded version" test uses a stub port. Every runtime, stream and files suite stubs member: () => true: runtime/src/test/fixtures.ts:99, patches/src/RuntimeStream.test.ts:63, primitives/src/FilesApi.test.ts:76 and apps/server/src/StreamLifecycle.test.ts:137.
    • Add one server-level test: remove a member from the patch's only team, then check that their open stream closes and their next broker call is refused.

Stack-wide

  • Duplicated audience state (item 3). The fence sums lifecycle_revision + audience_revision (SubscriptionReads.ts:178). That sum, and the "numeric and monotonic" test in RuntimeStream.test.ts, go once audience changes bump lifecycle_revision.
  • Activation switch (item 2). Server.ts captures Audiences.Activation and re-provides it.
  • fix(access): protect patch metadata and simplify agent checks #1367's MCP item belongs here (see the adapter point above).

@vsrikar08 vsrikar08 added the one-way Rolling production back past this PR would break the release before it label Nov 10, 2026
@vsrikar08
vsrikar08 force-pushed the feat/1288-owner-recovery branch from 0dea95c to 2fa0b10 Compare November 10, 2026 06:35
@vsrikar08
vsrikar08 force-pushed the feat/1287-audience-enforcement branch from 7da2ad1 to 23a4857 Compare November 10, 2026 06:35
@github-actions github-actions Bot added size:l 501-1,000 changed lines and removed size:m 100-500 changed lines labels Nov 10, 2026
@vsrikar08

Copy link
Copy Markdown
Collaborator Author

Addressed Allison’s agreed review in ed528c7, pushed at e542116:

  • Browser and MCP share targeted Patches.admitsMember; callbacks no longer construct portal cards and retired patches refuse them consistently.
  • Invocation-local authorization is reused while member/patch authority is unchanged; credential checks, guest reach, direct/nested admission and fail-closed behavior remain.
  • Removed blanket membership query dependencies while retaining actual directory reads, document membership wakes and delivery checks. Patch fences use feat(patches): share patches with teams and named guests #1357’s numeric lifecycle revision directly; obsolete sum test and activation wiring are gone.
  • Added the full-server stored-team revocation/restoration case: subscribed stream closes, next table broker call and reconnect refuse, restoration permits fresh admission. MCP retirement assertion fails on the old adapter and passes with the fix.

Updated this PR’s description and #1287 with evidence and verification limits. Formatting, lint, 24 typecheck tasks and synth pass. All 15 affected suites pass across focused runs; final combined 64/65, then the workerd query suite passes 3/3 alone. Full verification was attempted but stopped after broad platform/provider, CLI and source-copy failures; CI remains the full-suite check.

Per Srikar’s latest instruction, work stops at #1360/#1287. No dependent PR or combined testing branch was changed. No new issue/PR, merge or deployment.

@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:primitives Patch tables and files area:server Touches the server area one-way Rolling production back past this PR would break the release before it size:l 501-1,000 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants