MoonshotAI / MoonshotAI/MoonEP
Use proper exceptions instead of assert for user-facing validation
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.1k
- Forks
- 134
- PR merge metrics
- No merged PRs in 30d
Description
Problem
The codebase uses assert statements extensively for input validation and invariant checking (in api.py, buffer.py, planning.py, dispatch.py, combine.py, etc.). In Python, assert statements are stripped when running with -O (optimize) flag, which is common in production environments. This means all safety checks silently disappear in production.
Example
# buffer.py — currently
assert src_rank != self.rank, "Cannot map local tensor"
# Should be
if src_rank == self.rank:
raise ValueError("Cannot map local tensor: src_rank equals current rank")
Scope
Affected files:
moonep/api.py— context creation, dispatch/combine validationmoonep/buffer.py— VMM allocation, IPC fd exchangemoonep/planning.py— planning kernel validationmoonep/dispatch.py— dispatch kernel validationmoonep/combine.py— combine kernel validationmoonep/grad_reduce.py— grad reduce validation
Recommendation
Replace all user-facing assert with ValueError / RuntimeError / TypeError. Keep assert only for truly internal invariants that should never fire regardless of input.
Priority order:
buffer.py— IPC fd exchange and VMM allocation (resource leak risk)api.py— top-level API validation (user-facing)- Kernel launch functions — shape/dtype validation
Impact
Production safety. Without this fix, running with python -O silently disables all validation, potentially causing undefined behavior (wrong results, GPU crashes, or silent memory corruption) instead of clear error messages.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by auditing the assertions in moonep/buffer.py and moonep/api.py, then review planning.py, dispatch.py, combine.py, and grad_reduce.py for user-facing validation. Run the relevant entry points with and without Python's -O flag to compare behavior. Done means user-facing checks raise suitable exceptions under optimization while truly internal invariants remain assertions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend, distributed-systems
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100