fix: LM transport ceiling per provider (read_timeout_s + num_retries)
The bug his log pinned: local EXTRACT died at 2407.3s = 4 attempts x 600s + 7s backoff — dspy's retry loop (default num_retries=3) ran honestly but every attempt hit the SAME wall: lm15's default read timeout of 600s (and the silent-ollama proxy in front cuts at its own READ_TIMEOUT=600 too). Retries can't help when each attempt dies at the same ceiling — the 27b on a single 3090 legitimately needs minutes for a long EXTRACT output (his nvidia-smi: 21GB resident, 64k context, ~52% util). The fix: the ceiling is CONFIG, not code. - config.yaml: local read_timeout_s=1800 (one honest 30-min attempt), num_retries=1 (one re-try after a genuine cut, not 3x30min); ollama-cloud read_timeout_s=300 (glm answers EXTRACT in ~3s), num_retries=2 (cloud retries are cheap). - configure_lm forwards read_timeout_s as dspy.LM(timeout=...) — dspy 3.4.1 routes it to lm15 Timeouts(read/write/pool) — and num_retries to the retry loop (LMTransportError is retryable). - run.log first line now reports the ceiling (no more silent 600s walls — you SEE what will kill a slow call). - Unset keys -> dspy defaults (600s / retries 3), nothing invented. Verified on the wire (tests/lm_transport_wire.py): a hang server + timeout=3 kills the call at 3.1s (not 600s); num_retries=1 gives exactly 2 attempts (3.2s = 2x1s + backoff). Suite: 21 files green.
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
"""Live wire check: does config timeout= actually bound the HTTP read?
|
||||
|
||||
Starts a local server that NEVER answers (a socket that accepts and
|
||||
hangs), points the LM at it with a tiny timeout, and asserts the call
|
||||
dies in ~timeout (not dspy's default 600s, not forever). This is the
|
||||
one-hop proof that the ceiling travels configure_lm -> dspy.LM ->
|
||||
lm15 engine -> the wire. Offline (127.0.0.1), one call, seconds.
|
||||
"""
|
||||
import os
|
||||
import socket
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
|
||||
HOST, PORT = "127.0.0.1", 0 # ephemeral
|
||||
|
||||
|
||||
def hang_server(stop: threading.Event, port_box: list):
|
||||
srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
srv.bind((HOST, PORT))
|
||||
srv.listen(4)
|
||||
port_box.append(srv.getsockname()[1])
|
||||
srv.settimeout(1.0)
|
||||
while not stop.is_set():
|
||||
try:
|
||||
conn, _ = srv.accept()
|
||||
# read nothing more; just hold the connection open forever
|
||||
conn.settimeout(5.0)
|
||||
try:
|
||||
conn.recv(65536)
|
||||
except OSError:
|
||||
pass
|
||||
except socket.timeout:
|
||||
continue
|
||||
srv.close()
|
||||
|
||||
|
||||
def main():
|
||||
port_box: list = []
|
||||
stop = threading.Event()
|
||||
t = threading.Thread(target=hang_server, args=(stop, port_box), daemon=True)
|
||||
t.start()
|
||||
while not port_box:
|
||||
time.sleep(0.05)
|
||||
port = port_box[0]
|
||||
|
||||
import dspy
|
||||
import floop.llm as llm
|
||||
orig_load = llm._load_yaml
|
||||
llm._load_yaml = lambda: {"lm": {
|
||||
"default": "hang",
|
||||
"hang": {"base_url": f"http://127.0.0.1:{port}/v1",
|
||||
"model": "test-model", "max_tokens": 8,
|
||||
"temperature": 0.0,
|
||||
"read_timeout_s": 3, "num_retries": 0},
|
||||
}}
|
||||
try:
|
||||
os.environ["FLOOP_LM"] = "hang"
|
||||
llm.configure_lm()
|
||||
lm = llm._ACTIVE
|
||||
assert lm.kwargs["timeout"] == 3.0, lm.kwargs
|
||||
t0 = time.monotonic()
|
||||
try:
|
||||
lm(messages=[{"role": "user", "content": "hi"}])
|
||||
print("FAIL: the hang server answered?!")
|
||||
return 1
|
||||
except Exception as e:
|
||||
dt = time.monotonic() - t0
|
||||
# the call must die at ~3s (+ handshake slack), NOT 600s
|
||||
assert dt < 10, f"timeout did not bound the read: {dt:.1f}s"
|
||||
print(f"ok: read died at {dt:.1f}s (timeout=3 honored on the wire; "
|
||||
f"exception={type(e).__name__})")
|
||||
return 0
|
||||
finally:
|
||||
stop.set()
|
||||
llm._load_yaml = orig_load
|
||||
os.environ.pop("FLOOP_LM", None)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
rc = main()
|
||||
print("WIRE CHECK:", "PASS" if rc == 0 else "FAIL")
|
||||
sys.exit(rc)
|
||||
Reference in New Issue
Block a user