MoonshotAI / MoonshotAI/MoonEP

Replace 30+ key context dict with typed dataclass

Open
#2 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.1k
Forks
134
PR merge metrics
No merged PRs in 30d

Description

Problem

The api.py context dictionary has 30+ keys passed around as a plain dict. This is error-prone:

  • No type hints → no IDE autocompletion
  • No validation → typos in key names silently fail
  • No documentation → each consumer has to guess what keys exist

Example

# Current — plain dict with 30+ keys
ctx = {
    "rank": 0, "num_ranks": 16, "E": 896, "B": 16,
    "H": 128, "H_prime": 128, "K": 16,
    # ... 20+ more
}
# Passed to every function; misspelling a key = silent KeyError at runtime

# Suggested — typed dataclass
@dataclass
class MoonEPContext:
    rank: int
    num_ranks: int
    E: int          # total experts
    B: int          # local prefetch slots
    H: int          # hidden dim
    H_prime: int    # expert FFN dim
    K: int          # top-k
    # ...

Impact

  • Developer experience: IDE support, autocompletion, type checking
  • Maintainability: clear contract of what the context contains
  • Debugging: ctx.H vs ctx["H"] — the former fails at construction time if missing, the latter fails deep in a kernel launch

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in api.py by locating where the 30+ key context dictionary is constructed and passed to consumers, then inventory the keys and their uses. Define the typed context contract from that usage and update the affected consumers. Done means the context is no longer passed as a plain dict and its fields provide the stated typing and validation benefits.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend-api-design
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.