mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-19 06:30:54 +08:00
Merge pull request #332 from Coff0xc/fix/mcp-null-env
fix(mcp): keep MCP env a writable map when JSON is null
This commit is contained in:
@@ -49,6 +49,7 @@ All notable changes to this project are documented in this file. The format is b
|
||||
|
||||
### Fixed
|
||||
|
||||
- **Browser MCP env null no longer crashes startup**: a stored MCP `env` of JSON `null` unmarshaled into a nil map, and `syncBrowserMCPProxy` then assigned `NODE_EXTRA_CA_CERTS` when traffic capture was on, panicking the process on every start. `decodeStrMap` now always returns a writable map.
|
||||
- **Provider refusals reported as refusals**: a turn the provider's safety system declined (Anthropic `stop_reason: "refusal"`, OpenAI-compatible `finish_reason: "content_filter"`) has no text and no tool calls, so it ended as `completed` with "the model ended this turn normally", and the idle-turn rerun resent the same conversation up to the empty-response retry count, where it is expected to be refused again. The LLM recorder now hands each call's stop reason to the run (`llmrec.WithStopSink`, `agent.WithStopTracker`). After a refusal the idle-turn rerun is skipped, and the run summary says the provider refused the turn and the intent was not completed.
|
||||
- **LLM health badge on every task path**: `/system/llm/` read a breaker state that only the failover Pool wrote, so a profile used by an explicit task chain, by a bound agent with failover off, or as the global provider stayed "Healthy" through a real outage. Every task LLM attempt now records its outcome through the same policy the Pool uses, keyed by the profile that served it. The LLM recording page also explains an empty list when the `llm_record` toggle is off instead of looking broken.
|
||||
- **LLM health persistence** (#304): persisted breaker rows are applied in sequence at startup and written before the database closes, and a slow write no longer holds the registry lock while it runs.
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDecodeStrMapJSONNull(t *testing.T) {
|
||||
m := decodeStrMap(json.RawMessage("null"))
|
||||
if m == nil {
|
||||
t.Fatal("JSON null must decode to an empty map, not nil")
|
||||
}
|
||||
m["NODE_EXTRA_CA_CERTS"] = "/tmp/ca.pem"
|
||||
if m["NODE_EXTRA_CA_CERTS"] != "/tmp/ca.pem" {
|
||||
t.Fatal("decoded map must be writable")
|
||||
}
|
||||
|
||||
empty := decodeStrMap(nil)
|
||||
if empty == nil {
|
||||
t.Fatal("empty input must decode to an empty map")
|
||||
}
|
||||
|
||||
got := decodeStrMap(json.RawMessage(`{"FOO":"bar"}`))
|
||||
if got["FOO"] != "bar" {
|
||||
t.Fatalf("got %#v", got)
|
||||
}
|
||||
|
||||
invalid := decodeStrMap(json.RawMessage(`["not","an","object"]`))
|
||||
if invalid == nil {
|
||||
t.Fatal("invalid JSON must decode to an empty map")
|
||||
}
|
||||
}
|
||||
+6
-2
@@ -782,8 +782,12 @@ func decodeStrSlice(raw json.RawMessage) []string {
|
||||
|
||||
func decodeStrMap(raw json.RawMessage) map[string]string {
|
||||
out := map[string]string{}
|
||||
if len(raw) > 0 {
|
||||
_ = json.Unmarshal(raw, &out)
|
||||
if len(raw) == 0 {
|
||||
return out
|
||||
}
|
||||
if err := json.Unmarshal(raw, &out); err != nil || out == nil {
|
||||
// JSON null unmarshals into a nil map. Callers write env["k"]=v.
|
||||
return map[string]string{}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user