fix(library): 收口 B1-R1/B2-R1/B5-R1 并让恢复链经过正式队列终态

B1-R1: 演练写集改为受限 restore-drill(V2 信封/contract 1/schema 摘要,零对象、零索引、零本地映射,来源身份必填)。B2-R1: verify 作业先建不可变 operation 并携带 operation_id,同 job recover 的网关 claim 同时携带原 operation 与 recovery 身份。B5-R1: 前端按 scope 世代与动作序号丢弃迟到响应,不污染新 scope 或父级旧回调。harness 的 recovery 改由生产 jobs.Worker.RunOnce 消费并读回 jobs 终态;原失败窗口作业保持 failed,不改写历史。
This commit is contained in:
姚章浩
2026-11-03 13:02:42 +08:00
parent f9457fab52
commit b4add6c9b0
12 changed files with 1515 additions and 18 deletions
+4 -4
View File
@@ -23,7 +23,7 @@ func TestCanaryPersistsAndRegistersEvidenceBeforeWrite(t *testing.T) {
root := t.TempDir()
ledger := drillLedger()
registered, marked, written := false, false, false
err := writeDrillCanary(context.Background(), root, &ledger, "canary-id",
err := writeDrillCanary(context.Background(), root, &ledger, "canary-id", nil,
func(context.Context) error {
if !registered {
t.Fatal("risk marker preceded durable registration")
@@ -67,7 +67,7 @@ func TestCanaryNeverWritesWithoutDurableLedger(t *testing.T) {
}
ledger := drillLedger()
marked, written := false, false
err := writeDrillCanary(context.Background(), root, &ledger, "canary-id",
err := writeDrillCanary(context.Background(), root, &ledger, "canary-id", nil,
func(context.Context) error { marked = true; return nil },
func(context.Context) error { marked = true; return nil },
func(context.Context) error { written = true; return nil })
@@ -80,7 +80,7 @@ func TestCanaryNeverWritesWithoutDurableLedger(t *testing.T) {
func TestCanaryNeverWritesWhenRegistrationFails(t *testing.T) {
ledger := drillLedger()
marked, written := false, false
err := writeDrillCanary(context.Background(), t.TempDir(), &ledger, "canary-id",
err := writeDrillCanary(context.Background(), t.TempDir(), &ledger, "canary-id", nil,
func(context.Context) error { marked = true; return nil },
func(context.Context) error { return errors.New("governance registration unavailable") },
func(context.Context) error { written = true; return nil })
@@ -92,7 +92,7 @@ func TestCanaryNeverWritesWhenRegistrationFails(t *testing.T) {
func TestCanaryNeverWritesWhenRiskMarkerFails(t *testing.T) {
ledger := drillLedger()
written := false
err := writeDrillCanary(context.Background(), t.TempDir(), &ledger, "canary-id",
err := writeDrillCanary(context.Background(), t.TempDir(), &ledger, "canary-id", nil,
func(context.Context) error { return errors.New("journal unavailable") },
func(context.Context) error { return nil },
func(context.Context) error { written = true; return nil })
+11
View File
@@ -252,6 +252,11 @@ func Run(ctx context.Context, config appconfig.Config, scope, jobID string, opts
report.Canary = canary
progress.report("canary", "running", "写入一个隔离 canary,验证校验能发现差异")
if err := writeDrillCanary(ctx, config.LibraryArchiveRoot, &ledger, canary,
func(set *libraryrelease.WriteSet) error {
// 计划必须在 Seal/落盘/登记之前定型:对象网关控制器按登记摘要加载,
// 这里补 V2 信封、目标 schema、来源身份与当前 owned attempt 绑定。
return target.PrepareDrillPlan(ctx, set)
},
func(ctx context.Context) error {
if err := window.MarkContentRisk(ctx); err != nil {
return err
@@ -397,8 +402,14 @@ func ledgerClone(set *libraryrelease.WriteSet) *libraryrelease.WriteSet {
// writeDrillCanary 是"写入前先留痕"的唯一实现:seal → 落盘 → 登记 → 标风险 → 写。
// 任何一步失败都不写目标;登记在标风险之前,恢复入口才拿得到这份写集合。
func writeDrillCanary(ctx context.Context, root string, ledger *libraryrelease.WriteSet, id string,
prepare func(*libraryrelease.WriteSet) error,
mark func(context.Context) error, record func(context.Context) error, write func(context.Context) error) error {
ledger.Rows = append(ledger.Rows, libraryrelease.WriteSetRow{Table: "knowledge_tags", ID: id, Existing: false})
if prepare != nil {
if err := prepare(ledger); err != nil {
return err
}
}
if err := ledger.Seal(); err != nil {
return err
}