Repository navigation
fix(sentry): retry proof writes and stop reporting handled failures #715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import { readThroughCache } from '#shared/server/cache' | ||
| import { dependencyOutageError } from '#shared/server/dependency-outage' | ||
| import { defineApiHandler } from '#shared/server/handler' | ||
| import { presentPnpmPackage } from '../../presenters/pnpm-package' | ||
| import { pnpmPackageQuery, pnpmPackageSlug } from '../../schemas/pnpm-package' | ||
|
|
@@ -36,7 +37,10 @@ export default defineApiHandler({ | |
| if (!row.rendered_skill_path || row.source_resolved === 0) | ||
| return { _tag: 'Absent' } as const | ||
| const source = resolveRepoSourceIdentityFromRow({ owner: row.owner, repo: row.repo }, row) | ||
| return detectPnpmPackage({ ...source, ref: row.rendered_commit_sha ?? row.default_branch ?? 'HEAD', skillPath: row.rendered_skill_path! }, fetch) | ||
| const detected = await detectPnpmPackage({ ...source, ref: row.rendered_commit_sha ?? row.default_branch ?? 'HEAD', skillPath: row.rendered_skill_path! }, fetch) | ||
| if (detected._tag === 'Unavailable') | ||
| emitOperationalEvent(createWideEvent({ operation: 'skill-package-detect', outcome: 'failed' })) | ||
| return detected | ||
| }, | ||
| { | ||
| ttl: 3600, | ||
|
|
@@ -45,7 +49,7 @@ export default defineApiHandler({ | |
| }, | ||
| ) | ||
| if (result._tag === 'Unavailable') | ||
| throw createError({ statusCode: 503, message: 'Package details are unavailable. Try again later.' }) | ||
| throw dependencyOutageError({ dependency: 'GitHub or npm', message: 'Package details are unavailable. Try again later.' }) | ||
| return result | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor (61/100): Package inspection failures are reported as upstream outages The detector returns Unavailable for both upstream request failures and local inspection failures, including an archive that exceeds the site's byte cap or fails tar validation. The existing oversized-package fixture exercises that branch. The route now marks both cases as a dependency outage, causing server beforeSend to suppress the 503. Its replacement wide event contains only the operation and outcome, so repeated inspection failures are indistinguishable from upstream outages. Carry a failure category through package detection and the cache, and apply the outage mark only to transient dependency failures.
|
||
| }, | ||
| presenter: presentPnpmPackage, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| import type { H3Event } from 'h3' | ||
| import type { DuplicateCandidate, DuplicateGroupRecommendation } from './skill-duplicate-canonical' | ||
| import type { RegistrySkill } from './skills-registry' | ||
| import { createError } from 'h3' | ||
| import { getDB } from '#server/utils/db' | ||
| import { dependencyOutageError } from '#shared/server/dependency-outage' | ||
| import { | ||
| canonicalTrustFirstSort, | ||
| duplicateRankingSignals, | ||
|
|
@@ -382,8 +382,9 @@ export async function hybridSkillSearch( | |
| semantic && expansion ? semanticSkillSearch(event, expansion, SEMANTIC_TOP_K) : Promise.resolve(null), | ||
| ]) | ||
|
|
||
| // Each lane already recorded its own failure as a wide event. | ||
| if (lexicalKeys === null && semanticHits === null && expansionHits === null) | ||
| throw createError({ statusCode: 503, statusMessage: 'Search is temporarily unavailable.' }) | ||
| throw dependencyOutageError({ dependency: 'D1 and Vectorize', statusMessage: 'Search is temporarily unavailable.' }) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor (57/100): Search suppresses reports for permanent database query failures lexicalSkillSearch converts every rejected query to null and emits a wide event with only the operation and outcome. In lexical-only mode, a permanent D1 query error such as a missing skills_fts table therefore takes the same path as a disconnected database. The new outage tag suppresses the resulting 503 in Sentry, leaving the wide event unable to distinguish a broken schema from downtime. Preserve the lexical failure category and reserve the outage mark for failures classified as transient.
|
||
|
|
||
| const semanticKeys = semanticHits?.map(skillKey) ?? [] | ||
| const expansionKeys = expansionHits?.map(skillKey) ?? [] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import type { Breadcrumb, Event } from '@sentry/nuxt' | ||
| import type { Breadcrumb, Event, EventHint } from '@sentry/nuxt' | ||
| import { isTransientError } from '@harlan-zw/nuxt-sentry/server' | ||
|
|
||
| export const SENTRY_DSN = 'https://b275b367f8096d04db8c2ebcfadc3aba@o4510507748163584.ingest.us.sentry.io/4511781692506112' | ||
|
|
||
|
|
@@ -76,24 +77,6 @@ export function isBestEffortCacheWriteError(error: unknown): boolean { | |
| return typeof message === 'string' && message.startsWith('KV PUT failed:') | ||
| } | ||
|
|
||
| /** | ||
| * The suffix shared by the intended upstream-outage 503s the registry handlers | ||
| * raise after `fetchUpstreamTree` or `fetchUpstreamText` reports the outage as | ||
| * an operational wide event ('Skill source is unavailable upstream', | ||
| * 'SKILL.md source is unavailable upstream', 'Asset source is unavailable | ||
| * upstream', Sentry SKILLD-11 and SKILLD-1E). Nitro forwards the thrown | ||
| * `createError` to Sentry as unhandled, so the capture duplicates a failure | ||
| * class the wide event already records. The server Sentry config drops that | ||
| * signature in `beforeSend`; every other error still reaches Sentry. | ||
| * | ||
| * The gone-source 410 ('Skill source is gone upstream') is a permanent | ||
| * verdict, not an outage, and does not carry the suffix, so it still lands. | ||
| */ | ||
| export function isExpectedUpstreamOutageError(error: unknown): boolean { | ||
| const message = sentryExceptionMessage(error) | ||
| return typeof message === 'string' && message.endsWith('unavailable upstream') | ||
| } | ||
|
|
||
| /** | ||
| * The message Chrome rejects a `postMessage` on a closed `BroadcastChannel` | ||
| * with (`InvalidStateError`, Sentry SKILLD-12). nuxt-skew-protection's | ||
|
|
@@ -108,6 +91,67 @@ export function isClosedBroadcastChannelError(error: unknown): boolean { | |
| return message === 'Failed to execute \'postMessage\' on \'BroadcastChannel\': Channel is closed' | ||
| } | ||
|
|
||
| const CLIENT_NOISE_MESSAGE = /ResizeObserver loop|AsyncData request cancelled by |signal is aborted without reason|\/builds\/meta\/[\w-]+\.json": 404 / | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor (67/100): The browser filter hides missing manifests for the current build The path pattern matches every build ID under /builds/meta/, including the ID running in the reporting browser. If a deployment is missing its current manifest, that browser's 404 is dropped the same way as an expired tab's 404. The keep-case in the new test uses /builds/latest.json, which is a different endpoint and never matches the pattern. Compare the requested manifest ID with the running build ID and retain the report when the filter cannot establish that the requested build is retired.
|
||
|
|
||
| /** | ||
| * Browser reports that name no site defect. | ||
| * | ||
| * - `ResizeObserver loop ...`: a browser layout notice that `window.onerror` | ||
| * delivers as an error (SKILLD-5B). | ||
| * - A cancelled request: Nuxt aborts an AsyncData fetch that a newer call or an | ||
| * unmount replaced (SKILLD-4Q, SKILLD-4S, SKILLD-59). `isTransientError` is | ||
| * the rule every site using `@harlan-zw/nuxt-sentry` already applies. | ||
| * - A retired build's meta: a tab older than the skew protection window asks | ||
| * for its own build meta and gets 404 (SKILLD-4Y), the stale-deploy class | ||
| * `ignoreErrors` already drops for chunks. | ||
| */ | ||
| function isClientNoiseError(error: unknown): boolean { | ||
| if (isTransientError(error)) | ||
| return true | ||
| const message = sentryExceptionMessage(error) | ||
| return typeof message === 'string' && CLIENT_NOISE_MESSAGE.test(message) | ||
| } | ||
|
|
||
| function isClientDroppedSignature(error: unknown): boolean { | ||
| return isClosedBroadcastChannelError(error) || isClientNoiseError(error) | ||
| } | ||
|
|
||
| /** | ||
| * The kind of value a messageless error was thrown with, never its content. | ||
| * | ||
| * Nuxt wraps a thrown non-Error, such as a load `Event`, in an H3 error with | ||
| * an empty message, so the report reads "No error message" and loses the one | ||
| * fact that explains it (SKILLD-54). | ||
| */ | ||
| function describeThrownCause(error: unknown): string | undefined { | ||
| if (!(error instanceof Error) || error.message !== '' || error.cause === undefined) | ||
| return undefined | ||
| const cause = error.cause | ||
| if (typeof globalThis.Event === 'function' && cause instanceof globalThis.Event) { | ||
| const target = cause.target as { tagName?: unknown } | null | ||
| return typeof target?.tagName === 'string' ? `Event:${cause.type}:${target.tagName}` : `Event:${cause.type}` | ||
| } | ||
| if (cause instanceof Error) | ||
| return cause.name | ||
| if (typeof cause !== 'object' || cause === null) | ||
| return typeof cause | ||
| return Object.prototype.toString.call(cause).slice(8, -1) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor (72/100): Thrown-cause tags accept arbitrary text and can interrupt error reporting For an empty-message Error with an object cause, Object.prototype.toString reads the cause's Symbol.toStringTag. That property can supply arbitrary text, which filterClientReport puts in thrown.cause and scrubSentryEvent leaves intact. A throwing getter also makes beforeSend fail before it can return the original report. Custom event types and Error names likewise reach the tag as free-form text. Map causes to fixed category labels and avoid reading custom metadata from arbitrary objects.
|
||
| } | ||
|
|
||
| /** | ||
| * The browser `beforeSend`: drops the signatures above, tags what a | ||
| * messageless error was thrown with, and scrubs everything it keeps. | ||
| */ | ||
| export function filterClientReport<T extends Event>(event: T, hint: EventHint): T | null { | ||
| const values = event.exception?.values ?? [] | ||
| if (isClientDroppedSignature(hint.originalException) || values.some(isClientDroppedSignature)) | ||
| return null | ||
| const thrownCause = describeThrownCause(hint.originalException) | ||
| if (thrownCause) | ||
| event.tags = { ...event.tags, 'thrown.cause': thrownCause } | ||
| return scrubSentryEvent(event) | ||
| } | ||
|
|
||
| /** | ||
| * The message prefix the MCP streamable transport rejects a probe with | ||
| * ('Not Acceptable: Client must accept text/event-stream' for an Accept-less | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trivial (38/100): Vue templates bypass the ES2023 array-method guard
ESLint's core no-restricted-properties rule visits the script AST. Vue template expressions are visited through Vue's separate template visitor, so a toSorted call in a v-for or binding passes this rule and still runs in browsers without that method.
Add a Vue template restriction for the same three array methods.