fix(auth): keep old clients connected across scope changes #10298
Mergedjuliusmarmingemerged 13 commits into
t3code/auth-terminal-read-scope fromrefs/pull/10298/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- @@ -41,8 +43,5 @@4143 );42444345 /** An explicit action may ask the server while its grant is still unresolved. */44-function allowsHostMedia(session: Pick<AuthSessionState, "authenticated" | "scopes"> | null) {45- return (46- session === null ||47- (session.authenticated && session.scopes?.includes(AuthFilesystemReadScope) === true)48- );46+function allowsHostMedia(session: SessionGrantInput | null) {47+ return session === null || sessionGrantsScope(session, AuthFilesystemReadScope);
- apps/server/src/persistence/Migrations/050_ExpandLegacyAuthScopes.ts lines 36 to 36OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +16,21 @@16+ */17+export default Effect.gen(function* () {18+ const sql = yield* SqlClient.SqlClient;19+ const expandTable = (table: "auth_pairing_links" | "auth_sessions") =>20+ Effect.gen(function* () {21+ const rows =22+ table === "auth_pairing_links"23+ ? yield* sql<{ readonly id: string; readonly scopes: string }>`24+ SELECT id, scopes25+ FROM auth_pairing_links26+ WHERE revoked_at IS NULL AND consumed_at IS NULL27+ `28+ : yield* sql<{ readonly id: string; readonly scopes: string }>`29+ SELECT session_id AS id, scopes30+ FROM auth_sessions31+ WHERE revoked_at IS NULL32+ `;33+ for (const row of rows) {34+ const scopes = yield* decodeScopes(row.scopes).pipe(Effect.option);35+ if (scopes._tag === "None") continue;36+ const expanded = expandLegacyScopes(scopes.value);
juliusmarminge changed the title
- apps/server/src/auth/SessionStore.ts line 433Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -420,4 +420,4 @@420420 const DEFAULT_WEBSOCKET_TOKEN_TTL = Duration.minutes(5);421421422422 const SessionClaims = Schema.Struct({423- v: Schema.Literal(1),423+ v: Schema.Literals([1, 2]),
- apps/server/src/auth/http.ts line 328OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -322,8 +324,5 @@322324 const requestedScopes =323325 args.payload.scope === undefined324326 ? undefined325- : parseAllowedOAuthScope({326- value: args.payload.scope,327- allowedScopes: new Set(AuthGrantScope.literals),328- });327+ : (parseOAuthScope(args.payload.scope)?.filter(Schema.is(AuthGrantScope)) ?? null);329328 if (requestedScopes === null) {
juliusmarminge added labelsmacroscope-review
- @@ -385,3 +451,4 @@385451 authenticated: Schema.Boolean,386452 auth: ServerAuthDescriptor,387453 scopes: Schema.optionalKey(AuthEnvironmentScopes),454+ permissions: authScopeResponseFields.permissions,
- apps/web/src/components/PermissionUpdateNotice.tsx line 50Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +19,21 @@19+ environmentId: EnvironmentId;20+ label: string;21+}) {22+ const session = useAtomValue(environmentSession.sessionStateAtom(environmentId));23+ const navigate = useNavigate();24+ useEffect(() => {25+ if (26+ session._tag !== "Success" ||27+ session.waiting ||28+ !sessionHasLegacyPermissions(session.value)29+ )30+ return;31+ if (shown.has(environmentId)) return;32+ const key = `t3code:permission-update:v1:${environmentId}`;33+ try {34+ if (getLocalStorageItem(key, Schema.Boolean)) return;35+ } catch {36+ // An unavailable store must not prevent the notice.37+ }38+ shown.add(environmentId);39+ const id = toastManager.add({
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
juliusmarminge merged this365aa87
juliusmarminge closed this
Sign in to join this conversation.
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Baseline: unavailable · PR result:
fe220d7· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.