server_api::{ensure_loaded, model_busy, load_post} stamp last_activity from state.services.clock instead of
tokio::time::Instant::now() (instant-now:strata-control 34 -> 31; SystemClock returns the same value). The baseline is
tightened. docs/experiments/stra-338-gateway-track.md records the commands, the per-step test-outcome comparison (Linux:
597 ok before, 615 ok after, 0 changed, 0 missing), the gate movement and what was not done;
docs/architecture/gateway-ports.md shows the AppState groups and the domain crate.
AppState (app/state.rs) is now lifecycle + EngineLink (client port, control channel, worker status, pool,
queue timeout) + HttpPolicy (api key, CORS, trusted origins) + ModelView (name, aliases, tokenizer, template,
vision port, prefix-cache and memory views) + Services (response store, monitor, MCP port, settings, clock,
started_at). Field uses were rewritten mechanically (state.worker -> state.engine.worker, ...); no handler logic
changed. The old impl_default_for_appstate.rs, which held the route table and the admin handlers, is app/routes.rs,
app/admin_routes.rs and app/readiness.rs.
main.rs (1156 lines: an 840-line argument match, the serve function, two helpers) is now 8 lines. The argument match
is split into command groups under src/cli/ (operations, model_fetch, model_inspect, model_ensure, model_prepare,
kar_inspect, kar_verify, kar_overlay, model_text; each owns its arms in their old order and answers Ok(false) for a
line it does not own), serve() and shutdown_signal() are src/serve.rs (the composition root), the usage text is
cli/usage.rs. The binary name and every command line are unchanged.
Architecture gate: control-plane/src/main.rs leaves the oversize list (1156 -> 8). --allow-increase was used because
the type change forces the AppState struct literals in seven already-oversize test/example files to nest by group:
cp_replay.rs +7, responses/tests.rs +11, backend_worker_http.rs +14, mcp_hub.rs +3, memory_gate_http.rs +7,
vision_http.rs +6, desktop-core api_over_runtime.rs +6 (55 lines in all, against 1148 lines removed from main.rs).
Test outcomes are unchanged (597 ok / 2 ignored before and after, 14 new tests from S16).
AppState now holds ports instead of concrete types: `engine: Option<SharedEngine>` replaces the
mpsc::Sender<GenerationCommand>, `responses: SharedResponseStore` replaces Arc<RwLock<ResponseHistory>>,
`clock: SharedClock` serves queue deadlines, uptime and response timestamps, `mcp` is a ToolHub and `vision` a
VisionEncoder. The channel (adapters::ChannelEngine), the history with its disk snapshot
(responses::HistoryResponseStore), the system clock, mcp::Hub and vision::Vision are the adapters; main.rs serve()
composes them. No behaviour change: the HTTP handlers make the same calls in the same order, the queue claim race is
unchanged, only the deadline now reads the injected clock.
Ports are called per request, never per token or stream event (docs/architecture/gateway-ports.md).
ports/fakes has an in-memory adapter per port; control-plane/tests/ports_fakes.rs (12 tests), queue.rs and
adapters/channel_engine.rs add tests that drive the real handlers through them.
Architecture gate: dyn-trait:strata-control fell 35 -> 21 (a BoxError alias replaces 20 `Box<dyn Error>` spellings,
which pays for the 6 new port aliases); main.rs 1156 -> 1155 lines. Also adds scripts/dev/test-outcomes.py (per-test
outcome comparison of two cargo test logs) and scripts/dev/wsl-cargo.sh.
scripts/dev/split_module.py (lexer-based, with 16 self-tests) moves the top-level fn and impl items of 59 oversize module files in control-plane, desktop-core, model-format, gateway-text, leleka-memory, experimental-ref, context, serving-policy, tokenizer, backend-api, quant-core, harmony, igpu, libc-shim, npu-service and runtime-client into foo/<name>.rs groups of about 250 lines; types, constants, macros, nested modules and tests stay, every path stays valid through pub use re-exports, restricted visibilities keep their scope one level down, include paths and super:: paths are shifted. Not touched: leleka-runtime, cuda-driver, native-cpu-expert, sampler-ref and cpu-* (hot path, next wave) and the files kar-off-ab edits.
The baseline drops from 311 to 263 oversize files and from 273,600 to about 233,000 lines; the path-include ratchet ignores dir/name.rs child declarations.