Skip to content

feat: multiple Google Workspace connectors per organization — each member signs in to each, agent picks by name - #3427

Merged
benjaminshafii merged 12 commits into
devfrom
feat/google-workspace-multi-account
Aug 2, 2026
Merged

benjaminshafii merged 12 commits into
devfrom
feat/google-workspace-multi-account

Conversation

@benjaminshafii

Copy link
Copy Markdown
Member

An organization can now register N Google Workspace connectors (e.g. one per Google domain). Each is its own row with its own OAuth client; each member connects their own account to each; capabilities are namespaced native:<connectionId>:<tool> so the agent picks the right inbox by connector name — no account parameter.

Backward compatibility (by design, not migration)

  • Existing orgs keep provider_id = "google-workspace" literally (alias): no credential rewrite, no token revocation, no Google Console edit.
  • Redirect URI unchanged (provider-scoped); connector id travels in signed OAuth state.
  • Un-namespaced getCapabilitiesGoogleWorkspace* names still resolve to the default connector (asserted by existing tests).
  • Native rows are fenced out of every MCP handshake path (transport, tools list/call, discovery, callback binding, plugin bindings).

Also fixes (standalone value)

  • Connected account email is now recorded (id_token → userinfo, best-effort) and shown: card badge Connected — [email protected], description names the service.
  • Google authorize prompt is consent select_account — a second connect gets a real account chooser instead of silently reusing the signed-in account.
  • Gmail deep links use authuser=<email> instead of hardcoded mail/u/0 (wrong mailbox for anyone signed into multiple Googles). Exact u/0 fallback when email unknown.

Tests run (commands + results)

  • pnpm --filter @openwork-ee/den-api exec tsc --noEmit — clean
  • bun (real MySQL): google-workspace-capabilities 29/29 · native-capabilities (new) 7/7 incl. credential-isolation crux (two tokens, right one hits fake Google API, asserted on Authorization header) · native-provider-scopes 6/6 · gmail-draft, rotation, revocation — green
  • Every red suite baseline-checked against origin/dev (native-provider-connections 2 fails, mcp-connections-tools 4, mcp-connections-edit 8 — all reproduce on dev): zero introduced failures
  • pnpm evals:typecheck, pnpm evals:spec (PR lane) green; eval package tests 117/117
  • String-level check that blocking nightly flows are unaffected: no flow asserts mail/u/0; "Connected with your own account." kept intact as prefix; badge checks are includes("Connected")

E2E evidence (partial — stated honestly)

App-driving spec evals/specs/google-workspace-multi-account.slow.test.ts (enacts the approved voiceover): best run validated 4/8 frames against the real Electron app + real Den + mock Google (two connectors listed, service named on card, detail panel, Labs authorize with real account chooser witnessed by the mock). Photo roll posted below.

Known-incomplete: frames 5–8 (both-emails list, agent-picks-Labs e2e, wrong-mailbox-empty witness, single-domain no-regression) are unit-proven server-side but have no green app-driven run yet. The spec is .slow + opt-in (OPENWORK_EVAL_GOOGLE_MULTI_ACCOUNT_SPEC=1) and skips cleanly in PR CI and nightly — same precedent as org-connector-two-members.

To un-gate the spec (follow-up): bound every helper wait; fresh sign-in before teardown (long runs hit 403 fresh_auth_required); provision script that boots Den with DEN_GOOGLE_OAUTH_*/DEN_GOOGLE_API_BASE_URL pointed at the mock (the one genuinely missing infra piece); nightly model+key for the agent turn.

Repro for reviewers: evals/scripts/dev-den.ts + set the four DEN_GOOGLE_* vars to the mock (startMockGoogle, port 3980), then run the spec opted-in.

@vercel

vercel Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
openwork-app Ready Ready Preview Aug 2, 2026 2:46pm
openwork-den Ready Ready Preview Aug 2, 2026 2:46pm
openwork-den-worker-proxy Ready Ready Preview Aug 2, 2026 2:46pm
openwork-landing Ready Ready Preview, v0 Aug 2, 2026 2:46pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
openwork-diagnostics Skipped Skipped Aug 2, 2026 2:46pm

