Show a distinct no-permission state for approvals#3318
Open
dmarticus wants to merge 2 commits into
Open
Conversation
The approvals endpoints are org-admin gated and answer 404 for non-admins, which previously rendered as a generic "Couldn't load approvals" failure. The fetcher now throws a typed ApiRequestError (same message format, so existing string-matching catch sites keep working), the approvals hooks flag the 404 as a permission error and stop polling/retrying it, and both approvals panes render a calm "You need organization admin access" empty state instead. Generated-By: PostHog Code Task-Id: 8713c915-6ca4-444b-824f-343ec148e128
|
✨ Submitted to Merge by @dmarticus. It will be added to the merge queue once all branch protection rules pass, there are no merge conflicts with the target branch, and impacted targets for the current PR head commit have been uploaded. See more details here. |
|
React Doctor found no issues in the changed files. 🎉 Reviewed by React Doctor for commit |
Contributor
|
Reviews (1): Last reviewed commit: "feat(approvals): show a distinct no-perm..." | Re-trigger Greptile |
…-agent hook Rename the refetchInterval callback parameter from `query` to `q` in both approvals hooks so it no longer shadows the outer `const query`, and add a dedicated test file for useAgentApplicationApprovals covering the 404 no-retry path, 500 retry path, success, and the !!idOrSlug enabled gate. Generated-By: PostHog Code Task-Id: 8713c915-6ca4-444b-824f-343ec148e128
daniloc
approved these changes
Jul 13, 2026
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
Tool approvals are org-admin-only, and the backend deliberately answers a 404 (not a 403) when the caller isn't an organization admin. The console's approvals surfaces treated that 404 like any other failure and showed "Couldn't load approvals", so non-admins read the feature as broken — and the panes kept polling the endpoint every 10s even though it could never succeed.
Changes
packages/api-client/src/fetcher.ts: non-2xx responses now throw a typedApiRequestErrorwith a.statusfield. The message keeps the exact legacyFailed request: [<status>] <body>format, so all existing catch sites that string-match on it are unaffected. Added arequestErrorStatus()helper.useAgentFleetApprovals/useAgentApplicationApprovalsexposeisPermissionError, skip react-query retries on the 404 admin gate, and stop the 10srefetchIntervalonce the permission error is known (this also stops the wasted polling behind the pending-count strip on the applications list).AgentFleetApprovalsPane/AgentApprovalsPanerender a dedicated calm empty state — "You need organization admin access" with no retry affordance — while genuine failures keep the "Couldn't load approvals" state. Fixed the copy, which previously said "team-admin"; the actual gate is organization-membership admin. For the per-agent pane, 404→no-permission is safe becauseAgentDetailLayoutonly renders the pane's content after the application itself has loaded.DeepLinkApprovalModalandAgentApprovalDetailneed no changes: the modal uses the session-principal-scoped ingress endpoint (not the admin gate) and already handles 404/403, and the detail view is prop-driven from the list.How did you test this?
fetcher.test.ts(typed status + legacy message format preserved on both throw sites,requestErrorStatus) anduseAgentFleetApprovals.test.tsx(404 →isPermissionErrorwith no retry, 500 → genuine error with retries, success path, predicate cases).pnpm typecheckfor@posthog/api-clientand@posthog/ui; full test suites for both packages pass (160 files / 1433 tests in ui, 75 in api-client); Biome clean on changed files.Automatic notifications
Created with PostHog Code