Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ const homeTrendingRows = computed(() => {
.map((row, index) => ({ row, rank: index + 1 }))
.filter(({ row }) => !missingAvatars.value.has(row.owner))
const positions = new Map(trendingOrder.value.map((key, index) => [key, index]))
return rows.toSorted((a, b) => (positions.get(a.row.key) ?? a.rank) - (positions.get(b.row.key) ?? b.rank))
return rows.sort((a, b) => (positions.get(a.row.key) ?? a.rank) - (positions.get(b.row.key) ?? b.rank))
})

/**
Expand Down
20 changes: 20 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,26 @@ export default antfu({
'ts/no-redeclare': 'off',
},
}, ...harlanzw({ base: { type: 'app' } }), {
// Browsers that load the client still lack the ES2023 array copies, and one
// call broke the homepage there (Sentry SKILLD-4P). The first five entries
// repeat antfu's defaults, since a rule override replaces the whole list.
files: ['app/**', 'layers/*/app/**'],
name: 'skilld/client-array-copies',
rules: {
'no-restricted-properties': [

Copy link
Copy Markdown
Contributor

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.

  • Ask an agent to verify and fix this finding

Harlan Agent Kit posted this automated review. It is not Harlan's personal review or approval. AI open source policy.

'error',
{ property: '__proto__', message: 'Use `Object.getPrototypeOf` or `Object.setPrototypeOf` instead.' },
{ property: '__defineGetter__', message: 'Use `Object.defineProperty` instead.' },
{ property: '__defineSetter__', message: 'Use `Object.defineProperty` instead.' },
{ property: '__lookupGetter__', message: 'Use `Object.getOwnPropertyDescriptor` instead.' },
{ property: '__lookupSetter__', message: 'Use `Object.getOwnPropertyDescriptor` instead.' },
...['toSorted', 'toReversed', 'toSpliced'].map(property => ({
property,
message: 'Older browsers that load the client lack this ES2023 method. Copy the array first, for example `[...items].sort()`.',
})),
],
},
}, {
// The isolated proof needs Container 1.0 tooling. The site keeps its version.
files: ['pnpm-workspace.yaml'],
rules: {
Expand Down
14 changes: 10 additions & 4 deletions layers/identity/server/utils/signup-click-proof.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { H3Event } from 'h3'
import { retryIdempotentD1Write } from '@harlan-zw/nuxt-cloudflare/d1'
import { getHeader, getRequestURL, setHeader, useSession } from 'h3'
import { useRuntimeConfig } from 'nitropack/runtime'

Expand Down Expand Up @@ -54,10 +55,15 @@ export async function issueSignupClickProof(event: H3Event): Promise<string | nu
const expiresAt = now + PROOF_SECONDS
const session = await proofSession(event)
const db = event.context.platform.db
await db.batch([
db.prepare('DELETE FROM signup_click_proofs WHERE expires_at <= ?1').bind(now),
db.prepare('INSERT INTO signup_click_proofs (nonce, expires_at) VALUES (?1, ?2)').bind(nonce, expiresAt),
])
// D1 never retries a write, and every page with a sign-up link runs this one (SKILLD-42).
// OR IGNORE makes a replay after a lost but committed batch a no-op.
await retryIdempotentD1Write({
safety: { _tag: 'replay-safe' },
run: () => db.batch([
db.prepare('DELETE FROM signup_click_proofs WHERE expires_at <= ?1').bind(now),
db.prepare('INSERT OR IGNORE INTO signup_click_proofs (nonce, expires_at) VALUES (?1, ?2)').bind(nonce, expiresAt),
]),
})
await session.update({ nonce, page, client: clientKey(event), expiresAt })
return nonce
}
Expand Down
3 changes: 2 additions & 1 deletion layers/registry/server/api/skill-asset/[...slug].get.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { readCache, writeCache } from '#shared/server/cache'
import { dependencyOutageError } from '#shared/server/dependency-outage'
import { defineApiHandler } from '#shared/server/handler'
import { normalizeSkillAssetFilePath } from '#shared/skill-asset-path'
import { resolveRepoSourceIdentityFromRow } from '../../utils/repo-source-identity'
Expand Down Expand Up @@ -130,7 +131,7 @@ export default defineApiHandler({
// reads as deleted for the rest of the cache window.
emitOperationalEvent(createWideEvent({ 'operation': 'skill-asset-fetch', 'outcome': 'failed', 'upstream.status': upstream.status ?? 0, 'attempt': upstream.attempts }))
setHeader(event, 'retry-after', ASSET_RETRY_AFTER)
throw createError({ statusCode: 503, message: 'Asset source is unavailable upstream' })
throw dependencyOutageError({ dependency: 'raw.githubusercontent.com', message: 'Asset source is unavailable upstream' })
}

const raw = upstream.body
Expand Down
8 changes: 6 additions & 2 deletions layers/registry/server/api/skill-package/[...slug].get.ts
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'
Expand Down Expand Up @@ -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,
Expand All @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  • Ask an agent to verify and fix this finding

Harlan Agent Kit posted this automated review. It is not Harlan's personal review or approval. AI open source policy.

},
presenter: presentPnpmPackage,
Expand Down
3 changes: 2 additions & 1 deletion layers/registry/server/api/skills-raw/[...slug].get.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ReadThroughCache } from '#shared/server/cache'
import { readThroughCache } from '#shared/server/cache'
import { dependencyOutageError } from '#shared/server/dependency-outage'
import { defineApiHandler } from '#shared/server/handler'
import { normalizeSkillAssetFilePath } from '#shared/skill-asset-path'
import { loadStoredSkillRow, readReferencedFile, readStoredSkillMd, resolveReferencedFileTarget } from '../../utils/skill-stored-source'
Expand Down Expand Up @@ -94,7 +95,7 @@ export default defineApiHandler({
throw createError({ statusCode: 404, message: 'Referenced file not found in repository' })
if (raw._tag === 'unavailable') {
emitOperationalEvent(createWideEvent({ 'operation': 'skill-raw-content-fetch', 'outcome': 'failed', 'upstream.status': raw.status ?? 0, 'attempt': raw.attempts }))
throw createError({ statusCode: 503, message: 'Referenced file source is unavailable upstream' })
throw dependencyOutageError({ dependency: 'raw.githubusercontent.com', message: 'Referenced file source is unavailable upstream' })
}
return { body: raw.body, source: target.source } satisfies ReferencedFile
},
Expand Down
5 changes: 3 additions & 2 deletions layers/registry/server/utils/skill-search.ts
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,
Expand Down Expand Up @@ -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.' })

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  • Ask an agent to verify and fix this finding

Harlan Agent Kit posted this automated review. It is not Harlan's personal review or approval. AI open source policy.


const semanticKeys = semanticHits?.map(skillKey) ?? []
const expansionKeys = expansionHits?.map(skillKey) ?? []
Expand Down
4 changes: 2 additions & 2 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,9 @@ export default defineNuxtConfig({
binding: 'KV_DATA',
},
'cache': {
// Best-effort route-cache writes over KV_CACHE: the driver wraps
// Best-effort route-cache reads and writes over KV_CACHE: the driver wraps
// unstorage's cloudflare-kv-binding, floors every TTL at Cloudflare's
// 60-second minimum, and turns write rejections into wide events
// 60-second minimum, and turns read and write rejections into wide events
// instead of propagating them to Nitro's `captureError` (issue #156).
driver: fileURLToPath(new URL('./server/runtime/kv-cache-storage.ts', import.meta.url)),
binding: 'KV_CACHE',
Expand Down
15 changes: 4 additions & 11 deletions sentry.client.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createSentryInitOptions } from '@harlan-zw/nuxt-sentry/server'
import * as Sentry from '@sentry/nuxt'
import { isClosedBroadcastChannelError, isLocalReportingHost, scrubSentryBreadcrumb, scrubSentryEvent, SENTRY_DSN, SENTRY_TUNNEL_PATH } from './shared/sentry'
import { filterClientReport, isLocalReportingHost, scrubSentryBreadcrumb, scrubSentryEvent, SENTRY_DSN, SENTRY_TUNNEL_PATH } from './shared/sentry'

if (!import.meta.dev && window.location.protocol === 'https:' && !isLocalReportingHost(window.location.hostname)) {
// No `release` here on purpose. The Sentry bundler plugin injects the release
Expand Down Expand Up @@ -30,15 +30,8 @@ if (!import.meta.dev && window.location.protocol === 'https:' && !isLocalReporti
/Importing a module script failed/i,
/error loading dynamically imported module/i,
],
// nuxt-skew-protection's multi-tab plugin closes its BroadcastChannel on
// app:error, and an in-flight version update can still post to it. The
// rejection is a benign tab-close race (SKILLD-12), so drop that one
// signature and keep every other error.
beforeSend(event, hint) {
const values = event.exception?.values ?? []
if (isClosedBroadcastChannelError(hint.originalException) || values.some(isClosedBroadcastChannelError))
return null
return scrubSentryEvent(event)
},
// Drops the closed BroadcastChannel race (SKILLD-12), cancelled requests,
// and other reports that name no site defect. See `filterClientReport`.
beforeSend: filterClientReport,
})
}
11 changes: 6 additions & 5 deletions server/plugins/sentry.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { createSentryInitOptions } from '@harlan-zw/nuxt-sentry/server'
import { SDK_VERSION } from '@sentry/cloudflare'
import { sentryCloudflareNitroPlugin } from '@sentry/nuxt/module/plugins'
import { isBestEffortCacheWriteError, isExpectedUpstreamOutageError, isMcpAcceptProbeError, isMcpProtocolProbeError, scrubSentryBreadcrumb, scrubSentryEvent } from '../../shared/sentry'
import { isBestEffortCacheWriteError, isMcpAcceptProbeError, isMcpProtocolProbeError, scrubSentryBreadcrumb, scrubSentryEvent } from '../../shared/sentry'
import { isDependencyOutageError } from '../../shared/server/dependency-outage'

function isDroppedSignature(error: unknown): boolean {
return isBestEffortCacheWriteError(error) || isExpectedUpstreamOutageError(error) || isMcpAcceptProbeError(error) || isMcpProtocolProbeError(error)
return isBestEffortCacheWriteError(error) || isDependencyOutageError(error) || isMcpAcceptProbeError(error) || isMcpProtocolProbeError(error)
}

export default defineNitroPlugin((nitroApp) => {
Expand All @@ -26,9 +27,9 @@ export default defineNitroPlugin((nitroApp) => {
traceLifecycle: 'static',
beforeSendTransaction: scrubSentryEvent,
// Nitro's route cache catches its own KV write failures and forwards the
// caught error here as unhandled (SKILLD-17). The registry handlers'
// intended upstream-outage 503s land here the same way (SKILLD-11,
// SKILLD-1E), as do MCP probe rejections: 406 (SKILLD-35) and 400 (SKILLD-3H).
// caught error here as unhandled (SKILLD-17). A handler's
// `dependencyOutageError` 503 lands here the same way (SKILLD-11,
// SKILLD-44), as do MCP probe rejections: 406 (SKILLD-35) and 400 (SKILLD-3H).
// All are failure classes already answered or recorded, so drop the
// duplicates and keep the wide events as the visibility path.
beforeSend(event, hint) {
Expand Down
22 changes: 19 additions & 3 deletions server/runtime/kv-cache-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ export interface KvCacheStorageOptions {
*
* So a rejected write resolves and reports as a `cache-write` wide event
* instead. This is not a silent catch: a KV outage stays visible as a rise in
* failed cache writes, and reads are untouched, so a failed read still behaves
* as a miss.
* failed cache writes.
*
* Reads follow the same rule. Nitro already treats a rejected read as a miss,
* then forwards the rejection to `captureError` too, so each `KV GET failed:
* 500` became an unhandled Sentry issue on a request that was still served
* (SKILLD-28). A rejected read resolves to a miss here and reports as a
* `cache-read` wide event, the event `readCache` already records.
*
* Every write carries a TTL of at least 60 seconds, the floor Cloudflare KV
* enforces, matching the guarantee `@harlan-zw/nuxt-cloudflare`'s own cache
Expand All @@ -40,7 +45,7 @@ export default defineDriver((options: KvCacheStorageOptions) => {
throw new Error(`[kv-cache-storage] defaultTtl must be an integer of at least ${MIN_TTL_SECONDS} seconds, received ${options.defaultTtl}`)

const driver = cloudflareKvBinding(options)
const { setItem } = driver
const { getItem, setItem } = driver
if (!setItem)
throw new Error('[kv-cache-storage] cloudflare-kv-binding driver must implement setItem')

Expand All @@ -49,6 +54,17 @@ export default defineDriver((options: KvCacheStorageOptions) => {
options,
name: 'cloudflare-kv-cache',
flags: { ...driver.flags, ttl: true },
getItem(key, transactionOptions) {
return Promise.resolve(getItem(key, transactionOptions)).catch((error: unknown) => {
emitOperationalEvent(createWideEvent({
'operation': 'cache-read',
'outcome': 'failed',
'cache.readFailed': true,
'reason': error instanceof Error ? error.message : String(error),
}))
return null
})
},
setItem(key, value, transactionOptions = {}) {
const requestedTtl = Number(transactionOptions.ttl)
const ttl = Number.isFinite(requestedTtl) && requestedTtl > 0
Expand Down
82 changes: 63 additions & 19 deletions shared/sentry.ts
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'

Expand Down Expand Up @@ -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
Expand All @@ -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 /

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  • Ask an agent to verify and fix this finding

Harlan Agent Kit posted this automated review. It is not Harlan's personal review or approval. AI open source policy.


/**
* 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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  • Ask an agent to verify and fix this finding

Harlan Agent Kit posted this automated review. It is not Harlan's personal review or approval. AI open source policy.

}

/**
* 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
Expand Down
Loading
Loading