diff --git a/docs/architecture/tech-debt.md b/docs/architecture/tech-debt.md index 22b71f63..ae6a6255 100644 --- a/docs/architecture/tech-debt.md +++ b/docs/architecture/tech-debt.md @@ -210,51 +210,38 @@ their doc comment now says by which phase), `ConversationManager` (a domain type The order: every ratchet of `architecture-baseline.json` goes to zero in the code, or to a named entry of the `exceptions` list of `architecture.json` (crate, file, ratchet, reason; the gate reads it, an entry that excuses nothing or has no reason is an error). Numbers are production code of the low-level crates (`cuda-driver`, `cuda-model`, `model-format`, `native-cpu-expert`, `leleka-memory`, `memory-os`, `libc-shim`, `cpu-sys`, the gpt-oss -workers and the small libraries), before -> after, from `scripts/check-architecture.py`. +workers and the small libraries), before -> after, from `scripts/check-architecture.py`. After the pass **no low-level crate has a number left in the +baseline**; what stays is the exceptions list (151 entries for these crates). -| Ratchet | Before | After | How | -|---|---|---|---| -| `allow-unused-imports` | 552 | 0 | `scripts/dev/prune_unused_imports.py`: strips the allow, compiles with one job per feature set (`cuda-driver`, `sm86`, all features), deletes the imports the compiler reports in every compilation unit, puts `#[cfg(test)]` on the ones only the library's unit tests use. Most of the 410 `cuda-driver` allows sat on `pub use` re-exports that needed no allow at all | -| `glob-super-import` | 3 | 2 (cuda-driver, see below) | `root_exports.rs` names its paths (`crate::x`, `leleka_cuda_model::serving_context`) | -| `path-include` | 132 | 0 counted (1 in `cuda-driver`, see below) | `scripts/dev/path_to_layout.py`: walks the module tree (a file loaded by `#[path]` resolves its children next to itself, a default file in a directory of its name), moves the module files to `/.rs` with `git mv`, drops the attribute, rewrites `include_*!` paths and the paths scripts quote (`scripts/dev/update_path_refs.py`). 502 files moved (`cuda-driver` 472, `model-format` 27, `native-cpu-expert` 3); module paths did not change. The gate now treats `#[cfg(test)] #[path = "../tests/x.rs"] mod x;` as test code | -| `env-read` | 30 | 0 outside EXC_ENV exceptions | one reader per crate: new typed `settings.rs` in `cpu-worker`, `tokenizer`, `gptoss-npu`, `gpu-npu-worker`, `igpu`, `npu-service`, `leleka-memory`, `gptoss`, `model-format` (functions named after the variable, returning parsed values); `obs` parses `LELEKA_LOG*` in `level.rs`; `cuda-model` has `env_switch::EnvSwitch` (the name, a typed rule, the answer cached on first read). Exceptions: the readers above, `cpu-kernels` (parses the ISA request), `libc-shim` and `memory-os` (platform adapters), the `npu-worker` and `native-parity-bench` roots | -| `dyn-trait` | 52 outside `cuda-driver` | 0 outside EXC_DYN exceptions | callbacks and probes became generics (`&mut (impl FnMut(..) + ?Sized)`, `&(impl ProcSource + ?Sized)`); what stays is a port boundary (`MemoryPressure`, `ProcSource`, `PageLocking`, `ModelBytes`, `PageSource`, `PrefillAccelerator`, `LayerCache`, the GPU probe closure), a trait method that must be dyn-compatible, `Box` of a library boundary, or the type-erased job of the worker pool | -| `instant-now` | 54 outside the driver and the CPU pool | 0 outside EXC_INSTANT exceptions | the clock adapter (`obs/time/clock.rs`) and measurement timers (stage laps and wall times printed in the workers' timing lines, load reports); each carries a comment that says so. `leleka-memory` reads `SystemClock` | -| `process-global` | 50 outside the driver and the CPU pool | 0 outside EXC_GLOBAL exceptions | immutable tables (regex, half table), operator settings read once, the process-wide logger, the process singletons the S13/S14 injection is for (`Governor::global()`, `Inventory`, the serving context, the verify stamps) | +| Ratchet | Before | After | Exceptions | How | +|---|---|---|---|---| +| `allow-unused-imports` | 552 | 0 | 0 | `scripts/dev/prune_unused_imports.py` strips the allow, compiles with one job per feature set (`cuda-driver`, `sm86`, all features), deletes the imports the compiler reports in every compilation unit and puts `#[cfg(test)]` on the ones only the library's unit tests use. Most of the 410 `cuda-driver` allows sat on `pub use` re-exports that needed no allow at all | +| `glob-super-import` | 3 | 0 | 0 | `root_exports.rs` names its paths; `head_dispatch` was compiled twice (declared by two parents with `#[path]`, so its glob meant two things): it is the one module `native_head_dispatch.rs` now; `copy_ring_layer.rs` (400 lines) is split into `copy_ring_layer` (execution) and `copy_ring_projection` (projection launches, status words) with explicit imports | +| `path-include` | 132 | 0 | 0 | `scripts/dev/path_to_layout.py` walks the module tree (a file loaded by `#[path]` resolves its children next to itself, a default file in a directory of its name), moves each module file to `/.rs` with `git mv`, drops the attribute and rewrites `include_*!` and the paths that scripts quote (`scripts/dev/update_path_refs.py`). 502 files moved (`cuda-driver` 472, `model-format` 27, `native-cpu-expert` 3); module paths did not change. The gate treats `#[cfg(test)] #[path = "../tests/x.rs"] mod x;` as test code | +| `env-read` | 30 | 0 | 19 | one reader per crate: typed `settings.rs` in `cpu-worker`, `tokenizer`, `gptoss-npu`, `gpu-npu-worker`, `igpu`, `leleka-memory`, `gptoss`, `model-format` (functions named after the variable, returning parsed values); `obs` parses `LELEKA_LOG*` in `level.rs`; `cuda-model` has `env_switch::EnvSwitch` (variable name, typed rule, answer cached on the first read), and the 26 on/off switches of `cuda-driver` are entries of its `settings.rs` catalogue. Exceptions: those readers, `cpu-kernels` (parses the ISA request), `libc-shim` and `memory-os` (platform adapters), the `npu-worker` and `native-parity-bench` roots. `cuda-driver` and `native-cpu-expert` keep a pass-through `var`/`var_os` for the option parsers (stager, stream-all, chain flags, sm120 switches, the pool's `STRATA_*`): their typed `Settings` value is the one open item of this ratchet | +| `dyn-trait` | 97 | 0 | 38 | callbacks and probes became generics (`&mut (impl FnMut(..) + ?Sized)`, `&(impl ProcSource + ?Sized)`, `&(impl ArenaMap + ?Sized)`, `&mut (impl Write + ?Sized)`); what stays is a port boundary (`MemoryPressure`, `ProcSource`, `PageLocking`, `ModelBytes`, `PageSource`, `PrefillAccelerator`, `LayerCache`, the GPU probe closure, the GEMM provider and the arena views of the verifier and the copy ring), a trait method that must be dyn-compatible, `Box` of a library boundary, or the type-erased job of the worker pool | +| `instant-now` | 106 | 0 | 48 | the clock adapter (`obs/time/clock.rs`) and measurement timers (stage laps and wall times printed in the workers' timing lines, load reports, the driver's launch-path spans and the CPU expert pool's phase timers); each carries a comment that says so. `leleka-memory` reads `SystemClock`. Replacing a timer by the `Clock` port would add a field or a generic to every launch owner and pool | +| `process-global` | 173 | 0 | 46 | `cuda-driver`: 96 -> 18 files left (the switches moved to `EnvSwitch`; what stays are parsed operator settings, probe and proof memos, the VRAM ledger); immutable tables (regex, half table), the process-wide logger, the process singletons the S13/S14 injection is for (`Governor::global()`, `Inventory`, the serving context, the verify stamps) | -The test run (`cargo test`, slim profile) of `cuda-model`, `obs`, `leleka-memory`, `tokenizer`, `model-format`, `gptoss`, `cpu-worker`, `igpu`, -`memory-os`, `experimental-ref` and `npu-service`: all green except the three known `qwen_artifact_binding` tests of `model-format` -(`cargo check --workspace --all-targets` is clean; `cuda-driver` and `native-cpu-expert` follow the hot-path branch, see below). +**Names.** 52 modules called after two things (`*_and_*`) are named after their responsibility, with the `*_and_*` names of test sentences left on purpose +(5): `cpu-sys` `avx2_and_avxvnni` -> `x86_dot_kernels`, `igpu` `error_and_kind` -> `gpu_error`, `cuda-driver` `projection_grids_and_bounds` -> +`projection_geometry`, `matrix_vector_buffers_and_shape` -> `matrix_vector_planning`, `original_expert_cache_open_and_slots` -> `original_expert_cache_slots`, +`gptoss` `state_and_cache` -> `decode_state`, `openvino` `compile_and_infer` -> `inference_runtime` (the full list is in the commit). **Docs.** The 604 generated +headers of these crates (`Methods of ...`, `Functions: ...`, `Split out of ...`) are real descriptions (what the file holds and why it is a file of its own); +the agents that wrote them reported about 80 files whose name does not match their content (for example `cuda-driver` `bringup_trace_enabled.rs` holds the +driver bring-up core, `qsa_prompt_kv_drop.rs` the `QsaPromptStage` owner): those renames are the next naming pass. -### (e) Stage 10 pass: control-plane, desktop-core, deploy and the small crates (owner order 2026-11-14, branch `claude/debt-control`) +**Verification.** `cargo check --workspace --all-targets` is clean after the pass; `cuda-driver` also with `sm86`. Tests (`cargo test`, slim profile, GPU modules +skipped): `cuda-model`, `obs`, `leleka-memory`, `tokenizer`, `model-format`, `gptoss`, `cpu-worker`, `igpu`, `memory-os`, `experimental-ref`, `npu-service` green except the three known +`qwen_artifact_binding` tests of `model-format` (NTFS). **Identity.** Imports, moves, renames, doc headers, the settings readers and the exceptions do not change generated +code. The commits that touch the driver wrappers and the CPU expert pool (EnvSwitch in 26 decode and prefill switches, the `ArenaMap`/`Write` generics, the single +`head_dispatch`, the `copy_ring_layer` split, the timer comments) are on `claude/debt-hot-low`, which stays out of `main` until the two-binary identity gate has passed +on them (`scripts/laptop/identity-gate.sh`; not run: it needs the memory the containers hold). -Crates: `strata-control`, `strata-desktop-core`, `leleka-deploy`, `leleka-gateway-domain`, `leleka-gateway-text`, `leleka-backend-api`, `leleka-runtime-client`, `leleka-npu-service`. Numbers are from `scripts/check-architecture.py`; a site that must stay is a named entry of `exceptions` in `architecture.json` (crate, file, ratchet, reason), not a baseline number. - -| Ratchet | before | after (outside the exceptions) | -|---|---|---| -| `glob-super-import` | `deploy` 15, `control` 9 | 0 | -| `allow-unused-imports` | `control` 48, `desktop-core` 9, 4 small crates 9 | 0 | -| `env-read` | `deploy` 41, `control` 14, `desktop-core` 13, `gateway-text` 2, `npu-service` 1 | 3 (`control`, hot files, see below); each crate has one reader module | -| `dyn-trait` | `deploy` 17, `control` 11, `gateway-domain` 2, `desktop-core` 2, `backend-api` 1 | 0 | -| `path-include` | `desktop-core` 2 | 0 (`evaluation_measurement` is a module of the library; both binaries use it) | -| `instant-now` | `deploy` 28, `control` 22, `desktop-core` 14, `npu-service` 5, `backend-api` 2 | `control` 15 and `desktop-core` 4 in hot files, see below; the rest 0 | -| `process-global` | `control` 8, `gateway-text` 4, `gateway-domain` 2 | 2 (`control`, hot files) | - -**One reader per crate.** `env_settings.rs` in `strata-control`, `strata-desktop-core`, `leleka-deploy`, `leleka-gateway-text` and `leleka-npu-service` is the only file that calls `std::env::var`; the other modules ask for a typed value (`env_settings::number::("STRATA_QUEUE_TIMEOUT_S")`, `supervisor_status_file()`, `hub_token()`, `stage_trace()`, `home_dir()`, `hf_token_set()`). The reads stay live, so the order of the checks and the messages of the run configuration are as before. `leleka-deploy` passes its `LELEKA_*` lookup around as `EnvLookup = fn(&str) -> Option` (a function pointer, no `dyn`), the tests pass `env_settings::nothing` or a non-capturing closure. - -**Clock.** `leleka-deploy`: the supervisor owns an `AnyClock` (a manual one in tests) and the command flows read `SystemClock` of `leleka-obs`. `strata-control`: the MCP hub and servers and the hardware series hold an `AnyClock`; `model/file_download.rs` uses the gateway `SystemClock`. `strata-desktop-core`: the node's inventory cache holds an `AnyClock`, the asynchronous deadlines read `clock::RuntimeClock` (tokio's clock, which `tokio::time::pause` controls). Exceptions: the two adapters and the manual clock fixture, the node subscription's freshness stamps, the NPU profile laps and the scripted engine's pacing. - -**Exceptions (reasons in `architecture.json`).** `dyn-trait`: the five `Shared*` ports of `strata-control` and `AppState`'s codec (composition), `SharedCodec`, the error source chain, the per-request token-bytes closure, the two tonic streaming types of `desktop-core`, the scripted engine's responder. `process-global`: the compiled pinned chat template, the schema validity cache, the request metrics registry, the gpt-oss prompt date set at start-up, the stage-trace table. - -**Names and docs.** About 150 generated doc headers (`Methods of ...`, `Functions: ...`, `Unit tests of this module (split out ...)`) are real sentences that say what the file holds and why it is separate. 60 modules were renamed by what they hold with `scripts/dev/rename_module.py` (`worker/generation_result.rs` -> `worker_entry.rs`, `model/fetch_one.rs` -> `file_download.rs`, `mtp_fetch/mtime_ns.rs` -> `command_line.rs`, `server_api/slots.rs` -> `status_routes.rs`, `desktop-core` `gateway/secret.rs` -> `pool_gateway.rs`, ...). `*_methods` group modules and `ConversationManager` are in `engine-core`/the engine, not in these crates. - -**Left, with the next step.** - -| What | Why | Next step | -|---|---|---| -| hot-path sites (`env-read` 3, `instant-now` 15 + 4, `process-global` 2 in `control`/`desktop-core`) | admission, streaming and the gRPC client are held back until the two-binary identity run | branch `claude/debt-hot-control` | -| Windows-only files (`key_init/windows.rs`, `facts/windows.rs`, `winfront/*`, `winservice/*`) | edited by hand (names read from the code); no Windows `cargo check` could run because `leleka-memory` and `leleka-model-format` do not compile for Windows at this commit (`governor/operations.rs`, `qwen4exp_*`: unresolved imports under `cfg(windows)`) | a Windows `cargo check -p leleka-deploy -p strata-control` once those two crates compile there | -| deploy end-to-end tests `dry_run_*` and `reconfigure_flow::*` | need free VRAM and a quiet GPU (host checks read `nvidia-smi`); they fail on the busy laptop with "GPU memory: ... free but the engine needs ..." | run on the 5090 | +**Left.** (1) the typed `Settings` value of `cuda-driver` and the CPU expert pool (above); (2) injecting a `Clock` into the driver launch owners and the pool instead of the +measurement-timer exceptions, and the S13/S14 injection of the process singletons: both need the engine crate; (3) the file names whose content differs from their +name; (4) the Windows-only code (`libc-shim`, 9 platform-cfg files of `cuda-driver`) was edited without a native Windows `cargo check`; (5) `cargo check -p leleka-cuda-driver` without +`--features cuda-driver` has never compiled (379 errors at the base commit too); the product always builds with the feature. ### (d) Other open items of this file (unchanged by the pass; the owner's order for them)