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
62 changes: 62 additions & 0 deletions apps/web/src/pages/home/components/chat-error-block.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ let host: HTMLElement
function mountBlock(opts: {
locale?: 'en' | 'zh' | 'ja'
code?: string
args?: Record<string, string>
message?: string
requestId?: string
traceId?: string
Expand All @@ -32,6 +33,7 @@ function mountBlock(opts: {
error: {
type: 'error',
code: opts.code,
args: opts.args,
request_id: opts.requestId,
trace_id: opts.traceId,
content: '',
Expand Down Expand Up @@ -150,4 +152,64 @@ describe('ChatErrorBlock', () => {
expect(host.textContent).toContain(expectedCopy)
expect(buttons()).toContain(expectedDetails)
})

it('shows upstream details in Details drawer without correlation IDs and includes them in Copy', async () => {
const writeText = vi.fn().mockResolvedValue(undefined)
Object.defineProperty(navigator, 'clipboard', {
value: { writeText },
configurable: true,
})

const upstream = 'HTTP 400 · context_length_exceeded: max 8192 tokens\nProvider Request ID: req_upstream_1'
mountBlock({
code: 'agent.provider_request_rejected',
message: 'The model provider rejected the request.',
args: { upstream },
})
await nextTick()

const detailsButton = [...host.querySelectorAll('button')].find(el => el.textContent?.trim() === 'Details')!
expect(detailsButton).toBeTruthy()
expect(detailsButton.getAttribute('aria-expanded')).toBe('false')

detailsButton.click()
await nextTick()
expect(detailsButton.getAttribute('aria-expanded')).toBe('true')
expect(host.textContent).toContain(upstream)

copyButton()!.click()
await Promise.resolve()
await nextTick()
expect(writeText).toHaveBeenCalledWith(`The model provider rejected the request.\n${upstream}`)
})

it('orders upstream details above Request ID when both are present', async () => {
const writeText = vi.fn().mockResolvedValue(undefined)
Object.defineProperty(navigator, 'clipboard', {
value: { writeText },
configurable: true,
})

const upstream = 'HTTP 429 · rate_limit_exceeded: Slow down'
mountBlock({
code: 'agent.provider_rate_limited',
message: 'Rate limit reached.',
args: { upstream },
requestId: 'req-memoh-1',
})
await nextTick()

const detailsButton = [...host.querySelectorAll('button')].find(el => el.textContent?.trim() === 'Details')!
detailsButton.click()
await nextTick()

const text = host.textContent ?? ''
expect(text.indexOf(upstream)).toBeGreaterThan(-1)
expect(text.indexOf('Request ID: req-memoh-1')).toBeGreaterThan(text.indexOf(upstream))

copyButton()!.click()
await Promise.resolve()
await nextTick()
expect(writeText).toHaveBeenCalledWith(`Rate limit reached.\n${upstream}\nRequest ID: req-memoh-1`)
})
})
33 changes: 29 additions & 4 deletions apps/web/src/pages/home/components/chat-error-block.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ const errorCode = computed(() => {
return parseMemohError(props.error)?.code ?? ''
})

const errorArgs = computed<Record<string, unknown> | undefined>(() => {
const direct = (props.error as { args?: unknown } | undefined)?.args
if (direct && typeof direct === 'object' && !Array.isArray(direct)) {
return direct as Record<string, unknown>
}
return parseMemohError(props.error)?.args
})

const upstreamText = computed(() => {
const raw = errorArgs.value?.upstream
return typeof raw === 'string' ? raw.trim() : ''
})

const isProviderSettingsError = computed(() =>
PROVIDER_SETTINGS_CODES.has(errorCode.value),
)
Expand All @@ -82,12 +95,13 @@ const correlationText = computed(() => {
if (requestId) return `${t('common.requestId')}: ${requestId}`
return traceId ? `${t('common.traceId')}: ${traceId}` : ''
})
const showDetailsToggle = computed(() => Boolean(correlationText.value))
const showDetailsToggle = computed(() => Boolean(upstreamText.value || correlationText.value))

const report = computed(() => {
const { requestId, traceId } = correlation.value
return [
props.message,
upstreamText.value,
requestId ? `${t('common.requestId')}: ${requestId}` : '',
traceId ? `${t('common.traceId')}: ${traceId}` : '',
].filter(Boolean).join('\n')
Expand Down Expand Up @@ -190,9 +204,20 @@ function hasPrimaryAction() {
:class="detailsOpen ? 'grid-rows-[1fr]' : 'grid-rows-[0fr]'"
>
<div class="min-h-0 overflow-hidden">
<p class="mt-3 select-text break-all border-t border-border-soft pt-3 text-body tabular-nums text-muted-foreground">
{{ correlationText }}
</p>
<div class="mt-3 space-y-1.5 border-t border-border-soft pt-3">
<p
v-if="upstreamText"
class="select-text break-words whitespace-pre-wrap font-mono text-body leading-relaxed text-muted-foreground"
>
{{ upstreamText }}
</p>
<p
v-if="correlationText"
class="select-text break-all text-body tabular-nums text-muted-foreground"
>
{{ correlationText }}
</p>
</div>
</div>
</div>
</div>
Expand Down
18 changes: 18 additions & 0 deletions apps/web/src/pages/providers/components/model-item.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,24 @@ describe('Provider model item', () => {
expect(el.textContent).not.toContain('dial tcp')
})

it('shows sanitized args.upstream inline below a rejected model test', async () => {
const upstream = 'HTTP 400 · model_not_found: Unknown model\nProvider Request ID: req_m1'
mocks.postTest.mockResolvedValue({
data: {
status: 'error',
reachable: true,
latency_ms: 25,
code: 'agent.provider_request_rejected',
args: { upstream },
},
})
const el = await mount()
await runTest(el)

expect(el.textContent).toContain('errors.agent.provider_request_rejected')
expect(el.textContent).toContain(upstream)
})

it('shows the model description below the model metadata', async () => {
const el = await mount('General-purpose model with vision and tool calling.')

Expand Down
14 changes: 13 additions & 1 deletion apps/web/src/pages/providers/components/model-item.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@
{{ testError }}
</span>
</div>
<p
v-if="testUpstreamError"
class="mt-1 select-text whitespace-pre-wrap break-words font-mono text-caption leading-relaxed text-muted-foreground"
>
{{ testUpstreamError }}
</p>
<p
v-if="modelDescription"
data-model-description
Expand Down Expand Up @@ -147,7 +153,7 @@ import { useQueryCache } from '@pinia/colada'
import { ref, computed } from 'vue'
import { useI18n } from 'vue-i18n'
import { getModelDescription } from '@/utils/model-description'
import { resolveApiErrorMessage } from '@/utils/api-error'
import { parseMemohError, resolveApiErrorMessage } from '@/utils/api-error'
import { withoutLegacyKeys } from '@/components/create-model/model-config'

const props = withDefaults(defineProps<{
Expand All @@ -172,6 +178,7 @@ const queryCache = useQueryCache()
const testLoading = ref(false)
const testResult = ref<ModelsTestResponse | null>(null)
const testError = ref('')
const testUpstreamError = ref('')
const enableLoading = ref(false)
const enableOverride = ref<boolean | null>(null)

Expand Down Expand Up @@ -210,6 +217,7 @@ async function runTest() {
testLoading.value = true
testResult.value = null
testError.value = ''
testUpstreamError.value = ''
try {
const { data } = await postModelsByIdTest({
path: { id: props.model.id },
Expand All @@ -218,10 +226,14 @@ async function runTest() {
testResult.value = data ?? null
if (data && data.status !== 'ok') {
testError.value = testFailureText(data)
const upstream = data.args?.upstream
testUpstreamError.value = typeof upstream === 'string' ? upstream.trim() : ''
}
} catch (err: unknown) {
testResult.value = { status: 'error' }
testError.value = resolveApiErrorMessage(err, t('models.testFailed'))
const upstream = parseMemohError(err)?.args?.upstream
testUpstreamError.value = typeof upstream === 'string' ? upstream.trim() : ''
} finally {
testLoading.value = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,18 @@ describe('provider test connection states', () => {
app.unmount()
root.remove()
})

it('shows sanitized args.upstream summary on non-auth probe failure', async () => {
const upstream = 'HTTP 429 · rate_limit_exceeded: Too many requests'
const { app, root } = await mountAndRunTest({
status: 'error',
reachable: true,
code: 'agent.provider_rate_limited',
args: { upstream },
})
expect(root.textContent).toContain('errors.agent.provider_rate_limited')
expect(root.textContent).toContain(upstream)
app.unmount()
root.remove()
})
})
16 changes: 15 additions & 1 deletion apps/web/src/pages/providers/components/provider-form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@
<template v-else>
{{ testError }}
</template>
<p
v-if="testUpstreamError"
class="mt-1.5 select-text border-t border-border-soft pt-1.5 font-mono text-caption leading-relaxed text-muted-foreground"
>
{{ testUpstreamError }}
</p>
</HoverCardContent>
</HoverCard>

Expand Down Expand Up @@ -405,7 +411,7 @@ import type {
import { useI18n } from 'vue-i18n'
import { ConfirmPopover, DeviceCodePanel, SettingsRow, SettingsSection, toast } from '@felinic/ui'
import { useProviderModelCatalog } from '@/composables/useProviderModelCatalog'
import { resolveApiErrorMessage } from '@/utils/api-error'
import { parseMemohError, resolveApiErrorMessage } from '@/utils/api-error'
import { modelSourceNeedsApiKey, providerCatalogEntry } from '@/constants/model-sources'

const { t, te } = useI18n()
Expand Down Expand Up @@ -450,6 +456,7 @@ let testGeneration = 0
const testLoading = ref(false)
const testResult = ref<ProvidersTestResponse | null>(null)
const testError = ref('')
const testUpstreamError = ref('')
const oauthStatus = ref<ProvidersOAuthStatus | null>(null)
const oauthStatusLoading = ref(false)
const authorizeLoading = ref(false)
Expand Down Expand Up @@ -486,6 +493,7 @@ async function runTest() {
testLoading.value = true
testResult.value = null
testError.value = ''
testUpstreamError.value = ''
try {
const { data } = await postProvidersByIdTest({
path: { id: props.provider.id },
Expand All @@ -495,10 +503,14 @@ async function runTest() {
testResult.value = data ?? null
if (testResult.value?.status !== 'ok') {
testError.value = testFailureText(testResult.value)
const upstream = testResult.value?.args?.upstream
testUpstreamError.value = typeof upstream === 'string' ? upstream.trim() : ''
}
} catch (err: unknown) {
if (generation !== testGeneration) return
testError.value = resolveApiErrorMessage(err, t('provider.testFailed'))
const upstream = parseMemohError(err)?.args?.upstream
testUpstreamError.value = typeof upstream === 'string' ? upstream.trim() : ''
} finally {
testLoading.value = false
}
Expand All @@ -508,6 +520,7 @@ watch(() => props.provider?.id, () => {
testGeneration++
testResult.value = null
testError.value = ''
testUpstreamError.value = ''
})

const clientTypeOptions = computed(() =>
Expand Down Expand Up @@ -648,6 +661,7 @@ watch(
testGeneration++
testResult.value = null
testError.value = ''
testUpstreamError.value = ''
},
)

Expand Down
14 changes: 14 additions & 0 deletions docs/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,20 @@ queries of URLs in it and bound its length. A failure inside Memoh on the way
(reading the Agent's configuration, looking the workspace up) is not the
agent's and stays internal.

A second diagnostic detail channel covers model provider responses and internal
runtime/transport failures in self-hosted Memoh (`agent.provider_*`,
`agent.response_timeout`, `agent.response_interrupted`, `agent.tool_timeout`,
`runtime_run_failed`, `runtime_prompt_failed`, and `internal`). On both chat
runs and provider/model connectivity probes, `models.UpstreamErrorSummary`
passes through verbatim, length-bounded details into `args.upstream`
(`apperror.ProviderErrorArgUpstream`) without regex redaction: `*sdk.APIError`
responses (including `HTTP 401`) format their status code, upstream error code
or type, upstream message (with UTF-8 body fallback only when `Message` is
empty), and `RequestID`; transport and internal errors pass through
`err.Error()`. History persistence stores `error_args` alongside `error_code`
so expanded error details survive page reloads, while IM channels continue to
render localized copy for the error code alone.

A runtime driver reports a failure as an `external.Failure` of one of three
sorts: what the agent said (`FailureReported`), a sign-in
(`FailureAuthRequired`), or one of Memoh's own rules refusing the request
Expand Down
Loading
Loading