feat(ai): external responder for external-* model ids (reference runs)
모델 id가 external- 로 시작하면 ai-agent 가 LLM API 를 부르지 않고 각 턴(시스템 프롬프트·대화 이력·도구 정의·강제 제출 여부)을 GET /external/next 로 내어주고 POST /external/reply 로 답을 받는다. 진단 루프·프롬프트·도구·턴 상한은 다른 모델과 동일하므로, API 경로가 없는 모델(Claude Mythos 5.1 을 Claude Code 서브에이전트가 구동)의 참고 측정에 쓴다. 토큰 사용량은 알 수 없어 0 으로 기록한다. external-* 진단은 EXTERNAL_DIAGNOSE_TIMEOUT_S(기본 1500초), 한 턴은 EXTERNAL_TURN_TIMEOUT_S(기본 1200초)까지 기다리고, 하네스는 같은 모델에 26분을 기다린다. /selfcheck 에 external_responder 상태(대기 턴·마지막 폴링 시각)를 추가.
This commit is contained in:
1 parent
85d99324a1
commit
ed3d41d399
8 files changed
+585
-6
No files matched your search
+16
-3
@@ -10,6 +10,7 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
@@ -226,14 +227,26 @@ func (r *AlertRouter) cancelTimer(fp string) {
|
||||
}
|
||||
}
|
||||
|
||||
// diagnoseTimeout bounds one /diagnose call: 3 minutes for API models (the AI VM gives up at 170 s); external-*
|
||||
// models (reference runs answered by a client outside the VM, apps 2026-10-16) get 26 minutes, one more than the AI
|
||||
// VM's EXTERNAL_DIAGNOSE_TIMEOUT_S default, so the VM's own error reaches the diagnosis event first.
|
||||
func diagnoseTimeout(model string) time.Duration {
|
||||
if strings.HasPrefix(model, "external-") {
|
||||
return 26 * time.Minute
|
||||
}
|
||||
return 3 * time.Minute
|
||||
}
|
||||
|
||||
// diagnose asks the AI VM (design 6.3 strict schema). Until WP-12 the endpoint is absent; the failure is recorded as an event.
|
||||
func (r *AlertRouter) diagnose(alert map[string]any, runID, sid *string) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
|
||||
defer cancel()
|
||||
reqBody := map[string]any{"alert": alert, "run_id": runID, "scenario_id": sid}
|
||||
model := ""
|
||||
if cur := r.app.runs.current(); cur != nil && runID != nil && cur.RunID == *runID && cur.Model != "" {
|
||||
reqBody["model"] = cur.Model // campaign-level model selection (the AI VM falls back to its default when absent)
|
||||
model = cur.Model
|
||||
reqBody["model"] = model // campaign-level model selection (the AI VM falls back to its default when absent)
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), diagnoseTimeout(model))
|
||||
defer cancel()
|
||||
b, _ := json.Marshal(reqBody)
|
||||
req, _ := http.NewRequestWithContext(ctx, "POST", r.app.cfg.AIDiagnoseURL, bytes.NewReader(b))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
@@ -44,3 +44,20 @@ func TestDedupeSameAlertName(t *testing.T) {
|
||||
t.Fatal("dedupe off")
|
||||
}
|
||||
}
|
||||
|
||||
// external-* models (reference runs served by a client outside the AI VM) get the long diagnose timeout; the model id
|
||||
// itself passes the run request bound.
|
||||
func TestDiagnoseTimeoutByModel(t *testing.T) {
|
||||
if d := diagnoseTimeout("claude-sonnet-5-5"); d != 3*time.Minute {
|
||||
t.Fatalf("api model timeout %v", d)
|
||||
}
|
||||
if d := diagnoseTimeout(""); d != 3*time.Minute {
|
||||
t.Fatalf("default model timeout %v", d)
|
||||
}
|
||||
if d := diagnoseTimeout("external-claude-mythos-5-1"); d != 26*time.Minute {
|
||||
t.Fatalf("external model timeout %v", d)
|
||||
}
|
||||
if !modelRe.MatchString("external-claude-mythos-5-1") {
|
||||
t.Fatal("external model id must pass modelRe")
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -49,7 +49,8 @@ type RunRequest struct {
|
||||
AutoApproveAfterS *int `json:"auto_approve_after_s"` // measurement mode (model comparison without a human in the loop): nil/0 = off
|
||||
}
|
||||
|
||||
// modelRe bounds the model id (empty = AI VM default). The AI VM routes by prefix: claude-* -> Anthropic, else OpenAI.
|
||||
// modelRe bounds the model id (empty = AI VM default). The AI VM routes by prefix: claude-* -> Anthropic,
|
||||
// external-* -> external responder (reference runs, longer diagnose timeout in alerts.go), else OpenAI.
|
||||
var modelRe = regexp.MustCompile(`^[A-Za-z0-9._:-]{0,64}$`)
|
||||
|
||||
func NewRunManager(a *App) *RunManager { return &RunManager{app: a} }
|
||||
|
||||
Reference in new issue
Block a user