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(agentic_rag): make the decisionhead package compile without cgo (#21932)
CCLUCKYb494fec2322c
diff --git a/internal/agentic_rag/decisionhead/decisionhead.go b/internal/agentic_rag/decisionhead/decisionhead.goindex 59f5ada94e..73e409e79c 100644--- a/internal/agentic_rag/decisionhead/decisionhead.go+++ b/internal/agentic_rag/decisionhead/decisionhead.go@@ -115,7 +115,7 @@ func open(cfg Config) (*judge, error) {// degradation on every chunk.func openScorer(cfg Config, modelPath string) (scorer, error) {if cfg.URL == "" {- return OpenSession(modelPath)+ return openInProcess(modelPath)}remote := newRemoteScorer(cfg.URL)ctx, cancel := context.WithTimeout(context.Background(), probeTimeout)@@ -129,9 +129,7 @@ func openScorer(cfg Config, modelPath string) (scorer, error) {// Close releases the checkpoint's ONNX session. It is what tests and a// deliberate teardown use; a server holds the shared judge for its lifetime.func (j *judge) Close() {- if session, ok := j.model.(*Session); ok {- session.Close()- }+ closeInProcess(j.model)}var (diff --git a/internal/agentic_rag/decisionhead/session.go b/internal/agentic_rag/decisionhead/session.goindex 82cb668822..609ddc0146 100644--- a/internal/agentic_rag/decisionhead/session.go+++ b/internal/agentic_rag/decisionhead/session.go@@ -112,6 +112,21 @@ func OpenSession(modelPath string) (*Session, error) {return &Session{sess: sess}, nil}+// openInProcess is the cgo branch of openScorer's URL-less path. It is the+// only place outside session.go that names Session, so the !cgo fallback in+// session_nocgo.go can replace it without the rest of the package caring.+func openInProcess(modelPath string) (scorer, error) {+ return OpenSession(modelPath)+}++// closeInProcess releases the underlying session when the scorer is the+// in-process one; remote scorers hold nothing to free.+func closeInProcess(m scorer) {+ if s, ok := m.(*Session); ok {+ s.Close()+ }+}+// Poisoned reports whether a cancelled Run left the session unusable.func (s *Session) Poisoned() bool { return s.poisoned }diff --git a/internal/agentic_rag/decisionhead/session_nocgo.go b/internal/agentic_rag/decisionhead/session_nocgo.gonew file mode 100644index 0000000000..e096b95b82--- /dev/null+++ b/internal/agentic_rag/decisionhead/session_nocgo.go@@ -0,0 +1,30 @@+//go:build !cgo++// 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 decisionhead++import "errors"++// Without cgo the ONNX Runtime cannot be linked, so the package has no+// in-process scorer and only a configured sidecar URL can serve decisions.+// This mirrors the *_nocgo fallbacks of the DeepDoc native backend and keeps+// the package compilable under CGO_ENABLED=0; the failure lands in open()'s+// degraded path, where sharedJudge logs once and Split/Judge keep everything.+func openInProcess(_ string) (scorer, error) {+ return nil, errors.New("decisionhead: the in-process scorer requires a cgo build; configure the sidecar URL instead")+}++func closeInProcess(_ scorer) {}diff --git a/internal/agentic_rag/decisionhead/session_nocgo_test.go b/internal/agentic_rag/decisionhead/session_nocgo_test.gonew file mode 100644index 0000000000..19819e444c--- /dev/null+++ b/internal/agentic_rag/decisionhead/session_nocgo_test.go@@ -0,0 +1,32 @@+//go:build !cgo++// 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 decisionhead++import "testing"++// sharedJudge turns a failed open() into a one-line log and a disabled judge,+// so the !cgo fallback must fail CLOSED: a (nil, nil) return would install a+// scorer-less judge and the first forward pass would nil-deref.+func TestOpenInProcessFailsClosedWithoutCgo(t *testing.T) {+ scorer, err := openInProcess("unused-model-path")+ if err == nil {+ t.Fatal("openInProcess must return an error without cgo, got nil")+ }+ if scorer != nil {+ t.Fatal("openInProcess must not return a scorer without cgo")+ }+}