Repository navigation
fix: share one OAuth session between run sync and the Pi agent - #1358
Merged
Merged
Conversation
Run sync refreshed the login's OAuth token from its own queue while the agent kept the token it booted with, so a mid-run rotation left the Pi gateway re-mint and PostHog MCP on a replaced token. `src/agent/oauth-session.ts` now holds the run's credentials the way `gateway-session.ts` holds gateway auth: one process-wide holder with a shared in-flight rotation. The host supplies the rotation, since the agent never talks OAuth. Run sync, the Pi gateway re-mints and Pi MCP read the current token from it, and the MCP token env follows each rotation. Dev builds log the holder's lifecycle with token fingerprints. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🧙 Wizard CIRun the Wizard CI and test your changes against wizard-workbench example apps by replying with a GitHub comment using one of the following commands: Test all apps:
Test all apps in a directory:
Test an individual app:
Show more apps
Test against a Context Mill branch:
Add Results will be posted here when complete. |
The gateway cache was keyed by the OAuth access token, so every rotation missed it and minted again, and mints are capped per week. The OAuth session now tracks each login's token lineage, and the gateway keys its cache by the lineage's first token. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tsx runs leave NODE_ENV unset, so IS_DEV hid the lines there. The --local-* flags use the same !IS_PRODUCTION_BUILD gate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Drop the token hashes and per-reader lines; CodeQL flags hashing a credential. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…zard into posthog/run-sync-no-refresh # Conflicts: # src/lib/task-stream/wizard-run-sync.ts
edwinyjlim
approved these changes
Sep 25, 2026
edwinyjlim
left a comment
Member
There was a problem hiding this comment.
approve, but I think we should move oauth-session to /shared
other services besides agent will call oauth
Member
There was a problem hiding this comment.
idk if this should live under /agent
The agent, run sync and the host all read it, so it belongs beside auth-session-state rather than behind the agent entry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On the
wizard-runvariant, run sync refreshes the OAuth token while the agent runs. The Pi agent keeps its boot token for gateway re-mints and PostHog MCP, and the server revokes that token on refresh, so those calls fail.Changes
One session holds the run's OAuth token. Every caller asks it for the current token, and the first read that finds the token near expiry rotates it once for everyone.
src/shared/oauth-session.ts. Holds the token for the agent, run sync and the host, and runs one rotation at a time.[oauth-session] token rotatedline per rotation.The Anthropic harness still reads the boot token.
Test plan
Full local stack with the first-party token TTL cut to 52 minutes, driven in tmux on a one-file app.
posthog-integrationran on the Pi orchestrator with the local MCP andwizard-run-sync=wizard-run, and exited 0.posthog_exec.completed.Key log lines
Run log (auth, rotation, MCP, run sync, task usage)
Backend requests for the run
Checks
pnpm typecheck, ESLint and Prettier are clean.🤖 Generated with Claude Code