Skip to content

Address PR #252 review findings: error handling, types, tests#257

Merged
neuromechanist merged 3 commits intodevelopfrom
feature/issue-256-review-findings
Mar 9, 2026
Merged

Address PR #252 review findings: error handling, types, tests#257
neuromechanist merged 3 commits intodevelopfrom
feature/issue-256-review-findings

Conversation

@neuromechanist
Copy link
Member

Summary

Addresses all findings from the comprehensive PR #252 review (5 specialized agents: code-reviewer, silent-failure-hunter, test-analyzer, comment-analyzer, type-design-analyzer).

Error Handling (7 fixes)

  • Add CorruptMirrorError/ValueError handling to all 4 mirror endpoints that were missing it
  • Block unknown models on platform/community keys (fail-closed instead of fail-open)
  • Add OSError handling to create_mirror_endpoint
  • Make cleanup_expired_mirrors resilient to per-mirror deletion failures
  • Narrow _cleanup_mirrors scheduler catch to expected exception types
  • Add field_validator to RefreshMirrorRequest.community_ids
  • Replace deprecated asyncio.get_event_loop() with get_running_loop()

Type Design (4 improvements)

  • Make MirrorInfo a frozen dataclass with tuple community_ids
  • Move is_safe_identifier to src/core/validation.py (shared utility)
  • Add non-negativity validation to MODEL_PRICING at import time
  • Expand SecureFormatter key patterns for Anthropic/OpenAI keys

Comment/Docstring Fixes (4 fixes)

  • Fix enable_caching docstring ("enabled" -> "requested")
  • Fix asyncio.to_thread comment (code uses run_in_executor)
  • Fix get_model docstring example (claude-3-5-sonnet -> claude-3.5-sonnet)
  • Fix ContextVar comment accuracy (request lifecycle, not per-task copy)

Tests (9 new tests)

  • active_mirror_context: set/reset, exception safety, validation
  • MirrorInfo invariants: empty ids, invalid id, immutability, serialization round-trip
  • TTL clamping in create_mirror
  • run_sync_now invalid sync_type validation
  • Updated cost protection test for fail-closed behavior

Test plan

  • All 86 unit tests pass (77 existing + 9 new)
  • Full test suite: 1681 passed (6 pre-existing failures unrelated to this PR)
  • Ruff lint and format pass
  • Pre-commit hooks pass

Closes #256

Error handling:
- Add CorruptMirrorError/ValueError handling to all mirror endpoints
- Block unknown models on platform/community keys (fail-closed)
- Add OSError handling to create_mirror_endpoint
- Make cleanup_expired_mirrors resilient to per-mirror failures
- Narrow scheduler cleanup catch to expected exception types
- Add field_validator to RefreshMirrorRequest.community_ids

Type design:
- Make MirrorInfo a frozen dataclass with tuple community_ids
- Move is_safe_identifier to src/core/validation.py (shared utility)
- Add non-negativity validation to MODEL_PRICING at import time
- Expand SecureFormatter key patterns for Anthropic/OpenAI keys

Code quality:
- Replace deprecated asyncio.get_event_loop() with get_running_loop()
- Fix ContextVar comment accuracy (request lifecycle, not per-task)
- Use get_active_mirror() instead of _active_mirror_id.get()
- Fix docstring inaccuracies (caching, asyncio, model names)

Tests:
- Add active_mirror_context tests (set/reset, exception safety)
- Add MirrorInfo invariant tests (empty ids, invalid id, immutability)
- Add serialization round-trip test
- Add TTL clamping test
- Add run_sync_now invalid sync_type test
- Update cost protection test for fail-closed behavior

Closes #256
- Change redaction string from "sk-or-v1-***[redacted]" to
  "***[key-redacted]" since the pattern now covers multiple providers
- Remove __all__ from mirror.py since no callers use wildcard imports
  from that module (is_safe_identifier now lives in core.validation)
- Add missing ValueError handling in delete_mirror_endpoint for
  consistency with all other mirror endpoints
- Add community ID validation in MirrorInfo.__post_init__ so corrupt
  metadata with path-traversal community IDs is caught at load time
- Document CorruptMirrorError in refresh_mirror docstring
@neuromechanist neuromechanist merged commit 8d1d407 into develop Mar 9, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant