RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
fix(ingestion): carry component outputs in the pipeline operation log DSL (#18774)
euvrec284417d0538
diff --git a/internal/ingestion/task/debug_log_sink_test.go b/internal/ingestion/task/debug_log_sink_test.goindex 49520a74a6..9e6c820ebe 100644--- a/internal/ingestion/task/debug_log_sink_test.go+++ b/internal/ingestion/task/debug_log_sink_test.go@@ -467,8 +467,9 @@ func TestDebugLogSink_RealPipeline_EndMarkerCarriesDSL(t *testing.T) {// so it would not catch this. This test closes that end-to-end gap.//// It also pins the inverse: component "d" (stub returning {"ok":true}) has NO-// recognized output key, so its params.outputs must be absent — the safe-empty-// contract the front-end renders as a blank step.+// recognized output key, so its params.outputs carries no format keys — the+// safe-empty contract the front-end renders as a blank step (the TrackElapsed+// bookkeeping pair is still present).func TestDebugLogSink_RealPipeline_EndMarkerDSLShowsChunks(t *testing.T) {const (compC = "trace.RealStubChunks"@@ -557,10 +558,19 @@ func TestDebugLogSink_RealPipeline_EndMarkerDSLShowsChunks(t *testing.T) {t.Errorf("c params.setups must be carried from DSL: %#v", cParams)}- // Component "d" emits {"ok":true} -> no recognized format -> outputs absent.+ // Component "d" emits {"ok":true} -> no recognized format -> NO format keys+ // are invented; the TrackElapsed bookkeeping pair the real pipeline run+ // stamped is still carried so the timeline can show its elapsed time.dParams := components["d"].(map[string]any)["obj"].(map[string]any)["params"].(map[string]any)- if _, exists := dParams["outputs"]; exists {- t.Errorf("d has no recognized output, outputs must be absent: %#v", dParams)+ dOutputs, ok := dParams["outputs"].(map[string]any)+ if !ok {+ t.Fatalf("d (no payload format) must still carry bookkeeping outputs: %#v", dParams)+ }+ if _, exists := dOutputs["output_format"]; exists {+ t.Errorf("d has no recognized output, output_format must be absent: %#v", dOutputs)+ }+ if _, exists := dOutputs["_elapsed_time"]; !exists {+ t.Errorf("d outputs._elapsed_time must be carried: %#v", dOutputs)}// The END marker MESSAGE must be the JSON dump of the LAST component'sdiff --git a/internal/ingestion/task/debug_result_dsl.go b/internal/ingestion/task/debug_result_dsl.goindex 01034c70ab..b921968907 100644--- a/internal/ingestion/task/debug_result_dsl.go+++ b/internal/ingestion/task/debug_result_dsl.go@@ -13,22 +13,23 @@// See the License for the specific language governing permissions and// limitations under the License.//-// This file is the Go analogue of Python's `Graph.__str__`-// (agent/canvas.py:119) used by the dataflow debug "View result" page.-// Python attaches `dsl = json.loads(str(self))` to the END debug-log marker-// (rag/flow/pipeline.py:98); the front-end reads `dsl.components[<id>].obj`-// to render each component's parsed output. Go has no per-component `__str__`-// serialization, so BuildDebugResultDSL combines the STATIC DSL structure-// (component_name / downstream / params / graph.nodes) with the RUN output map-// (state.go:284 `out[<componentID>] = <outputs>`) to emit the identical JSON-// shape. Result is a strict subset (UI-relevant fields only) of Python's, so-// the front-end renders chunks with parity and a smaller payload.+// This file builds the run-result DSL attached to the dataflow debug-log END+// marker (agent/canvas.py:126, rag/flow/pipeline.py:104) and persisted as the+// pipeline operation-log DSL; the front-end "View result" page reads+// `dsl.components[<id>].obj` to render each component's parsed output.+// BuildDebugResultDSL combines the STATIC DSL structure (component_name /+// downstream / params / graph.nodes) with the RUN output map (state.go:284+// `out[<componentID>] = <outputs>`). Every non-`components` top-level key+// (graph / path / task_id / …) is carried verbatim; each rebuilt obj keeps+// the UI-relevant fields, so the front-end renders chunks at a smaller+// payload.package taskimport ("encoding/json""fmt"+ "reflect""strings"pipelinepkg "ragflow/internal/ingestion/pipeline"@@ -48,6 +49,12 @@ type ResultSink interface {// mirroring NormalizeChunks (chunk_utils.go:27).var outputFormats = []string{"chunks", "json", "text", "html", "markdown"}+// bookkeepingKeys are the TrackElapsed stamps every component's run output+// carries. They are copied into the outputs wrapper (as plain {value, type}+// entries) so the front-end timeline can render per-node elapsed times even+// for components with no recognized payload format (e.g. File).+var bookkeepingKeys = []string{"_elapsed_time", "_created_time"}+// vectorKeys are dropped from payloads while copying. The front-end never// renders raw vectors and Python's serialized component obj excludes them;// stripping keeps the Redis-stored debug log at Python-scale size.@@ -126,15 +133,34 @@ func BuildDebugResultDSL(dsl string, output map[string]any) (map[string]any, errfor k, v := range staticParams {mergedParams[k] = deepCopy(v, false)}- if format, payload := detectFormat(lookupComponentOutput(output, id)); format != "" {- mergedParams["outputs"] = map[string]any{- format: map[string]any{- "value": deepCopy(payload, true),- "type": "",- },- "output_format": map[string]any{"value": format},+ runOut, _ := lookupComponentOutput(output, id).(map[string]any)+ outputsWrapper := map[string]any{}+ if format, payload := detectFormat(runOut); format != "" {+ value := deepCopy(payload, true)+ outputsWrapper[format] = map[string]any{+ "value": value,+ "type": pythonTypeName(value),+ }+ outputsWrapper["output_format"] = map[string]any{+ "value": format,+ "type": pythonTypeName(format),}}+ // TrackElapsed stamps the bookkeeping pair into every component's run+ // output (internal/agent/canvas/node_body.go). Carry them into the+ // outputs wrapper as plain {value, type} entries so the front-end+ // timeline renders per-node elapsed times — it reads exactly+ // params.outputs._elapsed_time.value+ // (web/src/pages/dataflow-result/hooks.ts; agent/component/base.py+ // set_output's the same keys).+ for _, k := range bookkeepingKeys {+ if v, ok := runOut[k]; ok && v != nil {+ outputsWrapper[k] = map[string]any{"value": v, "type": pythonTypeName(v)}+ }+ }+ if len(outputsWrapper) > 0 {+ mergedParams["outputs"] = outputsWrapper+ }built[id] = map[string]any{"obj": map[string]any{@@ -146,10 +172,18 @@ func BuildDebugResultDSL(dsl string, output map[string]any) (map[string]any, err}}- result := map[string]any{- "components": built,- "graph": deepCopy(root["graph"], false),+ // Carry every non-components top-level key (graph, path, task_id,+ // canvas_type, ...) verbatim (contract: agent/canvas.py:126). The+ // persisted log DSL round-trips through the front-end rerun flow, so a+ // dropped key is lost to every consumer.+ result := make(map[string]any, len(root)+1)+ for k, v := range root {+ if k == "components" {+ continue+ }+ result[k] = deepCopy(v, false)}+ result["components"] = builtreturn result, nil}@@ -205,6 +239,32 @@ func detectFormat(out any) (string, any) {return "", nil}+// pythonTypeName returns the type string recorded next to every output value —+// str(type(value)) (agent/component/base.py:467) — for the values a Go run+// output carries. Every sequence reports "list" and every mapping "dict",+// regardless of the Go element type.+func pythonTypeName(v any) string {+ switch v.(type) {+ case nil:+ return "<class 'NoneType'>"+ case bool:+ return "<class 'bool'>"+ case string:+ return "<class 'str'>"+ case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:+ return "<class 'int'>"+ case float32, float64:+ return "<class 'float'>"+ }+ switch reflect.TypeOf(v).Kind() {+ case reflect.Slice, reflect.Array:+ return "<class 'list'>"+ case reflect.Map:+ return "<class 'dict'>"+ }+ return fmt.Sprintf("<class '%T'>", v)+}+// deepCopy returns a JSON-compatible deep copy of v (maps/slices/primitives),// preserving structure but sharing nothing mutable with the source. When// stripVector is true it additionally drops vector keys (see IsVectorKey) fromdiff --git a/internal/ingestion/task/debug_result_dsl_test.go b/internal/ingestion/task/debug_result_dsl_test.goindex 90b812af5f..7fecbe9b30 100644--- a/internal/ingestion/task/debug_result_dsl_test.go+++ b/internal/ingestion/task/debug_result_dsl_test.go@@ -45,19 +45,27 @@ func TestBuildDebugResultDSL(t *testing.T) {{"id": "begin", "data": {"name": "开始"}},{"id": "a", "data": {"name": "解析"}},{"id": "b", "data": {"name": "分词"}}- ]}+ ]},+ "path": ["begin", "a", "b"],+ "task_id": "task-42",+ "canvas_type": "dataflow"}}`// Run output: keyed by component id (state.go:284 `out[ref]=v`). `a` emits- // chunks, `b` emits plain text, `begin` has no recognized output key.+ // chunks, `b` emits plain text, `begin` carries only the TrackElapsed+ // bookkeeping pair — the shape real no-payload components (e.g. File)+ // produce, since the canvas wraps every component body in TrackElapsed.output := map[string]any{"a": map[string]any{"chunks": []any{map[string]any{"text": "hello", "vector": []float64{0.1, 0.2}},},+ "_elapsed_time": 0.35,+ "_created_time": 100.0,},- "b": map[string]any{"text": "plain"},+ "b": map[string]any{"text": "plain", "_elapsed_time": 0.02},+ "begin": map[string]any{"_elapsed_time": 0.01, "_created_time": 99.0},}result, err := BuildDebugResultDSL(dsl, output)@@ -73,6 +81,22 @@ func TestBuildDebugResultDSL(t *testing.T) {t.Fatalf("want 3 components (begin,a,b), got %d: %#v", len(components), components)}+ // Non-components top-level keys are carried verbatim (agent/canvas.py:126):+ // the persisted log DSL round-tripped by the rerun flow must not drop+ // path/task_id/canvas_type/graph.+ if p, _ := result["path"].([]any); len(p) != 3 || p[0] != "begin" || p[2] != "b" {+ t.Errorf("result.path=%#v want [begin a b]", result["path"])+ }+ if tid, _ := result["task_id"].(string); tid != "task-42" {+ t.Errorf("result.task_id=%v want task-42", result["task_id"])+ }+ if ct, _ := result["canvas_type"].(string); ct != "dataflow" {+ t.Errorf("result.canvas_type=%v want dataflow", result["canvas_type"])+ }+ if g := result["graph"]; g == nil {+ t.Error("result.graph must be carried, got nil")+ }+// --- component "a": must carry chunks under params.outputs ---a, ok := components["a"].(map[string]any)if !ok {@@ -105,6 +129,22 @@ func TestBuildDebugResultDSL(t *testing.T) {if !ok || of["value"] != "chunks" {t.Errorf("components.a output_format=%#v want {value:\"chunks\"}", aOutputs["output_format"])}+ // The outputs wrapper records str(type(value)) type strings+ // (agent/component/base.py:467), not "".+ if of["type"] != "<class 'str'>" {+ t.Errorf("components.a output_format.type=%#v want <class 'str'>", of["type"])+ }+ // TrackElapsed bookkeeping rides along as plain {value, type} entries so+ // the front-end timeline renders per-node elapsed times.+ if et, _ := aOutputs["_elapsed_time"].(map[string]any); et["value"] != 0.35 {+ t.Errorf("components.a outputs._elapsed_time=%#v want {value:0.35}", aOutputs["_elapsed_time"])+ }+ if ct, _ := aOutputs["_created_time"].(map[string]any); ct["value"] != 100.0 {+ t.Errorf("components.a outputs._created_time=%#v want {value:100}", aOutputs["_created_time"])+ }+ if et, _ := aOutputs["_elapsed_time"].(map[string]any); et["type"] != "<class 'float'>" {+ t.Errorf("components.a outputs._elapsed_time.type=%#v want <class 'float'>", aOutputs["_elapsed_time"])+ }chunksOut, ok := aOutputs["chunks"].(map[string]any)if !ok {t.Fatalf("components.a outputs.chunks wrong type: %#v", aOutputs["chunks"])@@ -113,6 +153,9 @@ func TestBuildDebugResultDSL(t *testing.T) {if len(chunksVal) != 1 {t.Fatalf("components.a outputs.chunks.value len=%d want 1", len(chunksVal))}+ if chunksOut["type"] != "<class 'list'>" {+ t.Errorf("components.a outputs.chunks.type=%#v want <class 'list'>", chunksOut["type"])+ }chunk0, _ := chunksVal[0].(map[string]any)if chunk0["text"] != "hello" {t.Errorf("chunk text=%v want hello", chunk0["text"])@@ -134,17 +177,29 @@ func TestBuildDebugResultDSL(t *testing.T) {if bOutputs["output_format"].(map[string]any)["value"] != "text" {t.Errorf("components.b output_format=%#v want {value:\"text\"}", bOutputs["output_format"])}+ if tt := bOutputs["text"].(map[string]any)["type"]; tt != "<class 'str'>" {+ t.Errorf("components.b outputs.text.type=%#v want <class 'str'>", tt)+ }// static params.field_name carried (used by front-end chunk text key).if fn, _ := bParams["field_name"].(string); fn != "content" {t.Errorf("components.b params.field_name=%v want content", fn)}- // --- component "begin": no recognized output -> outputs empty, safe ---+ // --- component "begin": no recognized payload format, so no output_format+ // is invented — but the TrackElapsed bookkeeping keys must still surface+ // as outputs so the timeline shows its elapsed time. ---begin, _ := components["begin"].(map[string]any)beginObj, _ := begin["obj"].(map[string]any)beginParams, _ := beginObj["params"].(map[string]any)- if _, exists := beginParams["outputs"]; exists {- t.Errorf("begin has no run output, outputs must be absent: %#v", beginParams)+ beginOutputs, ok := beginParams["outputs"].(map[string]any)+ if !ok {+ t.Fatalf("begin (bookkeeping-only output) must still carry params.outputs: %#v", beginParams)+ }+ if _, exists := beginOutputs["output_format"]; exists {+ t.Errorf("begin has no payload format, output_format must be absent: %#v", beginOutputs)+ }+ if et, _ := beginOutputs["_elapsed_time"].(map[string]any); et["value"] != 0.01 {+ t.Errorf("begin outputs._elapsed_time=%#v want {value:0.01}", beginOutputs["_elapsed_time"])}// --- graph.nodes copied through ---@@ -204,7 +259,7 @@ func TestBuildDebugResultDSL_NestedState(t *testing.T) {map[string]any{"text": "hello", "vector": []float64{0.1, 0.2}},},},- "b": {"text": "plain"},+ "b": {"text": "plain", "_elapsed_time": 0.02},},}@@ -251,6 +306,10 @@ func TestBuildDebugResultDSL_NestedState(t *testing.T) {if of, _ := bOutputs["output_format"].(map[string]any); of["value"] != "text" {t.Errorf("components.b output_format=%#v want {value:\"text\"}", bOutputs["output_format"])}+ // Bookkeeping keys must resolve through the SAME nested-state lookup.+ if et, _ := bOutputs["_elapsed_time"].(map[string]any); et["value"] != 0.02 {+ t.Errorf("components.b outputs._elapsed_time=%#v want {value:0.02}", bOutputs["_elapsed_time"])+ }}// TestLookupComponentOutput locks the resolution rules of@@ -428,3 +487,35 @@ func TestDetectFormat_Priority(t *testing.T) {})}}++// TestPythonTypeName locks the type-string mapping: scalar kinds map to their+// Python scalar classes, and every sequence/mapping reports list/dict+// regardless of the Go element type — typed containers like []int must not+// leak Go type syntax into the persisted log.+func TestPythonTypeName(t *testing.T) {+ cases := []struct {+ name string+ in any+ want string+ }{+ {"nil", nil, "<class 'NoneType'>"},+ {"bool", true, "<class 'bool'>"},+ {"string", "s", "<class 'str'>"},+ {"int", 3, "<class 'int'>"},+ {"int64", int64(3), "<class 'int'>"},+ {"float64", 0.5, "<class 'float'>"},+ {"[]any", []any{1, "a"}, "<class 'list'>"},+ {"[]map[string]any", []map[string]any{{"k": 1}}, "<class 'list'>"},+ {"typed slice []int", []int{1, 2}, "<class 'list'>"},+ {"array", [2]int{1, 2}, "<class 'list'>"},+ {"map[string]any", map[string]any{"k": 1}, "<class 'dict'>"},+ {"typed map", map[string]string{"k": "v"}, "<class 'dict'>"},+ }+ for _, c := range cases {+ t.Run(c.name, func(t *testing.T) {+ if got := pythonTypeName(c.in); got != c.want {+ t.Errorf("pythonTypeName(%#v) = %q, want %q", c.in, got, c.want)+ }+ })+ }+}diff --git a/internal/ingestion/task/pipeline_executor.go b/internal/ingestion/task/pipeline_executor.goindex 46b497d400..3b5404d48e 100644--- a/internal/ingestion/task/pipeline_executor.go+++ b/internal/ingestion/task/pipeline_executor.go@@ -989,23 +989,48 @@ func (s *PipelineExecutor) runPipelineWithDSL(ctx context.Context, dsl string) (return nil, dsl, err}- // Surface the debug-run result DSL to any sink that implements ResultSink- // (the DebugLogSink used by canvas-debug runs). This mirrors Python's- // END-marker `dsl` attachment (rag/flow/pipeline.py:98) so the front-end- // "View result" page can render parsed chunks. The probe is an optional- // capability: non-debug (DB-backed) sinks ignore it and the ProgressSink- // contract is unchanged, keeping the coupling one-directional.- if rs, ok := s.progressSink.(ResultSink); ok {- if resultDSL, e := BuildDebugResultDSL(dsl, output); e == nil {- rs.SetResult(resultDSL, output)- }- }+ logDSL := s.buildLogDSL(dsl, output)payload, err := pipelinepkg.ExtractPayload(dsl, output)if err != nil {return nil, dsl, err}- return payload, dsl, nil+ return payload, logDSL, nil+}++// buildLogDSL returns the DSL string recorded for a pipeline run: the+// run-result DSL (static canvas structure + each component's runtime outputs+// merged into obj.params.outputs) when it can be built and marshaled,+// otherwise the static dsl unchanged — log recording must never fail a run.+//+// BuildDebugResultDSL needs the full run output, which is in scope only inside+// runPipelineWithDSL: the extracted payload returned there no longer carries+// output["state"]. Two consumers:+// - canvas-debug runs hand the map to the DebugLogSink END marker via the+// ResultSink capability (END-marker `dsl` attachment,+// rag/flow/pipeline.py:98);+// - persist (dataset parse) runs return its JSON as the log DSL so the+// pipeline operation log carries every component's output+// (dsl=str(pipeline), rag/svr/task_executor_refactor/dataflow_service.py)+// — without it the dataset log "View result" page renders blank panels.+//+// The sink probe stays an optional capability: non-debug (DB-backed) sinks+// ignore it and the ProgressSink contract is unchanged.+func (s *PipelineExecutor) buildLogDSL(dsl string, output map[string]any) string {+ logDSL := dsl+ if resultDSL, e := BuildDebugResultDSL(dsl, output); e == nil {+ if rs, ok := s.progressSink.(ResultSink); ok {+ rs.SetResult(resultDSL, output)+ }+ if raw, e := json.Marshal(resultDSL); e == nil {+ logDSL = string(raw)+ } else {+ common.Warn(fmt.Sprintf("marshal run-result dsl for pipeline log: %v", e))+ }+ } else {+ common.Warn(fmt.Sprintf("build run-result dsl for pipeline log: %v", e))+ }+ return logDSL}// debugPageCapPages is the number of leading pages a canvas-debugdiff --git a/internal/ingestion/task/pipeline_executor_test.go b/internal/ingestion/task/pipeline_executor_test.goindex ecae6a6c08..c052d56901 100644--- a/internal/ingestion/task/pipeline_executor_test.go+++ b/internal/ingestion/task/pipeline_executor_test.go@@ -2,7 +2,9 @@ package taskimport ("context"+ "encoding/json""errors"+ "math""reflect""sync""testing"@@ -888,3 +890,128 @@ func TestMergeCompiledVariants(t *testing.T) {t.Fatalf("merged variants = %v, want %v", got, want)}}++// TestRunPipelineWithDSL_LogDSLCarriesOutputs locks the dataset-parse+// "View result" contract: the DSL runPipelineWithDSL returns for the pipeline+// operation log (Execute passes it straight to recordPipelineLog) must carry+// each component's runtime outputs under obj.params.outputs, mirroring+// Python's dsl=str(pipeline)+// (rag/svr/task_executor_refactor/dataflow_service.py). Before this, the log+// stored the raw static DSL, so the dataset log "View result" page rendered+// blank panels and "0s" elapsed times even though the chunks were indexed —+// the front-end renders those panels exclusively from+// dsl.components[<id>].obj.params.outputs+// (web/src/pages/dataflow-result/parser.tsx, hooks.ts).+//+// It drives the REAL runPipelineWithDSL with stub ingestion components, so+// the log DSL is built from an actual run output (nested under+// output["state"][<id>] by finalizeResult), not a hand-built one, and the+// enveloped {"dsl": {...}} input is unwrapped to the front-end shape+// (top-level components).+func TestRunPipelineWithDSL_LogDSLCarriesOutputs(t *testing.T) {+ const (+ compC = "logdsl.RealStubChunks"+ compD = "logdsl.RealStubD"+ )+ runtime.MustRegister(compC, runtime.CategoryIngestion,+ func(_ string, _ map[string]any) (runtime.Component, error) { return traceChunkComponent{}, nil },+ runtime.Metadata{Version: "1.0.0"})+ runtime.MustRegister(compD, runtime.CategoryIngestion,+ func(_ string, _ map[string]any) (runtime.Component, error) { return traceStubComponent{}, nil },+ runtime.Metadata{Version: "1.0.0"})++ dsl := `{"dsl":{"components":{+ "begin":{"obj":{"component_name":"Begin","params":{}},"downstream":["c"]},+ "c":{"obj":{"component_name":"` + compC + `","params":{"setups":{"pdf":{"parse_method":"general"}}}},"upstream":["begin"],"downstream":["d"]},+ "d":{"obj":{"component_name":"` + compD + `","params":{}},"upstream":["c"]}+ },"path":["begin","c","d"],"graph":{"nodes":[{"id":"begin","data":{"name":"开始"}},{"id":"c","data":{"name":"解析"}},{"id":"d","data":{"name":"分词"}}]}}}`++ svc := mustNewPipelineExecutor(t, makeTaskCtx(), "flow-logdsl", 0)+ _, logDSL, err := svc.runPipelineWithDSL(t.Context(), dsl)+ if err != nil {+ t.Fatalf("runPipelineWithDSL: %v", err)+ }++ var doc map[string]any+ if err := json.Unmarshal([]byte(logDSL), &doc); err != nil {+ t.Fatalf("log DSL is not valid JSON: %v body=%s", err, logDSL)+ }+ // The enveloped canvas DSL must come back unwrapped: the front-end reads+ // dsl.components at the top level.+ components, ok := doc["components"].(map[string]any)+ if !ok {+ t.Fatalf("log DSL must carry top-level components (unwrapped canvas envelope): %s", logDSL)+ }++ // Chunk-emitting component: params.outputs.chunks + output_format.+ cParams, ok := components["c"].(map[string]any)["obj"].(map[string]any)["params"].(map[string]any)+ if !ok {+ t.Fatalf("log DSL components.c.obj.params missing: %s", logDSL)+ }+ cOutputs, ok := cParams["outputs"].(map[string]any)+ if !ok {+ t.Fatalf("REGRESSION: log DSL has no params.outputs for chunk component c; "++ "the dataset log 'View result' page would render a blank panel. params=%#v", cParams)+ }+ if of, _ := cOutputs["output_format"].(map[string]any); of["value"] != "chunks" {+ t.Errorf("c output_format=%#v want {value:\"chunks\"}", cOutputs["output_format"])+ }+ chunksVal, _ := cOutputs["chunks"].(map[string]any)["value"].([]any)+ if len(chunksVal) != 1 {+ t.Fatalf("c chunks.value len=%d want 1", len(chunksVal))+ }+ // TrackElapsed bookkeeping must ride along so the timeline shows real+ // per-node elapsed times (hooks.ts reads outputs._elapsed_time.value).+ et, ok := cOutputs["_elapsed_time"].(map[string]any)+ if !ok {+ t.Fatalf("c outputs._elapsed_time missing: %#v", cOutputs)+ }+ if _, ok := et["value"].(float64); !ok {+ t.Errorf("c outputs._elapsed_time.value=%#v want float64", et["value"])+ }+ // TrackElapsed stamps _created_time as an RFC3339Nano wall-clock string;+ // the outputs wrapper carries it verbatim with its type string.+ if cct, ok := cOutputs["_created_time"].(map[string]any); ok {+ cs, ok := cct["value"].(string)+ if !ok || cs == "" {+ t.Errorf("c outputs._created_time.value=%#v want non-empty string", cct["value"])+ } else if _, err := time.Parse(time.RFC3339Nano, cs); err != nil {+ t.Errorf("c outputs._created_time.value %q is not RFC3339Nano: %v", cs, err)+ }+ if cct["type"] != "<class 'str'>" {+ t.Errorf("c outputs._created_time.type=%#v want <class 'str'>", cct["type"])+ }+ } else {+ t.Errorf("c outputs._created_time missing: %#v", cOutputs)+ }+ // Non-components top-level keys are carried verbatim; this fixture's DSL+ // declares "path" — the round-tripped log must keep it for rerun-flow+ // consumers.+ if p, _ := doc["path"].([]any); len(p) != 3 || p[0] != "begin" || p[2] != "d" {+ t.Errorf("log DSL path=%#v want [begin c d]", doc["path"])+ }+}++// TestBuildLogDSL_FallbackToStaticDSL pins the guarantee that log recording+// never fails a run: when the run-result DSL cannot be built or cannot be+// marshaled, buildLogDSL must return the static dsl unchanged rather than a+// half-written payload.+func TestBuildLogDSL_FallbackToStaticDSL(t *testing.T) {+ svc := mustNewPipelineExecutor(t, makeTaskCtx(), "flow-logdsl-fallback", 0)++ // Marshal failure: NaN is a valid float64 payload, so the run-result DSL+ // builds fine but json.Marshal rejects it.+ dsl := `{"dsl":{"components":{"a":{"obj":{"component_name":"X","params":{}}}}}}`+ if got := svc.buildLogDSL(dsl, map[string]any{+ "a": map[string]any{"text": math.NaN()},+ }); got != dsl {+ t.Errorf("marshal failure: log DSL must fall back to the static dsl\n got: %s\nwant: %s", got, dsl)+ }++ // Build failure: a DSL without a components map cannot produce a+ // run-result DSL at all.+ badDSL := `{"dsl":{"path":["a"]}}`+ if got := svc.buildLogDSL(badDSL, nil); got != badDSL {+ t.Errorf("build failure: log DSL must fall back to the static dsl\n got: %s\nwant: %s", got, badDSL)+ }+}