@benjaminshafii

Copy link
Copy Markdown
Member Author

Photo roll — google-workspace-multi-account

✅ 4/4 frames passed · 0 failed · 0 unvalidated · 8 expectations passed · 0 failed

1. Acme Robotics is visibly listed as a Google Workspace connection this person can sign in to

  • ✅ PASS Acme Robotics is visibly listed as a Google Workspace connection this person can sign in to — The “Acme Robotics” row shows a Google icon, “Connection,” “Google Workspace,” and a “Sign in” button.
  • ✅ PASS No Acme Labs connection or 'Something went wrong' crash message is visible yet — No “Acme Labs” or “Something went wrong” message is visible; the only Acme entry shown is “Acme Robotics.”

Acme Robotics is visibly listed as a Google Workspace connection this person can sign in to

2. Acme Robotics and Acme Labs are both visible, as two separate Google Workspace connections

  • ✅ PASS Acme Robotics and Acme Labs are both visible, as two separate Google Workspace connections — Two separate Google-icon rows labeled “Acme Robotics” and “Acme Labs” are visible, each showing Google Workspace provider text.
  • ✅ PASS The original Acme Robotics connection is still present and no crash message is visible — The “Acme Robotics” connection row is visible near the bottom, and no crash or error message appears anywhere on the page.

Acme Robotics and Acme Labs are both visible, as two separate Google Workspace connections

3. A Google Workspace connection detail visibly offers connecting this person's own account

  • ✅ PASS A Google Workspace connection detail visibly offers connecting this person's own account — The panel says “Google Workspace” and “Connect your own account to use it,” with a visible “Connect your account” button.
  • ✅ PASS No shared password is requested and no crash message is visible — The screen shows “Authentication: OAuth required”; no password request or crash/error message is visible.

A Google Workspace connection detail visibly offers connecting this person's own account

4. OpenWork visibly shows that Acme Labs browser authorization is in progress

  • ✅ PASS OpenWork visibly shows that Acme Labs browser authorization is in progress — Acme Labs shows Status: “Waiting for browser...” and a button with a loading spinner labeled “Waiting for browser...”.
  • ✅ PASS The app has not silently reported success and no OAuth launch error is visible — The visible status remains “Waiting for browser...”; no success confirmation or OAuth error message is shown.

OpenWork visibly shows that Acme Labs browser authorization is in progress


Roll created 2026-08-02T11:54:22.092Z · Source: evals/results/rolls/2026-08-02T11-54-22-092Z-google-workspace-multi-account/roll.json · Repro: pnpm --dir evals run publish:pr -- --pr 3427 --roll 2026-08-02T11-54-22-092Z-google-workspace-multi-account

… chooser, and stop deep-linking to u/0

Foundation for multiple Google Workspace connectors per organization. No
user-visible multi-account behavior yet; every change here is additive and
backward compatible.

- external_mcp_connection gains kind + native_provider_key so a row can
  represent a native OAuth connector instead of an external MCP server
  (migration 0050, additive, no constraints and no backfill)
- the native OAuth callback now resolves the account's email from the
  id_token, falling back to the provider's userinfo endpoint, and persists
  it as externalAccountId. Resolution is strictly best-effort: a missing
  claim, a failed fetch, or a junk response still completes the connect
  exactly as before
- Google's authorize prompt becomes "consent select_account" so a member
  who is already signed in is actually offered the account chooser
- Gmail draft and thread links use authuser=<email> instead of the
  hardcoded mail/u/0, which resolves to whichever Google account happens to
  be first in the browser. Falls back to the exact previous u/0 output when
  the email is unknown

The redirect_uri, every route path, and all generated capability names are
unchanged.
`pnpm fraimz --all` runs every file in evals/flows on the nightly lane, so a
scaffolded flow whose frames are still `ctx.assert(false)` turns nightly red
until the feature lands.

