Skip to content

Commit 6e289c9

Browse files
westgatewestgate
authored andcommitted
S202: deep debt execution — capability-based evolution
- Hardcoded "toadstool" literals → PRIMAL_NAME constant (self_identity, bear_dog/client, identity.rs) - "coral_reef_available" → "shader_compiler_available" (capability-based API) - ~15 doc comments evolved from primal names to capability wording - Removed dead proxy_to_barracuda alias - DRY'd jsonrpc_server.rs: dispatch_or_parse_error() replaces 3 dupes - serialport feature-gated in specialty crate (ecoBin compliance) - DEBT.md: D-ASYNC-DYN-MARKERS → Known Limitations (not actionable) - DOCUMENTATION.md updated to S202 - cargo clean: 57.8GB artifacts removed Made-with: Cursor
1 parent ce5af44 commit 6e289c9

32 files changed

Lines changed: 172 additions & 119 deletions

File tree

CHANGELOG.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,33 @@ All notable changes to ToadStool will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [Unreleased] - April 11, 2026 (Sessions 43-201)
8+
## [Unreleased] - April 11, 2026 (Sessions 43-202)
9+
10+
### Session S202 (Apr 11, 2026) — Deep Debt Execution: Capability-Based Evolution
11+
12+
#### Hardcoded Literal Evolution
13+
- EVOLVED: `self_identity.rs``"toadstool"` literal → `PRIMAL_NAME` constant (single-sourced)
14+
- EVOLVED: `bear_dog/client.rs``"toadstool"` audit service_id → `PRIMAL_NAME`
15+
- EVOLVED: `identity.rs` — JSON-RPC `capabilities.list` type field → `PRIMAL_NAME`
16+
- EVOLVED: `dispatch/capabilities.rs``"coral_reef_available"``"shader_compiler_available"` (capability-based API key)
17+
18+
#### Primal-Name Doc Comments → Capability Wording
19+
- Evolved ~15 production doc comments across `bear_dog/client.rs`, `auth.rs`, `coordinator/adapter.rs`, `coordinator/mod.rs`, `adapters/mod.rs`, `capabilities/mod.rs`, `services/mod.rs`, `infrastructure_templates.rs`, `primal_sockets/mod.rs`, `primal_identity.rs`, `primal_discovery_mdns.rs`, `doctor/types.rs`, `config_utils/network.rs`, `capability_types.rs`, `executor/workload/runtime.rs`, `services/types.rs`
20+
- Philosophy: "We don't know specific primals. We know capabilities."
21+
22+
#### Dead Code Removal
23+
- REMOVED: `proxy_to_barracuda` legacy alias (dead code, `#[expect(dead_code)]` — no callers)
24+
25+
#### Smart Refactoring
26+
- `jsonrpc_server.rs`: Extracted `dispatch_or_parse_error()` helper — DRY'd 3 duplicated parse-error-response patterns (Unix NDJSON, TCP, BTSP)
27+
28+
#### Dependency Evolution
29+
- `toadstool-runtime-specialty`: `serialport` made optional behind `serial-transport` feature (ecoBin compliance — C/libudev not pulled into default builds)
30+
31+
#### Quality Gates
32+
- `cargo fmt`: PASS
33+
- `cargo clippy -- -D warnings`: PASS (0 warnings)
34+
- `cargo test --workspace`: PASS (0 failures)
935

1036
### Session S201 (Apr 11, 2026) — primalSpring Gap Closure & Coverage Push
1137

DEBT.md

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Active Technical Debt Register
22

3-
**Date**: April 11, 2026 — S201
3+
**Date**: April 11, 2026 — S202
44
**Philosophy**: Math is universal, precision is silicon. Workarounds are
55
short-term solutions that increase debt. We aim to solve deep debt over
66
iterations, evolving toward vendor-agnostic, capability-based solutions.
@@ -43,13 +43,14 @@ Dead u8 alignment check removed S197. Evolution: fuzz the access paths, consider
4343
`NonNull::slice_from_raw_parts` for fat-pointer representation.
4444
Files: `buffer/access.rs`.
4545

