Files
OmniRoute/src/lib/initCloudSync.ts
Markus Hartung 04dba0460e fix(responses-continuation): recover a real id/output for passthrough and translate-mode replies (#11434)
Retargetado para release/v3.8.51 (release/v3.8.50 está congelada — freeze issue #11439). Validado em lote combinado (batch-0824h2, junto de #11435/#11436/#11437) contra o tip de release/v3.8.51: typecheck:core limpo, gates estáticos OK, 127/127 testes focados passando.

Investigação sólida com repro real via container isolado, três causas independentes identificadas e corrigidas com testes de regressão dedicados para cada uma. Obrigado pela contribuição!
2026-08-24 19:57:12 -03:00

57 lines
2.0 KiB
TypeScript

import initializeCloudSync from "@/shared/services/initializeCloudSync";
import { startModelSyncScheduler } from "@/shared/services/modelSyncScheduler";
import { isAutomatedTestProcess } from "@/shared/utils/testProcess";
import { getJobRegistry } from "@/lib/jobRegistry";
import { registerBudgetResetJob } from "@/lib/jobs/budgetResetJob";
import { registerTokenHealthCheck } from "@/lib/jobs/tokenHealthCheckJob";
import { backfillVolcPlanAutoSync } from "@/lib/providers/volcPlanAutoSyncBackfill";
// Initialize runtime background sync services once per server process.
let initialized = false;
export function shouldSkipCloudSyncInitialization(
env: NodeJS.ProcessEnv = process.env,
argv: string[] = process.argv
): boolean {
if (env.NEXT_PHASE === "phase-production-build") {
return true;
}
const raw = env.OMNIROUTE_DISABLE_BACKGROUND_SERVICES;
if (raw && new Set(["1", "true", "yes", "on"]).has(raw.trim().toLowerCase())) {
return true;
}
return isAutomatedTestProcess(argv, env) && env.OMNIROUTE_ENABLE_RUNTIME_BACKGROUND_TASKS !== "1";
}
export async function ensureCloudSyncInitialized() {
if (shouldSkipCloudSyncInitialization()) {
return false;
}
if (!initialized) {
try {
await initializeCloudSync();
await backfillVolcPlanAutoSync();
startModelSyncScheduler();
// startAll() runs each interval job's first tick synchronously, so it has to
// come after initializeCloudSync(). The old wiring got that ordering two
// different ways: the budget reset was started right here, and the health
// check's first sweep sat behind a 10s timer. Awaiting the init is a firmer
// guarantee than the timer was.
const registry = getJobRegistry();
registerBudgetResetJob(registry);
registerTokenHealthCheck(registry);
await registry.startAll();
initialized = true;
} catch (error) {
console.error("[ServerInit] Error initializing background sync services:", error);
}
}
return initialized;
}
export default ensureCloudSyncInitialized;