New app-driving proof belongs in evals/specs as a photo-roll spec (see
org-connector-two-members.slow.test.ts and the pr-photo-roll skill), which the
nightly spec lane runs separately and which publishes evidence to the PR. The
voiceover script stays as the approved narration for that spec.
…aces it needs

Writes the proof before the feature. The spec enacts the approved narration in
evals/voiceovers/google-workspace-multi-account.md and encodes the definition
of done, including the halves that are easy to skip:

- the mailbox is the witness: the supplier draft must appear in the Labs
  mailbox AND the Robotics mailbox must be empty
- the two connectors' drafts must not share a credential token
- the user-facing request must not contain either connector id, so "the agent
  picked the right connector" cannot pass by being told the answer
- the Gmail link must carry authuser= and must not be /mail/u/0/
- a single-domain organization must still see exactly one card and one button

Six primitives it needs do not exist yet. They are declared here as typed
stubs that throw a message naming the primitive and how to build it, so the
spec compiles and fails for the right reason instead of failing to compile:
startMockGoogle, createNativeConnector, readSessionToolCalls, provisionOrg.
openConnectionsSurface/waitForConnectionCard/revealText are promoted out of
org-connector-two-members rather than stubbed, since working copies existed.

Gated behind OPENWORK_EVAL_GOOGLE_MULTI_ACCOUNT_SPEC so an unconfigured run
skips cleanly; it is .slow, so it never enters the PR lane.
…ll two accounts apart

The first of the six primitives the multi-account spec needs. Written as a
focused mock beside scripts/mock-oauth-mcp-server.mjs rather than an extension
of it: six existing eval flows depend on that script's single-account
behaviour, and the safest way to not regress them is to leave it byte-unchanged.

The fixture provides what the old one structurally could not:
- an id_token carrying the authorizing account's email, plus /userinfo, so Den
  can record WHICH account connected
- a real chooser page when prompt contains select_account, with chooseAccount()
  resolving only once the callback has actually been served, never on a timer
- per-account mailboxes, every draft attributed to the credential that created
  it, so a spec can assert the draft landed in one inbox and not the other

draftsFor() returns promptly with [] for an empty mailbox instead of blocking
for the full timeout, because the negative half of the isolation assertion is
the half that matters and a primitive that makes it slow is a primitive that
makes it get dropped.
…rganization

An organization can now register more than one Google Workspace connector.
A connector is an external_mcp_connection row with kind='native_provider':
its OAuth client lives in org_oauth_client and each member's tokens live in
connected_account, both keyed by the connector row id. The existing
(org_membership_id, provider_id) unique index then makes per-connector
isolation automatic rather than something to enforce.

Backward compatibility is by alias, not migration. An organization that
already configured Google keeps provider_id='google-workspace' literally in
both tables and keeps appearing with id "google-workspace". Nothing is
rewritten, because rewriting provider_id would look like an OAuth client
rotation and revoke every member's tokens.

The redirect URI stays keyed by provider, not by connector, so customers do
not have to touch the Google Cloud Console entry they already pasted. The
connector id travels in the signed OAuth state instead.

Native rows are fenced out of every MCP handshake path — transport, catalog,
tool calls, connect/start discovery, the external OAuth callback binding, and
plugin MCP requirement binding — since a Google connector has no MCP server
behind it and would otherwise fail deep inside a handshake.

Capability namespacing is deliberately not here: un-namespaced Google
capability names still resolve to the organization's default connector.

test(evals): implement provisionOrg, and make the local Den reproducible

provisionOrg creates a real isolated organization with a known shape so a
spec can assert that a single-domain company still sees exactly one card.
evals/scripts/dev-den.ts captures the setup that previously took manual
archaeology: db:push rather than db:migrate (the chain cannot build a
database from scratch), an isolated port and database, and the trusted
origins that otherwise fail as a 403 at sign-in looking like a product bug.
…hat exists

The spec was requesting a "gmail" scope feature that the provider registry
does not define, and the route correctly rejected it. The first fix attempt
added "gmail" to NATIVE_OAUTH_PROVIDERS as an alias for the compose scope,
which is product code bending to fit a test; reverted. The spec now asks for
gmailDraft, which is the real feature name for creating drafts.

