fix(circuit-breaker): add enabled config flag as escape hatch
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
const CircuitBreakerConfigSchema = z.object({
|
const CircuitBreakerConfigSchema = z.object({
|
||||||
|
enabled: z.boolean().optional(),
|
||||||
maxToolCalls: z.number().int().min(10).optional(),
|
maxToolCalls: z.number().int().min(10).optional(),
|
||||||
windowSize: z.number().int().min(5).optional(),
|
windowSize: z.number().int().min(5).optional(),
|
||||||
repetitionThresholdPercent: z.number().gt(0).max(100).optional(),
|
repetitionThresholdPercent: z.number().gt(0).max(100).optional(),
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ export const DEFAULT_MESSAGE_STALENESS_TIMEOUT_MS = 1_800_000
|
|||||||
export const DEFAULT_MAX_TOOL_CALLS = 200
|
export const DEFAULT_MAX_TOOL_CALLS = 200
|
||||||
export const DEFAULT_CIRCUIT_BREAKER_WINDOW_SIZE = 20
|
export const DEFAULT_CIRCUIT_BREAKER_WINDOW_SIZE = 20
|
||||||
export const DEFAULT_CIRCUIT_BREAKER_REPETITION_THRESHOLD_PERCENT = 80
|
export const DEFAULT_CIRCUIT_BREAKER_REPETITION_THRESHOLD_PERCENT = 80
|
||||||
|
export const DEFAULT_CIRCUIT_BREAKER_ENABLED = true
|
||||||
export const MIN_RUNTIME_BEFORE_STALE_MS = 30_000
|
export const MIN_RUNTIME_BEFORE_STALE_MS = 30_000
|
||||||
export const MIN_IDLE_TIME_MS = 5000
|
export const MIN_IDLE_TIME_MS = 5000
|
||||||
export const POLLING_INTERVAL_MS = 3000
|
export const POLLING_INTERVAL_MS = 3000
|
||||||
|
|||||||
@@ -31,12 +31,57 @@ describe("loop-detector", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
|
enabled: true,
|
||||||
maxToolCalls: 120,
|
maxToolCalls: 120,
|
||||||
windowSize: 10,
|
windowSize: 10,
|
||||||
repetitionThresholdPercent: 70,
|
repetitionThresholdPercent: 70,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("#given no enabled config", () => {
|
||||||
|
test("#when resolved #then enabled defaults to true", () => {
|
||||||
|
const result = resolveCircuitBreakerSettings({
|
||||||
|
circuitBreaker: {
|
||||||
|
maxToolCalls: 100,
|
||||||
|
windowSize: 5,
|
||||||
|
repetitionThresholdPercent: 60,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(result.enabled).toBe(true)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("#given enabled is false in config", () => {
|
||||||
|
test("#when resolved #then enabled is false", () => {
|
||||||
|
const result = resolveCircuitBreakerSettings({
|
||||||
|
circuitBreaker: {
|
||||||
|
enabled: false,
|
||||||
|
maxToolCalls: 100,
|
||||||
|
windowSize: 5,
|
||||||
|
repetitionThresholdPercent: 60,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(result.enabled).toBe(false)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("#given enabled is true in config", () => {
|
||||||
|
test("#when resolved #then enabled is true", () => {
|
||||||
|
const result = resolveCircuitBreakerSettings({
|
||||||
|
circuitBreaker: {
|
||||||
|
enabled: true,
|
||||||
|
maxToolCalls: 100,
|
||||||
|
windowSize: 5,
|
||||||
|
repetitionThresholdPercent: 60,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(result.enabled).toBe(true)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("detectRepetitiveToolUse", () => {
|
describe("detectRepetitiveToolUse", () => {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import type { BackgroundTaskConfig } from "../../config/schema"
|
import type { BackgroundTaskConfig } from "../../config/schema"
|
||||||
import {
|
import {
|
||||||
|
DEFAULT_CIRCUIT_BREAKER_ENABLED,
|
||||||
DEFAULT_CIRCUIT_BREAKER_REPETITION_THRESHOLD_PERCENT,
|
DEFAULT_CIRCUIT_BREAKER_REPETITION_THRESHOLD_PERCENT,
|
||||||
DEFAULT_CIRCUIT_BREAKER_WINDOW_SIZE,
|
DEFAULT_CIRCUIT_BREAKER_WINDOW_SIZE,
|
||||||
DEFAULT_MAX_TOOL_CALLS,
|
DEFAULT_MAX_TOOL_CALLS,
|
||||||
@@ -7,6 +8,7 @@ import {
|
|||||||
import type { ToolCallWindow } from "./types"
|
import type { ToolCallWindow } from "./types"
|
||||||
|
|
||||||
export interface CircuitBreakerSettings {
|
export interface CircuitBreakerSettings {
|
||||||
|
enabled: boolean
|
||||||
maxToolCalls: number
|
maxToolCalls: number
|
||||||
windowSize: number
|
windowSize: number
|
||||||
repetitionThresholdPercent: number
|
repetitionThresholdPercent: number
|
||||||
@@ -24,6 +26,7 @@ export function resolveCircuitBreakerSettings(
|
|||||||
config?: BackgroundTaskConfig
|
config?: BackgroundTaskConfig
|
||||||
): CircuitBreakerSettings {
|
): CircuitBreakerSettings {
|
||||||
return {
|
return {
|
||||||
|
enabled: config?.circuitBreaker?.enabled ?? DEFAULT_CIRCUIT_BREAKER_ENABLED,
|
||||||
maxToolCalls:
|
maxToolCalls:
|
||||||
config?.circuitBreaker?.maxToolCalls ?? config?.maxToolCalls ?? DEFAULT_MAX_TOOL_CALLS,
|
config?.circuitBreaker?.maxToolCalls ?? config?.maxToolCalls ?? DEFAULT_MAX_TOOL_CALLS,
|
||||||
windowSize: config?.circuitBreaker?.windowSize ?? DEFAULT_CIRCUIT_BREAKER_WINDOW_SIZE,
|
windowSize: config?.circuitBreaker?.windowSize ?? DEFAULT_CIRCUIT_BREAKER_WINDOW_SIZE,
|
||||||
|
|||||||
Reference in New Issue
Block a user