Skip to content

Commit 405fc45

Browse files
committed
fix: address gold-standard review findings
Critical: - Remove rich from requirements.txt (now optional in pyproject.toml) - Fix stale tiers=DEFAULT_TIERS warning messages referencing removed param - Complete @xenova/transformers → @huggingface/transformers migration across all TS packages, docs, examples, and CI config - Revert workspace:* → workspace:^ (preserves semver on publish) Security: - Use hmac.compare_digest for constant-time auth token comparison - Guard record() with _lock for thread-safe counter reads Quality: - Preserve _LazyModule.__name__ alias after dict merge - Add __bool__=False to _MissingIntegration for truthiness compat - Fix CHANGELOG import time to match actual measurement (~20ms) - Fix import ordering (ruff I001)
1 parent 409651b commit 405fc45

File tree

17 files changed

+203
-474
lines changed

17 files changed

+203
-474
lines changed

.github/models.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ ml_models:
4747

4848
installation:
4949
python: "pip install fastembed"
50-
typescript: "npm install @xenova/transformers"
50+
typescript: "npm install @huggingface/transformers"
5151

5252
# Heuristic Models (No ML Required)
5353
heuristic_models:

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3333

3434
### Changed
3535

36-
- **Lazy imports**`import cascadeflow` no longer eagerly loads all providers, numpy, or heavyweight submodules. Import time reduced from ~1900ms to <200ms.
36+
- **Lazy imports**`import cascadeflow` no longer eagerly loads all providers, numpy, or heavyweight submodules. Import time reduced from ~1900ms to ~20ms via PEP 562 lazy loading.
3737
- **`__all__` reduced** — From 127 to ~20 essential public symbols. Non-essential exports remain accessible but are not star-exported.
3838
- **`rich` moved to optional** — No longer a core dependency; falls back to stdlib logging when not installed. Install with `pip install cascadeflow[rich]`.
3939
- **Integration import errors** — Failed optional integration imports now return proxy objects that raise `ImportError` with install hints on use, instead of silently returning `None`.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ For advanced quality validation, enable ML-based semantic similarity checking to
289289
**Step 1:** Install the optional ML packages:
290290

291291
```bash
292-
npm install @cascadeflow/ml @xenova/transformers
292+
npm install @cascadeflow/ml @huggingface/transformers
293293
```
294294

295295
**Step 2:** Enable semantic validation in your cascade:

cascadeflow/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ def _load(self):
4646
if not self.__loaded:
4747
import importlib
4848

49+
alias = self.__name__
4950
real = importlib.import_module(self.__real_name)
5051
self.__dict__.update(real.__dict__)
52+
self.__name__ = alias # preserve alias name after dict merge
5153
self.__loaded = True
5254

5355
def __getattr__(self, name: str):

