Skip to content

hardening/v1.0.0: Gold-standard release hardening#169

Merged
saschabuehrle merged 14 commits intomainfrom
hardening/v1.0.0
Mar 8, 2026
Merged

hardening/v1.0.0: Gold-standard release hardening#169
saschabuehrle merged 14 commits intomainfrom
hardening/v1.0.0

Conversation

@saschabuehrle
Copy link
Copy Markdown
Collaborator

Summary

14 commits across 7 phases addressing all findings from 4 independent audits (security, DX, performance, release readiness) plus a comprehensive code review.

Phase 1: Metadata & Doc Fixes

  • Fix dead docs URL, SECURITY.md version, author branding, README code block

Phase 2: CHANGELOG.md

  • Keep a Changelog format covering v1.0.0 highlights

Phase 3: Lazy Imports (Performance Critical)

  • Import time: 1900ms → 16ms via PEP 562 lazy loading
  • Lazy numpy in semantic router, lazy provider classes, lazy __init__.py
  • _LazyModule proxy for backward-compatible sys.modules aliases

Phase 4: DX Fixes

  • Add langchain optional dependency extra
  • Remove 6 deprecated CascadeAgent constructor params
  • _MissingIntegration proxy replacing None stubs with actionable ImportError

Phase 5: Proxy Gateway Security

  • CORS default: "*"None (opt-in)
  • --auth-token Bearer token support with constant-time comparison
  • --max-body-bytes request size limit (10MB default)

Phase 6: Thread Safety & Performance

  • Threading lock for SDK patch/unpatch state
  • Thread-safe HarnessRunContext counters via _increment() + guarded record()
  • Bounded deque(maxlen=1000) trace buffer
  • Pre-compile all regex patterns in ComplexityDetector.__init__()

Phase 7: Remaining Cleanup

  • rich moved from core dep to optional extra with stdlib fallback
  • Python 3.13 classifier + CI matrix
  • Remove CI || echo test swallowing
  • @xenova/transformers@huggingface/transformers (complete migration)

Review Fix

  • Constant-time auth comparison (hmac.compare_digest)
  • Complete @xenova/transformers migration across all packages/docs
  • Fix stale tiers=DEFAULT_TIERS references
  • _LazyModule.__name__ preservation, _MissingIntegration.__bool__

Test plan

  • Python: 1186 passed, 69 skipped, 0 failed
  • TypeScript: 1095 passed, 21 skipped (42 test files)
  • Ruff: all checks passed
  • Mypy: no issues in 148 source files
  • python -m build --sdist: success
  • Import time: 16ms (target <200ms)
  • TS build: ml + core + n8n all build clean

- Fix docs URL: cascadeflow.dev → cascadeflow.ai in pyproject.toml
- Update SECURITY.md supported version: 0.7.x → 1.0.x
- Fix __author__: "Sascha Buehrle" → "Lemony Inc."
- Fix branding in requirements.txt: CascadeFlow → cascadeflow
- Fix README code block language: python → bash for pip install
- Update init() docstring to describe actual SDK patching behavior
- Add missing License :: OSI Approved :: MIT License classifier
Keep a Changelog format covering all v1.0.0 highlights including
harness API, framework integrations, security hardening, lazy imports,
and breaking changes from this hardening cycle.
Move numpy import inside methods that use it so that
`import cascadeflow` does not trigger a numpy load.
Only BaseProvider, ModelResponse, and PROVIDER_CAPABILITIES are
imported eagerly. All 9 provider classes and PROVIDER_REGISTRY
are loaded on first access.
- Rewrite cascadeflow/__init__.py with _LazyModule proxy for backward-compat
  sys.modules aliases (no eager import of core/schema packages)
- Rewrite core/__init__.py with PEP 562 lazy imports (defers litellm via batch)
- Move ~100 symbols to _LAZY_IMPORTS dict, loaded on first access
- Reduce __all__ from 127 to ~20 essential public API symbols
- Remove stale __version__ strings from 7 submodule __init__.py files
- Fix telemetry get_telemetry_info() to use package-level version
Add `langchain = ["langchain-core>=0.2.0"]` to optional-dependencies
and include it in the `all` extra bundle.
Remove v0.1.x backward-compat parameters from CascadeAgent constructor:
config, tiers, workflows, enable_caching, cache_size, enable_callbacks.

These were deprecated since v0.2 and scheduled for removal. The backward
compat block (warnings + silent conversion) is removed. Attributes
tier_router, _legacy_tiers, _legacy_workflows default to None.
Replace None stubs with _MissingIntegration proxy that raises
ImportError with install hint on any attribute access or call.
Users get actionable error messages like:
  "LangChain requires additional dependencies. Install with:
   pip install cascadeflow[langchain]"

Also update tier-related tests to reflect deprecated param removal.
- Change CORS default from '*' (open) to None (opt-in)
- Add auth_token field to ProxyConfig; Bearer token check on all
  endpoints except /health (returns 401 on mismatch)
- Add max_body_bytes (default 10 MB) with 413 rejection
- Expose --auth-token and --max-body-bytes CLI flags
Wrap patch_openai(), unpatch_openai(), patch_anthropic(), and
unpatch_anthropic() in _patch_lock to prevent race conditions when
init()/reset() are called from multiple threads.
- Add _lock and _increment() method to HarnessRunContext for
  thread-safe counter updates from concurrent instrument hooks
- Change _trace from list to collections.deque(maxlen=1000) — removes
  manual slicing, O(1) append, automatic eviction
- Update instrument.py to use ctx._increment() instead of direct +=
Move all re.search() calls in detect() and helper methods to use
pre-compiled patterns: trivial/code patterns, conditional/requirement
words, keyword boundary patterns, complexity signals, function call
indicators, trivial concepts, multi-word technical terms, and
long-context QA markers. Also promote context/question marker lists
to class-level constants.
- Move rich from core dependency to optional extra with stdlib fallback
  in utils/helpers.py (setup_logging gracefully degrades)
- Add Python 3.13 classifier and CI test matrix entry
- Remove || echo "No tests defined yet" CI fallback that swallowed failures
- Migrate @xenova/transformers → @huggingface/transformers (deprecated)
- Fix workspace:^ → workspace:* in langchain-cascadeflow package.json
- Remove License classifier conflicting with PEP 639 license field
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)
@saschabuehrle saschabuehrle merged commit e779ba5 into main Mar 8, 2026
33 checks passed
@saschabuehrle saschabuehrle deleted the hardening/v1.0.0 branch March 8, 2026 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant