Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(skills): stop reporting every skill load failure as "not found" (#89903)

Carlos Marchal7451703360a7
diff --git a/products/skills/frontend/LLMSkillScene.tsx b/products/skills/frontend/LLMSkillScene.tsx
index 6049f54d5a6b..2254a5e726f2 100644
--- a/products/skills/frontend/LLMSkillScene.tsx
+++ b/products/skills/frontend/LLMSkillScene.tsx
@@ -16,6 +16,7 @@ import {
import { LemonBanner, LemonButton, LemonSelect, LemonTag, LemonTextArea, Link } from '@posthog/lemon-ui'
import { AccessControlAction } from 'lib/components/AccessControlAction'
+import { AccessDenied } from 'lib/components/AccessDenied'
import { CodeSnippet, Language } from 'lib/components/CodeSnippet/CodeSnippet'
import { NotFound } from 'lib/components/NotFound'
import { FEATURE_FLAGS } from 'lib/constants'
@@ -85,6 +86,10 @@ export function LLMSkillScene(): JSX.Element {
downloadingZip,
isSkillFormDirty,
nextVersion,
+ skillName,
+ selectedVersion,
+ isSkillAccessDenied,
+ hasSkillLoadError,
} = useValues(llmSkillLogic)
const { searchParams } = useValues(router)
// Reuse the list scene's publish flow: its action, per-skill in-flight guard, and resolved
@@ -103,12 +108,9 @@ export function LLMSkillScene(): JSX.Element {
loadMoreVersions,
downloadSkill,
cancelEditing,
+ loadSkill,
} = useActions(llmSkillLogic)
- if (isSkillMissing) {
- return <NotFound object="skill" />
- }
-
if (shouldDisplaySkeleton) {
return (
<div className="flex flex-col gap-2">
@@ -119,6 +121,41 @@ export function LLMSkillScene(): JSX.Element {
)
}
+ if (isSkillAccessDenied) {
+ return <AccessDenied object="skill" />
+ }
+
+ if (hasSkillLoadError) {
+ return (
+ <LemonBanner type="error" action={{ children: 'Try again', onClick: loadSkill }}>
+ Couldn't load this skill. Try again, and if it keeps happening contact support.
+ </LemonBanner>
+ )
+ }
+
+ if (isSkillMissing) {
+ return (
+ <NotFound
+ object="skill"
+ caption={
+ // The resolve endpoint returns the same 404 for a missing skill and a missing
+ // version, so the caption can only name what the URL asks for.
+ selectedVersion !== null ? (
+ <>
+ This link points to version {selectedVersion}.{' '}
+ <Link to={urls.skill(skillName)}>Try the latest version</Link>, or{' '}
+ <Link to={urls.skills()}>browse all skills</Link>.
+ </>
+ ) : (
+ <>
+ Check the skill name in the URL, or <Link to={urls.skills()}>browse all skills</Link>.
+ </>
+ )
+ }
+ />
+ )
+ }
+
// A direct link with `?edit=true` shouldn't grant edit access the New version button
// wouldn't otherwise give — fall back to the read-only view when the user can't actually publish.
const canEditSkill = userHasAccess(AccessControlResourceType.LlmSkill, AccessControlLevel.Editor)
diff --git a/products/skills/frontend/llmSkillLogic.test.ts b/products/skills/frontend/llmSkillLogic.test.ts
index 6002d2c87e8c..dc58edb66390 100644
--- a/products/skills/frontend/llmSkillLogic.test.ts
+++ b/products/skills/frontend/llmSkillLogic.test.ts
@@ -2,7 +2,7 @@ import { expectLogic } from 'kea-test-utils'
import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
-import { ApiError } from '~/lib/api-error'
+import { ApiError, NetworkError } from '~/lib/api-error'
import { initKeaTests } from '~/test/init'
import {
@@ -312,4 +312,58 @@ describe('llmSkillLogic', () => {
)
})
})
+
+ describe('load failures', () => {
+ let logic: ReturnType<typeof llmSkillLogic.build>
+
+ beforeEach(() => {
+ jest.clearAllMocks()
+ initKeaTests()
+ })
+
+ afterEach(() => {
+ logic?.unmount()
+ })
+
+ it.each([
+ ['a 404', new ApiError('Not found', 404), { missing: true, accessDenied: false, loadError: false }],
+ [
+ 'a permission-denied 403',
+ new ApiError('Forbidden', 403, undefined, { code: 'permission_denied' }),
+ { missing: false, accessDenied: true, loadError: false },
+ ],
+ [
+ 'a 403 that is not about object access',
+ new ApiError('Forbidden', 403),
+ { missing: false, accessDenied: false, loadError: true },
+ ],
+ ['a 500', new ApiError('Server error', 500), { missing: false, accessDenied: false, loadError: true }],
+ [
+ 'a dropped connection',
+ new NetworkError('network'),
+ { missing: false, accessDenied: false, loadError: true },
+ ],
+ ])('resolves %s to its own state', async (_label, error, expected) => {
+ mockResolve.mockRejectedValue(error)
+
+ logic = llmSkillLogic({ skillName: 'my-test-skill' })
+ logic.mount()
+ await expectLogic(logic).toDispatchActions(['loadSkillFailure'])
+
+ expect(logic.values.isSkillMissing).toBe(expected.missing)
+ expect(logic.values.isSkillAccessDenied).toBe(expected.accessDenied)
+ expect(logic.values.hasSkillLoadError).toBe(expected.loadError)
+ expect(logic.values.breadcrumbs.at(-1)?.name).toBe('my-test-skill')
+
+ mockResolve.mockResolvedValue(resolveResponse(mockSkill))
+ mockFilesRetrieve.mockResolvedValue(MOCK_FILE)
+ logic.actions.loadSkill()
+ expect(logic.values.hasSkillLoadError).toBe(false)
+ await expectLogic(logic).toDispatchActions(['loadSkillSuccess'])
+
+ expect(logic.values.isSkillMissing).toBe(false)
+ expect(logic.values.isSkillAccessDenied).toBe(false)
+ expect(logic.values.hasSkillLoadError).toBe(false)
+ })
+ })
})
diff --git a/products/skills/frontend/llmSkillLogic.ts b/products/skills/frontend/llmSkillLogic.ts
index 991536a32a2f..5ffab6943065 100644
--- a/products/skills/frontend/llmSkillLogic.ts
+++ b/products/skills/frontend/llmSkillLogic.ts
@@ -17,6 +17,7 @@ import { loaders } from 'kea-loaders'
import { actionToUrl, combineUrl, router, urlToAction } from 'kea-router'
import { ApiConfig, ApiError } from '~/lib/api'
+import { isAccessDeniedError } from '~/lib/api-error'
import { lemonToast } from '~/lib/lemon-ui/LemonToast/LemonToast'
import { urls } from '~/scenes/urls'
import { Breadcrumb } from '~/types'
@@ -124,6 +125,12 @@ export interface PublishConflict {
latestVersion: number | null
}
+export interface SkillLoadError {
+ /** Undefined when the request never reached the server: a `NetworkError` carries no status. */
+ status: number | undefined
+ code: string | null
+}
+
// Sorted by path so a reorder that ends up byte-identical on the server is not presented as a change.
function sortSkillFilesByPath(files: SkillFormFileValues[]): SkillFormFileValues[] {
return [...files].sort((a, b) => a.path.localeCompare(b.path))
@@ -202,12 +209,14 @@ export interface llmSkillLogicValues {
}>
downloadingZip: boolean
fileContentsLoading: boolean
+ hasSkillLoadError: boolean
isDiffVisible: boolean
isEditMode: boolean
isHistoricalVersion: boolean
isNewSkill: boolean
isOutlineExpanded: boolean
isPublishReviewOpen: boolean
+ isSkillAccessDenied: boolean
isSkillFormDirty: boolean
isSkillFormSubmitting: boolean
isSkillFormValid: boolean
@@ -220,6 +229,7 @@ export interface llmSkillLogicValues {
ownersEditing: boolean
publishConflict: PublishConflict | null
savingOwners: boolean
+ selectedVersion: number | null
shouldDisplaySkeleton: boolean
showSkillFormErrors: boolean
skill: ResolvedLLMSkill | SkillFormValues | null
@@ -234,7 +244,9 @@ export interface llmSkillLogicValues {
skillFormTouched: boolean
skillFormTouches: Record<string, boolean>
skillFormValidationErrors: DeepPartialMap<SkillFormValues, ValidationErrorType>
+ skillLoadError: SkillLoadError | null
skillLoading: boolean
+ skillName: string
skillOwners: readonly UserBasicApi[]
versionDescription: string
versions: LLMSkillVersionSummaryApi[]
@@ -387,10 +399,15 @@ export interface llmSkillLogicMeta {
key: string
__keaTypeGenInternalSelectorTypes: {
isNewSkill: (arg: any) => boolean
+ skillName: (arg: SkillLogicProps) => string
+ selectedVersion: (arg: SkillLogicProps) => number | null
+ isSkillAccessDenied: (skillLoadError: SkillLoadError | null) => boolean
+ hasSkillLoadError: (skillLoadError: SkillLoadError | null, isSkillAccessDenied: boolean) => boolean
isSkillMissing: (
skill: ResolvedLLMSkill | SkillFormValues | null,
skillLoading: boolean,
- skillFetched: boolean
+ skillFetched: boolean,
+ skillLoadError: SkillLoadError | null
) => boolean
shouldDisplaySkeleton: (
skill: ResolvedLLMSkill | SkillFormValues | null,
@@ -401,6 +418,7 @@ export interface llmSkillLogicMeta {
isHistoricalVersion: (skill: ResolvedLLMSkill | SkillFormValues | null) => boolean
breadcrumbs: (
skill: ResolvedLLMSkill | SkillFormValues | null,
+ skillName: string,
searchParams: Record<string, any>
) => Breadcrumb[]
isViewMode: (mode: SkillMode, arg: any) => boolean
@@ -480,6 +498,17 @@ export const llmSkillLogic = kea<llmSkillLogicType>([
loadSkillFailure: () => true,
},
],
+ skillLoadError: [
+ null as SkillLoadError | null,
+ {
+ loadSkill: () => null,
+ loadSkillSuccess: () => null,
+ loadSkillFailure: (_, { errorObject }) => ({
+ status: errorObject?.status,
+ code: errorObject?.code ?? null,
+ }),
+ },
+ ],
versionsLoading: [
false,
{
@@ -747,10 +776,43 @@ export const llmSkillLogic = kea<llmSkillLogicType>([
selectors({
isNewSkill: [() => [(_, props) => props], (props) => props.skillName === 'new'],
+ skillName: [
+ () => [(_: unknown, props: SkillLogicProps) => props],
+ (props: SkillLogicProps): string => props.skillName,
+ ],
+
+ selectedVersion: [
+ () => [(_: unknown, props: SkillLogicProps) => props],
+ (props: SkillLogicProps): number | null => props.selectedVersion ?? null,
+ ],
+
+ isSkillAccessDenied: [
+ (s) => [s.skillLoadError],
+ (skillLoadError: SkillLoadError | null): boolean =>
+ skillLoadError !== null && isAccessDeniedError(skillLoadError),
+ ],
+
+ hasSkillLoadError: [
+ (s) => [s.skillLoadError, s.isSkillAccessDenied],
+ (skillLoadError: SkillLoadError | null, isSkillAccessDenied: boolean): boolean =>
+ skillLoadError !== null && skillLoadError.status !== 404 && !isSkillAccessDenied,
+ ],
+
+ // A 404 is the only failure that proves the skill isn't there. Every other failure (no access,
+ // a server error, a request that never left the browser) leaves the question open, so it gets
+ // its own state rather than telling the user a skill they may well own does not exist.
isSkillMissing: [
- (s) => [s.skill, s.skillLoading, s.skillFetched],
- (skill: ResolvedLLMSkill | SkillFormValues | null, skillLoading: boolean, skillFetched: boolean) =>
- skillFetched && !skillLoading && skill === null,
+ (s) => [s.skill, s.skillLoading, s.skillFetched, s.skillLoadError],
+ (
+ skill: ResolvedLLMSkill | SkillFormValues | null,
+ skillLoading: boolean,
+ skillFetched: boolean,
+ skillLoadError: SkillLoadError | null
+ ) =>
+ skillFetched &&
+ !skillLoading &&
+ skill === null &&
+ (skillLoadError === null || skillLoadError.status === 404),
],
shouldDisplaySkeleton: [
@@ -769,8 +831,12 @@ export const llmSkillLogic = kea<llmSkillLogicType>([
],
breadcrumbs: [
- (s) => [s.skill, router.selectors.searchParams],
- (skill: LLMSkillApi | SkillFormValues | null, searchParams: Record<string, any>): Breadcrumb[] => [
+ (s) => [s.skill, s.skillName, router.selectors.searchParams],
+ (
+ skill: LLMSkillApi | SkillFormValues | null,
+ skillName: string,
+ searchParams: Record<string, any>
+ ): Breadcrumb[] => [
{
name: 'Skills',
path: combineUrl(urls.skills(), searchParams).url,
@@ -782,7 +848,9 @@ export const llmSkillLogic = kea<llmSkillLogicType>([
? isSkill(skill)
? `${skill.name} v${skill.version}`
: skill.name || 'New skill'
- : 'New skill',
+ : skillName === 'new'
+ ? 'New skill'
+ : skillName,
key: 'Skill',
},
],