fix: default provider policy, anti-stall self-kill, _schema NameError (cobra PR #17)
This commit is contained in:
@@ -2017,12 +2017,17 @@ _PROVIDER_POLICIES = {
|
||||
"tool_output_limit": 8000, "max_input_items": 250},
|
||||
}
|
||||
|
||||
_DEFAULT_PROVIDER_POLICY = {
|
||||
"compaction": "balanced", "context_size": 128000,
|
||||
"tool_output_limit": 6000, "max_input_items": 60,
|
||||
}
|
||||
|
||||
def provider_policy(target_url=None, backend=None):
|
||||
host = urllib.parse.urlparse(target_url or TARGET_URL).netloc.lower()
|
||||
for key, policy in _PROVIDER_POLICIES.items():
|
||||
if key in host:
|
||||
return policy
|
||||
return {}
|
||||
return dict(_DEFAULT_PROVIDER_POLICY)
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════════
|
||||
# Adaptive context compaction (model-aware)
|
||||
@@ -7247,7 +7252,8 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
||||
print(f"[{self._session_id}] [smart-continue] XML injection retry failed: {e}", file=sys.stderr)
|
||||
break
|
||||
_nudge_msg = {"role": "user", "content": nudge_text}
|
||||
nudge_messages = oa_input_to_messages(_preprocess_vision_input(input_data, _schema) if _schema and not _schema.supports_vision else input_data) + [_nudge_msg]
|
||||
_nudge_schema = _load_schema(model=model)
|
||||
nudge_messages = oa_input_to_messages(_preprocess_vision_input(input_data, _nudge_schema) if _nudge_schema and not _nudge_schema.supports_vision else input_data) + [_nudge_msg]
|
||||
instructions = body.get("instructions", "").strip()
|
||||
if instructions:
|
||||
nudge_messages.insert(0, {"role": "system", "content": instructions})
|
||||
@@ -8180,7 +8186,8 @@ def _handle_shutdown_signal(sig, frame):
|
||||
|
||||
def _anti_stall_cleanup():
|
||||
my_pid = os.getpid()
|
||||
my_port = PORT
|
||||
my_ppid = os.getppid()
|
||||
my_pgid = os.getpgid(0)
|
||||
killed = []
|
||||
try:
|
||||
import subprocess as _sp
|
||||
@@ -8190,7 +8197,24 @@ def _anti_stall_cleanup():
|
||||
if not pid_str or not pid_str.isdigit():
|
||||
continue
|
||||
pid = int(pid_str)
|
||||
if pid == my_pid:
|
||||
if pid == my_pid or pid == my_ppid:
|
||||
continue
|
||||
try:
|
||||
pgid = os.getpgid(pid)
|
||||
if pgid == my_pgid:
|
||||
continue
|
||||
except OSError:
|
||||
pass
|
||||
try:
|
||||
stat = open(f"/proc/{pid}/stat").read().split()
|
||||
start_ticks = int(stat[21])
|
||||
import time as _t
|
||||
ticks_per_sec = os.sysconf('SC_CLK_TCK')
|
||||
start_time = start_ticks / ticks_per_sec
|
||||
age = _t.time() - start_time
|
||||
if age < 60:
|
||||
continue
|
||||
except Exception:
|
||||
continue
|
||||
try:
|
||||
os.kill(pid, signal.SIGTERM)
|
||||
|
||||
Reference in New Issue
Block a user