46-
### D-FUZZ-TARGETS — PARTIAL S197
46+
### D-FUZZ-TARGETS — CI & corpus (infra landed S197, remaining work)
4747
**Scope**: Workspace | **Dir**: `fuzz/`
4848
Initial `cargo-fuzz` / `libfuzzer` infrastructure added (S197). Three targets:
4949
`fuzz_jsonrpc_parse` (JSON-RPC 2.0 deser), `fuzz_config_toml` (config deser +
5050
validation), `fuzz_btsp_framing` (BTSP length-prefixed frame decode).
5151
Remaining: integrate into CI, add seed corpus, run extended campaigns, add
5252
proptest bridge for property-based input generation.
53+
See also: `D-FUZZ-TARGETS-UNSAFE` (GPU buffer access paths).
5354
Files: `fuzz/Cargo.toml`, `fuzz/fuzz_targets/*.rs`.
5455

5556

@@ -62,12 +63,37 @@ leaf and the 0.38 version is safe; the only impact is having two rustix majors i
6263
the dependency tree.
6364
Files: `v4l2/ioctl.rs`, `drm/device.rs`, `v4l2/device.rs`.
6465

65-
### D-ASYNC-DYN-MARKERS
66+
## Known Limitations (not actionable debt)
67+
68+
### D-ASYNC-DYN-MARKERS — Rust language constraint
6669
**Scope**: Workspace (~55 files) | **Marker**: `NOTE(async-dyn)`
6770
Traits using `#[async_trait]` because native `async fn` in `dyn Trait` is not yet
6871
stable in Rust. Cannot resolve until Rust stabilizes this feature. The `#[async_trait]`
6972
dependency is pure Rust (proc-macro) and zero-overhead at runtime for non-dyn paths.
70-
**Not actionable** — marker is accurate documentation.
73+
**Not actionable** — resolves when Rust stabilizes the feature. Markers are accurate documentation.
74+
75+
## S202 Resolved Debt (Deep Debt Execution: Capability-Based Evolution)
76+
77+
### D-HARDCODED-PRIMAL-LITERALS — RESOLVED S202
78+
Production `"toadstool"` string literals in `self_identity.rs`, `bear_dog/client.rs`,
79+
and `identity.rs` now use the `PRIMAL_NAME` constant from `toadstool_common::constants`.
80+
`"coral_reef_available"` JSON-RPC key evolved to `"shader_compiler_available"`.
81+
82+
### D-PRIMAL-NAME-DOCS — RESOLVED S202
83+
~15 production doc comments referencing primal names (BearDog, NestGate, Songbird,
84+
Squirrel) evolved to capability-based wording. Serde aliases and legacy mapping
85+
tables retained for backward compatibility.
86+
87+
### D-SERIALPORT-DEFAULT — RESOLVED S202
88+
`serialport` in `toadstool-runtime-specialty` made optional behind `serial-transport`
89+
feature. Default builds no longer pull C/libudev transitive dependencies.
90+
91+
### D-DEAD-BARRACUDA-ALIAS — RESOLVED S202
92+
`proxy_to_barracuda` dead code alias removed from `nautilus_handlers.rs`.
93+
94+
### D-JSONRPC-PARSE-DRY — RESOLVED S202
95+
Triplicated parse-error response pattern in `jsonrpc_server.rs` (Unix, TCP, BTSP)
96+
extracted into `dispatch_or_parse_error()` helper.
7197

7298
## S201 Resolved Debt (primalSpring Gap Closure & Coverage Push)
7399

DOCUMENTATION.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ToadStool Documentation Hub
22

3-
**Last Updated**: April 11, 2026 — S200
3+
**Last Updated**: April 11, 2026 — S202
44

55
---
66

