Repository navigation
fix(auth): restore MCP connections per turn actor only - #1414
Conversation
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]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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]>
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]>
There was a problem hiding this comment.
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]>
There was a problem hiding this comment.
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:
- remember who connected a provider
- restore only that person's providers
- never rebuild live MCP from shared thread tool/skill history
- 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.
Co-Authored-By: David Cramer <[email protected]>
There was a problem hiding this comment.
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 emptySkillSandbox, 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 successfulloadSkillfrom 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.actorIdis not an actor id. The writer passescredentialUserSubjectId, 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 argumentcredentialSubjectId. 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]>
Co-Authored-By: David Cramer <[email protected]>
Co-Authored-By: David Cramer <[email protected]>
Co-Authored-By: David Cramer <[email protected]>
…ration-actor-scope # Conflicts: # packages/junior/tests/integration/durable-queue.test.ts Co-Authored-By: David Cramer <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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.

Fixes the Miguel case from #1377: a later person in a thread no longer inherits another person's prior MCP connections.
Change
mcp_provider_connectedProof
Integration suite
mcp-auth-orchestration.test.tsthrough the real Slack path (only Slack HTTP + model stream faked):Not in this PR
mcp-oauth-callback.test.ts)pending-auth.test.ts)Requested by David Cramer.