Address PR #252 review findings: error handling, types, tests#257
Merged
neuromechanist merged 3 commits intodevelopfrom Mar 9, 2026
Merged
Address PR #252 review findings: error handling, types, tests#257neuromechanist merged 3 commits intodevelopfrom
neuromechanist merged 3 commits intodevelopfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)
CorruptMirrorError/ValueErrorhandling to all 4 mirror endpoints that were missing itOSErrorhandling tocreate_mirror_endpointcleanup_expired_mirrorsresilient to per-mirror deletion failures_cleanup_mirrorsscheduler catch to expected exception typesfield_validatortoRefreshMirrorRequest.community_idsasyncio.get_event_loop()withget_running_loop()Type Design (4 improvements)
MirrorInfoa frozen dataclass withtuplecommunity_idsis_safe_identifiertosrc/core/validation.py(shared utility)MODEL_PRICINGat import timeSecureFormatterkey patterns for Anthropic/OpenAI keysComment/Docstring Fixes (4 fixes)
enable_cachingdocstring ("enabled" -> "requested")asyncio.to_threadcomment (code usesrun_in_executor)get_modeldocstring example (claude-3-5-sonnet->claude-3.5-sonnet)Tests (9 new tests)
active_mirror_context: set/reset, exception safety, validationMirrorInfoinvariants: empty ids, invalid id, immutability, serialization round-tripcreate_mirrorrun_sync_nowinvalid sync_type validationTest plan
Closes #256