@@ -30,23 +30,19 @@ These root documents were **fully resolved** and **fossilized** in wateringHole
3030

3131
---
3232

33-
## Current State (S200 — April 11, 2026)
33+
## Current State (S202 — April 11, 2026)
3434

35-
**Post-budding, dependency-sovereign, IPC-first, fully concurrent.** barraCuda is a separate primal at `ecoPrimals/barraCuda/`. ToadStool is the hardware infrastructure layer — GPU/NPU/CPU discovery, capability probing, workload orchestration, and shader dispatch.
35+
**Post-budding, dependency-sovereign, IPC-first, fully concurrent, capability-based.** barraCuda is a separate primal at `ecoPrimals/barraCuda/`. ToadStool is the hardware infrastructure layer — GPU/NPU/CPU discovery, capability probing, workload orchestration, and shader dispatch.
3636

3737
- **21,600+ tests**, 0 failures, 0 clippy warnings, 0 fmt diffs. Full workspace concurrent test suite.
3838
- **~69 JSON-RPC methods**. Wire Standard L3 (partial): `cost_estimates`, `operation_dependencies`. IPC compliant (`health.liveness``{"status":"alive"}`, `health.readiness` → ready+version, `health.check` full envelope, `capabilities.list`, `identity.get`, socket at `$XDG_RUNTIME_DIR/biomeos/toadstool.sock`).
3939
- **Pipeline dispatch**`compute.dispatch.pipeline.submit` + `.status` for ordered multi-stage workloads (DAG, topological sort, result forwarding). Resolves neuralSpring PG-05.
40-
- **Deep debt audit (S200)**: 0 production unwraps, 0 production mocks, 0 hardcoded primal names. Service discovery refactored. rustix aligned to 1.x across workspace (except display V4L2 ioctl migration pending).
40+
- **Capability-based everywhere (S202)**: 0 production hardcoded primal names, 0 production mocks, 0 production unwraps, 0 TODOs/FIXMEs. All primal references use `PRIMAL_NAME` constant or capability identifiers. API keys evolved (e.g., `shader_compiler_available`).
4141
- **TS-01 / shader compiler discovery**`visualization_client.rs` uses unified `capability.discover` (no `CORALREEF_*` env, no coralreef-core.json, no coralreef dir scan).
4242
- **BTSP Phase 2** — Handshake enforced on every UDS accept path (JSON-RPC + tarpc + daemon servers).
43-
- **OpenCL deprecated**`ocl` removed; GPU OpenCL paths stubbed; `GpuFramework::OpenCl` retained as deprecated variant.
44-
- **glowPlug/ember subsystem** — toadStool-native hardware lifecycle (absorbed from coralReef). `toadstool-glowplug`, `toadstool-ember`, `toadstool-hw-safe` crates.
45-
- **~66 unsafe blocks (all in hw-safe/GPU/VFIO/display containment crates)**; S198 hardening (nvpmu ABI types, V4L2 fd checks, secure_enclave `madvise`). 41 crates forbid, 6 deny `unsafe_code`.
46-
- **ecoBin v3.0** — Zero C FFI deps. Crypto delegated to security service. HTTP delegated to coordination service. Optional **musl-static** ~11MB x86_64 PIE binary validated (S198).
47-
- **Capability-based discovery** — Primals discover each other by capability, not name. Self-knowledge principle. S176–S198: struct fields, docs, `SocketPathEnv` / `resolve_capability_socket_fallback`, embedded `thiserror` stubs. **~400** intentional legacy-compat refs remain (serde aliases, env var fallbacks, parse_type).
43+
- **34 unsafe blocks (all in hw-safe/GPU/VFIO/display containment crates)**; all SAFETY-documented. 41 crates forbid, 6 deny `unsafe_code`.
44+
- **ecoBin v3.0** — Zero C FFI deps. `serialport` feature-gated in specialty crate (S202). Crypto delegated to security service. HTTP delegated to coordination service.
4845
- **Headless GPU**`TOADSTOOL_HEADLESS=1` env var for pure headless operation. wgpu crash isolation via `catch_unwind` + thread timeout.
49-
- **BTSP Tier 2**`validate_insecure_guard()` at server startup (GAP-MATRIX-12). Family-scoped socket handshake on all transports (S198 completes UDS parity).
5046
- **Fully concurrent tests** — All tests run with unlimited parallelism. Zero `#[serial]`. Zero fixed sleeps in non-chaos tests.
5147
- **AGPL-3.0-or-later** — All Cargo.toml + all .rs files aligned. `deny.toml` enforced.
5248

