feat(auth): separate diagnostics and usage permissions #9790
Mergedjuliusmarmingemerged 12 commits into
t3code/auth-preview-scope fromrefs/pull/9790/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
- apps/web/src/state/usage.ts line 59OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -45,3 +48,12 @@45484649 const statuses: EnvironmentUsageStatus[] = [];4750 for (const [environmentId, presentation] of presentations) {51+ const sessionResult = get(environmentSession.sessionStateAtom(environmentId));52+ const session = Option.getOrNull(AsyncResult.value(sessionResult));53+ const isCheckingAccess =54+ sessionResult.waiting || (session === null && sessionResult._tag !== "Failure");55+ const canReadDiagnostics =56+ sessionResult._tag === "Success" &&57+ !isCheckingAccess &&58+ session?.authenticated === true &&59+ (session.scopes?.includes(AuthDiagnosticsReadScope) ?? false);
juliusmarminge changed the title
- apps/mobile/src/state/usage.ts lines 68 to 70OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -48,3 +51,20 @@48514952 const statuses: EnvironmentUsageStatus[] = [];5053 for (const [environmentId, presentation] of presentations) {54+ const sessionResult = get(environmentSession.sessionStateAtom(environmentId));55+ const session = Option.getOrNull(AsyncResult.value(sessionResult));56+ const isCheckingAccess = session === null && sessionResult._tag !== "Failure";57+ const canReadDiagnostics =58+ sessionResult._tag === "Success" &&59+ !isCheckingAccess &&60+ session?.authenticated === true &&61+ (session.scopes?.includes(AuthDiagnosticsReadScope) ?? false);62+ if (!canReadDiagnostics) {63+ statuses.push({64+ environmentId,65+ label: presentation.entry.target.label,66+ isPending: isCheckingAccess,67+ canReadDiagnostics: false,68+ error: isCheckingAccess69+ ? null70+ : "This connection does not have access to diagnostics and usage.",
- @@ -126,3 +131,7 @@126131 <Text className="py-16 text-center text-base text-foreground-muted">127132 Connect an environment to see usage.128133 </Text>134+ ) : !canReadDiagnostics ? (135+ <Text className="py-16 text-center text-base text-foreground-muted">136+ This connection does not have access to diagnostics and usage.137+ </Text>
- apps/mobile/src/features/usage/UsageRouteScreen.tsx line 198OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -183,5 +181,18 @@183181 <Text className="py-16 text-center text-base text-foreground-muted">184182 Connect an environment to see usage.185183 </Text>184+ ) : !canReadDiagnostics ? (185+ <View className="gap-2 py-16">186+ {environments.map((environment) => (187+ <Text188+ key={environment.environmentId}189+ className="text-center text-base text-foreground-muted"190+ >191+ {environments.length > 1 ? `${environment.label}: ` : null}192+ {environment.error}193+ </Text>194+ ))}195+ </View>186196 ) : (187197 <>198+ <UsageCoverageNotice
- @@ -977,3 +979,12 @@977979 ? Option.getOrElse(data.partialFailure, () => false)978980 : false;979981982+ if (!canReadDiagnostics) {983+ return (984+ <SettingsPageContainer>985+ <p className="text-sm text-muted-foreground">986+ This connection does not have access to diagnostics.987+ </p>988+ </SettingsPageContainer>989+ );990+ }@@ -184,4 +182,21 @@184182 Connect an environment to see usage.185183 </Text>184+ ) : !canReadDiagnostics ? (185+ <View className="gap-2 py-16">186+ {environments.map((environment) => (187+ <Text188+ key={environment.environmentId}189+ className="text-center text-base text-foreground-muted"190+ >191+ {environments.length > 1 ? `${environment.label}: ` : null}192+ {environment.error}193+ </Text>194+ ))}195+ </View>186196 ) : (187197 <>198+ <UsageCoverageNotice199+ environments={environments}200+ merged={merged}201+ isPartial={isPartial}202+ />
- packages/client-runtime/src/state/usageAccess.ts line 38Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +18,21 @@18+ // An unprepared offline connection cannot finish its session check. Keep19+ // it out of pending totals until the connection starts another attempt.20+ const isPending =21+ input.connectionPhase === "connected" ||22+ input.connectionPhase === "connecting" ||23+ input.connectionPhase === "reconnecting";24+ return {25+ canReadDiagnostics: false,26+ isPending,27+ error: isPending ? null : "This environment is not connected.",28+ };29+ }30+ const canReadDiagnostics =31+ input.session.authenticated &&32+ input.session.scopes?.includes(AuthDiagnosticsReadScope) === true;33+ return {34+ canReadDiagnostics,35+ isPending: false,36+ error: canReadDiagnostics37+ ? null38+ : "This connection does not have access to diagnostics and usage.",
- @@ -129,3 +131,4 @@129131 AuthProvidersManageScope,130132 AuthEnvironmentMaintainScope,131133 AuthPreviewOperateScope,134+ AuthDiagnosticsReadScope,
- apps/mobile/src/features/usage/UsageRouteScreen.tsx lines 595 to 599OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -575,5 +594,6 @@575594 }576595 if (!environment.isConnected)577596 return environment.summary ? "Disconnected · showing saved usage" : "Waiting for connection…";597+ // The reason matters: a denied grant and a failed scan need different fixes.578598 if (environment.error)579- return environment.summary ? "Usage unavailable · showing saved totals" : "Usage unavailable";599+ return environment.summary ? `${environment.error} Showing saved totals.` : environment.error;
juliusmarminge added labelsmacroscope-review
juliusmarminge merged this57b2418
juliusmarminge closed this
Sign in to join this conversation.




Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Baseline: unavailable · PR result:
588aea0· 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.