fix(mcp): применение не теряет одобренный план из-за опроса сборщиков

Операция с сервисным шагом брала глобальную блокировку конфигурации неблокирующим try-lock. Пока сборщик трафика или uptime держал её в разделяемом режиме, рантайм получал обычный Error и записывал rejected/DEVICE_UNAVAILABLE: одобренный человеком план терялся (стенд IPsec 2026-11-21: 2 из 24 применений). Теперь рантайм ждёт блокировку до 30 с; занятость отдаётся кодом CONFIGURATION_BUSY/409 с прежним текстом; неожиданные исключения рантайма пишутся в журнал с классом и замаскированным сообщением. SQL-тест: разделяемое удержание, отказ без ожидания, отказ по сроку, вход после освобождения.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
DenozordecandClaude Opus 5.5 committed 2026-11-21 16:05:24 +07:00
1 parent 2be3a207f6
commit a7d85fd0f1
3 files changed
+42 -5

No files matched your search

+7 -1
View File
@@ -63,6 +63,8 @@ import { lockRoutingReservationAdmissionSource, readScopedRoutingPathAdmissionDe
import { executeReservedRoutingStep, hasConfirmedReservedRoutingForward, type ReservedRoutingStepOutcome } from "./routing-reserved-step.js"
let activeRunners = 0
// Collectors hold the global configuration lock shared for a few seconds per router read.
export const MCP_APPLY_LOCK_WAIT_MS = 30_000
const runnerQueue: Array<() => void> = []
async function runBounded(work: () => Promise<void>) {
if (activeRunners >= 2) await new Promise<void>(resolve => runnerQueue.push(resolve))
@@ -751,7 +753,8 @@ async function executeOperationWithLease(operationId: string, principal: McpPrin
await authorizeCatalog()
}
})
await (evidence.steps.some(step => step.kind === "service") ? withApplicationMutationLock(applyWithLocks) : applyWithLocks())
// Collectors hold the global lock shared while they read routers; wait for them instead of losing the approved plan.
await (evidence.steps.some(step => step.kind === "service") ? withApplicationMutationLock(applyWithLocks, { waitMs: MCP_APPLY_LOCK_WAIT_MS }) : applyWithLocks())
assertOperationConfigurationLockCheckpoint()
const receiptId = plan.operation_id === SERVER_PROBE_OPERATION ? diagnosticReceipt?.receiptId : undefined
const finishedAt = await transaction(async client => {
@@ -779,6 +782,9 @@ async function executeOperationWithLease(operationId: string, principal: McpPrin
if (routingReservationId && hasConfirmedReservedRoutingForward(error)) confirmed = Math.max(confirmed, 1)
if (error instanceof VrfProductionAcknowledgedFailure) confirmed = Math.max(confirmed, error.acknowledgedWrites)
const code = error instanceof VrfProductionClaimOutcomeUnknown ? "VRF_CLAIM_OUTCOME_UNKNOWN" : error instanceof McpError ? error.code : "DEVICE_UNAVAILABLE"
// The generic fallback hid the cause of every unexpected failure; keep the class and a redacted message in the log.
if (code === "DEVICE_UNAVAILABLE" && !(error instanceof McpError)) console.error(JSON.stringify({ event: "mcp.operation.unexpected-error", operationId, operation: plan.operation_id,
errorClass: error instanceof Error ? error.constructor.name : typeof error, message: String(redact(error instanceof Error ? error.message : String(error))).slice(0, 300) }))
const nativeProgress = serviceNativeProgress(error, activeServiceStep, evidence.mutationCost)
const diagnosticProgress = serviceDiagnosticProgress(error, diagnosticOnly && activeServiceStep, operationId, evidence.mutationCost)
const diagnosticNotStarted = diagnosticOnly && confirmed === 0 && code === "READ_CANCELLED" &&