Skip to content

fix(auth): restore MCP connections per turn actor only - #1414

Merged
dcramer merged 18 commits into
mainfrom
test/mcp-auth-orchestration-actor-scope
Aug 11, 2026
Merged

dcramer merged 18 commits into
mainfrom
test/mcp-auth-orchestration-actor-scope

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Fixes the Miguel case from #1377: a later person in a thread no longer inherits another person's prior MCP connections.

Change

  • store who connected each MCP provider on mcp_provider_connected
  • restore only that person's connections on every turn, including same-turn resume
  • do not rebuild live MCP clients from shared thread tool history or skills loaded from that history
  • intentional use still connects on demand under the current person
  • old events with no person id are not used for restore

Proof

Integration suite mcp-auth-orchestration.test.ts through the real Slack path (only Slack HTTP + model stream faked):

  • first MCP use parks for the person who asked and continues after they link
  • same person later reuses their connection with no new prompt
  • same person gets a new prompt when stored access is gone
  • second person who intentionally uses MCP parks for themselves only
  • passive side message does not change owner or send an auth link
  • passive side message while auth is waiting leaves the original person parked
  • auth waiting, then same person says never mind → answer that message, no second auth link
  • after Alice used MCP, Bob's unrelated request does not get an auth link
  • Bob's follow-up does not restore Alice's MCP connection under Bob
  • Alice used provider A; Bob uses provider B → Bob does not get an auth prompt for A
  • Alice used open MCP; Bob parks and completes OAuth for Eval Auth → resume does not warm Alice's provider under Bob

Not in this PR

  • non-MCP plugin auth on the full path (still needs a real sandbox auth signal)
  • OAuth callback route details (mcp-oauth-callback.test.ts)
  • pending-auth freshness rules (pending-auth.test.ts)

Requested by David Cramer.

Prove MCP auth pause, same-actor reuse, and cross-actor authority through
the durable queue. Fake only Slack HTTP and the model stream.

Co-Authored-By: David Cramer <[email protected]>
@vercel

vercel Bot commented Aug 11, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
junior Error Error Aug 11, 2026 8:17pm
junior-docs Ready Ready Preview Aug 11, 2026 8:17pm

Request Review

Keep one product outcome per case. Drop passive-reply cases that forced
should_reply and duplicated the cross-actor turn contract, and fold first-use
park/resume into the same-actor reuse setup. OAuth callback and pending-auth
freshness stay in their owning suites.

Co-Authored-By: David Cramer <[email protected]>
Extract the production ingress → queue → agent harness and model stream
helpers into conversation-work fixtures. Slim MCP auth orchestration and
durable-queue suites onto the shared path so cases keep only unique concerns.

Co-Authored-By: David Cramer <[email protected]>
Expand the durable-queue MCP suite beyond the Miguel case. Cover first use
and resume, same-actor reuse, missing credentials, intentional cross-actor
use, passive skip, pending-auth bystander, and subscribed continuation.
Keep only the two restore-under-wrong-actor contracts failing today.

Co-Authored-By: David Cramer <[email protected]>
@sentry-junior sentry-junior Bot changed the title test(auth): cover actor-scoped MCP auth UX test(auth): cover actor-owned MCP connect and reuse Aug 11, 2026
When auth is waiting and the same person sends a later plain message like
"never mind", answer that message and do not send another auth link.

Co-Authored-By: David Cramer <[email protected]>
Store who connected each MCP provider and restore only that person's
connections on later turns. New turns no longer rebuild live MCP clients
from shared thread history.

Co-Authored-By: David Cramer <[email protected]>
@sentry-junior sentry-junior Bot changed the title test(auth): cover actor-owned MCP connect and reuse fix(auth): restore MCP connections per turn actor only Aug 11, 2026
Comment thread packages/junior/src/chat/agent/index.ts Resolved

@sentry-junior sentry-junior Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

One residual hole still looks real.

On same-turn resume, restoreFromTurnHistory rebuilds MCP from full session Pi history and from skills reloaded out of that same shared history. The session record is seeded with the whole thread, so after Alice used Linear and Bob parks for Eval Auth OAuth, Bob's resume can still try to warm Linear under Bob.

