按用户明确要求,治理封存不再替 WeKnora 判断正文块“应该”有独立索引: 删除 status/chunk_type/parent/mixed/flat 推导的 needOriginal、mixedDocs 及覆盖门槛;删除 parent 类型搭配限制,仅保留父引用存在与同 knowledge。 capture/preflight/archive/load/replay/writeset 共用校验同步更新,移除已无 用途的 worker 永久失败分类。 保留真实导出范围、PG/ES 原始正文/问题 metadata/vector、tenant/KB/ knowledge/chunk 身份、清单摘要、资源字节、Wiki/问题索引 source_id 及真实 悬空引用等完整性检查;不修改源端,不补数据/索引。旧测试改为原样捕获正例, 新增 status0/2 缺正文索引和父类型不匹配的接受回归,以及 archive/readback 逐行/逐记录比对。 验证:v071、cmd/worker、Go 全量、make verify 17 项。
This commit is contained in:
@@ -1,51 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"knowledge-governance/internal/jobs"
|
||||
)
|
||||
|
||||
func TestLibraryCaptureValidationFailureIsTerminal(t *testing.T) {
|
||||
original := errors.New("LIBRARYCTL_FAILED: unverified legacy library chunk index coverage;已执行 recover 并确认写入者恢复")
|
||||
got := terminalLibraryCaptureError(original)
|
||||
terminal, code := jobs.Terminal(got)
|
||||
if !terminal || code != jobs.ErrCodeValidationFailed {
|
||||
t.Fatalf("validation failure must park immediately: terminal=%v code=%q err=%v", terminal, code, got)
|
||||
}
|
||||
if got.Error() != original.Error() {
|
||||
t.Fatalf("original cause changed: got %q want %q", got.Error(), original.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestLibraryCaptureTransientFailureStillRetries(t *testing.T) {
|
||||
for _, message := range []string{
|
||||
"library agent is unreachable",
|
||||
"context deadline exceeded",
|
||||
`LIBRARYCTL_FAILED: job "lib-internal-x" already exists with state "failed";已执行 recover 并确认写入者恢复`,
|
||||
} {
|
||||
got := terminalLibraryCaptureError(errors.New(message))
|
||||
if terminal, code := jobs.Terminal(got); terminal {
|
||||
t.Fatalf("%q must stay retryable, got terminal code=%q", message, code)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLibraryCaptureOriginalFailureSurvivesRetryOverwrite(t *testing.T) {
|
||||
// 队列第二次 attempt 的 already exists 不能替换第一因;分类器保留首个
|
||||
// 校验错误为永久失败,因此队列不会产生第二次自动 attempt。
|
||||
first := errors.New("LIBRARYCTL_FAILED: unverified legacy library chunk index coverage;已执行 recover 并确认写入者恢复")
|
||||
second := errors.New(`LIBRARYCTL_FAILED: job "lib-internal-20261105T054158" already exists with state "failed";已执行 recover 并确认写入者恢复`)
|
||||
classified := terminalLibraryCaptureError(first)
|
||||
if terminal, _ := jobs.Terminal(classified); !terminal {
|
||||
t.Fatal("first validation error must terminate before retry")
|
||||
}
|
||||
if terminal, _ := jobs.Terminal(second); terminal {
|
||||
t.Fatal("second retry error must not be terminal")
|
||||
}
|
||||
if !strings.Contains(classified.Error(), "unverified legacy library chunk index coverage") {
|
||||
t.Fatalf("first cause lost: %v", classified)
|
||||
}
|
||||
}
|
||||
+1
-24
@@ -101,29 +101,6 @@ func stageSizesFrom(manifest librarysnapshot.Manifest) map[string]stageSize {
|
||||
// libraryCaptureJobType is shared with the API which enqueues it.
|
||||
const libraryCaptureJobType = "library.capture"
|
||||
|
||||
// 这些是源库内容/索引覆盖的确定性校验失败,不是网络抖动。agent 已经
|
||||
// 执行 recover 并确认写入者恢复后,继续自动重试只会复用失败 journal,
|
||||
// 用第二次“already exists”覆盖真正的第一因。只对这类错误走永久失败;
|
||||
// 不可达、超时、journal 竞争等仍保留正常重试。
|
||||
var terminalLibraryCaptureMarkers = []string{
|
||||
"unverified legacy library chunk index coverage",
|
||||
"missing library generated question index",
|
||||
"missing indexed library chunk",
|
||||
"empty library index content",
|
||||
}
|
||||
|
||||
func terminalLibraryCaptureError(err error) error {
|
||||
if err == nil || !strings.Contains(err.Error(), "已执行 recover 并确认写入者恢复") {
|
||||
return err
|
||||
}
|
||||
for _, marker := range terminalLibraryCaptureMarkers {
|
||||
if strings.Contains(err.Error(), marker) {
|
||||
return jobs.Permanent(jobs.ErrCodeValidationFailed, err)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// librarySyncJobType 是生产同步作业的队列类型;与封存严格分开,状态不共用。
|
||||
const librarySyncJobType = "library.sync"
|
||||
|
||||
@@ -388,7 +365,7 @@ func workerHandlers(store *postgresstore.Store, config appconfig.Config) (map[st
|
||||
_ = store.AdvanceLibraryJob(ctx, libraryJobID, governance.LibraryJobFailed, "export", err.Error(),
|
||||
"agent 已执行恢复检查;确认来源 healthy 后可重试同一作业号", "", "", finishedAt)
|
||||
log.Printf("library capture failed scope=%s capture_job=%s: %v", payload.Scope, payload.CaptureJob, err)
|
||||
return terminalLibraryCaptureError(err)
|
||||
return err
|
||||
}
|
||||
// 执行后复核:结果里 agent 自报的身份必须还是期望实例,否则这次封存
|
||||
// 可能来自别的栈,绝不能登记成"本实例的测试封存"。
|
||||
|
||||
Reference in New Issue
Block a user