fix(web): fail-fast when invoke lock is busy; document single-interp limit
Long sse-live chats held INVOKE_LOCK indefinitely and starved short routes (UI freeze). Timed try-lock returns interpreter busy → HTTP 503; ADR 0008 records that HTTP is multi-goroutine while Marqdo evaluation stays single-flight. Also lands plan/delta streaming and soft map guards used by qdagent chat. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
b792f44556
commit
1b11fe063a
11 files changed
+838
-163
No files matched your search
@@ -799,6 +799,13 @@ func (g *gzipResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
||||
return nil, nil, fmt.Errorf("underlying ResponseWriter does not support hijacking")
|
||||
}
|
||||
|
||||
func (g *gzipResponseWriter) Flush() {
|
||||
_ = g.w.Flush()
|
||||
if f, ok := g.ResponseWriter.(http.Flusher); ok {
|
||||
f.Flush()
|
||||
}
|
||||
}
|
||||
|
||||
type statusRecorder struct {
|
||||
http.ResponseWriter
|
||||
status int
|
||||
@@ -816,6 +823,14 @@ func (s *statusRecorder) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
||||
return nil, nil, fmt.Errorf("underlying ResponseWriter does not support hijacking")
|
||||
}
|
||||
|
||||
// Flush must be forwarded so sse-live / EventBus token streams are not buffered
|
||||
// behind access-log wrapping (otherwise clients see 0 bytes until the invoke ends).
|
||||
func (s *statusRecorder) Flush() {
|
||||
if f, ok := s.ResponseWriter.(http.Flusher); ok {
|
||||
f.Flush()
|
||||
}
|
||||
}
|
||||
|
||||
func writeJSON(w http.ResponseWriter, code int, v any) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(code)
|
||||
|
||||
@@ -137,6 +137,11 @@ func (st *state) handleInvoke(w http.ResponseWriter, r *http.Request, route invo
|
||||
if err != nil {
|
||||
code := http.StatusInternalServerError
|
||||
msg := err.Error()
|
||||
if strings.Contains(msg, "interpreter busy") {
|
||||
w.Header().Set("Retry-After", "2")
|
||||
jsonErr(w, http.StatusServiceUnavailable, msg)
|
||||
return
|
||||
}
|
||||
if strings.Contains(msg, "unknown library") ||
|
||||
strings.Contains(msg, "call_lib_path: need") ||
|
||||
strings.Contains(msg, "not allowed") ||
|
||||
@@ -260,6 +265,10 @@ func (st *state) handleInvokeLiveSSE(w http.ResponseWriter, r *http.Request, rou
|
||||
done := make(chan callResult, 1)
|
||||
go func() {
|
||||
v, e := plugin.CallLibPath(route.FnPath, args)
|
||||
if e != nil && strings.Contains(e.Error(), "interpreter busy") {
|
||||
// Another invoke still holds the lock — surface as failed run, not hang.
|
||||
e = fmt.Errorf("interpreter busy: try again shortly")
|
||||
}
|
||||
done <- callResult{value: v, err: e}
|
||||
}()
|
||||
|
||||
@@ -339,13 +348,20 @@ func normalizeLiveSSELine(seq uint64, line string) map[string]any {
|
||||
base["seq"] = seq
|
||||
return base
|
||||
}
|
||||
// LLM plugin / net SSE: {type:delta|reasoning, text:...}
|
||||
if t, _ := obj["type"].(string); t == "delta" || t == "reasoning" {
|
||||
// LLM plugin / net SSE: {type:delta|plan|reasoning, text:...}
|
||||
if t, _ := obj["type"].(string); t == "delta" || t == "plan" || t == "reasoning" {
|
||||
text, _ := obj["text"].(string)
|
||||
base["type"] = "message.delta"
|
||||
base["payload"] = map[string]any{"delta": text, "kind": t}
|
||||
return base
|
||||
}
|
||||
// Plan process cards — keep as message.delta for back-compat, but never
|
||||
// promote `result` into payload.delta (that caused full-answer duplication).
|
||||
if t, _ := obj["type"].(string); t == "decompose" || t == "decision" || t == "await" || t == "round" || t == "done" || t == "tool_start" || t == "tool_end" || t == "plan_act" {
|
||||
base["type"] = "message.delta"
|
||||
base["payload"] = obj
|
||||
return base
|
||||
}
|
||||
if text, ok := obj["text"].(string); ok && text != "" {
|
||||
base["type"] = "message.delta"
|
||||
base["payload"] = map[string]any{"delta": text}
|
||||
|
||||
Reference in new issue
Block a user