New turns look correct. The remaining leak is the resume path.

Please scope resume restore to this turn only (or drop shared Pi/skill inference for MCP entirely and re-activate from actor-owned connections + the pending/intentional provider for this turn), and add a multi-provider case: Alice connected provider A, Bob intentionally uses provider B and completes OAuth, Bob must not get an auth prompt for A.

Restore only providers the current actor previously connected. Same-turn
resume no longer infers MCP servers from full Pi history or skills loaded
from that history. Multi-provider cases prove Bob does not inherit Alice's
provider across a different-provider connect or OAuth resume.

Co-Authored-By: David Cramer <[email protected]>

@sentry-junior sentry-junior Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Stepped back and reviewed the design as a whole, not just the last commit.

Verdict: solid and maintainable. The rule is simple enough to keep:

  1. remember who connected a provider
  2. restore only that person's providers
  3. never rebuild live MCP from shared thread tool/skill history
  4. intentional use still connects under the current person

That matches the product rule and closes the Miguel case plus the earlier same-turn resume hole. The product change is small and local: event ownership, load-by-person, one restore loop. CI is green on the current head.

What works well

  • One source of truth for restore: actor-owned mcp_provider_connected.
  • Restore no longer has a second path through Pi history / skills. That dual path was the bug factory.
  • Ownership uses the credential subject, so delegated system turns stay correct.
  • Record only after a successful connect. A parked first auth does not pretend the person already connected.
  • Integration suite proves the common UX through the real queue path, including multi-provider and OAuth resume isolation.

Residual smell (not blocking)
Skill restore still reloads from shared prior history on new turns (restoreSkillRuntime). That no longer turns MCP on, so it is not the auth leak. It can still make another person's skill the active skill handle for sandbox tool filtering. Leave it out of this PR unless you want a follow-up that scopes skill restore the same way. Just do not re-wire skill restore back into MCP activation later.

Out of scope, still true
Non-MCP plugin auth on this full path is still the next product slice. This PR should not pretend to cover it.

I would ship this design as-is after draft → ready, with the skill-restore note as optional follow-up rather than a merge blocker.

@sentry-junior sentry-junior Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Two things need to change before this is safe to merge:

  • The last commit removes skill recovery for every resumed run, not only shared conversation history. A turn can call loadSkill, pause or yield, and resume in a fresh process. The resumed run now has an empty SkillSandbox, so skill-scoped tool filtering and implicit skill file access can change or fail mid-turn. The renamed MCP component case does not prove this contract; it succeeds through actor-owned MCP provider restore. Keep new turns empty, but restore the last successful loadSkill from the current turn when that turn resumes. Add one integration case through the queue that loads a non-MCP skill, pauses, resumes, and proves its skill-scoped behavior still works. Also prove that a later turn does not inherit it.

  • mcp_provider_connected.actorId is not an actor id. The writer passes credentialUserSubjectId, and the delegated system-run test correctly depends on ownership belonging to the credential subject rather than the actor. Name the stored field and projection argument credentialSubjectId. Keeping the wrong domain term at this auth boundary makes a future caller likely to pass the runtime actor and undo delegated restore isolation.

# Conflicts:
#	packages/junior/tests/integration/durable-queue.test.ts

Co-Authored-By: David Cramer <[email protected]>
Comment thread packages/junior/src/chat/agent/tools.ts Resolved
…ration-actor-scope

# Conflicts:
#	packages/junior/tests/integration/durable-queue.test.ts

Co-Authored-By: David Cramer <[email protected]>

@cursor cursor 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7ea9d27. Configure here.

Comment thread packages/junior/src/chat/agent/tools.ts Resolved
@dcramer
dcramer merged commit c6a1928 into main Aug 11, 2026
37 checks passed
@dcramer
dcramer deleted the test/mcp-auth-orchestration-actor-scope branch August 11, 2026 20:31

This branch had an error being deployed

1 failed (outdated) and 1 active deployments
Preview – junior-docs — aee2fc97 Deployed Aug 11, 2026 by vercel[bot]
Preview – junior — a7ac6efb Deployed Aug 11, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant