/** * Live heat affinity at pin-safe boundaries (SP-215, #115). * * Colibri REPIN analog: OPTIONAL live affinity updates that let the hot tier * track the live workload without thrashing. Updates are only evaluated at * pin-safe boundaries — moments where the session pin is already broken or * reopened, so affinity never smashes a warm pin: * * - FR-008 pin breaks (compaction, context overflow, cache economics, ...) * - SAAR idle reopen (`saar_idle_reopen`) * * Hysteresis (Colibri-style): a swap toward the heat-preferred tier requires * a success-rate advantage of at least `hysteresis_band` (~25%) over the * active tier, and at most `swap_cap` live swaps per session. Heat counts are * decayed at each swap so stale workload history cannot pin the affinity * forever. * * Default OFF (`live_update_enabled: false`) — the persisted histogram and * the first-turn soft bias (expected-cost.ts) work without live repinning. * This module never flips frugality defaults or absolute release gates. */ import type { Tier } from '../types/index.js'; import type { WorkloadHeatConfig } from '../types/schemas.js'; import type { WorkloadHeatKey, WorkloadHeatMap } from '../routing/workload-heat.js'; import type { PinLookupResult } from './session-pinner.js'; /** * True when a pin lookup result represents a pin-safe boundary: the pin is * already broken or reopened, so a live affinity update cannot smash a warm * pin. Hard-locked / sub-routed / in-use pins are NOT safe boundaries. */ export declare function isPinSafeBoundary(result: PinLookupResult): boolean; export type AffinitySwapReason = 'live_update_disabled' | 'not_pin_safe_boundary' | 'no_heat_data' | 'affinity_already_active' | 'hysteresis_hold' | 'swap_cap_reached' | 'heat_affinity_swap'; export interface AffinitySwapDecision { readonly shouldSwap: boolean; readonly targetTier: Tier | null; readonly reasonCode: AffinitySwapReason; /** Success-rate advantage of the candidate over the active tier (0 when N/A). */ readonly advantage: number; } export interface SessionAffinityState { readonly activeTier: Tier; readonly swapsThisSession: number; } /** Heat decay factor applied at each live swap (Colibri decaying heat). */ export declare const AFFINITY_SWAP_HEAT_DECAY = 0.5; /** * Per-session live affinity controller. Evaluates heat-preferred tier swaps * at pin-safe boundaries with hysteresis + swap cap. Stateless callers may * construct one controller per process; sessions are bounded by pin lifecycle * (`clearSession` on pin break/end). */ export declare class HeatAffinityController { private readonly config; private readonly sessions; constructor(config: WorkloadHeatConfig); /** Read-only per-session affinity state (telemetry/tests). */ getState(sessionId: string): SessionAffinityState | null; /** Drop session affinity state (pin break / session end). */ clearSession(sessionId: string): void; /** * Evaluate a live affinity swap at a pin-safe boundary. * * Gates, in order: live updates enabled → pin-safe boundary → heat data → * not already active → hysteresis band → swap cap. On swap, the session's * active tier moves and heat counts decay so the hot set tracks the live * workload. */ evaluateSwap(sessionId: string, boundary: PinLookupResult, key: WorkloadHeatKey, currentTier: Tier, heat: WorkloadHeatMap): AffinitySwapDecision; } //# sourceMappingURL=heat-affinity.d.ts.map