Skip to content

Commit fa06ec9

Browse files
author
Kevin Arthur
committed
fix(perf): disable incomplete native colorization path
1 parent 89ce870 commit fa06ec9

3 files changed

Lines changed: 39 additions & 96 deletions

File tree

‎apps/desktop/src-tauri/src/lib.rs‎

Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -558,15 +558,11 @@ fn native_ai_status(_app: tauri::AppHandle) -> bool {
558558
}
559559
}
560560

561-
/// Generic native ONNX inference for colorization workflows (SCUNet, SAM2,
562-
/// DDColor). Accepts a model type, model path, optional image data as
563-
/// base64, optional pre-computed tensors, and model-specific parameters.
564-
/// Returns inference outputs and timing information.
561+
/// Reserved native ONNX inference command for colorization workflows.
565562
///
566-
/// The frontend's provider abstraction calls this command when native AI
567-
/// is available (native_ai_status returns true). The command validates
568-
/// the model path, creates or reuses a session, and runs inference
569-
/// outside the UI thread.
563+
/// This route must report itself as unavailable until it performs verified
564+
/// inference. Returning an empty output map with a native execution-provider
565+
/// label would make capability diagnostics and provider routing misleading.
570566
#[allow(unused_variables)]
571567
#[tauri::command]
572568
async fn native_colorize_infer(
@@ -579,40 +575,17 @@ async fn native_colorize_infer(
579575
target_width: Option<u32>,
580576
target_height: Option<u32>,
581577
) -> Result<NativeInferResult, String> {
582-
#[cfg(feature = "ai")]
583-
{
584-
if !ensure_native_ai(&app) {
585-
return Err("Native ONNX Runtime not available".into());
586-
}
587-
588-
let start = std::time::Instant::now();
589-
590-
// Decode image data if provided
591-
let _image_bytes = if let Some(b64) = &image_data_base64 {
592-
use base64::Engine;
593-
base64::engine::general_purpose::STANDARD
594-
.decode(b64)
595-
.map_err(|e| format!("Failed to decode image data: {e}"))?
596-
} else {
597-
Vec::new()
598-
};
599-
600-
// For now, return a structured response indicating the command
601-
// is received and the model type. Full inference pipeline
602-
// implementation requires ort session management per model type.
603-
let elapsed_ms = start.elapsed().as_millis() as u64;
604-
605-
Ok(NativeInferResult {
606-
outputs: std::collections::HashMap::new(),
607-
execution_provider: "native-ort".to_string(),
608-
processing_time_ms: elapsed_ms,
609-
})
610-
}
611-
#[cfg(not(feature = "ai"))]
612-
{
613-
let _ = (app, model_type, model_path, image_data_base64, tensors, infer_params, target_width, target_height);
614-
Err("Native AI not compiled in (missing 'ai' feature)".into())
615-
}
578+
let _ = (
579+
app,
580+
model_type,
581+
model_path,
582+
image_data_base64,
583+
tensors,
584+
infer_params,
585+
target_width,
586+
target_height,
587+
);
588+
Err("Native colorization is unavailable: ONNX inference is not implemented".into())
616589
}
617590

618591
#[derive(Debug, Serialize, Deserialize)]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { describe, expect, it } from 'vitest';
2+
import { nativeScunetInfer, nativeTauriColorizationProvider } from './nativeTauriProvider';
3+
4+
describe('native Tauri colorization availability', () => {
5+
it('does not advertise an incomplete inference implementation', async () => {
6+
expect(await nativeTauriColorizationProvider.isAvailable()).toBe(false);
7+
});
8+
9+
it('rejects direct inference without transferring image data', async () => {
10+
const pixels = new Uint8ClampedArray(4);
11+
const imageData = { data: pixels, width: 1, height: 1 } as ImageData;
12+
13+
await expect(nativeScunetInfer(imageData, '/models/scunet.onnx', 0.5)).rejects.toThrow(
14+
/not implemented/i,
15+
);
16+
});
17+
});

‎packages/engine/src/colorization/providers/nativeTauriProvider.ts‎

Lines changed: 7 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,13 @@ import type { ColorizationProvider } from '../providerAbstraction';
3030

3131
const NATIVE_PROVIDER_ID = 'native-tauri';
3232

33-
/**
34-
* Check if we're running inside Tauri with native AI available.
35-
*/
36-
async function checkTauriNativeAi(): Promise<boolean> {
37-
try {
38-
if (
39-
typeof window === 'undefined' ||
40-
!(window as unknown as Record<string, unknown>).__TAURI_INTERNALS__
41-
) {
42-
return false;
43-
}
44-
const { invoke } = await import('@tauri-apps/api/core');
45-
const status = await invoke('native_ai_status');
46-
return status === true;
47-
} catch {
48-
return false;
49-
}
50-
}
33+
const NATIVE_COLORIZATION_UNAVAILABLE =
34+
'Native colorization is unavailable because its ONNX inference pipeline is not implemented';
5135

5236
/**
5337
* Invoke a native inference command through Tauri IPC.
5438
*/
55-
async function nativeInfer(params: {
39+
async function nativeInfer(_params: {
5640
modelType: string;
5741
modelPath: string;
5842
imageData?: ArrayBuffer;
@@ -65,40 +49,7 @@ async function nativeInfer(params: {
6549
executionProvider: string;
6650
processingTimeMs: number;
6751
}> {
68-
const { invoke } = await import('@tauri-apps/api/core');
69-
70-
// Convert ImageData ArrayBuffer to base64 for IPC transport
71-
const inputPayload: Record<string, unknown> = {
72-
modelType: params.modelType,
73-
modelPath: params.modelPath,
74-
targetWidth: params.targetWidth,
75-
targetHeight: params.targetHeight,
76-
};
77-
78-
if (params.imageData) {
79-
// Convert ArrayBuffer to Uint8Array for base64 encoding
80-
const bytes = new Uint8Array(params.imageData);
81-
let binary = '';
82-
for (let i = 0; i < bytes.length; i++) {
83-
binary += String.fromCharCode(bytes[i]!);
84-
}
85-
inputPayload.imageDataBase64 = btoa(binary);
86-
}
87-
88-
if (params.tensors) {
89-
inputPayload.tensors = params.tensors;
90-
}
91-
92-
if (params.params) {
93-
inputPayload.inferParams = params.params;
94-
}
95-
96-
const result = await invoke('native_colorize_infer', inputPayload);
97-
return result as {
98-
outputs: Record<string, unknown>;
99-
executionProvider: string;
100-
processingTimeMs: number;
101-
};
52+
throw new Error(NATIVE_COLORIZATION_UNAVAILABLE);
10253
}
10354

10455
/**
@@ -113,7 +64,9 @@ export const nativeTauriColorizationProvider: ColorizationProvider = {
11364
name: 'Native ONNX Runtime (Tauri)',
11465
estimatedPeakMemory: 2 * 1024 * 1024 * 1024, // ~2GB for SAM2 encoder
11566

116-
isAvailable: () => checkTauriNativeAi(),
67+
// The native AI runtime is used by other verified features, but this
68+
// provider must remain unavailable until colorization returns real output.
69+
isAvailable: () => false,
11770

11871
supportsModel: (modelId: string) => {
11972
const supported = new Set([

0 commit comments

Comments
 (0)