Repository navigation
docs: surface file-size and module-split thresholds in code-guidelines - #1181
Conversation
The file-size and module-split thresholds (800/1,200/1,500-line table, the nemotron_h.rs and llama4.rs exceptions, and the inline-test-to-sibling-file tiering) previously existed only in the agent-facing .claude/skills/mlxcel-code-structure/SKILL.md, which no contributor-facing document referenced. PR #1173's commit body cited a nonexistent "500-line limit" because the real guidance was not discoverable from docs/ or CONTRIBUTING.md. Add a "File Size and Module Structure" section to docs/code-guidelines.md as the single authoritative home for these numbers, covering the size table, the two documented exceptions with their reasons, the inline-test-versus-sibling-file threshold, and the helpers/tests naming convention. Widen CONTRIBUTING.md's three references to docs/code-guidelines.md, which previously described it narrowly as "the shared-function rules," to also cover the new section, and add a Code standards bullet pointing at it directly. The local .claude/skills/mlxcel-code-structure/SKILL.md was also edited to link to the new section instead of restating the numbers, but that path is gitignored repo-wide (see .gitignore) and is not part of this commit.
…bout an untracked file The section asserted that .claude/skills/mlxcel-code-structure/SKILL.md links here instead of restating the thresholds. That is not verifiable from this repository: .gitignore line 28 ignores /.claude/, so the skill file ships no tracked content here, and the copy that is tracked lives in the internal development repository where it still carries the table. Restates the sentence as the rule it was meant to express: this section is authoritative, and anything citing the numbers should link here rather than repeat them. That is true today and stays true regardless of what any particular consumer currently contains.
Three of the four examples were wrong against the current tree. qwen2.rs is a 31-line re-export shim over llama3, not a 600-line complete model, so it was replaced with dbrx.rs (606 lines, 15 struct/impl definitions, no re-export). nemotron_h.rs is about 2,900 lines rather than 2,342, and llama4.rs about 1,860 rather than 1,499. The llama4 entry was also miscast. It has a llama4_helpers.rs, so it is not a file that ignored the guidance; it is the 1,200+ row working as intended, which is a more useful thing to show than a second exception. nemotron_h.rs remains the standing exception and is the only one of the two with no helpers file. Adds a line telling readers the figures are approximate and to check the file, since these numbers went stale once already in the source this section was assembled from.
The File Size and Module Structure section called `src/models/nemotron_h.rs` the standing exception, which is false on this tree. Measured with `wc -l`, `src/models/gemma4.rs` is 6,680 lines with no helpers file, `src/models/gemma3n.rs` is 5,594 and `src/models/qwen3_5.rs` is 3,451 with no helpers file, all larger than nemotron_h.rs at 2,914. Nine files under `src/models/` exceed 2,000 lines and seven of those carry no helpers file, so the singular framing told a contributor the tree has one carve-out when it has many, and it left the real outliers unnamed. The replacement demotes nemotron_h.rs to a documented exception, names gemma4.rs, qwen3_5.rs and gemma3n.rs as debt rather than precedent, and says explicitly that the largest file in the tree is not a number to cite in a review. The llama4 bullet also overstated its own extraction. `src/models/llama4_helpers.rs` is 84 lines against llama4.rs at 1,862, so calling it the bulk that could be lifted out was wrong, and llama4.rs does cross the 1,500+ row without splitting into a directory module, so framing it as the table working overclaimed. The bullet now names what actually moved (mask construction and weight loading) and drops the claim that the file is not an exception. `docs/README.md` entry 19 still described `code-guidelines.md` as covering only the `// Used by:` convention and the JIT kernel rule, so a contributor browsing the docs index would not learn that the thresholds live there. That is the same discoverability gap this branch set out to close. The entry now leads with the file-size and module-split thresholds, including the `<name>_helpers.rs` extraction point and the inline-tests-to-`_tests.rs` move. Refs #1178
Implementation Review SummaryIntentGive the file-size and module-split thresholds a contributor-facing home in Independent verification of every factual claim in the new sectionAll measured against the branch with
The threshold table is a faithful transcription of the source ( Findings addressed
Curation judgmentThe subset carried over is right. The issue's Technical Considerations names four things that should travel with the thresholds (the 200-line inline-test rule, the Cross-repo duplicationWithin this repository the numbers now live in exactly one tracked place: Verification
|
Bilingual report covering the relocation of the file-size thresholds into contributor-facing docs: why the guidance was unreachable rather than merely hard to find, why the numbers had to be verified rather than transcribed, and the cross-repository duplication that remains because the tracked copy of the skill file lives in the internal development repository. Records the four figures that were stale and the exception framing that survived the first correction.
lablup#1181) ## Summary The file-size and module-split thresholds existed only in the agent-facing `.claude/skills/mlxcel-code-structure/SKILL.md`, with no contributor-facing document referencing them, which is how PR lablup#1173's commit body ended up citing a nonexistent "500-line limit." This PR adds a "File Size and Module Structure" section to `docs/code-guidelines.md` as the single authoritative home for those numbers, and widens the places that describe that document so the guidance is reachable by the normal contributor path. ## Option chosen Option 1 from the issue: the thresholds live in `docs/code-guidelines.md`, and the section states as a rule that anything else citing them, agent-facing tooling under `.claude/skills/` included, should link there rather than restate them. This is preferable because the thresholds are project convention that any human contributor needs, not agent-specific configuration; a document only agents read is the wrong home for a rule contributors are expected to follow. The tradeoff is that the skill file's structural rules are now split across two documents for a reader working through it top to bottom, but the pointer names exactly what moved and where, so that cost is small next to having one number that cannot drift. The rule is written prescriptively rather than as a claim about what any particular consumer currently contains, because no such claim is verifiable from this repository. ## Correction to the brief The brief this implementation started from asserted that `.claude/skills/` is tracked in this repository and instructed treating the skill-file edit as a real committed change. That is incorrect: `.gitignore` line 28 is `/.claude/`, committed at `HEAD`, and `git ls-files .claude/` returns zero files, so the entire `.claude/` directory is untracked here and ships no content with the repository. What was missing was therefore not de-duplication within this repository but a discoverable, contributor-facing home for the numbers, which this PR adds. ## What changed - `docs/code-guidelines.md`: new "File Size and Module Structure" section before "Shared Function Comments", carrying the size table (under 800 fine as a single file, 800 to 1,200 acceptable with a helpers file, 1,200+ extract `<name>_helpers.rs`, 1,500+ consider a directory module, 2,000+ with no helpers file as the anti-pattern), the reason-based exception for `nemotron_h.rs`, `llama4.rs` as an illustration of the 1,200+ row, an explicit note that several files sit well past the thresholds and should be read as debt rather than as precedent, the inline-test-versus-sibling-`_tests.rs` threshold (roughly 100 lines to move, 200 at the latest) with the wiring both forms of which this repository already uses, and the `<name>_helpers.rs` / `<name>_tests.rs` naming convention. - `CONTRIBUTING.md`: widened the intro paragraph and the "Quick links" row describing `docs/code-guidelines.md`, which called it narrowly the shared-function rules, and added a "Code standards" bullet linking straight to the new section. - `docs/README.md`: widened entry 19, which described `code-guidelines.md` as covering only the `// Used by:` convention and the JIT kernel rule, so the docs index names the thresholds too. Every line count quoted in the new section was measured against this branch rather than carried over, because the source this section was assembled from had gone stale: it recorded `nemotron_h.rs` at 2,342 lines (actually 2,914) and `llama4.rs` at 1,499 (actually 1,862), and its "complete model in one file" example, `qwen2.rs`, is a 31-line re-export shim over `llama3`, so `dbrx.rs` (606 lines, a full model through `impl LanguageModel`) replaced it. The section also tells readers the figures are approximate and to check the file rather than trust a number quoted anywhere, that section included. What was deliberately left in the skill file rather than carried into `docs/`: the module-versus-directory trigger, trait-placement rules, the model-registration checklist, subsystem dependency-direction rules, error-handling and config-deserialization patterns, and the rest of the anti-patterns table. That material is about how to structure new code while implementing a model, not something a contributor looks up as a size or split threshold. Out of scope, per the issue: the `0adb53c5` commit body on `main` is not rewritten, the PR lablup#1173 technical report already records the discrepancy correctly, and the thresholds themselves are unchanged, only relocated and surfaced. ## Test plan - [x] Documentation-only change; no code or test files touched, so there is nothing for `cargo test` to exercise. - [x] Every file path and line count cited in the new section verified against this branch with `wc -l`, including that `nemotron_h.rs` has no sibling `_helpers.rs` and `llama4.rs` does. - [x] Confirmed `gemma3n_helpers.rs`, `llama4_helpers.rs` and `qwen3_next_helpers.rs` are the only `*_helpers.rs` files under `src/models/`. - [x] Confirmed `dbrx.rs` is a complete model (`Attention`, `SparseMoeBlock`, `DecoderLayer`, `DbrxModel`, `impl LanguageModel`) rather than a re-export shim. - [x] Confirmed the outlier claim: `gemma4.rs` 6,680 lines and `qwen3_5.rs` 3,451 lines both with no helpers file, `gemma3n.rs` 5,594 lines, and nine files under `src/models/` over 2,000 lines. - [x] Confirmed the `CONTRIBUTING.md` anchor `#file-size-and-module-structure` matches the `## File Size and Module Structure` heading, with no duplicate heading that would shift the slug. - [x] Confirmed the described sibling-test wiring matches this repository: both `#[cfg(test)] mod <name>_tests;` and the `#[path = "..."]` form are in use. Closes lablup#1178
Summary
The file-size and module-split thresholds existed only in the agent-facing
.claude/skills/mlxcel-code-structure/SKILL.md, with no contributor-facing document referencing them, which is how PR #1173's commit body ended up citing a nonexistent "500-line limit." This PR adds a "File Size and Module Structure" section todocs/code-guidelines.mdas the single authoritative home for those numbers, and widens the places that describe that document so the guidance is reachable by the normal contributor path.Option chosen
Option 1 from the issue: the thresholds live in
docs/code-guidelines.md, and the section states as a rule that anything else citing them, agent-facing tooling under.claude/skills/included, should link there rather than restate them. This is preferable because the thresholds are project convention that any human contributor needs, not agent-specific configuration; a document only agents read is the wrong home for a rule contributors are expected to follow. The tradeoff is that the skill file's structural rules are now split across two documents for a reader working through it top to bottom, but the pointer names exactly what moved and where, so that cost is small next to having one number that cannot drift.The rule is written prescriptively rather than as a claim about what any particular consumer currently contains, because no such claim is verifiable from this repository.
Correction to the brief
The brief this implementation started from asserted that
.claude/skills/is tracked in this repository and instructed treating the skill-file edit as a real committed change. That is incorrect:.gitignoreline 28 is/.claude/, committed atHEAD, andgit ls-files .claude/returns zero files, so the entire.claude/directory is untracked here and ships no content with the repository. What was missing was therefore not de-duplication within this repository but a discoverable, contributor-facing home for the numbers, which this PR adds.What changed
docs/code-guidelines.md: new "File Size and Module Structure" section before "Shared Function Comments", carrying the size table (under 800 fine as a single file, 800 to 1,200 acceptable with a helpers file, 1,200+ extract<name>_helpers.rs, 1,500+ consider a directory module, 2,000+ with no helpers file as the anti-pattern), the reason-based exception fornemotron_h.rs,llama4.rsas an illustration of the 1,200+ row, an explicit note that several files sit well past the thresholds and should be read as debt rather than as precedent, the inline-test-versus-sibling-_tests.rsthreshold (roughly 100 lines to move, 200 at the latest) with the wiring both forms of which this repository already uses, and the<name>_helpers.rs/<name>_tests.rsnaming convention.CONTRIBUTING.md: widened the intro paragraph and the "Quick links" row describingdocs/code-guidelines.md, which called it narrowly the shared-function rules, and added a "Code standards" bullet linking straight to the new section.docs/README.md: widened entry 19, which describedcode-guidelines.mdas covering only the// Used by:convention and the JIT kernel rule, so the docs index names the thresholds too.Every line count quoted in the new section was measured against this branch rather than carried over, because the source this section was assembled from had gone stale: it recorded
nemotron_h.rsat 2,342 lines (actually 2,914) andllama4.rsat 1,499 (actually 1,862), and its "complete model in one file" example,qwen2.rs, is a 31-line re-export shim overllama3, sodbrx.rs(606 lines, a full model throughimpl LanguageModel) replaced it. The section also tells readers the figures are approximate and to check the file rather than trust a number quoted anywhere, that section included.What was deliberately left in the skill file rather than carried into
docs/: the module-versus-directory trigger, trait-placement rules, the model-registration checklist, subsystem dependency-direction rules, error-handling and config-deserialization patterns, and the rest of the anti-patterns table. That material is about how to structure new code while implementing a model, not something a contributor looks up as a size or split threshold.Out of scope, per the issue: the
0adb53c5commit body onmainis not rewritten, the PR #1173 technical report already records the discrepancy correctly, and the thresholds themselves are unchanged, only relocated and surfaced.Test plan
cargo testto exercise.wc -l, including thatnemotron_h.rshas no sibling_helpers.rsandllama4.rsdoes.gemma3n_helpers.rs,llama4_helpers.rsandqwen3_next_helpers.rsare the only*_helpers.rsfiles undersrc/models/.dbrx.rsis a complete model (Attention,SparseMoeBlock,DecoderLayer,DbrxModel,impl LanguageModel) rather than a re-export shim.gemma4.rs6,680 lines andqwen3_5.rs3,451 lines both with no helpers file,gemma3n.rs5,594 lines, and nine files undersrc/models/over 2,000 lines.CONTRIBUTING.mdanchor#file-size-and-module-structurematches the## File Size and Module Structureheading, with no duplicate heading that would shift the slug.#[cfg(test)] mod <name>_tests;and the#[path = "..."]form are in use.Closes #1178