Skip to content

fix(runtime): Resume OAuth turns through the conversation worker - #1913

Merged
dcramer merged 3 commits into
mainfrom
fix/oauth-resume-execution-lock
Sep 24, 2026
Merged

dcramer merged 3 commits into
mainfrom
fix/oauth-resume-execution-lock

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

An OAuth-resumed Turn could run beside queued work in the same Conversation. Both runs changed agent history. The resumed Turn then failed to save its continuation with AgentHistoryBranchError.

Route Slack OAuth continuation through the existing conversation worker. Callbacks store an idempotent turn_authorized event for the paused checkpoint and wake the queue. Only the worker records authorization in agent history and runs the Turn, under its conversation lease. It checks the pending request, actor, provider, scope, and MCP attempt before resuming.

Remove the duplicate MCP and plugin OAuth execution paths, their result/failure handlers, and the extra resume lock. Preserve the local CLI and dashboard callback paths. Keep persisted MCP configuration and tool channel when the worker rebuilds the Run.

This replaces the first shared-lock patch. A regression proved that patch fails when queued event work starts first: its execution lock blocks the OAuth credential write. Queue ownership avoids both orderings without another execution lock.

Validation:

  • Both OAuth-first and event-first races pass through production queue wiring. The event-first test fails with the original shared-lock worker and callback restored.
  • 289 focused tests passed across OAuth, local CLI, dashboard authorization, Slack continuation, dispatch, checkpoints, and worker recovery.
  • Full component suite: 722 tests passed. This includes the prior CI failure, updated to test the worker lease rather than the removed thread lock.
  • Typecheck, full lint (including file-length, test-architecture, and ast-grep), formatting, and diff checks passed.

Evidence: Sentry event.

via David Cramer.

--

View Junior Session [Sentry]

@vercel

vercel Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
junior-docs Ready Ready Preview Sep 24, 2026 2:31am UTC

Request Review

Keep OAuth callbacks out of agent execution and history writes. Save authorization readiness for the paused checkpoint, then let the existing worker lease own continuation. Remove duplicate callback execution and the extra resume lock.

Prove both OAuth-first and event-first ordering through real queue wiring. Replace stale thread-lock recovery coverage with the worker lease contract.

Co-Authored-By: David Cramer <[email protected]>
@sentry-junior sentry-junior Bot changed the title fix(runtime): Serialize queued work with OAuth resumes fix(runtime): Resume OAuth turns through the conversation worker Sep 24, 2026
The MCP callback now queues continuation before it returns. Accept success without waitUntil work in its harness test while retaining the generic OAuth and unexpected-background-work guards.
@github-actions

Copy link
Copy Markdown
Contributor

6 screenshot changes — 6 changed · 0 added · 0 removed

Review screenshots in Frameshift

Conversation Attachment · Desktop
Conversation Attachment · Desktop
Changed
Conversation Create Focused · Desktop
Conversation Create Focused · Desktop
Changed
Conversation Create Focused · Mobile
Conversation Create Focused · Mobile
Changed
Conversation Detail · Desktop
Conversation Detail · Desktop
Changed
Conversations · Desktop
Conversations · Desktop
Changed
Conversations · Mobile
Conversations · Mobile
Changed

@dcramer
dcramer marked this pull request as ready for review September 24, 2026 03:11
@github-actions github-actions Bot added the risk: high PR risk score: high label Sep 24, 2026
@dcramer
dcramer merged commit a2ac98b into main Sep 24, 2026
45 checks passed
@dcramer
dcramer deleted the fix/oauth-resume-execution-lock branch September 24, 2026 03:13

@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 3 potential issues.

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 bd69c6d. Configure here.

...(routing.location ? { location: routing.location } : undefined),
source,
...(surface ? { surface } : undefined),
toolChannelId: destination.channelId,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Dispatch OAuth resume branches history

High Severity

The worker records authorization_completed in conversation history, then a dispatch resume feeds the agent piMessages that omit that event. The next checkpoint prefix-check fails with AgentHistoryBranchError, so the authorized Turn never continues.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit bd69c6d. Configure here.

(!("userId" in actor) || actor.userId !== authorization.actorId)
) {
throw new Error("Authorization actor does not match the paused Turn");
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

System-actor OAuth resumes are rejected

Medium Severity

The new resume check requires the paused Turn actor to have a userId equal to the authorizing user. Event and other system Turns store EVENT_SYSTEM_ACTOR, so a valid user OAuth callback fails the Turn instead of continuing it.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit bd69c6d. Configure here.

authSession,
queue: options.conversationWorkQueue,
provider,
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Wake errors fail completed OAuth

Medium Severity

Slack OAuth now awaits queue wake after tokens are stored and the one-time session or state is deleted. A later event-store or queue error is returned as authorization failure, so the original Turn never resumes and the user cannot retry the same callback.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit bd69c6d. Configure here.

This branch was successfully deployed

1 active deployment
Preview – junior-docs — bd69c6d6 Deployed Sep 24, 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