Skip to content

feat(guests): admins block guests from a connection - #1112

Merged
allisonmahmood merged 2 commits into
mainfrom
guests/3-block-guests
Oct 31, 2026
Merged

allisonmahmood merged 2 commits into
mainfrom
guests/3-block-guests

Conversation

@allisonmahmood

Copy link
Copy Markdown
Owner

What changed

Admins had no way to keep a sensitive connection away from a patch's guests. A connection's page now has Block guests: only admins can use it, and members see whether it's on. While it's on, any patch whose current version declares that connection turns its guests away from their next call. Their grants stay, so they're back once the block is off or the patch stops declaring the connection. Members are unaffected.

The owner and admins see why on the patch's card and in Needs attention. A publish that turns guests away still succeeds, and its warnings say why. Warnings only appear for a patch with active grants.

This is the third of six stacked PRs. Sharing has no surface until PR 5, so the tests and screenshots write grants directly.

Closes #1078

Look at

  • One rule, one wording. GuestGrants.unavailable(patch, version, blocked) gains ConnectionBlocked { integration, handle }. GuestGrants.describe is the only place a reason becomes words, and the card, Needs attention and publish all use it.
  • Who pays for the block read.
    • ConnectionStore.blockingGuests(ids) reads any number of connections' flags in one query, so patches never reads the connections table.
    • Only a grant holder's admission reads the flags. GuestGrants.host takes the version the door already holds and reads the grant, with the patch's state and current version, in one query. It goes on to the flags only when a grant is found.
    • Members' calls do no new reads. LoadedVersion.admitsGuests is gone: the runtime port asks host(loaded, userId) for anyone outside the company and fails with SourceUnavailable.
  • Warnings without an N+1.
    • unavailableToGuests(companyId) makes one query for the company's live, company-only patches with active grants and their current declarations, plus one block read. Only an owner's or admin's pages run it.
    • Publish uses unavailableAfterPublish. It's silent for a new patch, a patch without grants, or one going public.
  • The control follows the connection page's existing post buttons. Everyone sees a Guests: Allowed / Blocked fact. Admins also get Block guests or Allow guests, and a member's POST answers 403.

Screenshots

These follow pnpm dev compare's method: full page at 1280 and 390 px, scale 2, signed in as Allison (admin) on two fresh attio instances, base 9f487c1 and head 27e0a14. Compare itself can't reach this state, because the connection page is addressed by a per-instance id and the grant needs sharing (PR 5). So both sides first got the same state: a guest from Pine Studio with a grant on Deal desk, written directly. On head, attio/crm was then blocked through the page's own POST.

Connection page, desktop. Head shows Guests: Blocked and Allow guests.

after

Before

before

Before, phone After, phone

Deal desk's card, desktop.

after

Before

before

Before, phone After, phone

Needs attention, desktop.

after

Before

before

How it was verified

New focused tests:

✓ apps/server/src/Guests.test.ts > a tier 2 patch's guest > turns guests away while a connection the patch uses blocks them, and lets them back after
✓ packages/integrations/src/ConnectionPages.test.ts > company connection pages > lets only an admin block guests from a connection, and shows everyone which
✓ packages/portal/src/PortalPages.test.ts > warns its owner when a patch with guests uses a connection that blocks them
✓ packages/patches/src/PatchesApi.test.ts > Postgres declaration publishing > publishes a version its guests can't open, and says why only when it has guests
✓ packages/patches/src/GuestGrants.test.ts > turns guests away from a version using a connection that blocks them, and only then
  • The server journey runs over the whole server with real workerd:
    • A guest's call to a marked handler of a tier 2 patch that declares a connection succeeds.
    • The admin then posts Block guests on the connection's page. The guest's next call is access_denied, while the admin's own call still answers.
    • After Allow guests, the same guest is back without being shared again.
  • The publish test checks that a publish to a patch with no guests carries no guest warning. With a guest it's still a PublishUpdated success, and its warnings hold GuestGrants.warning(ConnectionBlocked …). The CLI exits 0 on a successful publish whatever its warnings say (ADR-0004).
  • The migration test now reads the connections-per-integration upgrade with today's store on today's schema. A connection made before this column reads blockGuests: false.
  • Full suites pass for integrations, runtime, serving, patches, portal, primitives, mcp and apps/server.
  • pnpm check: format, lint, typecheck and synth pass.
    • The offline tests fail only suites this PR doesn't touch: cliPublish, cliLook, cliLifecycle, cli, Engine and RequestEvents. They come from stray GET / requests reaching local test servers on this machine.
    • RequestEvents and Engine pass when rerun alone.
  • pnpm verify: postgres-concurrency, cli-smoke, install and tier2-smoke pass.
    • test failed the same stray-request CLI suites, plus LocalTaskProvider, a Supervisor timeout and RequestEvents, none of which this PR touches.
    • browser stopped at tier1.spec.ts "hostile navigation…", where a stray / reached its foreign-origin server, as on PR 2.
  • docs/API.md is unchanged: the wire doesn't change, and blockGuests stays off the public connections API because nothing reads it there.

