import { TurnPendingServingPolicyV1, TurnServingPolicyV1, type TurnServingPolicyReadV1 } from "@opengeni/contracts"; import { type Database } from "../database.js"; import { lockTurnAttemptWriteFenceTx, type TurnAttemptFenceRejectReason } from "../session-attempt-fence.js"; type TurnScope = { accountId: string; workspaceId: string; sessionId: string; turnId: string; }; export declare const SUBSCRIPTION_CORE_SERVING_FAILOVER_LIMIT = 4; export declare class SubscriptionCoreServingFailoverLimitError extends Error { readonly steps: number; constructor(steps: number); } type ServingWriteFence = Extract>, { allowed: true; }>; type ServingInput = TurnScope & { /** D-43. An omitted gate is OFF; C2 supplies the deployment setting. */ crossProviderFailoverEnabled?: boolean | undefined; attemptId: string; executionGeneration: number; policy: TurnServingPolicyV1["policy"]; connectionId: string; reason: TurnServingPolicyV1["reason"]; }; type ServingWriteResult = { accepted: true; installed: boolean; revision: TurnServingPolicyV1; modelChangeCount: number; } | { accepted: false; reason: TurnAttemptFenceRejectReason | "disabled" | "accepted_policy_absent" | "credential_restricted" | "failover_bound_exceeded"; }; /** Owns its transaction: call only AFTER placement commits, using a pool handle. * The fence takes the turn FOR UPDATE. Request reservation takes it FOR SHARE * then the binding FOR UPDATE. Writing here while placement holds a binding * would invert that order and deadlock. Any future switched event must be in * THIS fenced transaction, never in placement; C1 emits no event. * * The turn lock serializes append and dedupe. Exactly one receipt is allowed per * (turn, execution generation), including claim-time recording and retries. * Conflicting retries fail closed; neither the accepted policy nor old receipts * can be replaced. This is persistence, not placement or renewed authority. */ export declare function recordSubscriptionCoreServingPolicyForTurnAttempt(db: Database, input: ServingInput): Promise; /** C2 recovery seam: the caller MUST already hold this exact allowed fence in * this same transaction, acquired before any binding locks. No transaction or * fence is opened here. C2 will call it inside recovery's atomic transition, * after placement commits. A plain placement transaction is not a write fence. */ export declare function stageSubscriptionCorePendingServingPolicyTx(tx: Database, input: ServingInput, fence: ServingWriteFence): Promise; /** null means not visible, not "no revisions". Retains caller session RLS. */ export declare function readSubscriptionCoreServingPolicyForTurn(db: Database, input: TurnScope): Promise; /** D-39 counting read; a hidden turn must never manufacture a zero count. */ export declare function countSubscriptionCoreTurnServingPolicyChanges(db: Database, input: TurnScope): Promise; /** One scoped read counts every provider, including held providers, plus * committed model/provider changes. Hidden turns cannot invent a zero budget. */ export declare function readSubscriptionCoreTurnFailoverBudget(db: Database, input: TurnScope): Promise<{ changes: number; refusals: number; steps: number; } | null>; export {};