/**
 * Cross-process admission gate (daemon-side).
 *
 * The daemon's /v1/messages proxy is the single chokepoint every client process
 * routes through. Bounding the number of concurrent in-flight requests per
 * upstream key here prevents multiple client processes (REPLs / windows /
 * parallel `owlcoda run`) from collectively bursting a shared upstream — the
 * cross-process gap the single-process adaptive controller can't close.
 *
 * v1 enforces a STATIC per-key bound (= OWLCODA_AGENT_MAX_CONCURRENCY). Making
 * the daemon bound adaptive (AIMD from first-hand rate-limit signal) is a
 * documented follow-up; client-side AIMD continues to run unchanged, so the
 * daemon adds a hard cross-process ceiling on top of per-client adaptation.
 *
 * Default-off contract: when OWLCODA_AGENT_ADAPTIVE_CONCURRENCY is unset,
 * admitRequest() is a zero-overhead no-op and the proxy path is unchanged.
 *
 * See docs/superpowers/specs/2026-05-29-cross-process-concurrency-coordinator-design.md
 */
import { IncomingMessage, ServerResponse } from 'node:http';
/** Thrown when a request can't be admitted (queue full or wait exceeded). */
export declare class AdmissionBackpressureError extends Error {
    readonly retryAfterMs: number;
    constructor(retryAfterMs: number, message: string);
}
export interface AdmissionGateOptions {
    /** Concurrency limit for a key (default: the static cap). */
    limitFor?: (key: string, cap: number) => number;
    queueMax?: () => number;
    waitMs?: () => number;
    backpressureRetryMs?: () => number;
}
export declare class AdmissionGate {
    private readonly states;
    private readonly limitFor;
    private readonly queueMax;
    private readonly waitMs;
    private readonly backpressureRetryMs;
    constructor(opts?: AdmissionGateOptions);
    /**
     * Acquire a slot for `key`. Resolves with a release() callback when admitted;
     * rejects with AdmissionBackpressureError (queue full / wait exceeded) or an
     * AbortError (signal aborted, e.g. client disconnect).
     */
    admit(key: string, cap: number, signal?: AbortSignal): Promise<() => void>;
    private makeRelease;
    private pump;
    private removeWaiter;
    private stateFor;
    /** Per-key observability snapshot (current state + lifetime counters). */
    snapshot(): Array<{
        key: string;
        inFlight: number;
        queued: number;
        limit: number;
        admitted: number;
        rejected: number;
    }>;
    /** Re-run admission for a key after its limit may have increased. */
    notifyLimitChanged(key: string): void;
    reset(): void;
    inFlightForTesting(key: string): number;
    queueDepthForTesting(key: string): number;
}
/** Stable per-upstream key: the real backend endpoint + model, not the proxy base. */
export declare function admissionKeyFromUpstream(endpointUrl: string, backendModel: string): string;
/**
 * Acquire a cross-process admission slot. No-op (zero overhead) when the
 * adaptive-concurrency flag is off.
 */
export declare function admitRequest(key: string, signal?: AbortSignal): Promise<() => void>;
/** Record a successful upstream request: AIMD may raise the limit → admit waiters. */
export declare function recordAdmissionSuccess(key: string): void;
/** Record a rate-limit signal: AIMD halves the limit (no pump — fewer slots). */
export declare function recordAdmissionRateLimit(key: string): void;
/** Observability snapshot of the admission gate (config + per-key live state + counters). */
export declare function admissionStatus(): {
    enabled: boolean;
    cap: number;
    queueMax: number;
    waitMs: number;
    keys: Array<{
        key: string;
        limit: number;
        inFlight: number;
        queued: number;
        admitted: number;
        rejected: number;
        success: number;
        rateLimit: number;
    }>;
};
/** GET /v1/admission — cross-process admission gate observability. */
export declare function handleAdmissionStatus(_req: IncomingMessage, res: ServerResponse): void;
export declare function __resetAdmissionForTesting(): void;
export declare function __admissionLimitForTesting(key: string, cap?: number): number;
export declare function __admissionGateForTesting(): AdmissionGate;
