mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-10-27 17:03:49 +08:00
fix(intercept): default judge failure retries to three
This commit is contained in:
1 parent
e66789633a
commit
ed7eda5e0c
4 files changed
+35
-16
No files matched your search
@@ -316,6 +316,7 @@ const (
|
|||||||
// Judge default values.
|
// Judge default values.
|
||||||
const (
|
const (
|
||||||
defaultJudgeTimeoutSecs = 15
|
defaultJudgeTimeoutSecs = 15
|
||||||
|
defaultJudgeRetryCount = 3
|
||||||
defaultJudgeFailAction = "ask"
|
defaultJudgeFailAction = "ask"
|
||||||
defaultJudgeAskTimeoutSecs = 300
|
defaultJudgeAskTimeoutSecs = 300
|
||||||
defaultJudgeAskTimeoutAction = "deny"
|
defaultJudgeAskTimeoutAction = "deny"
|
||||||
@@ -346,7 +347,7 @@ func (i *Interceptor) judgeConfig() JudgeConfig {
|
|||||||
Enabled: i.db.GetBool(settingJudgeEnabled, false),
|
Enabled: i.db.GetBool(settingJudgeEnabled, false),
|
||||||
ProfileID: int64(i.getSettingInt(settingJudgeProfileID, 0)),
|
ProfileID: int64(i.getSettingInt(settingJudgeProfileID, 0)),
|
||||||
TimeoutSeconds: i.getSettingInt(settingJudgeTimeoutSecs, defaultJudgeTimeoutSecs),
|
TimeoutSeconds: i.getSettingInt(settingJudgeTimeoutSecs, defaultJudgeTimeoutSecs),
|
||||||
RetryCount: min(max(i.getSettingInt(settingJudgeRetryCount, 0), 0), MaxJudgeRetryCount),
|
RetryCount: min(max(i.getSettingInt(settingJudgeRetryCount, defaultJudgeRetryCount), 0), MaxJudgeRetryCount),
|
||||||
RetryIntervalMS: min(max(i.getSettingInt(settingJudgeRetryIntervalMS, defaultJudgeRetryIntervalMS), 0), MaxJudgeRetryIntervalMS),
|
RetryIntervalMS: min(max(i.getSettingInt(settingJudgeRetryIntervalMS, defaultJudgeRetryIntervalMS), 0), MaxJudgeRetryIntervalMS),
|
||||||
FailAction: i.getSettingChoice(settingJudgeFailAction, defaultJudgeFailAction, "allow", "ask", "deny"),
|
FailAction: i.getSettingChoice(settingJudgeFailAction, defaultJudgeFailAction, "allow", "ask", "deny"),
|
||||||
AskTimeoutSeconds: i.getSettingInt(settingJudgeAskTimeoutSecs, defaultJudgeAskTimeoutSecs),
|
AskTimeoutSeconds: i.getSettingInt(settingJudgeAskTimeoutSecs, defaultJudgeAskTimeoutSecs),
|
||||||
|
|||||||
@@ -59,10 +59,11 @@ func TestJudgeRetryConfigDefaultsAndBounds(t *testing.T) {
|
|||||||
settings map[string]string
|
settings map[string]string
|
||||||
count, interval int
|
count, interval int
|
||||||
}{
|
}{
|
||||||
{"legacy", nil, 0, 1000},
|
{"default", nil, 3, 1000},
|
||||||
{"configured", map[string]string{settingJudgeRetryCount: "3", settingJudgeRetryIntervalMS: "25"}, 3, 25},
|
{"configured", map[string]string{settingJudgeRetryCount: "2", settingJudgeRetryIntervalMS: "25"}, 2, 25},
|
||||||
|
{"disabled", map[string]string{settingJudgeRetryCount: "0"}, 0, 1000},
|
||||||
{"immediate", map[string]string{settingJudgeRetryCount: "1", settingJudgeRetryIntervalMS: "0"}, 1, 0},
|
{"immediate", map[string]string{settingJudgeRetryCount: "1", settingJudgeRetryIntervalMS: "0"}, 1, 0},
|
||||||
{"malformed", map[string]string{settingJudgeRetryCount: "bad", settingJudgeRetryIntervalMS: "bad"}, 0, 1000},
|
{"malformed", map[string]string{settingJudgeRetryCount: "bad", settingJudgeRetryIntervalMS: "bad"}, 3, 1000},
|
||||||
{"negative", map[string]string{settingJudgeRetryCount: "-1", settingJudgeRetryIntervalMS: "-1"}, 0, 0},
|
{"negative", map[string]string{settingJudgeRetryCount: "-1", settingJudgeRetryIntervalMS: "-1"}, 0, 0},
|
||||||
{"excessive", map[string]string{settingJudgeRetryCount: "999", settingJudgeRetryIntervalMS: "999999999"}, 20, 3600000},
|
{"excessive", map[string]string{settingJudgeRetryCount: "999", settingJudgeRetryIntervalMS: "999999999"}, 20, 3600000},
|
||||||
} {
|
} {
|
||||||
@@ -149,16 +150,33 @@ func TestJudgeRetriesInvalidVerdict(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestJudgeLegacyConfigDoesNotRetry(t *testing.T) {
|
func TestJudgeDefaultRetriesAndExplicitDisable(t *testing.T) {
|
||||||
i := retryTestInterceptor(t, map[string]string{settingJudgeEnabled: "true", settingJudgeFailAction: "deny"})
|
for _, tc := range []struct {
|
||||||
calls := 0
|
name string
|
||||||
i.SetReviewer(func(context.Context, int64, string, ReviewInput) (Decision, error) {
|
settings map[string]string
|
||||||
calls++
|
wantCalls int
|
||||||
return Decision{}, errors.New("failed")
|
}{
|
||||||
})
|
{"default", nil, 4},
|
||||||
got, _ := i.Judge(t.Context(), "Bash", json.RawMessage(`{"command":"echo ok"}`))
|
{"disabled", map[string]string{settingJudgeRetryCount: "0"}, 1},
|
||||||
if calls != 1 || got.Action != "deny" || !got.ModelFallback {
|
} {
|
||||||
t.Fatalf("calls=%d out=%+v", calls, got)
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
settings := map[string]string{
|
||||||
|
settingJudgeEnabled: "true", settingJudgeFailAction: "deny", settingJudgeRetryIntervalMS: "0",
|
||||||
|
}
|
||||||
|
for key, value := range tc.settings {
|
||||||
|
settings[key] = value
|
||||||
|
}
|
||||||
|
i := retryTestInterceptor(t, settings)
|
||||||
|
calls := 0
|
||||||
|
i.SetReviewer(func(context.Context, int64, string, ReviewInput) (Decision, error) {
|
||||||
|
calls++
|
||||||
|
return Decision{}, errors.New("failed")
|
||||||
|
})
|
||||||
|
got, _ := i.Judge(t.Context(), "Bash", json.RawMessage(`{"command":"echo ok"}`))
|
||||||
|
if calls != tc.wantCalls || got.Action != "deny" || !got.ModelFallback {
|
||||||
|
t.Fatalf("calls=%d out=%+v", calls, got)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ const defaultJudge = (): JudgeConfig => ({
|
|||||||
profile_id: 0,
|
profile_id: 0,
|
||||||
prompt: "",
|
prompt: "",
|
||||||
timeout_seconds: 15,
|
timeout_seconds: 15,
|
||||||
retry_count: 0,
|
retry_count: 3,
|
||||||
retry_interval_ms: 1000,
|
retry_interval_ms: 1000,
|
||||||
fail_action: "ask",
|
fail_action: "ask",
|
||||||
ask_timeout_seconds: 300,
|
ask_timeout_seconds: 300,
|
||||||
|
|||||||
@@ -2512,7 +2512,7 @@ function route(m: string, path: string, seg: string[], q: URLSearchParams, b: Re
|
|||||||
profile_id: 0,
|
profile_id: 0,
|
||||||
prompt: "",
|
prompt: "",
|
||||||
timeout_seconds: 15,
|
timeout_seconds: 15,
|
||||||
retry_count: 0,
|
retry_count: 3,
|
||||||
retry_interval_ms: 1000,
|
retry_interval_ms: 1000,
|
||||||
fail_action: "ask",
|
fail_action: "ask",
|
||||||
ask_timeout_seconds: 300,
|
ask_timeout_seconds: 300,
|
||||||
|
|||||||
Reference in new issue
Block a user