cascadeflow/agent.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ async def run(
974974
logger.warning(
975975
f"user_tier='{user_tier}' specified but no tiers configured. "
976976
f"Ignoring tier parameter. To use tiers, initialize agent with: "
977-
f"CascadeAgent(models=[...], tiers=DEFAULT_TIERS)"
977+
f"HarnessConfig with tier-based rules"
978978
)
979979

980980
workflow_profile = None
@@ -1402,7 +1402,7 @@ async def run_streaming(
14021402
logger.warning(
14031403
f"user_tier='{user_tier}' specified but no tiers configured. "
14041404
f"Ignoring tier parameter. To use tiers, initialize agent with: "
1405-
f"CascadeAgent(models=[...], tiers=DEFAULT_TIERS)"
1405+
f"HarnessConfig with tier-based rules"
14061406
)
14071407

14081408
workflow_profile = None
@@ -1681,7 +1681,7 @@ async def stream_events(
16811681
logger.warning(
16821682
f"user_tier='{user_tier}' specified but no tiers configured. "
16831683
f"Ignoring tier parameter. To use tiers, initialize agent with: "
1684-
f"CascadeAgent(models=[...], tiers=DEFAULT_TIERS)"
1684+
f"HarnessConfig with tier-based rules"
16851685
)
16861686

16871687
workflow_profile = None

cascadeflow/harness/api.py

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -187,30 +187,31 @@ def record(
187187
_sanitize_trace_value(model, max_length=_MAX_MODEL_LEN) if model is not None else None
188188
)
189189

190-
self.last_action = safe_action
191-
self.model_used = safe_model
192-
entry: dict[str, Any] = {
193-
"action": safe_action,
194-
"reason": safe_reason,
195-
"model": safe_model,
196-
"run_id": self.run_id,
197-
"mode": self.mode,
198-
"step": self.step_count,
199-
"timestamp_ms": time.time() * 1000,
200-
"tool_calls_total": self.tool_calls,
201-
"cost_total": self.cost,
202-
"latency_used_ms": self.latency_used_ms,
203-
"energy_used": self.energy_used,
204-
"budget_state": {
205-
"max": self.budget_max,
206-
"remaining": self.budget_remaining,
207-
},
208-
}
209-
if applied is not None:
210-
entry["applied"] = applied
211-
if decision_mode is not None:
212-
entry["decision_mode"] = decision_mode
213-
self._trace.append(entry)
190+
with self._lock:
191+
self.last_action = safe_action
192+
self.model_used = safe_model
193+
entry: dict[str, Any] = {
194+
"action": safe_action,
195+
"reason": safe_reason,
196+
"model": safe_model,
197+
"run_id": self.run_id,
198+
"mode": self.mode,
199+
"step": self.step_count,
200+
"timestamp_ms": time.time() * 1000,
201+
"tool_calls_total": self.tool_calls,
202+
"cost_total": self.cost,
203+
"latency_used_ms": self.latency_used_ms,
204+
"energy_used": self.energy_used,
205+
"budget_state": {
206+
"max": self.budget_max,
207+
"remaining": self.budget_remaining,
208+
},
209+
}
210+
if applied is not None:
211+
entry["applied"] = applied
212+
if decision_mode is not None:
213+
entry["decision_mode"] = decision_mode
214+
self._trace.append(entry)
214215
_emit_harness_decision(entry)
215216

216217

cascadeflow/integrations/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ def __call__(self, *args, **kwargs):
3939
def __getattr__(self, name: str):
4040
self._fail()
4141

42+
def __bool__(self):
43+
return False
44+
4245
def __repr__(self):
4346
return f"<MissingIntegration {self._name!r}>"
4447

cascadeflow/proxy/server.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import asyncio
2626
import hashlib
27+
import hmac
2728
import inspect
2829
import json
2930
import os
@@ -619,7 +620,8 @@ def _check_auth(self, proxy: RoutingProxy) -> bool:
619620
if not token:
620621
return True
621622
auth = self.headers.get("Authorization", "")
622-
if auth == f"Bearer {token}":
623+
expected = f"Bearer {token}"
624+
if hmac.compare_digest(auth, expected):
623625
return True
624626
self.send_response(401)
625627
self.send_header("Content-Type", "application/json")

cascadeflow/routing/tier_routing.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@
22
Tier-aware routing for user tier management.
33
44
This module provides tier-based model filtering and budget enforcement.
5-
It's OPTIONAL - only activated when users provide 'tiers' parameter.
5+
It's OPTIONAL - only activated when tier rules are configured via HarnessConfig.
66
77
Usage:
88
>>> from cascadeflow import CascadeAgent
9-
>>> from cascadeflow.schema.config import DEFAULT_TIERS
109
>>>
11-
>>> # OPTIONAL: Enable tier routing
12-
>>> agent = CascadeAgent(models=[...], tiers=DEFAULT_TIERS)
13-
>>>
14-
>>> # Use tier-aware routing
10+
>>> # Use tier-aware routing via HarnessConfig
1511
>>> result = await agent.run("query", user_tier="free")
1612
>>>
1713
>>> # Or ignore tiers - works without them

docs/guides/custom_validation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ if (await checker.isAvailable()) {
904904

905905
**Installation:**
906906
```bash
907-
npm install @cascadeflow/ml @xenova/transformers
907+
npm install @cascadeflow/ml @huggingface/transformers
908908
```
909909

910910
---

0 commit comments

Comments
 (0)