Skip to content
Source
Sign inSign up
pingdotgg/t3code

feat(auth): separate diagnostics and usage permissions #9790

Mergedjuliusmarmingemerged 12 commits intot3code/auth-preview-scope fromrefs/pull/9790/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

Workspace read access also exposed trace logs, host process details, resource history, and usage data. Add diagnostics:read so those diagnostics can be granted independently.

Web and mobile queries and subscriptions follow each selected environment's grant. Usage retains a known grant during revalidation, loads environments progressively, and retries only failed environments. Initial or failed permission lookups grant no diagnostics access. Provider limits retain their existing permissions; pricing-override edits separately recheck settings:write on the owning environment.

New Standard grants and the explicit Read only preset include diagnostics access, preserving the preset's previous behavior. Custom grants can omit it. Existing credentials keep their recorded scopes; older servers must be upgraded before they can issue the new scope, then the client needs a fresh grant.

Earlier focused suites passed for all seven protected RPC reads with allowed and denied credentials, scope-loading failures and retained grants, multi-environment Usage retries, and pricing-edit revocation. Scoped web and mobile typechecks passed during stack verification. The pairing captures below predate the final integration.

Earlier-revision pairing UI, captured before the final stack integration:

BeforeAfter
Before: pairing permissionsAfter: diagnostics permission

Model: GPT 6 Astra. Harness: Codex.

Note

Add diagnostics-read scope and gate usage/diagnostics access on it

  • Adds diagnostics-read to the scope schema in auth.ts and to the RPC_REQUIRED_SCOPES map in RpcAuthorization.ts for trace/process diagnostics, resource history, telemetry subscription, usage summary, and usage-rate RPCs
  • Adds a shared resolveUsageAccess resolver in usageAccess.ts that converts connection state and session scopes into a diagnostics-access result, keeping cached grants usable while offline
  • Web (UsagePage.tsx, usage.ts, resourceTelemetryState.ts, DiagnosticsSettings.tsx) and mobile (UsageRouteScreen.tsx, usage.ts) now skip RPCs for environments lacking diagnostics-read and show per-environment access or connection errors instead of usage data
  • The connection-pairing UI in ConnectionsSettings.tsx can now delegate diagnostics-read independently, and it is included in the read-only pairing preset
  • Risk: diagnostics-read is added to the standard client scope set; existing clients without this scope in their session will be denied usage and diagnostics RPCs until re-paired or re-authenticated
📊 Macroscope summarized fffc283. 11 files reviewed, 1 issue evaluated, 0 issues filtered, 1 comment posted

🗂️ Filtered Issues


Note

High Risk Authorization boundary changes: clients with only orchestration:read lose usage and diagnostics until re-paired, and several RPCs move to a new required scope.

Overview Introduces diagnostics:read so trace/process diagnostics, resource telemetry/history, and usage RPCs are no longer bundled with orchestration:read. Server RPC scope maps and serverRetryResourceTelemetry now require diagnostics:read (retry also still needs environment:maintain via dual-scope enforcement in ws.ts).

Clients use shared resolveUsageAccess to decide per-environment access from connection phase and session scopes. Web and mobile skip usage/diagnostics queries when the grant is missing, show per-environment error copy instead of charts, and disable refresh when nothing can read diagnostics; pairing UI can delegate the new scope (included in the read-only preset).

