{"data":{"slug":"github-xberg-io-xberg-ai-rulez-skills-feature-flag-conventions-5dd44a6b0d82","title":"Feature Flag Conventions","summary":"Establish consistent feature flag naming and behavior across libraries and bindings.","url":"https:\/\/skillshunter.net\/skills\/github-xberg-io-xberg-ai-rulez-skills-feature-flag-conventions-5dd44a6b0d82","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-xberg-io-xberg-ai-rulez-skills-feature-flag-conventions-5dd44a6b0d82","markdown_url":"https:\/\/skillshunter.net\/skills\/github-xberg-io-xberg-ai-rulez-skills-feature-flag-conventions-5dd44a6b0d82.md","download_url":"https:\/\/skillshunter.net\/skills\/github-xberg-io-xberg-ai-rulez-skills-feature-flag-conventions-5dd44a6b0d82\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"This playbook focuses on standardizing feature flags for shared concerns like `otel` and `mcp`, ensuring consistent semantics across all libraries and bindings. It includes rules for mutual exclusivity, implication edges, and naming consistency.","instructions":"---\ntype: Playbook\ntitle: Feature Flag Conventions\ndescription: \"Edit Cargo features: ORT-free targets, aggregates, PDF backends and parity.\"\npaths:\n  - \"**\/Cargo.toml\"\n  - \"scripts\/ci\/check-feature-parity.py\"\nx-ai-rulez:\n  kind: skill\n  id: feature-flag-conventions\n  metadata:\n    name: feature-flag-conventions\n---\n\n# Feature-flag conventions\n\nShared concerns use the **same flag name with the same semantics** in every library. A consumer that learns `otel` or `mcp` once should get identical behavior across every library and its bindings. Repo-specific flags stay local \u2014 this contract governs only shared concerns.\n\n## Standard flags\n\n| Flag | Meaning | Default | Notes |\n|------|---------|---------|-------|\n| *(none)* `tracing` | Structured tracing is **always-on**, never a feature. | \u2014 | `tracing` is a non-optional dependency. Do not gate span emission. Un-gate any legacy optional `tracing` feature. |\n| `otel` | Opt-in OpenTelemetry \/ OTLP export layer, on top of always-on tracing. | off | Pulls `tracing-opentelemetry` + the `opentelemetry*` stack. This is the only observability feature. Reconcile any always-on OTLP deps behind it. |\n| `mcp` | Embedded Model Context Protocol server (stdio transport). | off | |\n| `mcp-http` | MCP Streamable HTTP transport; implies `mcp`. | off | `mcp-http = [\"mcp\", ...]`. |\n| `mimalloc` | Select the mimalloc global allocator. | off | Mutually exclusive with `jemalloc`; see the allocator rule below. |\n| `jemalloc` | Select the jemalloc global allocator. | off | Mutually exclusive with `mimalloc`. |\n| `cuda` \/ `metal` \/ `mkl` \/ `accelerate` | Device \/ BLAS acceleration backends where a crate exposes them. | off | Same names wherever acceleration is offered. |\n\n## Rules\n\n- **Names are the contract.** Never invent a synonym for a shared concern (`opentelemetry`, `observability`, `otlp` for what is `otel`; `model-context-protocol` for `mcp`). Rename divergent flags to match.\n- **Semantics travel with the name.** `otel` must mean the OTLP export layer everywhere, not \"enable tracing\" (tracing is always-on) and not a metrics-only subset.\n- **Always-on tracing, opt-in export.** Do not force the `opentelemetry` dependency tree on library consumers \u2014 keep it behind `otel` so a plain dependency stays lean.\n- **Implication edges are fixed**: `mcp-http` \u21d2 `mcp`; `otel` \u21d2 (always-on) tracing.\n- **Mutually-exclusive allocators** carry a both-enabled `compile_error!` guard by default. Exception: a crate that must build with `--all-features` (a coverage gate, `cargo doc --all-features`) resolves by precedence instead, `jemalloc` winning via `cfg(all(feature = \"mimalloc\", not(feature = \"jemalloc\")))`, and states why in a `~keep` comment at the `#[global_allocator]`.\n- Adding a shared flag to a new library? Copy the name, default, and implication edges from this table rather than redefining them. Coordinate a change to this contract across all libraries before landing it \u2014 no repo diverges unilaterally.\n\n## Xberg features\n\nAll Xberg features are in `crates\/xberg\/Cargo.toml`.\n\n### ORT-Incompatible Targets (WASM, Android x86_64 emulator)\n\nOnly ORT-dependent paths are incompatible. The same paths block both WASM (no native ORT linkage at all) and the `x86_64-linux-android` emulator triple (no pyke prebuilt; `aarch64-linux-android` does ship a prebuilt and gets full ORT):\n\n- `paddle-ocr` \u2014 ONNX Runtime + native C++ deps: not WASM-safe; no Android x86_64 prebuilt\n- `layout-detection` \u2014 depends on ONNX Runtime layout models: not WASM-safe; no Android x86_64 prebuilt (RT-DETR + table classifier are available off-ORT via the `layout-tract` sibling, below)\n- `embeddings` \u2014 depends on ONNX Runtime sentence-transformer models: not WASM-safe; no Android x86_64 prebuilt\n- `auto-rotate` \u2014 depends on ONNX Runtime orientation classifier: not WASM-safe; no Android x86_64 prebuilt (available off-ORT via the `auto-rotate-tract` sibling, below)\n- `formula-recognition` \u2014 LaTeX recognition for layout formula regions (RapidLaTeXOCR ONNX): ORT-dependent, opt-in, excluded from `full`\/`formats`\n\nPure-Rust **type-only** companion features expose the public config\/result types for the above without pulling in ORT:\n\n- `layout-types` \u2014 `LayoutDetectionConfig`, `TableModel`, `BBox`, `DetectionResult`, `LayoutClass`, `LayoutDetection`, `RecognizedTable`. `layout-detection` implies `layout-types`.\n- `auto-rotate-types` \u2014 `OrientationResult`. `auto-rotate` implies `auto-rotate-types`.\n- `embedding-presets` \u2014 `EmbeddingPreset` (already existed; pure-Rust preset metadata).\n\nPure-Rust **tract inference** variants run select ONNX models where native ORT cannot link, loading the\nsame `.onnx` artifacts through the `tract` engine (CPU-only, no native library):\n\n- `layout-detection` (ORT) \u2192 `layout-tract` (tract): RT-DETR layout detection + the PP-LCNet\n  wired\/wireless table classifier run on WASM and the Android x86_64 emulator. TATR, SLANeXT,\n  PP-DocLayout-V3, and YOLO stay ONNX Runtime-only (tract 0.23.4 op-coverage gaps).\n- `auto-rotate` (ORT) \u2192 `auto-rotate-tract` (tract): PP-LCNet document-orientation on WASM and the\n  Android x86_64 emulator.\n\nWASM\/Android-safe variants:\n\n- `ocr` (native) \u2192 `ocr-wasm` (uses `tesseract-wasm` + safe image deps) \u2014 Android keeps native `ocr`\n- `excel` (native) \u2192 `excel-wasm` (drops `tokio-runtime`) \u2014 Android keeps native `excel`\n- `tree-sitter` (native dlopen) \u2192 `tree-sitter-wasm` (statically-linked grammar pack). NOT in `wasm-target`: the 371-language grammar pack pushes the browser `.wasm` past jsDelivr's 50 MB per-file cap, breaking the CDN-hosted demo. WASM has no code intelligence; Android keeps native `tree-sitter`.\n- `liter-llm` \u2014 NOT in `no-ort-target`: tokenizers \u2192 hf-hub \u2192 ureq \u2192 rustls + socks are wasm-incompatible. Enabled explicitly by `android-target` and `full`; WASM has no LLM path\n- `stopwords` \u2014 pure-Rust, included in `no-ort-target`\n- `keywords` \u2014 pure-Rust YAKE\/RAKE, included in `no-ort-target`\n\nThe `no-ort-target` aggregate is the shared no-ORT base used by both `wasm-target` and `android-target`. `wasm-target = no-ort-target + excel-wasm + ocr-wasm + layout-tract + auto-rotate-tract + ner-candle-wasm` (NO tree-sitter \u2014 see above). `android-target` adds to `no-ort-target`: `excel`, `tree-sitter`, `ocr`, `sceptre-ocr-tract`, `paddle-ocr-tract`, `layout-tract`, `auto-rotate-tract`, `api`, `mcp`, `liter-llm`, `structured`, `hwpx`, `diff`, `classification`, `captioning`, `ner-llm`, `url-ingestion`. Read the manifest before assuming a member \u2014 both lists are edited often.\n\n### PDF Backend\n\n- `pdf` \u2014 the canonical PDF feature. It is a pure alias: `pdf = [\"pdf-native\"]`, and `pdf-native` carries the dependency set (`dep:xberg-native-pdf`, lopdf, image, flate2, html, image-encode). There is no feature literally named `xberg-native-pdf`. Included in `formats`, `full`, `no-ort-target`, and `wasm-target`.\n- `pdf-pdfium` \u2014 the pdfium FFI comparison backend (`crates\/xberg-pdfium-render`). Implies `tokio-runtime` because the pdfium calls are synchronous and must run under `spawn_blocking`. Opt-in; in no aggregate. Without it, selecting the pdfium backend fails loudly rather than falling back.\n\nConfig value, not feature: `PdfConfig.backend` (`core\/config\/pdf.rs`) parses exactly `\"native\"` and `\"pdfium\"`. The pre-1.1.0 spelling `\"pdf_oxide\"` is **rejected, not aliased** \u2014 deliberately, so it cannot survive in configs. Omitting the field defaults to `Native`.\n\n### ORT Variants (Mutually Exclusive)\n\n- `ort-bundled` \u2014 downloads official Microsoft ORT binaries; default when OCR\/ML features active\n- `ort-dynamic` \u2014 load ORT from system; only when system ORT is guaranteed present\n\n### Platform-Conditional\n\n- `xberg-paddle-ocr`, `hf-hub`, `pprof` \u2014 excluded on `wasm32`\n- `ureq`: `rustls` on non-Windows; `native-tls` on Windows\n- `xberg-ffi` and `xberg-dart` cargo dependencies are target-conditional: `cfg(target_os = \"android\")` (**both** ABIs \u2014 `aarch64` and `x86_64`) and `cfg(target_os = \"ios\")` select `android-target`, the pure-Rust tract ML surface with no ONNX Runtime; `cfg(target_os = \"windows\")` selects `windows-target` (full ORT ML via `ort-bundled`); `cfg(all(target_os = \"macos\", target_arch = \"x86_64\"))` selects `macos-intel-target`. All other targets (Linux, macOS arm64) get the full ORT-enabled feature set. Android and iOS run inference through `tract`, not ORT, on every ABI \u2014 there is no arch split that gives arm64 Android phones a native ORT build.\n\n### Aggregate Sets\n\n| Feature | Description |\n| --- | --- |\n| `formats` | Document formats **only**: pdf, excel, office, notebook, hwp, hwpx, iwork, email, html, xml, archives, mdx, svg, heic, wordperfect. No api\/mcp\/otel, no chunking, no OCR, no ML |\n| `analysis` | language-detection, chunking, quality, keywords, markdown-footnotes, diff |\n| `services` | api, mcp, otel |\n| `full` | `formats` + `analysis` + `services` + url-ingestion + every OCR backend + every ML feature |\n| `formats-no-heic` \/ `full-no-heic` | Same lists minus `heic` (and minus candle for `full-no-heic`), for targets with no libheif \/ no aarch64 `fullfp16` |\n| `no-ort-target` | Pure-Rust base: every capability that does not depend on ONNX Runtime |\n| `wasm-target` | `no-ort-target` + excel-wasm + ocr-wasm + layout-tract + auto-rotate-tract + ner-candle-wasm (no tree-sitter \u2014 grammar pack exceeds the CDN 50 MB cap) |\n| `android-target` | `no-ort-target` + the native-Linux\/tract set (see above); for the x86_64-linux-android emulator |\n| `windows-target` | Curated Windows host set: `full` minus `heic` (no libheif on the runner) |\n| `windows-gnu-target` | `windows-target` minus everything reaching ORT \u2014 pyke ships no gnu-ABI prebuilt |\n| `macos-intel-target` | `[\"full-no-heic\", \"ort-dynamic\"]` \u2014 no osx-x86_64 ORT prebuilt exists past 1.23 |\n| `mobile` | formats + analysis + ocr + tree-sitter + api-types + tokio-runtime |\n\nMember lists change often. Read `crates\/xberg\/Cargo.toml` before relying on any of these\ndescriptions for a specific feature.\n\n### CI parity guard (GH#1443)\n\n`mise run verify:feature-parity` runs\n`python3 scripts\/ci\/check-feature-parity.py crates\/xberg\/Cargo.toml`.\n\nIt compares only **code-bearing** features \u2014 those whose definition pulls a `dep:`, or whose\nname appears in a `#[cfg(feature = \"\u2026\")]` under `crates\/xberg\/src`. Pure aliases drop out\nwhile their members are still compared, so the rule cannot manufacture a false pass.\n\nGuarded pairs, with the deltas each subset is allowed:\n\n| Superset | Subset | May lack |\n| --- | --- | --- |\n| `full` | `windows-target` | `heic` |\n| `formats` | `formats-no-heic` | `heic` |\n| `full` | `full-no-heic` | `heic` + candle |\n| `full` | `macos-intel-target` | `heic` + candle |\n| `full` | `windows-gnu-target` | `heic` + candle + ORT-dependent |\n\n`android-target` and `no-ort-target` are **deliberately unguarded** (`UNGUARDED` in the\nscript): they substitute the tract stack or drop ORT outright, so encoding their deltas would\nturn the check into a change-detector that fires on every legitimate edit.\n\nConsequence: adding a feature to `full` without adding it to `windows-target` fails CI.\n\n### Build Profiles\n\n- `release` \u2014 LTO thin, codegen-units=1, strip\n- `profiling` \u2014 inherits release, retains debug info\n- `xberg-wasm` override: `opt-level=\"z\"` (size-optimized)\n- `sevenz-rust2` override: `opt-level=1` \u2014 **not 2**. The manifest comment is explicit: \"opt-level=2 still SIGBUS'd in go:e2e\". Raising it reintroduces the crash\n- `zip` override: `opt-level=2` (prevents SIGBUS on macOS ARM64)\n","use_cases":["Maintain consistent behavior for `otel` across all libraries","Ensure `mcp-http` implies `mcp` in all crates","Enforce mutually exclusive allocator flags like `mimalloc` and `jemalloc`"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/xberg-io\/xberg\/blob\/ffbf7971796a126fc52f6bb8fb40418772071f61\/.ai-rulez\/skills\/feature-flag-conventions\/SKILL.md","source_commit":"ffbf7971796a126fc52f6bb8fb40418772071f61","license":null,"version":null,"listing_approved_at":"2026-11-16","created_at":"2026-11-15T13:28:59.000000Z","updated_at":"2026-11-16T05:16:54.000000Z","seo_title":"Feature Flag Conventions for Consistent Behavior","seo_description":"Ensure feature flags maintain consistent semantics across libraries and bindings with standardized naming and behavior.","seo_keywords":["feature flag conventions","consistent feature behavior","shared flag semantics","allocator flag rules","mcp-http dependency","otel flag behavior"]}}