Skip to content

Commit dd48025

Browse files
committed
feat(librarian): Module C retrieval upgrades (stack base for #1088)
Dual-index retrieval, CRE summaries, prior cage, hub seed, edition remap, and related librarian defaults. Rewrites #1088 as the reviewable base; later stacked PRs add harvester, B2 eval, fixtures, mappings, and full-pipeline docs.
1 parent ff0b53a commit dd48025

86 files changed

Lines changed: 17222 additions & 289 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎application/prompt_client/litellm_router.py‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@
88

99
from __future__ import annotations
1010

11-
from cre_logging import get_logger
12-
13-
logger = get_logger(__name__)
14-
11+
import logging
1512
import os
1613
import time
1714
from typing import Any, Callable, List, Optional, Sequence
1815

19-
from application.prompt_client.llm_error_utils import is_rate_limit_error
16+
from application.prompt_client.llm_error_utils import (
17+
is_rate_limit_error,
18+
is_transient_llm_error,
19+
)
20+
21+
logger = logging.getLogger(__name__)
2022

2123
LlmFn = Callable[[str, str], str]
2224

@@ -47,21 +49,26 @@ def with_rate_limit_retry(
4749
max_retries: Optional[int] = None,
4850
retry_sleep_seconds: Optional[int] = None,
4951
) -> Any:
52+
"""Retry rate limits and transient connection/timeout blips."""
5053
default_retries, default_sleep = retry_policy()
5154
retries = default_retries if max_retries is None else max_retries
5255
sleep_s = default_sleep if retry_sleep_seconds is None else retry_sleep_seconds
5356
for attempt in range(retries + 1):
5457
try:
5558
return fn()
5659
except Exception as err:
57-
if not is_rate_limit_error(err) or attempt >= retries:
60+
retriable = is_transient_llm_error(err) or is_rate_limit_error(err)
61+
if not retriable or attempt >= retries:
5862
raise
63+
kind = "rate/quota" if is_rate_limit_error(err) else "transient"
5964
logger.info(
60-
"rate/quota limited during %s; sleeping %ss (attempt %s/%s)",
65+
"%s limited during %s; sleeping %ss (attempt %s/%s): %s",
66+
kind,
6167
context,
6268
sleep_s,
6369
attempt + 1,
6470
retries + 1,
71+
type(err).__name__,
6572
)
6673
time.sleep(sleep_s)
6774
raise RuntimeError("unreachable: retry loop exited unexpectedly")

‎application/prompt_client/llm_error_utils.py‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,38 @@ def is_rate_limit_error(err: BaseException) -> bool:
3131
if code == 429:
3232
return True
3333
return False
34+
35+
36+
def is_transient_llm_error(err: BaseException) -> bool:
37+
"""Connection / timeout blips that are safe to retry (not model refusal)."""
38+
if is_rate_limit_error(err):
39+
return True
40+
name = type(err).__name__.lower()
41+
if any(
42+
tok in name
43+
for tok in (
44+
"connect",
45+
"timeout",
46+
"apiconnection",
47+
"remoteprotocol",
48+
"network",
49+
)
50+
):
51+
return True
52+
msg = str(err).lower()
53+
return any(
54+
tok in msg
55+
for tok in (
56+
"connection reset",
57+
"connection aborted",
58+
"connection refused",
59+
"temporarily unavailable",
60+
"broken pipe",
61+
"timed out",
62+
"timeout",
63+
"errno 54",
64+
"errno 104",
65+
"server disconnected",
66+
"remote end closed",
67+
)
68+
)

0 commit comments

Comments
 (0)