diff --git a/docs/architecture/tech-debt.md b/docs/architecture/tech-debt.md index 6be20245..df49e5c0 100644 --- a/docs/architecture/tech-debt.md +++ b/docs/architecture/tech-debt.md @@ -54,7 +54,7 @@ What the pass did, by `scripts/dev/explicit_imports.py` (with `scripts/dev/rust_ | Crate | "Moved out" headers | `#[allow(unused_imports)] use super::*;` files | What stays a glob | |---|---|---|---| -| `cuda-driver` | 471 -> 0 | 564 -> 564 | all: the compile-and-prune loop reached a state it could not close (glob sources the tool cannot trace, `macro_rules!` and item-defining macro calls, 172 files under cfg-gated names, 17 under platform cfg); two attempts with the failing top-level modules excluded were interrupted by the laptop GPU stretch, so the crate got the doc headers only | +| `cuda-driver` | 471 -> 0 | 564 -> 564 in the first pass; 571 -> 3 production globs in the second pass (below) | | `engine-qwen35-cuda` | 343 -> 0 | 407 -> 236 | 127 platform cfg, 105 under cfg-gated names; `open_parts.rs` stays a glob on purpose (it is at the 400-line limit and the explicit list would put it over) | | `strata-control` | 66 -> 0 | 113 -> 22 | 5 platform cfg, 17 under cfg-gated names (the `responses` and `messages` trees) | | `leleka-model-format` | 54 -> 0 | 77 -> 10 | platform cfg (`bulk_read`, `gguf_resident`, `kar`) | @@ -69,12 +69,83 @@ explicit import would need the same `cfg`); a glob that comes from a crate outsi each: one author-side pass per crate, adding the cfg on the import or a platform-aware compile (a Windows `cargo check` for the crates that build there: `leleka-deploy`, `strata-control`, `leleka-model-format`); estimate one to two days for `cuda-driver` (group by top-level module, bisect the failing group), an hour for each other crate. -What is left of the owner's request in (c): the file names. They are descriptive in most places but still carry the split's function list -(`governor_admit_and_relieve.rs`, `tokenizer_error_display_error.rs`, `gguf_bpe_methods.rs`); a rename needs a person who knows the responsibility, so it -is not generated. The rule for new splits: after `scripts/dev/rustsplit`, run `python scripts/dev/explicit_imports.py ` -and write the real doc comment; the two new source ratchets `glob-super-import` and `allow-unused-imports` (`architecture.json`) fall with every file -that is fixed and fail the gate when a split adds one. `crates/libc-shim` (Windows-only, not built on Linux) was done by hand: `cuda_trace/enabled.rs` -is now `trace_state.rs` and `w_launch.rs` is `launch_interposers.rs`. +#### Second pass: the low-level crates (owner order 2026-11-14, branch `claude/arch-names-low`) + +The owner ordered the rework finished for the crates below the engine: the files with `#[allow(unused_imports)] use super::*;`, the names left by the +mechanical splits, and the cheap ratchets. Counts are production code, from `scripts/check-architecture.py`; the other agent's crates +(`engine-*`, `leleka-runtime`, `runtime-client`, `control-plane`, `desktop-core`, `deploy`, `gateway-*`) are not in these tables. + +| Ratchet, all low-level crates together | before | after | +|---|---|---| +| `glob-super-import` | 674 | 3 | +| `allow-unused-imports` | 1,097 | 552 (the rest are `pub use` re-exports and names of other cargo feature sets) | +| `env-read` | 122 | 28 (five crates now have one reader each, see below) | + +| Crate | `glob-super-import` | `allow-unused-imports` | +|---|---|---| +| `cuda-driver` | 571 -> 3 | 863 -> 410 | +| `native-cpu-expert` | 15 -> 0 | 89 -> 75 | +| `model-format` | 16 -> 0 | 32 -> 22 | +| `cpu-sys` | 13 -> 0 | 48 -> 35 | +| `igpu` | 18 -> 0 | 20 -> 2 | +| `gptoss` | 17 -> 0 | 16 -> 0 | +| `gptoss-npu`, `gptoss-igpu`, `openvino`, `gguf`, `cpu-kernels`, `gpu-npu-worker` | 24 -> 0 | 36 -> 0 | +| `cpu-worker`, `tokenizer`, `leleka-memory` | 3 -> 0 | 0 | + +**Imports.** `scripts/dev/explicit_imports.py` now converges on `cuda-driver`. What it learned, each from a failure of the first pass: + +* *Names behind a cfg.* A name that exists only under a `cfg` (the `cuda-driver` feature gate of the root exports) is imported without an attribute when the + module itself sits under the same gate, and with `#[cfg()] use super::..;` otherwise. It no longer treats every CamelCase or + CONSTANT import as a possible trait: it follows the `use` path to the definition (the 172 "cfg-gated names" files were mostly this). +* *Module paths.* Children declared by `#[path]` are ordered by module depth, not directory depth; a name reached through a glob chain (`pub use x::*` in a + `#[path]` module) resolves; a file declared by several parents is left alone; `include!`d files count as part of the includer (the four `ffi` files); + `std::arch` intrinsics (`_mm256_*`, `_CMP_*`) come through the glob of the parent and are imported by name; `static mut NAME` in an `extern` block is a name. +* *Test builds.* The cause of the old non-convergence: `cargo check --tests` also builds the library for the integration tests and prints a warning + that two units share only once, so a name that only the unit tests use looked unused and was removed. The prune now takes "unused" from the build without + `cfg(test)` and keeps a name as `#[cfg(test)] use` when the test items of the file mention it (a trait is kept for the test build to judge). +* *Gates.* The tool waits while `.git/laptop-gpu-wanted.flag` or `laptop-gpu-run.lock` exist (the laptop is the GPU test machine too) and while Windows has + less than 2.5 GB free (at most two minutes per build). `--prune` re-runs on an expanded crate; `ONLY` and `EXCLUDE` select top-level modules; + `BASE_CONFIG="--features cuda-driver"` is the smallest feature set that builds, where names used only by other feature sets get a narrow + `#[allow(unused_imports)]` with a comment. + +Left, with the next step: + +| Item | Why | Next step | +|---|---|---| +| `cuda-driver/src/root_exports.rs` (glob) | it re-exports `serving_context` (a module of `leleka-cuda-model` and a function of the same name); an explicit import clashes | re-export the function by its full path and name the module import differently in `lib.rs` | +| `cuda-driver/src/mtp_original_full_head_dispatch.rs` (glob) | declared as a module by three parents (`mtp_original_full_forward`, `mtp_original_prefill`, `mtp_original_scalar_prefill`), so its names differ per parent | one parent declares it; the others `use` it | +| `cuda-driver/src/mmq_original_group/copy_ring_layer.rs` (glob) | exactly 400 lines; the explicit list would put it at 403 | move its free functions (`format_index`, the projection handles) to a file of their own, then expand | +| 410 `allow(unused_imports)` in `cuda-driver`, 75 in `native-cpu-expert`, 35 in `cpu-sys`, 22 in `model-format` | `pub use` re-exports of the split files (the old paths), a few names of other cargo feature sets, `c_reference` | the re-exports stay while other crates and tests use the old paths; replace them one module at a time by the real path | +| `cuda-driver` in the default feature set | does not compile at the base commit either (`root_exports.rs` re-exports `original_verify::sm120::set_overrides` without the feature gate); the product builds with `--features cuda-driver`, which was checked, with `sm86` and with all features | put the missing `#[cfg]` on that line | +| the Windows-only code (9 platform-cfg files of `cuda-driver`) | the tool compiles on Linux; their unused names were kept under a narrow allow | a native Windows `cargo check -p leleka-cuda-driver --features cuda-driver` and a prune on it | +| `crates/libc-shim` | Windows only, nothing to expand | none | + +**Names.** 61 modules were renamed with `git mv` (the file, its directory, the `mod` line and the `#[path]` of its parent, the paths that name it, the doc +comment), by `scripts/dev/rename_module.py` and a mapping written by hand from what each file holds. Examples: `leleka-memory` +`governor/governor_methods/governor_admit_and_relieve.rs` -> `governor/operations/admission.rs` (with `setup`, `status_report`, `archive_guard`, +`archive_residency_tick`); `cuda-driver` `api/enabled.rs` and five more `enabled.rs` -> `driver_backed.rs`; the `*_methods.rs` files of `cuda-driver` -> +`*_lifecycle.rs`, `*_operations.rs` (a group of files that implement one type) or `window_launches.rs`; `native_parity/state.rs` -> `parity_session.rs`; +`original_expert_stager/shared.rs` -> `stager_workers.rs`; `tokenizer/.../tokenizer_error_display_error.rs` -> `error_messages.rs`; +`model-format/.../kar_error_display_error.rs` -> `inspection.rs`; `native-cpu-expert/src/rust_ggml_extra.rs` -> `rust_ggml_iq1_ternary_fp4.rs`. Every renamed +file has a doc comment that says what it holds and why it is a file of its own. Left on purpose: + +* the 55 `*_and_*.rs` names (33 in `cuda-driver`, 7 in `cpu-sys`, 7 in `igpu`, the rest elsewhere): each names the two things the file holds and its doc + line says so; a single word would need a split, which is a design change (next step with the owner of each crate); +* `cuda-model/src/mmq_original_prefill_misc.rs`: named after the CUDA source `mmq_original_prefill_misc.cu` and its PTX, which the sm86 table and the oracle script quote; +* `cuda-driver/src/qsa_resident_transfer/enabled.rs`: its parent also declares an inline `mod enabled` for the build without the feature, so only the pair can be renamed together; +* the `*_types.rs` and `*_drop.rs` files (a file of one type's definitions, a file of one `Drop`): the name says what is in it; +* test files named by the sentence of their test. + +**Cheap ratchets.** `env-read`: `cuda-driver` (67 -> 2), `native-cpu-expert` (19 -> 2), `cuda-model` (5 -> 2), `gptoss` (6 -> 1) and `model-format` (5 -> 1) read +the environment only in their new `settings.rs` (`settings::var`, `settings::var_os`: `#[inline]` pass-throughs; `scripts/dev/funnel_env_reads.py`). The reads, their +parsing and the `OnceLock` switches are where they were; the step to a parsed `Settings` value is the one listed in (b). `instant-now`, `process-global` +and `dyn-trait` did not move: the `Instant::now()` calls of these crates are stall and profile spans in the launch paths and the expert pool, which +this order said not to touch; they need a clock parameter that is designed once for the pool and the driver. + +**Identity.** Renames, imports and the settings funnel do not change generated code. The checks are `cargo check --all-targets` of the touched crates (the +driver with `--features cuda-driver`, with `sm86` and with all features), their tests, and the unchanged public paths. No GPU identity job was queued (the +server is busy with the owner's service); the laptop two-binary identity gate (base `23bdbb308`, new = main after both refactor branches) is the check +for the end state. ### (b) Source ratchets: measured, classified, not moved in this pass @@ -98,7 +169,7 @@ No source ratchet was raised. `leleka-memory`: `dyn-trait` 17 -> 12 (`HostFacts: 2. The decode-phase glue and the MTP window loop: `generate_mtp_resume` (250 lines, complexity 44), `generate`, `OriginalServeStack::open` (section `backend/`); needs the GPU identity and A/B gates, so it is a step of its own. 3. `WeightSource` follow-ups: shard open and bind, KAR verification, the governor's mappings (section S18). 4. Gateway: `create` (391 lines), `render_request_with` (385) and the other entries of the limits table at the end of this file. -5. The `leleka-memory` governor module is still split by function lists (`governor_methods/`, `governor_admit_and_relieve.rs`); the explicit imports are done where the platform cfg allows, the names need a responsibility pass (admission, pressure, archive guard, report). +5. Done in the second pass of (c): the `leleka-memory` governor is `governor/operations/{admission, setup, status_report, archive_guard, archive_residency_tick}.rs`. ## crates/engine-qwen35-cuda `backend/` (formerly leleka-runtime; STRA-338 S5a, S5b)