Release impact

Tick exactly one.

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

The migration adds a column whose default allows guests, so every existing connection behaves as before.

  • What does a revert leave behind? The block_guests column (0032_connections_block_guests) and any blocks admins have set.
  • Does the release before it still work with that? It runs, since it never reads the column. But it would let guests back into patches whose connections an admin blocked, and the rest of the guest stack is one-way. One-way: fix forward, with the whole stack shipping as one deploy.

Built by Claude Opus 5.5 in Claude Code (T3 Code), rebuilding Srikar Voleti's original guest stack (#1082–#1103).

Co-authored-by: Srikar Voleti [email protected]

@allisonmahmood allisonmahmood added the one-way Rolling production back past this PR would break the release before it label Oct 31, 2026
@github-actions github-actions Bot added area:server Touches the server area area:cli Touches the cli 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:l 501-1,000 changed lines labels Oct 31, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Sol review

Reviewed 27e0a14 against 9f487c1 (guests/2-tier2-handlers, #1110).

  1. Should fix — Spec: an ordinary publish can eject an eligible guest. packages/patches/src/GuestGrants.ts:355 compares the caller's version with currentVersionId freshly re-read by hostRow (lines 278–281). GrantedGuests.recheck first loads current version A; if eligible version B publishes before hostRow, this comparison returns false despite the active grant and both versions being eligible. StreamAdmission converts that to AccessDenied, and RuntimeStream closes the document. This breaks the brief's requirement that a guest's live stream survive a publish like a member's. I reproduced this deterministically using the real grant store and patch publishing persistence, inserting the publish between those reads: the recheck returned None.

    Fix: carry the caller's loaded state/current-version facts into host; re-read the grant and live connection flags, and cover this publish interleaving.

Standards: no additional findings. The service boundary, Schema decoding, Effect composition, shared UI components and focused tests look consistent.

Spec otherwise: checked next-call blocking and unblocking without re-sharing, the member admission fast path, active-grant-only batched warnings, successful publish with warnings, admin-only control rendering and POST, omission of blockGuests from the public API, and migration ordering (main: 0030; PR 1: 0031; this PR: 0032).

Validation: all 181 tests in the six focused suites passed; the additional interleaved-publish reproduction failed the expected continued-admission assertion. The existing rollback-rehearsal CI failure reports an unsettled Deploy run, rather than a code failure.

Verdict: SHOULD FIX before merge — one finding.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Fixed the should-fix in the Sol review in b27c9bb.

GuestGrants.host now judges the version the caller loaded. Its caller passes the patch's state and whether the version was current in that same read:

  • The serving door passes them from the patch it found.
  • Runtime passes them through a new optional LoadedVersion.current, which Patches' loader sets.

The grant query no longer joins patches. Only the grant and, for a grant holder, the version's connection blocks are read fresh, still in one blockingGuests read. A guest's stream recheck still re-finds the current version, so a publish carries them on to it.

The regression test is in GuestGrants.test.ts: grant, load the current version, publish a new one, then ask host about the version loaded before the publish. It failed before the fix and passes now. Typecheck and lint pass. The focused patches, runtime, serving, MCP and server guest suites pass (159 tests).

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Sol re-check

Rechecked b27c9bb2180ebde68f219f26bf04184c6ec42426 and the builder’s reply against the original finding.

Findings: no blockers, should-fix items, or nits. The earlier should-fix is resolved.

  • Race closed — packages/patches/src/GuestGrants.ts:355. Eligibility now uses the caller’s state/current facts; the grant query no longer reloads patch state. I reran the original deterministic reproduction, adapting only paths and the new host arguments: a real publish between the recheck’s version load and grant read now returns Some. Grants and connection blocks are still checked fresh.
  • Optional current is safe — packages/runtime/src/LoadedVersions.ts:17, apps/server/src/Server.ts:182. The adapter passes loaded.current === true; absence means false, never “assume current.” GuestGrants.host itself requires a boolean. Historical loads omit the marker and deny guests. Runtime’s state: "live" is justified by Patches.ts:1498, which excludes retired, deleted and disabled patches. The serving door passes the actual loaded state. The CLI dev runtime uses explicit identities/admission rather than this grant adapter, so its missing marker changes nothing; fixtures using the production adapter fail closed. A future guest-capable loader must explicitly set the marker. I would keep it optional: requiring a boolean is not necessary for correctness. A compiler-host overlay found 39 affected assignment sites in 38 files, mostly test/fixture bindings, including the Patches loader and devResources, plus the interface declaration itself.
  • Streams and members preserved — packages/runtime/src/GrantedGuests.ts:65. Guest rechecks still call find(patchId) without a version id. I verified the next recheck asks about the newly published version. Members retain their existing path and do not invoke the guest host or reload through this recheck.
  • Regression is focused and correct — packages/patches/src/GuestGrants.test.ts:109. It creates a real grant, loads A, persists B, then checks A using its original snapshot. That exercises the offending ordering without timing or mocked policy; the existing stream test and the original reproduction cover the surrounding runtime path.

No Effect service findings. Applicable mirrored surfaces were the runtime port, server adapter and serving door; this fix changes no wire/CLI contract, migration or rendered UI.

Validation: 86 tests passed across GuestGrants, server Guests, RuntimeProduction, RuntimeStream and serving Pages. The separate reproduction passed, including added checks for absent/historical markers, following the new current version, member bypass and retirement. No repository files changed or pushes made.

Verdict: PASS for this fix commit.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Acceptance: PASS with notes

Checked 591c350e0dccd033135ef741519e26bb0711eb13 (base ab19f74f1347024fbf13fbaa575457857788a233) on fresh guests and brightline instances, by gpt-6.1-sol in Codex (T3 Code).

The connection used here was a scenario-only Postgres fixture with invented metadata and unused credentials. Its guest-marked handlers used their own table; no external database or integration was contacted.

Done means

  • Admin-only connection control, default off: passed. Ada saw Guests Allowed and Block guests. Ben had no control, and his direct POST returned 403 without changing the flag. Ada blocked and unblocked through the browser page.
  • Next-call refusal and restoration: passed. Jo's marked query worked before blocking; after blocking it returned 403 access_denied, and a fresh patch load returned 404. Ben's query remained 200. Allow guests restored Jo without another grant. Removing the connection declaration also restored Jo while the connection stayed blocked.
  • Same actionable cause: passed. Ada's card and Needs attention named postgres/warehouse, “which blocks guests”, and the repairs. Ben's card omitted that warning. Revoking the last grant removed the warning from the card and subsequent publish.
  • Successful publish warnings: passed in text and JSON. Exit 0; JSON stderr was empty; warnings retained the guest warning beside the look warning.

Main-feature interaction

Host pull: kind "repo"; downloaded a usable source copy.
Current repo publish: exit 0, stderr empty, warnings:
  This repo has the Patchy look, but the current look is rev 1 by Ada Park:
  Acceptance look. ... run patchy refresh to bring it up to date.
  Guests can't open this patch. It uses postgres/warehouse, which blocks guests.
  Allow guests on that connection, or remove it from the patch.
Pulled copy after the current repo published: exit 2,
  { "kind": "rejected", "code": "behind", ... }
  • Jo's machine credential was refused both pull visit-log and list visit-log with “Patch not found”; no host source was downloaded.

Golden journeys

  • Guests: passed. Jo's marked write appeared live for Ben with Jo's name; unmarked clear was refused; member clear worked; grant revocation refused the marked query; CLI and portal logs named Jo.
  • Brightline: passed. Sign-in door, Home search, public/private sharing, Kudos live across Jordan/Priya, New Business move and reverse across Jordan/Allison, and Spend's own_approval refusal. No browser page errors.

Evidence

Guests, migrations, GuestGrants (including the interleaved-publish fix),
PatchesApi, ConnectionPages, ConnectionStore, PortalPages,
RuntimeProduction, RuntimeStream:
Test Files  9 passed (9)
Tests       234 passed (234)

Rollback answers: match the diff. Migration 0032 and blocks remain; an older release ignores blocks and would let guests back in. one-way is present. The CI rollback job passed all four upgrade/rollback/forward steps on its PR merge build; this does not change the documented guest-policy rollback limitation.

Not run

  • Live Attio/Pidgeon/Postgres calls, real Clerk sign-in/mail, and phone-width inspection. Connection recent-call guest naming passed in the focused suite rather than through a live integration.
  • Several CI jobs remain pending. A displayed zero-step matrix job belongs to a cancelled run, not a code failure; replacement platform jobs are running/passing.

Notes

@allisonmahmood
allisonmahmood force-pushed the guests/2-tier2-handlers branch from ab19f74 to 21c941c Compare October 31, 2026 17:07
Base automatically changed from guests/2-tier2-handlers to main October 31, 2026 17:17
allisonmahmood and others added 2 commits October 31, 2026 18:17
An admin can now block guests from a sensitive connection on its page. A patch
whose current version declares a blocked connection turns its guests away at
their next call, keeps their grants, and lets them back once the block is off
or the declaration is gone. Members are unaffected.

- 0032 adds connections.block_guests, false for every existing connection.
- ConnectionStore gains blockGuests and blockingGuests, one read for any
  number of connections, so patches never reads integrations' tables.
- GuestGrants.unavailable gains ConnectionBlocked; describe words every
  reason in one place. Only a grant holder's admission reads the block flags.
- The card, Needs attention and publish's warnings say why when a patch with
  active grants turns its guests away. A publish stays a success.

Co-authored-by: Srikar Voleti <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
GuestGrants.host compared the caller's loaded version with the patch's
current version read again in its grant query. A publish between the two
reads turned an eligible guest away, and a guest's stream recheck then
closed their live document.

The caller now passes the patch's state and whether the version was
current in its own read: the serving door from the patch it found, and
Runtime through LoadedVersion.current, set by Patches' loader. host reads
only the grant and, for a grant holder, the version's connection blocks
in one read.

Co-authored-by: Srikar Voleti <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allisonmahmood
allisonmahmood merged commit 3613e82 into main Oct 31, 2026
21 of 22 checks passed
@allisonmahmood
allisonmahmood deleted the guests/3-block-guests branch October 31, 2026 17:28
allisonmahmood added a commit that referenced this pull request Oct 31, 2026
## What changed

This adds release 31's What's new entry, written from `5888411`. It
covers everything merged since release 30's `through` (`e3d50f0`). It
also sets the `patchy` release to `0.31.0` in
`packages/patchy/package.json` and `CURRENT_RELEASE`.

| Change | PRs |
| --- | --- |
| New: share a patch with someone at another company from Share… in its
menu. They open it as themselves, find it under Shared with you, can be
picked wherever the patch asks for a person, and on a server-code patch
reach only what its builder opened to guests. The company-or-internet
choice moved into the same dialog, and agents can share too | #1108,
#1110, #1113, #1114 |
| New: People has a Guests tab, with each guest's patches, and admins
can remove a guest from all of them at once | #1115 |
| New: admins can block guests from a connection, and owners see why on
the patch's card | #1112 |

#1118 is release 30's own entry.

## Look at

- **The entry**, at the top of `releases` in
`packages/core/src/whatsNew.ts`. The four PRs that make sharing work are
one change, since nobody can share before Share… exists.
- **Rollback safety, from the live commit `54438fa` (release 30) to
`5888411`:** the same six PRs. #1108, #1110, #1112 and #1113 are
labelled `one-way`, and their answers agree:
- #1108 adds `patch_guest_grants` (migration `0031`). Release 30 starts
with it but ignores grants, so every guest loses access.
- #1110 adds the `guest: true` handler mark to tier 2 descriptors.
Release 30's schema refuses it, so it can't load tier 2 versions
published with it.
- #1112 adds `block_guests` (`0032`), and #1113 adds a directory trigger
(`0033`). Release 30 runs with both but would ignore admins' blocks and
resolve guests picked in member columns as nobody.
  - #1114 and #1115 add no migration or descriptor field.

**Rollback line:** Rolling back past #1110 would leave tier 2 versions
published with handlers marked for guests unloadable, because release
30's descriptor schema refuses `guest: true`, and past #1108 would cut
every guest off; fix forward instead.

## How it was verified

- **Tests.** `whatsNew.test.ts`, `schemas.test.ts` and
`WhatsNewPages.test.ts` pass (21 tests), and prettier passes on the
changed files.
- **The range.** Each of the six PRs was reviewed by GPT 6.1 Sol with
every finding resolved, and got a fresh acceptance PASS with notes at
its rebased head. Each landed with all 12 required checks green,
`rollback-rehearsal` included, and its squash tree matched the accepted
head.
- **Deploy state.** The live commit, pinned from `/healthz/deep`, is
`54438fa` (release 30). The Deploy run updated last succeeded, and none
is unfinished.

## Release impact

- [ ] **Breaking** — requires action from anyone already running this
- [x] **Not breaking** — no action required

Text and version numbers only. The `0.31.0` bump tells CLIs and patch
repos installed before this deploy to upgrade, as every release does.

- **What does a revert leave behind?** Nothing.
- **Does the release before it still work with that?** Yes.

Built by Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, through T3
Code.

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:cli Touches the cli area area:docs Touches the docs area area:integrations Company connections and integration implementations 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:l 501-1,000 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(guests): block sensitive connections and explain unavailable access

1 participant