diagnostics:read is added to standard client scopes in contracts; existing tokens keep their old scopes until re-issued. New server tests cover diagnostics-only vs orchestration-only access.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 0fd319bc8e567f55705ca39201c62ab36fe65908. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Summary by CodeRabbit

  • New Features

    • Added diagnostics and usage access controls for connections.
    • Read-only connection permissions now include diagnostics and usage access.
    • Added clearer status handling for connected, pending, denied, and failed sessions.
  • Improvements

    • Usage and diagnostics views now respect permissions for each selected environment.
    • Refresh actions run only where diagnostics access is available.
    • Displays environment-specific errors, including denied access and scan failures.
    • Resource telemetry actions now require the appropriate permissions.
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ℹ️ No successful main baseline artifact is available yet. This run establishes the initial measurement.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire—5.0 KiB—6.8 KiB✅
      CodexThread snapshot wire—3.8 KiB—4.9 KiB✅
      CodexLive turn WebSocket wire—1.2 KiB—2.0 KiB✅
      CodexLive turn WebSocket decoded—20.9 KiB—29.3 KiB✅
      CodexLive turn messages—2—8✅
      ClaudeTotal thread wire—5.0 KiB—6.8 KiB✅
      ClaudeThread snapshot wire—3.8 KiB—4.9 KiB✅
      ClaudeLive turn WebSocket wire—1.2 KiB—2.0 KiB✅
      ClaudeLive turn WebSocket decoded—21.2 KiB—29.3 KiB✅
      ClaudeLive turn messages—1—8✅

      Baseline: unavailable · PR result: 588aea0 · Source CI: success

      Scenario 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.

      • Codex decoded thread snapshot: 108.5 KiB
      • Claude decoded thread snapshot: 108.8 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    3. juliusmarminge changed the title

    4. apps/mobile/src/features/usage/UsageRouteScreen.tsx line 137OutdatedResolvedby juliusmarminge
    5. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This PR introduces a new diagnostics authorization boundary and changes access behavior for existing credentials across server RPCs, contracts, pairing defaults, and web/mobile clients. It also changes the standard/read-only permission defaults, with an unresolved medium-severity permission-status UX issue remaining.

      No code changes detected at 588aea0. Prior analysis still applies.

      Adjust the Minimum Blocking Severity for this repo — including turning it Off — in [Settings](https://app.macroscope.com/pingdotgg/settings#Repos). You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    6. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟠 High state/usage.ts:53

      A remembered environment with no prepared transport remains in Initial because sessionStateAtom evaluates to Effect.never, but this condition classifies every non-failure empty result as access-checking. Its isPending therefore stays true forever, keeping the usage page on the loading skeleton and hiding totals from other environments. Use the result's actual waiting state instead of treating Initial as pending.

            const isCheckingAccess = sessionResult.waiting;
      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/web/src/state/usage.ts around line 53:
      
      A remembered environment with no prepared transport remains in `Initial` because `sessionStateAtom` evaluates to `Effect.never`, but this condition classifies every non-failure empty result as access-checking. Its `isPending` therefore stays true forever, keeping the usage page on the loading skeleton and hiding totals from other environments. Use the result's actual waiting state instead of treating `Initial` as pending.
    7. Stale Bugbot comment from a previous run.

      apps/mobile/src/features/usage/UsageRouteScreen.tsx line 317OutdatedResolvedby juliusmarminge
    8. Fixed: both clients distinguish a live connection whose session check is pending from an available, offline, or failed connection without a session. The latter reports a coverage error and no longer holds other environments' totals on a loading state. Known grants remain available so disconnected usage can retain a cached summary. Focused tests cover all connection phases, cached grants, and session-check failures; using waiting alone would not resolve an Effect.never session check.

    9. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟠 High

      https://github.com/pingdotgg/t3code/blob/2c50f4dbf7f1ca06eefc5d136073a203a4d418f2/apps/web/src/lib/resourceTelemetryState.ts#L40

      A caller with environment:maintain but without diagnostics:read can still invoke retry and receive the resource telemetry snapshot, bypassing the new diagnostics permission. The gate only disables serverEnvironment.resourceTelemetry; retry still calls serverEnvironment.retryResourceTelemetry, whose result.value.snapshot contains current.latest. Require canReadDiagnostics before executing retry and include it in the callback dependencies.

      No longer relevant as of b39eefcf76290679b6b0c1d695804e063f5b91f6

    10. Stale Bugbot comment from a previous run.

    11. Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

      Fix All in Cursor Bugbot Autofix is [ON](https://www.cursor.com/dashboard/bugbot), but a cloud agent failed to start. Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 7772ff6886fada598ac402ad6603a6e225b8e34b. Configure [here](https://www.cursor.com/dashboard/bugbot).
      packages/contracts/src/auth.ts line 134Resolvedby juliusmarminge
    12. Bugbot is paused — on-demand spend limit reached

      Bugbot uses usage-based billing for this team and has hit its on-demand spend limit.

      A team admin can raise the spend limit in the Cursor dashboard, or wait for the next billing cycle to continue.

    13. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review Change StackReview Change Stack

      Important

      Review skipped

      We couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting @coderabbitai full review.

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      Note

      Reviews paused

      It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

      Use the following commands to manage reviews:

      • @coderabbitai resume to resume automatic reviews.
      • @coderabbitai review to trigger a single review.

      Use the checkboxes below for quick actions:

      • ▶️ Resume reviews
      • 🔍 Trigger review

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration

      Configuration used: Path: .coderabbit.yaml

      Review profile: CHILL

      Plan: Team

      Run ID: 869172e9-5780-4cf6-ba49-626f63188a73

      📥 Commits

      Reviewing files that changed from the base of the PR and between e00d9a8f5657ef36c80f5cc78dfd28b389d40b14 and c0e644c19615f22caeb756e887f68f8ec3dc3365.

      📒 Files selected for processing (4)
      • apps/server/src/auth/RpcAuthorization.ts
      • apps/server/src/server.test.ts
      • apps/server/src/ws.ts
      • packages/client-runtime/package.json

      Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.


      📝 Walkthrough

      Walkthrough

      The change adds diagnostics-read authorization, resolves access per environment, gates usage and diagnostic queries, restricts refresh operations, and displays environment-specific access errors across web and mobile interfaces.

      Changes

      Diagnostics access control

      Layer / File(s)Summary
      Access contract and resolver
      packages/contracts/src/auth.ts, packages/client-runtime/src/state/usageAccess.ts, packages/client-runtime/src/state/usageAccess.test.ts, packages/client-runtime/package.json
      Adds AuthDiagnosticsReadScope, includes it in supported scopes, and exports resolveUsageAccess with coverage for connection and session states.
      Server RPC authorization
      apps/server/src/auth/RpcAuthorization.ts, apps/server/src/ws.ts, apps/server/src/server.test.ts
      Requires diagnostics-read access for diagnostic, usage, telemetry, and history RPCs. Resource telemetry retry requires both maintenance and diagnostics scopes.
      Usage state resolution
      apps/web/src/state/usage.ts, apps/mobile/src/state/usage.ts, apps/web/src/state/usage.test.tsx
      Adds canReadDiagnostics, skips unauthorized usage queries, and limits refresh requests to authorized environments.
      Diagnostics and usage UI
      apps/web/src/components/settings/ConnectionsSettings.tsx, apps/web/src/components/settings/DiagnosticsSettings.tsx, apps/web/src/components/usage/UsagePage.tsx, apps/mobile/src/features/usage/UsageRouteScreen.tsx, apps/web/src/lib/resourceTelemetryState.ts
      Updates pairing permissions, disables unauthorized queries and refreshes, and displays environment-specific access errors while preserving saved totals when available.

      Priority: ➖ Normal

      Estimated code review effort: 4 (Complex) | ~45 minutes

      Sequence Diagram(s)

      sequenceDiagram
        participant UsageUI
        participant UsageState
        participant resolveUsageAccess
        participant UsageSummaryRPC
        UsageUI->>UsageState: Load selected environments
        UsageState->>resolveUsageAccess: Resolve connection and session access
        resolveUsageAccess-->>UsageState: Return diagnostics access status
        alt Diagnostics access granted
          UsageState->>UsageSummaryRPC: Request usage summary
          UsageSummaryRPC-->>UsageState: Return usage data
          UsageState-->>UsageUI: Render usage data
        else Diagnostics access denied
          UsageState-->>UsageUI: Return environment-specific access error
        end

      Suggested reviewers: t3dotgg, maria-rcks, bil0000

      Merge Risk: ⚪ Minimal · up to c0e64

      This change introduces a dedicated diagnostics-read permission and correctly enforces it (alongside the existing environment-maintain check) before diagnostic and telemetry retry operations run, with test coverage confirming unauthorized sessions are rejected. No functional or security defects were found in this authorization slice, so it is safe to merge as-is.

      🚥 Pre-merge checks | ✅ 4 | ❌ 1

      ❌ Failed checks (1 warning)

      Check nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring coverage is 18.18% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 15 files. (1 skipped:…Write docstrings for the functions missing them to satisfy the coverage threshold.
      ✅ Passed checks (4 passed)
      Check nameStatusExplanation
      Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Title check✅ PassedThe title clearly and concisely identifies the main change: separating diagnostics and usage permissions through a new authorization scope.
      Description check✅ PassedThe description explains what changed, why the change was needed, client behavior, compatibility considerations, testing, and UI changes with before-and-after images. It omits the template checklist a…
      Full details: Docstring Coverage

      Explanation

      Docstring coverage is 18.18% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 15 files. (1 skipped: 1 unsupported.)

      ✨ Finishing Touches 💡 2
      📝 Generate docstrings 💡
      • Create stacked PR
      • Commit on current branch
      🛠️ Fix failing CI checks 💡
      • Create stacked PR
      • Commit on current branch
      🧪 Generate unit tests (beta)
      • Create PR with unit tests
      • Commit unit tests in branch `t3code/auth-diagnostics-scope`

      Comment `@coderabbitai help` to get the list of available commands.
    14. Note

      GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

    15. Bugbot is paused — on-demand spend limit reached

      Bugbot uses usage-based billing for this team and has hit its on-demand spend limit.

      A team admin can raise the spend limit in the Cursor dashboard, or wait for the next billing cycle to continue.

    16. Note

      GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

    17. Bugbot is paused — on-demand spend limit reached

      Bugbot uses usage-based billing for this team and has hit its on-demand spend limit.

      A team admin can raise the spend limit in the Cursor dashboard, or wait for the next billing cycle to continue.

    18. juliusmarminge added labelsmacroscope-review

    19. juliusmarminge merged this57b2418

    20. juliusmarminge closed this

Sign in to join this conversation.