createNativeConnector posts the connector and its OAuth client through the
route that landed with the server work, and deleteConnection is confirmed to
work on native rows so the spec's onTestFinished cleanup is real.
Two fixes found by running the spec against the real app rather than reasoning
about it.

The DOM assertions passed while the frames failed: the connection card was in
the document but not on screen, so the vision model saw a truncated workspace
name instead. Every screenshot now reveals its subject first, which is what
revealText exists for — waitForText proves the DOM contains it, a frame proves
pixels.

The first frame also claimed Acme Robotics was "set up", which conflated the
admin having registered the connector with the member having connected their
own account. At that point in the story Jordan has not connected, and the app
correctly offers her a sign-in. The claim now says what a person would see.

Frames 1 and 2 pass: two separate Google connections visible side by side.
…idental layout claim

Two more corrections found by running against the real app.

The list surface offers each connection a "Sign in" next action and opens a
detail panel to authorize; "Connect your account" (mcp.org_connection_connect_action)
only exists in that panel. The third frame was asserting the panel's wording
against the list, so it counted zero buttons. It now asserts the two cards plus
the sign-in affordance, and the later connect flow already goes through the
detail panel correctly.

The second frame claimed the two connections were "side by side". They are
stacked vertically, and the vision model was right to say so — it passed once
and then failed on the same pixels, because the claim asserted incidental
layout rather than the fact being proven. Claims should describe what a human
would verify, or they are flaky by construction.
…h account is signed in

The member card for a native connector was anonymous: an admin names it
"Acme Robotics", and nothing on screen said Google Workspace. The vision
check caught this as a real product gap — it passed or failed depending on
whether the model credited the G favicon, which is what a human reviewer
would waver on too.

The usable-connections entries now carry nativeProviderKey (both the
toConnectionResponse mapper and buildNativeProviderEntry — native rows are
served by the latter, which is why fixing only the former changed nothing),
plus the caller's connected account email. The desktop prefixes the card
description with the service name and, once connected, appends
"Signed in as <email>." — keeping the existing sentence intact as a prefix
because other specs wait for it verbatim.

Also: frames now assert prompt CONTAINS select_account (the product
correctly sends "consent select_account"), the detail-panel frame replaces
a pixel-duplicate list frame, and openConnectionsSurface steers back in a
loop — the app opens a freshly created session on its own, and a single
navigation followed by a 60s wait parks the spec on /session forever. Its
failure now reports what was actually on screen.
"Connected" alone cannot tell two Google sign-ins apart, and the approved
demo narration promises the list shows the real email behind each connector.
The connected badge now reads "Connected — [email protected]" when the
account identity is known.

The spec's both-emails frame closes the Labs panel first and waits for both
addresses on the list before framing it.
…(connect/start, callback, status, disconnect, default resolution)

Warden NPN-7MR: an ungranted member could begin OAuth on a native connector
and back un-namespaced Google capabilities with it. Every member-facing
resolution of a connector row now goes through the grant-aware listing;
the legacy org_oauth_client-only alias keeps its implicitly org-wide
behavior unchanged.

@diff-warden diff-warden Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warden security clearance: clear. No new security issues found in this diff (45c4e5d708058bfd5512c26235146f683950d63f). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run

@benjaminshafii
benjaminshafii merged commit 69e3ccc into dev Aug 2, 2026
19 of 20 checks passed
benjaminshafii added a commit that referenced this pull request Aug 2, 2026

This branch was successfully deployed

4 active and 1 inactive deployments
Preview – openwork-den-worker-proxy — 45c4e5d7 Deployed Aug 2, 2026 by vercel[bot]
Preview – openwork-den — 45c4e5d7 Deployed Aug 2, 2026 by vercel[bot]
Preview – openwork-landing — 45c4e5d7 Deployed Aug 2, 2026 by vercel[bot]
Preview – openwork-app — 45c4e5d7 Deployed Aug 2, 2026 by vercel[bot]
Preview – openwork-diagnostics — 45c4e5d7 Deployed Aug 2, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant