@@ -101,55 +101,65 @@ Status MediapipeGraphDefinition::validateForConfigFileExistence() {
101101 config << ifs.rdbuf ();
102102 this ->mgconfig .setCurrentGraphPbTxtMD5 (ovms::FileSystem::getStringMD5 (config.str ()));
103103 this ->chosenConfig .assign (config.str ());
104- return parseGraphQueueSizeDirective () ;
104+ return StatusCode::OK ;
105105}
106106
107- Status MediapipeGraphDefinition::parseGraphQueueSizeDirective () {
108- // Scan pbtxt content for: # OVMS_GRAPH_QUEUE_SIZE: <value>
107+ Status MediapipeGraphDefinition::resolveGraphQueueSize () {
108+ // 1. Explicit pbtxt directive: # OVMS_GRAPH_QUEUE_SIZE: <value>
109+ // Always honored regardless of env var or calculator checks.
110+ // Value 0 or -1 disables the queue, AUTO or positive integer enables it.
109111 static const std::regex directiveRegex (
110112 R"( (?:^|\n)\s*#\s*OVMS_GRAPH_QUEUE_SIZE\s*:\s*(\S+)\s*(?:\r?\n|$))" );
111113 std::smatch match;
112- if (!std::regex_search (this ->chosenConfig , match, directiveRegex)) {
113- SPDLOG_TRACE (" OVMS_GRAPH_QUEUE_SIZE directive not found in pbtxt for mediapipe: {}" , getName ());
114- // FIXME (@atobisze): Temporarily, unit tests set OVMS_TEST_GRAPH_QUEUE_OFF=1 to keep
115- // the old behavior (queue disabled). Once all tests are validated with graph queue,
116- // remove this env-var check and always default to AUTO.
117- const char * testGuard = std::getenv (" OVMS_TEST_GRAPH_QUEUE_OFF" );
118- if (testGuard != nullptr && std::string (testGuard) == " 1" ) {
119- SPDLOG_DEBUG (" OVMS_TEST_GRAPH_QUEUE_OFF=1 set, graph queue disabled by default for mediapipe: {}" , getName ());
114+ if (std::regex_search (this ->chosenConfig , match, directiveRegex)) {
115+ std::string value = match[1 ].str ();
116+ if (value == " AUTO" ) {
117+ this ->mgconfig .setGraphQueueSizeAuto ();
118+ return StatusCode::OK;
119+ }
120+ auto parsed = stoi32 (value);
121+ if (!parsed.has_value ()) {
122+ SPDLOG_ERROR (" Invalid OVMS_GRAPH_QUEUE_SIZE value: '{}'. Expected integer or 'AUTO'." , value);
123+ return StatusCode::MEDIAPIPE_GRAPH_CONFIG_FILE_INVALID;
124+ }
125+ int queueSize = parsed.value ();
126+ if (queueSize < -1 ) {
127+ SPDLOG_ERROR (" Invalid OVMS_GRAPH_QUEUE_SIZE value: {}. Must be -1 or 0 (disabled), or a positive integer." , queueSize);
128+ return StatusCode::MEDIAPIPE_GRAPH_CONFIG_FILE_INVALID;
129+ }
130+ if (queueSize == 0 || queueSize == -1 ) {
131+ SPDLOG_DEBUG (" Graph queue explicitly disabled (OVMS_GRAPH_QUEUE_SIZE={}) for mediapipe: {}" , queueSize, getName ());
120132 return StatusCode::OK;
121133 }
122- // Production default: enable graph queue with AUTO sizing
123- this ->mgconfig .setGraphQueueSizeAuto ();
124- SPDLOG_DEBUG (" No OVMS_GRAPH_QUEUE_SIZE directive, defaulting to AUTO for mediapipe: {}" , getName ());
134+ unsigned int maxThreads = std::thread::hardware_concurrency ();
135+ if (maxThreads > 0 && queueSize > static_cast <int >(maxThreads)) {
136+ SPDLOG_ERROR (" Invalid OVMS_GRAPH_QUEUE_SIZE value: {}. Exceeds available hardware threads: {}." , queueSize, maxThreads);
137+ return StatusCode::MEDIAPIPE_GRAPH_CONFIG_FILE_INVALID;
138+ }
139+ this ->mgconfig .setGraphQueueSize (queueSize);
125140 return StatusCode::OK;
126141 }
127- std::string value = match[1 ].str ();
128- if (value == " AUTO" ) {
129- this ->mgconfig .setGraphQueueSizeAuto ();
142+
143+ // 2. Env var kill switch — suppresses the auto-enable default.
144+ // Used by unit tests (OVMS_TEST_GRAPH_QUEUE_OFF=1) to keep the old no-queue behavior
145+ // unless a graph explicitly opts in via OVMS_GRAPH_QUEUE_SIZE directive above.
146+ const char * testGuard = std::getenv (" OVMS_TEST_GRAPH_QUEUE_OFF" );
147+ if (testGuard != nullptr && std::string (testGuard) == " 1" ) {
148+ SPDLOG_DEBUG (" OVMS_TEST_GRAPH_QUEUE_OFF=1 set, graph queue disabled by default for mediapipe: {}" , getName ());
130149 return StatusCode::OK;
131150 }
132- // Try to parse as integer
133- auto parsed = stoi32 (value);
134- if (!parsed.has_value ()) {
135- SPDLOG_ERROR (" Invalid OVMS_GRAPH_QUEUE_SIZE value: '{}'. Expected integer or 'AUTO'." , value);
136- return StatusCode::MEDIAPIPE_GRAPH_CONFIG_FILE_INVALID;
137- }
138- int queueSize = parsed.value ();
139- if (queueSize < -1 ) {
140- SPDLOG_ERROR (" Invalid OVMS_GRAPH_QUEUE_SIZE value: {}. Must be -1 (disabled), or a positive integer." , queueSize);
141- return StatusCode::MEDIAPIPE_GRAPH_CONFIG_FILE_INVALID;
142- }
143- if (queueSize == 0 ) {
144- SPDLOG_ERROR (" Invalid OVMS_GRAPH_QUEUE_SIZE value: 0. Must be -1 (disabled), or a positive integer." );
145- return StatusCode::MEDIAPIPE_GRAPH_CONFIG_FILE_INVALID;
146- }
147- unsigned int maxThreads = std::thread::hardware_concurrency ();
148- if (maxThreads > 0 && queueSize > static_cast <int >(maxThreads)) {
149- SPDLOG_ERROR (" Invalid OVMS_GRAPH_QUEUE_SIZE value: {}. Exceeds available hardware threads: {}." , queueSize, maxThreads);
150- return StatusCode::MEDIAPIPE_GRAPH_CONFIG_FILE_INVALID;
151+
152+ // 3. Python calculator is not yet safe for graph pool reuse
153+ for (int i = 0 ; i < config.node ().size (); i++) {
154+ if (config.node (i).calculator () == PYTHON_NODE_CALCULATOR_NAME) {
155+ SPDLOG_DEBUG (" Graph contains Python calculator, graph queue disabled for mediapipe: {}" , getName ());
156+ return StatusCode::OK;
157+ }
151158 }
152- this ->mgconfig .setGraphQueueSize (queueSize);
159+
160+ // 4. Default: enable graph queue with AUTO sizing
161+ this ->mgconfig .setGraphQueueSizeAuto ();
162+ SPDLOG_DEBUG (" Graph queue set to AUTO for mediapipe: {}" , getName ());
153163 return StatusCode::OK;
154164}
155165
@@ -235,6 +245,10 @@ Status MediapipeGraphDefinition::validate(ModelManager& manager) {
235245 if (!status.ok ()) {
236246 return status;
237247 }
248+ status = this ->resolveGraphQueueSize ();
249+ if (!status.ok ()) {
250+ return status;
251+ }
238252 status = this ->initializeQueueIfRequired ();
239253 if (!status.ok ()) {
240254 return status;
0 commit comments