mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-14 02:42:24 +03:00
fix(core): resolve DB init race condition and reasoning translation (#12003)
Boarded with #11841/#11840/#11839 in one combined worktree: typecheck:core, check:file-size, check:changelog-integrity, check:complexity, check:cognitive-complexity, check:cycles all green; 24/24 focused tests pass. Both fixes are surgical and well-reasoned: explicit ensureDbInitialized() call for MCP stdio (verified the function exists at src/lib/db/core.ts:1496) avoids a startup race, and the reasoningContent fallback prevents empty message.content when only reasoning was returned. Thanks for tracking down both root causes.
This commit is contained in:
@@ -265,7 +265,15 @@ export function translateNonStreamingResponse(
|
||||
if (toolCalls.length > 0) {
|
||||
message.tool_calls = toolCalls;
|
||||
}
|
||||
if (message.content === undefined) {
|
||||
if (
|
||||
(!message.content ||
|
||||
(typeof message.content === "string" && message.content.trim().length === 0)) &&
|
||||
toolCalls.length === 0 &&
|
||||
replayableReasoningContent &&
|
||||
replayableReasoningContent.trim().length > 0
|
||||
) {
|
||||
message.content = replayableReasoningContent;
|
||||
} else if (message.content === undefined) {
|
||||
message.content = "";
|
||||
}
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ import {
|
||||
clampMcpAccessibilityConfig,
|
||||
type McpAccessibilityConfig,
|
||||
} from "../services/compression/engines/mcpAccessibility/constants.ts";
|
||||
import { getDbInstance } from "../../src/lib/db/core.ts";
|
||||
import { getDbInstance, ensureDbInitialized } from "../../src/lib/db/core.ts";
|
||||
import { normalizeQuotaResponse } from "../../src/shared/contracts/quota.ts";
|
||||
import { resolveOmniRouteBaseUrl } from "../../src/shared/utils/resolveOmniRouteBaseUrl.ts";
|
||||
import { sanitizeErrorMessage } from "../utils/error.ts";
|
||||
@@ -1527,10 +1527,10 @@ export function createMcpServer(options?: CreateMcpServerOptions): McpServer {
|
||||
* Called when `omniroute --mcp` is used.
|
||||
*/
|
||||
export async function startMcpStdio(): Promise<void> {
|
||||
await ensureDbInitialized();
|
||||
// Stdout is reserved for JSON-RPC — bin/mcpStdioConsoleGuard.mjs is preloaded via
|
||||
// `node --import` (see bin/mcp-server.mjs) so console.log/warn already redirect to
|
||||
// stderr before this module's own imports evaluate (DB init happens as a side effect of
|
||||
// createMcpServer()'s tool registration, earlier than any code placed here could catch).
|
||||
// stderr before this module's own imports evaluate.
|
||||
const server = createMcpServer();
|
||||
const transport = new StdioServerTransport();
|
||||
const version = process.env.npm_package_version || "1.8.1";
|
||||
|
||||
Reference in New Issue
Block a user