Retain producer files after failed extraction

This commit is contained in:
2026-11-30 03:58:26 +00:00
parent 7ad6b718a0
commit b6492ab4e8
3 changed files with 36 additions and 10 deletions

View File

@@ -11,7 +11,11 @@ them or change the agreed operator contract.
**Priority:** P2
**Status:** Pending
**Status:** Complete
Producer output is retained on failure; temporary promotion copies still clean
up. Stage regressions cover failed delivery and missing/invalid lanes, without
promoting incidental files. Verified with `go test ./internal/stage`.
**Stages:** 11–12; failure-evidence and workspace requirements in 16 and 21–23.

View File

@@ -151,14 +151,8 @@ func (extractStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (re
ReportPath: reportPath, LogPath: logPath, Timeout: timeout, Cache: cache,
Debug: notariusConfig.Debug, DebugDirectory: debugDirectory, References: referenceBindings,
}
accepted := false
defer func() {
if !accepted {
if cleanupErr := fileops.RemoveAllUnderRoot(filepath.Dir(outputRoot), outputRoot); cleanupErr != nil {
resultErr = errors.Join(resultErr, fmt.Errorf("extract: remove failed Notarius output root: %w", cleanupErr))
}
}
}()
// Producer files remain inspectable even when completion delivery fails.
// Only Narratio's temporary promotion copies are cleaned below.
adapterResult, err := env.Notarius.Run(ctx, request)
if err != nil {
return nil, fmt.Errorf("extract: run notarius: %w", err)
@@ -248,7 +242,6 @@ func (extractStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (re
"completion": completion,
}
result = &StageResult{Outputs: outputs, Logs: []string{reportPath, logPath}, Metadata: metadata}
accepted = true
return result, nil
}

View File

@@ -3,6 +3,7 @@ package stage
import (
"context"
"encoding/json"
"errors"
"os"
"path/filepath"
"strings"
@@ -46,6 +47,34 @@ func nativeRecordResult(m *manifest.Manifest, result *StageResult) {
m.Stages["extract"].Metadata = result.Metadata
}
func TestNativeExtractionFailureRetainsProducerFiles(t *testing.T) {
for _, failure := range []string{"delivery", "missing", "invalid"} {
t.Run(failure, func(t *testing.T) {
env, m, fake := nativeExtractFixture(t)
if failure == "delivery" {
fake.Err = errors.New("completion delivery failed")
} else {
env.Config.Pipeline.Notarius.Outputs["other"] = config.NotariusOutputConfig{LaneID: "other"}
if failure == "invalid" {
writeFile(t, filepath.Join(fake.Result.BundleRoot, "lanes", "other.json"), "invalid JSON")
}
}
result, err := (extractStage{}).Run(context.Background(), env, m)
if err == nil || result != nil {
t.Fatalf("failed extraction returned %v, %v", result, err)
}
for _, name := range []string{"lanes/npc-registry.json", "chunk-map.json"} {
if _, err := os.Stat(filepath.Join(fake.Result.BundleRoot, name)); err != nil {
t.Fatalf("producer evidence %s lost: %v", name, err)
}
}
if _, err := os.Stat(filepath.Join(sessionPathsForEnv(env, m.SessionID).ArtifactsDir, "npc_registry.json")); !os.IsNotExist(err) {
t.Fatalf("failed extraction promoted a product: %v", err)
}
})
}
}
func TestNativeExtractionPromotesRequiredLanesAndReusesCanonicalProducts(t *testing.T) {
env, m, fake := nativeExtractFixture(t)
reporter := &extractionWarnings{}