NEXT_STEPS.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# ToadStool -- Next Steps
22

3-
**Updated**: April 11, 2026 -- S201 (primalSpring Gap Closure & Coverage Push)
4-
**Status**: Production-grade | Rust edition **2024** (MSRV 1.85) | **AGPL-3.0-or-later** | **All quality gates green** | 21,600+ tests (0 failures) | **~69 JSON-RPC methods** | Wire Standard L3 (partial) | Zero C FFI deps (ecoBin v3.0) | Zero production unwraps | IPC-first | **43/43 crates with `unsafe_code` lint policy** | **~66 unsafe blocks** (all in hw containment) | **~80 justified #[allow]** | **0 production TODOs** | **~3m30s test runtime** | **rustix 1.x everywhere except display**
5-
**Latest**: S201primalSpring April 11 downstream audit closure: pipeline scheduling confirmed resolved (S199), +46 tests (wire L3 structural, dispatch types, security hardening submodules). S200 (prior): deep debt audit, service_discovery refactor, rustix evolution
3+
**Updated**: April 11, 2026 -- S202 (Deep Debt Execution: Capability-Based Evolution)
4+
**Status**: Production-grade | Rust edition **2024** (MSRV 1.85) | **AGPL-3.0-or-later** | **All quality gates green** | 21,600+ tests (0 failures) | **~69 JSON-RPC methods** | Wire Standard L3 (partial) | Zero C FFI deps (ecoBin v3.0) | Zero production unwraps | IPC-first | **43/43 crates with `unsafe_code` lint policy** | **34 unsafe blocks** (all in hw containment) | **~80 justified #[allow]** | **0 production TODOs** | **~3m30s test runtime** | **rustix 1.x everywhere except display** | **capability-based primal references (no hardcoded names)**
5+
**Latest**: S202Deep debt execution: hardcoded `"toadstool"` literals → `PRIMAL_NAME`, `"coral_reef_available"``"shader_compiler_available"`, ~15 doc comments evolved to capability wording, `serialport` feature-gated, dead code removed, `jsonrpc_server.rs` DRY'd. S201 (prior): primalSpring gap closure, +46 tests
66

77
---
88

@@ -163,7 +163,17 @@ names directly. Deprecated API definitions retained for backward compatibility o
163163

164164
---
165165

