ADR-001: Pure-Rust Fail-Closed Engine Across Nine Cross-Compilation Targets¶
| Attribute | Value |
|---|---|
| Status | Accepted |
| Date | 2026-11-22 |
| Deciders | FileCleaner Core Engineering |
| Supersedes | None (IMP-001, IMP-004, APP-001, APP-003 in RCA_REGISTER.md) |
Context¶
FileCleaner targets autonomous directory retention, backup vault protection, and S3/MinIO archival across
heterogeneous infrastructure: static Alpine/scratch containers (musl), glibc Linux servers (x86_64, ARM64,
ARMv7), Windows Server/ARM64 (MSVC), and Intel/Apple Silicon macOS workstations.
Two primary design constraints govern the engine architecture:
- Zero C/C++ Cross-Toolchain Friction: Introducing
-syscrates (openssl-sys,aws-lc-sys,ring,zstd-sys,liblz4-sys,bzip2-sys) forces externalcc,cmake,nasm, or sysroot toolchains across GitHub Actions runners and fails frequently onaarch64-unknown-linux-musl,armv7-unknown-linux-gnueabihf, andaarch64-pc-windows-msvc(IMP-001). - Zero Silent Data Loss: Cleanup automation runs unsupervised on critical database backups and active write
spools. Silent fallbacks—such as dropping from missing
birthtimetomtime, deleting unverified S3 uploads, ignoring lock probe failures, or letting retention caps override backup minimums—create unrecoverable outages.
Pure-Rust Crate Stack Architecture¶
flowchart TB
BIN["filecleaner Binary (Rust 2021, 9 Targets)"] --> CFG["Config & CLI<br/>clap v4 · serde · toml · serde_yaml_ng · chrono"]
BIN --> SCAN["Scan & Match<br/>walkdir · globset · regex"]
BIN --> COMP["Pure-Rust Codecs<br/>flate2 (miniz_oxide) · lz4_flex · brotli · zip (deflate)"]
BIN --> S3["Pure-Rust S3 & SigV4<br/>ureq v3 (rustls-no-provider) · rustls · rustls-rustcrypto · hmac · sha2 · base64"]
BIN --> OS["OS & Daemon<br/>notify · ctrlc · std::fs::FileTimes · #[cfg(unix)] libc · Windows share_mode(0)"]
Options Considered and Trade-Offs¶
| Option | Cross-Compilation Portability | Runtime Safety & Fail-Closed Guarantees | Binary Footprint & Ops Complexity | Verdict |
|---|---|---|---|---|
Option A: Shell + Cron + logrotate + aws-cli |
Low: GNU vs BSD flag drift (find, stat, sha256sum), unavailable natively on Windows |
Low: shell interpolation hazards, no unified 6-layer lock probe, weak stale-backup wipe guards | Requires Python, AWS CLI, logrotate, and shell runtimes in every container |
Rejected |
Option B: Rust Engine with -sys C Libraries & aws-lc-rs/ring |
Low: requires C cross-compilers, cmake, and NASM/Perl toolchains for musl and ARM/Windows ARM64 |
High if implemented manually, but native C dependency supply chain complicates static musl builds |
Larger build matrix complexity; slower local cross-checks | Rejected |
Option C: 100% Pure-Rust Fail-Closed Engine (miniz_oxide, lz4_flex, rustls-rustcrypto) |
High: compiles cleanly to all 9 targets with zero C -sys bindings (cargo-zigbuild for Linux cross) |
High: type-safe 6-phase pipeline, O_NOFOLLOW / share_mode(0), BackupGuard freezes, SHA-256 gated S3 |
Single static binary (~100% self-contained); zero runtime packages in Docker debian:bookworm-slim |
Selected |
Decision¶
Adopt Option C: engineer FileCleaner exclusively on pure-Rust crates paired with a fail-closed 6-phase execution pipeline:
- Automated Pure-Rust Supply-Chain Gate:
tests/governance_and_docs_test.rsparses bothCargo.tomlandCargo.lockon every CI run and fails the build if any-syscrate,ring,aws-lc-*,openssl*, ornative-tlsenters the build graph offilecleaner,ureq,rustls, orrustls-rustcrypto. - Stdlib Timestamp Restoration (
IMP-004): Preserveatime/mtimevia Rust stdlibstd::fs::File::set_times(std::fs::FileTimes) instead of unmaintained crates (filetime). - Pure-Rust Codecs & SigV4 S3 (
APP-003): Supportgzip(flate2/miniz_oxide),lz4(lz4_flex),brotli(brotli), andzip(zipwithdefault-features = false, features = ["deflate"]), alongsideureqv3 (rustls-no-provider,rustls-webpki-roots) backed byrustls-rustcryptoand custom AWS SigV4 signing (src/s3.rs). - Fail-Closed Safety Hierarchy:
InUseDetector(\(S_{\text{busy}}\)) andBackupGuard(\(P_{\text{floor}}\) and staleness freezes) unconditionally dominatemax_files,max_age, andmax_total_size, emittingRuleOutcome::Constrainedrather than relaxing safety floors.
Consequences¶
Positive¶
- Deterministic 9-Target Releases: All 9 release triples (
x86_64/aarch64Linuxgnuand staticmusl,armv7Linuxgnueabihf,x86_64/aarch64Windows MSVC,aarch64/x86_64macOS) build cleanly without native C dependencies, enabling scratch/minimal non-root Docker images (UID 10001). - Cryptographic Storage Guarantees: Local
Delete,Trash, andMovesteps cannot run afterUploadS3unless remoteHeadObject(x-amz-checksum-sha256+Content-Length) orGetObjectreadback confirms exact SHA-256 parity. - High Testability: Trait abstractions (
Clock,LockProbe,HookRunner,S3Uploader) achieve>= 90%line coverage (94.01%inv1.1.0) across unit, integration, and live Docker E2E suites.
Negative and Operational Risks¶
- No Zstandard (
zstd) Codec: Omittingzstd-sysexcludes.zstarchives until a mature pure-Rust streamingzstdencoder becomes viable without sacrificing cross-compilation invariants. rustls-rustcryptoPre-Release Maturity (APP-003): Pure-Rust cryptography trades peak hardware-accelerated TLS throughput for zero C build dependencies; WAN/LAN S3 I/O masks the CPU difference, and upgradingrustls-rustcryptoto0.1.x/1.0.xremains tracked once upstream releases stabilize.- Non-Linux Unix Open-FD Granularity (
APP-001): macOS and BSD lack Linux/proc/*/fd; un-flocked active writers without sidecars rely onmin_idle_ageandstability_windowuntil nativelibprocFD inspection (IDEA-004) lands inv1.2.
Related Reference and Procedures¶
- Configuration fields, codecs, S3 parameters, and
INV-CFG-*invariants: Configuration Schema & Invariants - CLI subcommands and exit-code contract: CLI Commands & Exit Codes
- Deployment SOP for Docker and systemd: Deploy FileCleaner with Docker and systemd
- Hook and TOCTOU hardening procedures: Enforce Pre-Delete Hooks and TOCTOU Guards
- Six-phase execution flow: Fail-Closed Six-Phase Pipeline