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(api): keep a parsing progress of 0.96 from being reported as 1.0 (#20414)
Sash87a4eab513ce
diff --git a/internal/utility/convert.go b/internal/utility/convert.goindex e15ab4edd6..552d014224 100644--- a/internal/utility/convert.go+++ b/internal/utility/convert.go@@ -25,12 +25,16 @@ import ("time")-// JSONFloat64 is a float64 that always marshals with decimal point+// JSONFloat64 is a float64 that always marshals with a decimal point.+// 0 encodes as 0.0. The value itself is kept, so a progress of 0.96 stays 0.96.type JSONFloat64 float64func (f JSONFloat64) MarshalJSON() ([]byte, error) {- // Always output with decimal point (e.g., 0.0 instead of 0)- return []byte(fmt.Sprintf("%.1f", float64(f))), nil+ s := strconv.FormatFloat(float64(f), 'f', -1, 64)+ if !strings.Contains(s, ".") {+ s += ".0"+ }+ return []byte(s), nil}// GetProjectBaseDirectory returns the current working directory.diff --git a/internal/utility/convert_json_float_test.go b/internal/utility/convert_json_float_test.gonew file mode 100644index 0000000000..870c300282--- /dev/null+++ b/internal/utility/convert_json_float_test.go@@ -0,0 +1,40 @@+//+// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+//+// http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.+//++package utility++import "testing"++func TestAProgressOf096IsNotReportedAsFinished(t *testing.T) {+ cases := []struct {+ in JSONFloat64+ want string+ }{+ {0.96, "0.96"},+ {0, "0.0"},+ {1, "1.0"},+ {-1, "-1.0"},+ }+ for _, c := range cases {+ got, err := c.in.MarshalJSON()+ if err != nil {+ t.Fatal(err)+ }+ if string(got) != c.want {+ t.Fatalf("MarshalJSON(%v) = %s, want %s", float64(c.in), got, c.want)+ }+ }+}