feat(monitor): 死信中文提示与成功/取消自动退信

This commit is contained in:
姚章浩
2026-09-15 14:37:46 +08:00
parent f8cef26f4a
commit 767684bb1f
11 changed files with 147 additions and 16 deletions
+4 -1
View File
@@ -37,7 +37,10 @@ describe('WeKnoraMonitorView',()=>{
})
it('shows inbox lanes for the knowledge-base diff view',()=>{
const attention=renderToStaticMarkup(<WeKnoraMonitorView {...baseProps} lane='attention' />)
for(const text of ['需要你出手','CR20A.pdf','remote_parse_failed','失败阶段 文档解析','批量重试所选(1)','死信(尝试耗尽,不可自动重试)'])expect(attention).toContain(text)
for(const text of ['需要你出手','CR20A.pdf','remote_parse_failed','失败阶段 文档解析','批量重试所选(1)','死信(重试次数用完,系统不再自动处理)','源头取件”=从钉钉/AList'])expect(attention).toContain(text)
const withFailures=renderToStaticMarkup(<WeKnoraMonitorView {...baseProps} lane='attention' failures={[{id:'jf-1',job_id:'job-1',job_type:'artifact.fetch',error_code:'handler_error',attempt:8,max_attempts_at_failure:8,state:'open',created_at:'2026-09-15T01:52:53Z',doc_name:'ATOM整机出厂测试.adoc',last_error:'artifact_fetch_retryable: source_unavailable'}]} />)
expect(withFailures).toContain('「ATOM整机出厂测试.adoc」')
expect(withFailures).toContain('来源服务当时不可达')
const inflight=renderToStaticMarkup(<WeKnoraMonitorView {...baseProps} lane='inflight' />)
for(const text of ['处理中','知识库解析进度','已导入 5750','待入库 120','对内 3300 / 4200','对外 1230 / 1550','源头取件 → Hash'])expect(inflight).toContain(text)
const queueView=renderToStaticMarkup(<WeKnoraMonitorView {...baseProps} lane='queue' />)
+16 -2
View File
@@ -29,6 +29,20 @@ const adviceFor = (stage: string, code: string) => {
return '确认错误码后可直接重试;尝试次数耗尽将进入死信队列。'
}
// failureHint turns a dead-letter row's machine code into a plain-Chinese
// diagnosis of what actually went wrong and what to do.
const failureHint = (failure: JobFailure) => {
const detail = `${failure.error_code} ${failure.last_error || ''}`
if (detail.includes('not ingestable')) return '钉钉侧该类型不是可下载文档(快捷方式、占位或内部对象),重试也不会成功;建议用“文件名筛选”把它排除,或在钉钉确认它是否为空目录残留。'
if (detail.includes('source_auth_required')) return '来源存储需要网页登录授权(服务凭据未配置),请联系管理员在“系统设置”重新扫码。'
if (detail.includes('invalid_format')) return '取回的内容不是有效的文档/文本格式,可能源头文件本身损坏;可下载原件确认后重试。'
if (detail.includes('source_unavailable')) return '来源服务当时不可达(网络/接口抖动)。任务若已自动重试成功,这里只是历史记录;仍在列表说明源头仍不可达。'
if (failure.error_code === 'test_upload_remote_failed' || detail.includes('test_upload_remote_failed')) return '向测试知识库上传被拒:确认 WeKnora 测试实例可达、目标知识库未停用后,点击重新入队。'
if (failure.error_code === 'remote_parse_failed') return '文档解析失败:建议先在 WeKnora 手动解析该文件确认格式,再重新入队。'
if (failure.error_code === 'handler_error') return '处理环节报错,展开原始错误定位;确认原因后可重新入队。'
return `错误码 ${failure.error_code}:确认原因后可重新入队。`
}
const pipelineStages = ['源头取件', 'Hash', 'OSS', '文档解析', 'WeKnora 上传', '索引', '完成']
const stageIndex = (label: string) => label === 'Hash / 文件校验' ? 1 : label === 'OSS' ? 2 : label === '文档解析' ? 3 : label === 'WeKnora 上传' ? 4 : label === '索引 / 增强' || label === '测试知识移除' || label === '治理策略' || label === '处理链路' ? 5 : -1
function chainSteps(item: TestPublication) {
@@ -179,8 +193,8 @@ export function WeKnoraMonitorView({
<div className="section-head"><h2>需要你出手({attentionItems.length})</h2><span className="spacer" /><button className="danger" disabled={!batchTargets.length || retryingIDs.length > 0} onClick={() => onBatchRetry(batchTargets)}>{retryingIDs.length ? '重试中…' : `批量重试所选(${batchTargets.length})`}</button></div>
{batchMessage ? <p className="queue-batch-message" role="status">{batchMessage}</p> : null}
{attentionItems.length ? attentionItems.map(actionTask) : emptyLane('没有失败或停滞的任务。')}
<div className="section-head sub"><h3>死信(尝试耗尽,不可自动重试)</h3><span className="tiny">原始任务与审计行保留不动;重新入队会创建新尝试</span></div>
{failures.length ? <ul className="dlq-list">{failures.map((failure) => <li key={failure.id}><span className="monitor-status failed">{failure.error_code}</span><b>{failure.job_type === 'test.upload' ? '上传解析' : failure.job_type === 'artifact.fetch' ? '源头取件' : failure.job_type}</b>{failure.publication_id ? <code>{failure.publication_id}</code> : null}<small>{failure.attempt}/{failure.max_attempts_at_failure} 次 · {new Date(failure.created_at).toLocaleString('zh-CN', { hour12: false })}</small>{failure.publication_id ? <button disabled={retryingIDs.includes(failure.publication_id)} onClick={() => onBatchRetry([failure.publication_id as string])}>重新入队</button> : null}</li>)}</ul> : emptyLane('当前没有等待处理的死信记录。')}
<div className="section-head sub"><h3>死信(重试次数用完,系统不再自动处理)</h3><span className="tiny">“源头取件”=从钉钉/AList 把原始文件拉回本地;“上传解析”=把文件送进知识库做解析。死信只是失败任务的登记表,不会改动原始记录;重新入队=再给它一次机会</span></div>
{failures.length ? <ul className="dlq-list">{failures.map((failure) => <li key={failure.id}><span className="monitor-status failed">{failure.error_code}</span><b>{failure.job_type === 'test.upload' ? '上传解析' : failure.job_type === 'artifact.fetch' ? '源头取件' : failure.job_type}</b>{failure.doc_name ? <b>「{failure.doc_name}」</b> : failure.publication_id ? <code>{failure.publication_id}</code> : null}<small>{failure.attempt}/{failure.max_attempts_at_failure} 次 · {new Date(failure.created_at).toLocaleString('zh-CN', { hour12: false })}</small><small>{failureHint(failure)}</small>{failure.publication_id ? <button disabled={retryingIDs.includes(failure.publication_id)} onClick={() => onBatchRetry([failure.publication_id as string])}>重新入队</button> : null}</li>)}</ul> : emptyLane('当前没有等待处理的死信记录。')}
</section> : null}
{lane === 'removal' ? <section className="inbox-section" aria-label="需下架">
<div className="section-head"><h2>需下架({laneCounts.removal})</h2><span className="tiny">来源目录里被改为“禁止导入”或撤销标注、但仍在知识库中可检索的文件</span></div>
+1 -1
View File
@@ -170,7 +170,7 @@ export async function retryPublicationsBatch(publicationIds: string[], reason: s
}
}
export interface JobFailure { id: string; job_id: string; job_type: string; publication_id?: string; source_item_id?: string; error_code: string; attempt: number; max_attempts_at_failure: number; change_set_id?: string; action?: string; target_kb_id?: string; state: 'open' | 'requeued' | 'abandoned'; created_at: string }
export interface JobFailure { id: string; job_id: string; job_type: string; publication_id?: string; source_item_id?: string; error_code: string; attempt: number; max_attempts_at_failure: number; change_set_id?: string; action?: string; target_kb_id?: string; state: 'open' | 'requeued' | 'abandoned'; created_at: string; doc_name?: string; last_error?: string }
export async function fetchJobFailures(signal?: AbortSignal): Promise<JobFailure[]> {
const response = await fetch('/api/v1/job-failures?state=open&limit=50', { headers: { Accept: 'application/json' }, signal })
+2 -1
View File
@@ -14,7 +14,8 @@
.queue-batch-message{margin:6px 0;color:var(--c-done)}
.dlq-panel{margin-top:14px}
.dlq-list{list-style:none;margin:8px 0 0;padding:0;display:flex;flex-direction:column;gap:6px}
.dlq-list li{display:flex;align-items:center;gap:10px;padding:8px 10px;border:1px solid var(--border-strong);border-radius:8px;background:var(--bg-page)}
.dlq-list li{display:flex;align-items:center;gap:10px;flex-wrap:wrap;padding:8px 10px;border:1px solid var(--border-strong);border-radius:8px;background:var(--bg-page)}
.dlq-list li small{flex-basis:100%;margin-left:2px;color:var(--ink-mute)}
.dlq-list small{margin-left:auto;color:var(--c-dead)}
.run-metrics{margin-top:14px}
.run-metrics-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(180px,1fr));gap:8px;margin-top:8px}