Skip to content

feat(google-docs): handle OAuth expiry mid-workflow with reauth modal []#10934

Draft
Mitch Goudy (mgoudy91) wants to merge 1 commit intomasterfrom
feat/google-docs-oauth-reauth-suspend
Draft

feat(google-docs): handle OAuth expiry mid-workflow with reauth modal []#10934
Mitch Goudy (mgoudy91) wants to merge 1 commit intomasterfrom
feat/google-docs-oauth-reauth-suspend

Conversation

@mgoudy91
Copy link
Copy Markdown
Contributor

@mgoudy91 Mitch Goudy (mgoudy91) commented Apr 27, 2026

Summary

  • Adds NeedsReauthSuspendPayload type (suspendStepId: 'needs-google-reauth') to the workflow type union
  • When the workflow suspends with that payload, ModalOrchestrator now shows a reconnect modal instead of an error modal — preserving all workflow progress
  • On successful reconnect, the fresh token is passed directly to resumeWorkflowRun so the workflow continues from where it left off rather than requiring a full restart
  • Adds oauthToken to ResumePayload type
  • Fixes the existing test suite to pass the two new required ModalOrchestrator props

Problem

OAuth tokens expire after ~1 hour. The previous UX was: workflow fails → generic error modal → user must reconnect → user must restart the entire workflow from scratch. All progress (document selection, content type selection, tab/image selection) was lost.

Solution

The agents-api step now suspends with needs-google-reauth instead of failing (see pairing PR). On the frontend:

  1. ModalOrchestrator.handleWorkflowResult detects suspendStepId === 'needs-google-reauth' and calls showReauthPrompt, which sets a new FlowStep.REAUTH state and saves the runId in pendingReauthRunId
  2. The REAUTH flow step renders the existing OAuthConnector inside the modal with an explanatory message
  3. handleReauthTokenChange is wired as the onOauthTokenChange callback — when the reconnect completes it immediately calls resumeWorkflow(pendingReauthRunId, { oauthToken: newToken }) and resumes polling
  4. If the resume itself fails, it falls through to showWorkflowError as a last resort

Pairing PR

This PR pairs with contentful/agents-api#447 which adds the suspend-on-401 logic to the workflow step.

Files changed

File Change
src/types/workflow.ts Add NeedsReauthSuspendPayload, add oauthToken to ResumePayload, update WorkflowRunResult union
src/hooks/useWorkflowAgent.ts Include NeedsReauthSuspendPayload in getSuspendPayload return type
src/locations/Page/components/mainpage/ModalOrchestrator.tsx Add FlowStep.REAUTH, pendingReauthRunId state, showReauthPrompt, handleReauthTokenChange, reauth modal render, new required props
src/locations/Page/Page.tsx Pass onOAuthConnectedChange and onOauthTokenChange to ModalOrchestrator
test/.../ModalOrchestrator.spec.tsx Add missing required props to defaultProps

Test plan

  • Trigger a needs-google-reauth suspend (mock it in useWorkflowAgent or deploy pairing agents-api PR) and confirm the reconnect modal appears mid-workflow
  • Complete the reconnect flow and confirm the workflow resumes and completes normally without restarting
  • Confirm the cancel/discard flow works correctly from the reauth modal
  • Confirm the token update from reconnect propagates to the main page OAuthConnector so the connected state stays in sync
  • Run existing test suite: npm run test in apps/google-docs

🤖 Generated with Claude Code

…h modal

When the agents-api workflow suspends with `needs-google-reauth`, show a
reconnect modal that preserves workflow progress. On successful reconnect the
fresh token is passed directly to resumeWorkflowRun so the workflow
continues from where it left off rather than requiring a full restart.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@mgoudy91 Mitch Goudy (mgoudy91) changed the title feat(google-docs): handle OAuth expiry mid-workflow with reauth modal feat(google-docs): handle OAuth expiry mid-workflow with reauth modal [] Apr 27, 2026
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