166-
## Completed This Session (S90-201)
166+
## Completed This Session (S90-202)
167+
168+
### Session S202: Deep Debt Execution — Capability-Based Evolution (Apr 11, 2026)
169+
- **Hardcoded literal evolution**: 3 production `"toadstool"` literals → `PRIMAL_NAME` constant (self_identity.rs, bear_dog/client.rs, identity.rs). `"coral_reef_available"` JSON-RPC key → `"shader_compiler_available"`.
170+
- **Primal-name doc evolution**: ~15 production doc comments evolved from primal names (BearDog, NestGate, Songbird, Squirrel) to capability-based wording. Serde aliases and legacy mapping tables retained.
171+
- **Dead code removal**: `proxy_to_barracuda` legacy alias removed (dead_code, no callers).
172+
- **Smart refactoring**: `jsonrpc_server.rs` — extracted `dispatch_or_parse_error()` helper, DRY'd 3 duplicated parse-error patterns.
173+
- **Dependency evolution**: `serialport` in `toadstool-runtime-specialty` made optional behind `serial-transport` feature.
174+
- **Unsafe audit**: 34 unsafe blocks confirmed — all in hw containment (mmap, ioctl, volatile MMIO, DMA), all genuinely necessary, all SAFETY-documented. No blocks removable.
175+
- **Mock audit**: Zero production mocks found. All Mock* types gated behind `#[cfg(test)]` or `test-mocks` feature.
176+
- **Large file audit**: Most >500-line files are test-only. `jsonrpc_server.rs` (659) was the main prod candidate (now DRY'd).
167177

168178
### Session S201: primalSpring Gap Closure & Coverage Push (Apr 11, 2026)
169179
- **primalSpring April 11 downstream audit**: Confirmed pipeline scheduling (`compute.dispatch.pipeline.submit`) fully resolved in S199. Stale audit entry closed. D-RUSTIX-DISPLAY-038 and D-ASYNC-DYN-MARKERS confirmed genuinely blocked.

crates/cli/src/commands/doctor/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ pub struct EcosystemReport {
5050
pub issues: Vec<String>,
5151
}
5252

53-
/// Status of a single primal (BearDog, NestGate, Songbird, etc.)
53+
/// Status of a single discovered primal (by capability)
5454
#[derive(Debug, Serialize)]
5555
pub struct PrimalStatus {
56-
/// Primal name (e.g. beardog, nestgate)
56+
/// Primal capability or service name
5757
pub name: String,
5858
/// Whether the primal socket file exists
5959
pub socket_exists: bool,

crates/cli/src/daemon/jsonrpc_server.rs

Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,23 @@ pub(crate) mod error_codes {
115115
pub use toadstool_common::constants::jsonrpc::error_codes::*;
116116
}
117117

118+
/// Parse a raw JSON line into a request, dispatch it, and return the response.
119+
async fn dispatch_or_parse_error(raw: &[u8], state: &ServerState) -> JsonRpcResponse {
120+
match serde_json::from_slice::<JsonRpcRequest>(raw) {
121+
Ok(request) => super::routes::handle_request(request, state).await,
122+
Err(e) => JsonRpcResponse {
123+
jsonrpc: toadstool_common::constants::jsonrpc::VERSION.to_string(),
124+
result: None,
125+
error: Some(JsonRpcError {
126+
code: error_codes::PARSE_ERROR,
127+
message: format!("Parse error: {e}"),
128+
data: None,
129+
}),
130+
id: None,
131+
},
132+
}
133+
}
134+
118135
/// Start JSON-RPC API server over Unix socket
119136
///
120137
/// # Deep Debt Evolution
@@ -243,19 +260,7 @@ async fn handle_tcp_connection(
243260
break;
244261
}
245262

246-
let response = match serde_json::from_slice::<JsonRpcRequest>(line.as_bytes()) {
247-
Ok(request) => super::routes::handle_request(request, &state).await,
248-
Err(e) => JsonRpcResponse {
249-
jsonrpc: toadstool_common::constants::jsonrpc::VERSION.to_string(),
250-
result: None,
251-
error: Some(JsonRpcError {
252-
code: error_codes::PARSE_ERROR,
253-
message: format!("Parse error: {e}"),
254-
data: None,
255-
}),
256-
id: None,
257-
},
258-
};
263+
let response = dispatch_or_parse_error(line.as_bytes(), &state).await;
259264

260265
let response_json = serde_json::to_string(&response)?;
261266
writer.write_all(response_json.as_bytes()).await?;
@@ -297,19 +302,7 @@ async fn handle_btsp_daemon_connection(
297302
loop {
298303
match btsp::framing::read_frame(&mut stream).await {
299304
Ok(frame) => {
300-
let response = match serde_json::from_slice::<JsonRpcRequest>(&frame) {
301-
Ok(request) => super::routes::handle_request(request, &state).await,
302-
Err(e) => JsonRpcResponse {
303-
jsonrpc: toadstool_common::constants::jsonrpc::VERSION.to_string(),
304-
result: None,
305-
error: Some(JsonRpcError {
306-
code: error_codes::PARSE_ERROR,
307-
message: format!("Parse error: {e}"),
308-
data: None,
309-
}),
310-
id: None,
311-
},
312-
};
305+
let response = dispatch_or_parse_error(&frame, &state).await;
313306
let response_json = serde_json::to_string(&response)?;
314307
if let Err(e) =
315308
btsp::framing::write_frame(&mut stream, response_json.as_bytes()).await
@@ -383,21 +376,7 @@ async fn handle_connection(stream: UnixStream, state: ServerState) -> crate::Res
383376
break;
384377
}
385378

386-
let response = match serde_json::from_slice::<JsonRpcRequest>(line.as_bytes()) {
387-
Ok(request) => super::routes::handle_request(request, &state).await,
388-
Err(e) => JsonRpcResponse {
389-
jsonrpc: toadstool_common::constants::jsonrpc::VERSION.to_string(),
390-
result: None,
391-
error: Some(JsonRpcError {
392-
code: error_codes::PARSE_ERROR,
393-
message: format!("Parse error: {e}"),
394-
data: None,
395-
}),
396-
id: None,
397-
},
398-
};
399-
400-
// Send response
379+
let response = dispatch_or_parse_error(line.as_bytes(), &state).await;
401380
let response_json = serde_json::to_string(&response)?;
402381
writer.write_all(response_json.as_bytes()).await?;
403382
writer.write_all(b"\n").await?;

crates/cli/src/daemon/nautilus_handlers.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,6 @@ pub async fn proxy_nautilus_rpc(method: &str, params: &Value) -> Result<Value, N
3737
})
3838
}
3939

40-
/// Legacy name — prefer [`proxy_nautilus_rpc`].
41-
#[expect(
42-
dead_code,
43-
reason = "API compat alias; default path uses proxy_nautilus_rpc"
44-
)]
45-
pub async fn proxy_to_barracuda(method: &str, params: &Value) -> Result<Value, NautilusRpcError> {
46-
proxy_nautilus_rpc(method, params).await
47-
}
48-
4940
#[cfg(test)]
5041
#[cfg(feature = "nautilus")]
5142
mod tests {

crates/cli/src/ecosystem/adapters/coordination/adapter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::ecosystem::capabilities::StandardCapability;
1212
/// Coordination adapter - provides coordination operations via capability discovery
1313
///
1414
/// This adapter discovers and invokes coordination services without knowing their identity.
15-
/// Services could be Songbird, Consul, etcd, Kubernetes service discovery, or custom implementations.
15+
/// Backends include Consul, etcd, Kubernetes service discovery, or any custom coordination provider.
1616
pub struct CoordinationAdapter {
1717
/// Universal service adapter for invoking capabilities
1818
universal: Arc<UniversalServiceAdapter>,

crates/cli/src/ecosystem/adapters/coordination/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: AGPL-3.0-or-later
22
//! Coordination adapter - capability-based coordination and service discovery
33
//!
4-
//! This adapter replaces the hardcoded Songbird integration with a generic
4+
//! This adapter replaces hardcoded coordination-service integration with a generic
55
//! coordination adapter that works with ANY service providing coordination capabilities.
66
//!
77
//! # Migration from Songbird

crates/cli/src/ecosystem/adapters/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//! invoked through protocol-agnostic interfaces.
77
//!
88
//! # Philosophy
9-
//! **"We don't know BearDog, NestGate, or Songbird. We know capabilities."**
9+
//! **"We don't know specific primals. We know capabilities."**
1010
//!
1111
//! Instead of hardcoded service connections, we discover services that provide
1212
//! the capabilities we need and interact with them through standard protocols.

0 commit comments

Comments
 (0)