<proposed_plan>
Section 1: Inputs summary
- Source plans ingested from `/home/ubuntu/xcodec-sr/SRPlans`: `Claude.md`, `GPT.md`, `GPT_PRO.md`, `Gemini.md`, `perplexity.md`.
- Integration constraints from your brief: low-latency voice-agent/TTS deployment, avoid default diffusion bottlenecks, preserve frozen encoder/VQ whenever possible, support controllable `{16,24,32,48}` output, maximize traceability.
- Repo-grounded implementation anchors confirmed: `vq/codec_decoder_vocos.py`, `lightning_module.py`, `inference.py`, `config/model/default.yaml`, `config/preprocess/default.yaml`, `config/train/default.yaml`.
- Traceability map: Plan A=`Claude`, Plan B=`GPT`, Plan C=`GPT_PRO`, Plan D=`Gemini`, Plan E=`perplexity`.

Section 2: Suggestion Inventory (by plan)
**Plan A (Claude)**
- A1: Decoder-only SR with frozen encoder is feasible and should be exploited.
- A2: Start with direct ISTFT-head retarget to 24k.
- A3: Keep compressed-frame modeling; scale hop/n_fft with target SR (50 fps principle).
- A4: Use linear weight interpolation for enlarged ISTFT projection init.
- A5: For 48k, add projection MLP before expanding backbone.
- A6: Use multi-band PQMF (4-band or 3-band reuse variant) with sub-band discriminators.
- A7: Consider MS-Vocos-style trainable synthesis filter for streaming.
- A8: Keep modular post-hoc BWE path available.
- A9: AP-BWE dual-stream amp/phase CNN as primary post-hoc candidate.
- A10: HiFi-GAN+ / MusicHiFi-BWE skip-connected upsampler as alternatives.
- A11: Explicit BWE failure-mode mitigation (HF discriminators, phase modeling, codec-domain training).
- A12: Optional one-step generative tier (FLowHigh/FlashSR/UniverSR-like).
- A13: Structured training recipe (loss stack, discriminator stack, staged schedule, LR partitioning).
- A14: Multi-rate controllability via SR conditioning.
- A15: VQ-token upsampling (prefer non-AR; AR latency concern).

**Plan B (GPT)**
- B1: Treat problem as bandwidth extension, not true signal recovery.
- B2: Highest-ROI baseline is post-BWE after current 16k decoder.
- B3: Ensure streaming/causal operation and fast/HQ mode toggle.
- B4: BBWEXNet-style causal U-Net is a practical low-latency option.
- B5: Prioritize 32k perceptual sweet spot before 48k.
- B6: Train with codec-decoded inputs to avoid train/infer domain gap.
- B7: Use causal sinc/polyphase pre-upsampling.
- B8: Use upper-band-weighted adversarial loss stack.
- B9: Predict only missing high-band residual.
- B10: Implement residual via PQMF or STFT mag/phase residual.
- B11: Native decoder retarget is valid with scaled hop/n_fft and HF-aware losses.
- B12: Optional distilled/one-step diffusion teacher-student and progressive SR conditioning.

**Plan C (GPT_PRO)**
- C1: Prefer decoder-aware BWE over blind terminal upsamplers.
- C2: Execute in ranked order: 24k retarget -> residual HF -> stronger decoder -> optional HQ generative.
- C3: Favor amplitude/phase or complex spectral decoding.
- C4: Add harmonic/source-filter priors for speech/F0 robustness.
- C5: Include lightweight missing-band models (AP-BWE/MS-BWE/BAE-Net/DSP-informed).
- C6: Keep 50Hz token cadence; scale waveform geometry by target SR.
- C7: Replace plain single linear head with dual-stream/harmonic-aware head.
- C8: Residual HF branch with deterministic low-band anchor.
- C9: Condition HF branch on latent + waveform/STFT context + optional F0/UV/energy.
- C10: Hard low-band bypass/identity to prevent regressions.
- C11: Auxiliary F0/UV/band-energy predictor from post-VQ latents.
- C12: APCodec/Wavehax-lite/HiFTNet-lite as stronger decoder replacements.
- C13: Additive branch gating: Base16 + HF24 + HF32 + HF48.
- C14: Band-aware objectives + teacher forcing/scheduled sampling for cascades.
- C15: Strict experiment ladder E0-E5; diffusion/flow as premium only.

**Plan D (Gemini)**
- D1: Multi-band sub-band reconstruction with PQMF.
- D2: Per-band mag/phase outputs from decoder head.
- D3: SnakeBeta + alias-free upsampling blocks in decoder.
- D4: Freeze encoder/semantic path; retrain decoder-side modules only.
- D5: Neural source-filter decomposition (periodic/noise source + filter).
- D6: Shared trunk with multi-head gated outputs by resolution.
- D7: Resolution-dropout training.
- D8: Sub-band discriminators for 8–16 and 16–24 kHz.
- D9: Generic upsamplers fail on FSQ-clean outputs; need token-conditioned generation.

**Plan E (perplexity)**
- E1: Proven decoder-only retrain with frozen encoder/quantizer.
- E2: Reported 24k variant uses hop=960 plus pre-VQ AvgPool to 25Hz.
- E3: Interpolate decoder weights from checkpoint.
- E4: Direct 48k ISTFT retarget (`n_fft=3840`, `hop=960`) is possible.
- E5: Increase backbone width/depth if 48k capacity is insufficient.
- E6: Vocos parameter sensitivity requires deliberate hyperparameter sweeps.
- E7: AP-BWE as post-filter.
- E8: MS-BWE cascade for controllable rates.
- E9: HiFi-GAN+ and UBGAN as alternative post-filters.
- E10: FLowHigh/FlowDec one-step generative options.
- E11: CodecFlow latent-space BWE path.
- E12: MB-iSTFT / 2D frequency upsampling option.
- E13: WaveNeXt / ComplexDec replacement options.
- E14: Multi-head ISTFT gating + resolution embedding + random resolution sampling.
- E15: Phased roadmap (quick 24k -> post-filter -> integrated 48k -> multi-rate gating).
- E16: Reuse pre-encoded data for rapid iteration.

Section 3: Coverage Matrix (table)
**Plan A**
| ID | Status | Reason + implications |
|---|---|---|
| A1 | ACCEPTED | Core premise matches constraints; enables decoder-focused roadmap. |
| A2 | ACCEPTED | Lowest-risk first milestone; fastest path to audible gain. |
| A3 | MODIFIED | Keep 50Hz cadence; use 24k@hop480 baseline, 32/48 progressive geometry next. |
| A4 | ACCEPTED | Reduces cold-start instability for new head dimensions. |
| A5 | MODIFIED | Add projection MLP only if 48k head underfits (triggered by metrics). |
| A6 | MODIFIED | PQMF multiband kept as fallback/parallel experiment, not default first path. |
| A7 | DEFERRED | Trainable synthesis filter postponed until base cascade is stable. |
| A8 | ACCEPTED | External post-filter path included for modular rollout/fallback. |
| A9 | ACCEPTED | AP-BWE design adopted in residual branch and external option. |
| A10 | MODIFIED | HiFi-GAN+/MusicHiFi used as baselines, not primary architecture. |
| A11 | ACCEPTED | Incorporated as mandatory guardrails in training/eval. |
| A12 | MODIFIED | One-step generative kept as optional HQ tier, not realtime default. |
| A13 | ACCEPTED | Adopted as main training protocol with staged optimization. |
| A14 | ACCEPTED | Multi-rate conditioning is part of final architecture. |
| A15 | DEFERRED | Non-AR token upsampling tracked as R&D; high integration cost now. |

**Plan B**
| ID | Status | Reason + implications |
|---|---|---|
| B1 | ACCEPTED | Sets correct objective: plausible HF synthesis, not reconstruction. |
| B2 | MODIFIED | Post-BWE is not sole first step; runs in parallel with native-24 retarget. |
| B3 | ACCEPTED | Runtime supports fast path + HQ path with latency-aware routing. |
| B4 | DEFERRED | BBWEXNet variant retained for benchmark/fallback only. |
| B5 | MODIFIED | Training starts at 24k; product default can move to 32k if SLO permits. |
| B6 | ACCEPTED | Dataset pipeline uses codec-decoded inputs as model inputs. |
| B7 | ACCEPTED | Deterministic causal/polyphase upsampling included pre-HF branch. |
| B8 | ACCEPTED | Upper-band weighted adversarial stack is mandatory. |
| B9 | ACCEPTED | Residual missing-band prediction is central design choice. |
| B10 | ACCEPTED | STFT residual is primary; PQMF variant kept as secondary branch. |
| B11 | ACCEPTED | Native retarget path included with HF-specific objectives. |
| B12 | ACCEPTED | Distilled one-step + progressive conditioning included as optional tiers. |

**Plan C**
| ID | Status | Reason + implications |
|---|---|---|
| C1 | ACCEPTED | Final design is decoder/token-aware, not blind waveform-only. |
| C2 | ACCEPTED | Implemented as canonical phase ordering. |
| C3 | MODIFIED | Dual amp/phase adopted now; full complex-decoder replacement deferred. |
| C4 | ACCEPTED | Harmonic/voicing priors added via conditioning branch. |
| C5 | MODIFIED | AP/MS-BWE integrated now; BAE-Net/DSP variants deferred benchmarks. |
| C6 | ACCEPTED | 50Hz token-rate invariance preserved. |
| C7 | ACCEPTED | Plain head upgraded to dual-stream/harmonic-aware form. |
| C8 | ACCEPTED | Residual HF branch with low-band anchor is primary mechanism. |
| C9 | ACCEPTED | Conditioning inputs include latent, base STFT, optional F0/UV/energy. |
| C10 | ACCEPTED | Hard low-band bypass enforced to prevent regressions. |
| C11 | ACCEPTED | Auxiliary voicing predictor included in training plan. |
| C12 | DEFERRED | Full decoder swaps are escalation options after plateau. |
| C13 | MODIFIED | Plain high-SR Vocos retained only as ablation baseline. |
| C14 | ACCEPTED | Band-aware losses + scheduled sampling adopted for cascades. |
| C15 | ACCEPTED | Experiment ladder E0-E5 is the formal evaluation sequence. |

**Plan D**
| ID | Status | Reason + implications |
|---|---|---|
| D1 | ACCEPTED | PQMF multiband included as selectable 48k strategy. |
| D2 | ACCEPTED | Per-band mag/phase output used in PQMF path design. |
| D3 | DEFERRED | SnakeBeta upsampling blocks tracked as experimental decoder variant. |
| D4 | ACCEPTED | Encoder/semantic frozen in primary experiments. |
| D5 | MODIFIED | Full source-filter decoder deferred; source/voicing priors added now. |
| D6 | ACCEPTED | Shared trunk + gated heads is adopted. |
| D7 | ACCEPTED | Resolution-dropout added for joint multi-rate robustness. |
| D8 | ACCEPTED | Band-specific discriminators are explicit training components. |
| D9 | ACCEPTED | Token-conditioned architecture chosen over generic post-upsamplers. |

**Plan E**
| ID | Status | Reason + implications |
|---|---|---|
| E1 | ACCEPTED | Decoder-only frozen-encoder baseline is foundational. |
| E2 | MODIFIED | Hop960+AvgPool tested as ablation, not default due temporal-rate tradeoff. |
| E3 | ACCEPTED | Weight interpolation is standard initialization step. |
| E4 | ACCEPTED | Direct 48k head path retained as one candidate in Phase 3. |
| E5 | ACCEPTED | Width/depth scaling gated by 48k quality/capacity diagnostics. |
| E6 | ACCEPTED | Hyperparameter sweeps mandated before architectural escalation. |
| E7 | ACCEPTED | AP-BWE supported as external and internalized design influence. |
| E8 | ACCEPTED | MS-BWE-style progressive cascade is integrated. |
| E9 | MODIFIED | HiFi-GAN+/UBGAN become benchmark/fallback deployments. |
| E10 | DEFERRED | FLowHigh/FlowDec in optional HQ lane after realtime path stabilizes. |
| E11 | DEFERRED | CodecFlow latent-flow tracked as long-horizon R&D. |
| E12 | MODIFIED | 2D freq upsample approach included as targeted 48k fallback experiment. |
| E13 | DEFERRED | WaveNeXt/ComplexDec deferred to v2 redesign track. |
| E14 | ACCEPTED | Multi-head gating + resolution conditioning included. |
| E15 | ACCEPTED | Final implementation mirrors this phased roadmap pattern. |
| E16 | ACCEPTED | Pre-encoded data reuse is built into all phases. |

Section 4: Conflicts & Resolutions
1. Conflict: first target rate (`24k first` vs `32k first` vs `direct 48k`).
Resolution: Train native 24k first for stability, then promote 32k as default if quality/latency trigger passes, and 48k as optional tier.
Decision trigger: choose 32k default if MOS/UTMOS gain over 24k is >=0.10 and p95 latency increase <=20%.

2. Conflict: 24k geometry (`hop=480, 50Hz`) vs (`hop=960 + AvgPool to 25Hz`).
Resolution: Default to 50Hz path; run 25Hz variant as controlled ablation only.
Decision trigger: adopt 25Hz only if quality is within 0.02 MOS and compute improves >=25%.

3. Conflict: external post-filter vs integrated decoder enhancement.
Resolution: Hybrid architecture: integrated residual branch is primary; AP-BWE-like external module remains fallback/rapid-ship path.
Decision trigger: fallback to external path if integrated branch misses realtime SLO by >15%.

4. Conflict: single wide ISTFT vs PQMF multiband vs source-filter.
Resolution: Primary = dual-stream STFT residual branch; secondary = PQMF multiband; source-filter priors added via conditioning before full replacement.
Decision trigger: switch to PQMF primary if HF artifact rate or LSD@8–24k remains above threshold after two sweeps.

5. Conflict: plain Vocos-at-higher-SR vs harmonic/phase-aware decoder variants.
Resolution: keep trunk, upgrade head to dual-stream + voicing conditioning first; full APCodec/Wavehax/HiFTNet replacements deferred.
Decision trigger: escalate if E4 plateau persists (<0.05 MOS gain across two major variants).

6. Conflict: diffusion/flow usage.
Resolution: not in default online path; offered as optional HQ async/premium tier.
Decision trigger: enable only if quality gain >=0.10 MOS with predictable cost envelope and no default-path SLO impact.

7. Conflict: controllability mechanism (`multi-head gating` vs `MS-BWE cascade`).
Resolution: combine both: additive cascaded high-band branches with runtime gating and target-rate embedding.
Decision trigger: if memory budget is exceeded, fall back to shared trunk + shallow rate heads.

Section 5: Ensembled Architecture (final)
**Title**
XSR-Ensemble v1: Native-24 Core + Token-Conditioned Residual High-Band Cascade (16/24/32/48)

**Brief summary**
- Keep encoder, semantic branch, and FSQ bottleneck unchanged.
- Upgrade decoder path in two layers: native 24k reconstruction + progressive high-band residual generation for 32/48k.
- Make SR selectable at inference via gating, with optional HQ generative tier off the realtime path.

**Final text diagram**
```text
Input: frozen X-Codec latents (vq_post_emb @ 50Hz) + optional decoder hidden
   |
   +--> Shared Decoder Trunk (existing VocosBackbone, trainable)
           |
           +--> Base16 Head (existing ISTFT head, 0-8k anchor)
           |
           +--> Native24 Dual-Stream Head (amp/phase-aware ISTFT, 0-12k)
           |
           +--> HF Residual Cascade (token-conditioned)
                 - HF24 branch: add 8-12k
                 - HF32 branch: add 12-16k
                 - HF48 branch: add 16-24k
                 - Conditions: vq_post_emb + base STFT + F0/UV/energy + target_sr embedding
                 - Low-band hard bypass
           |
           +--> Band Merger
                 - Default: STFT-band residual merge
                 - Optional: PQMF multi-band merge path
           |
           +--> Output Controller
                 - target_sr in {16,24,32,48}
                 - quality_tier in {realtime,hq}
                 - fast path / HQ path routing
           |
           +--> Optional external module
                 - AP-BWE/UBGAN/HiFi-GAN+ fallback
           |
           +--> Optional HQ async tier
                 - one-step flow/distilled diffusion refinement
```

**Data flow (request -> processing -> storage)**
1. Request arrives with `target_sr`, `quality_tier`, `streaming_mode`, `voice_id`.
2. Retrieve/generate codec latents (`vq_code`, `vq_post_emb`) from cache or upstream TTS stage.
3. Decode through shared trunk and select branch path by gate:
- `16k`: Base16 only.
- `24k`: Native24 head.
- `32k`: Native24 + HF24/HF32 branches.
- `48k`: Native24 + HF24/HF32/HF48 (or PQMF path if selected).
4. Optional external fallback post-filter if realtime SLA pressure or model-selection policy requires.
5. Optional HQ async refinement path for premium/offline.
6. Persist output audio to object storage; persist metadata/metrics to DB; cache intermediates for repeated prompts.

**Key components and responsibilities**
- Shared trunk: global temporal modeling at fixed 50Hz.
- Native24 head: baseline wideband improvement with minimal architecture shift.
- HF residual cascade: generates only missing bands, preserving low-band identity.
- Voicing conditioner: predicts/provides F0/UV/energy features to stabilize HF synthesis.
- Gating controller: enforces quality/latency policy and output-rate selection.
- External post-filter adapter: allows modular deployment and fallback.
- Eval/observability pipeline: enforces quality + SLO gates continuously.

**Important public API/interfaces/types changes**
- `decode(request)` request fields:
  - `target_sr: Literal[16000,24000,32000,48000]`
  - `quality_tier: Literal["realtime","hq"]`
  - `path_override: Optional[Literal["native","cascade","pqmf","external_bwe","hq_refine"]]`
- New model config fields:
  - `model.sr_gating.enabled`
  - `model.sr_gating.target_sr_embeddings`
  - `model.hf_cascade.enabled_branches = ["hf24","hf32","hf48"]`
  - `model.lowband_bypass.enabled`
  - `model.pqmf.enabled`
- New output metadata:
  - `selected_path`, `rtf`, `hf_energy_ratio`, `fallback_reason`.

**Security & privacy considerations**
- Encrypt audio artifacts at rest and in transit.
- Strict retention TTL for raw and generated audio.
- Role-based access for model endpoints and artifact stores.
- PII-safe logs: no raw waveform in logs/traces, only hashed IDs and metrics.

**Performance & cost considerations**
- Realtime default keeps transformer cadence fixed; extra cost concentrated in heads/branches.
- Compute scales with requested SR by gating branch execution.
- Cache reuse of latents/intermediates lowers repeated-utterance cost.
- HQ generative tier isolated to async path to protect latency-critical traffic.

Section 6: ADRs (key decisions)
- ADR-01 Core model strategy: Hybrid native decoder retarget + residual high-band cascade.
Context: reconcile native quality and modular low latency.
Decision: adopt hybrid.
Consequence: best balance of quality, extensibility, and rollout safety.

- ADR-02 Encoder/VQ mutability: keep frozen by default.
Context: existing pretrained bottleneck and cached data.
Decision: no encoder/VQ changes in v1.
Consequence: fast iteration, lower risk, limited latent bandwidth changes.

- ADR-03 Temporal rate policy: preserve 50Hz baseline.
Context: latency and trunk efficiency.
Decision: default 50Hz geometry; test 25Hz ablation only.
Consequence: predictable latency and minimal architectural churn.

- ADR-04 24k-first execution.
Context: strongest risk-adjusted win.
Decision: native 24k is first production milestone.
Consequence: quick quality uplift before 48k complexity.

- ADR-05 HF synthesis design.
Context: avoid low-band regressions.
Decision: residual high-band only with hard low-band bypass.
Consequence: better stability and interpretable errors.

- ADR-06 Controllability mechanism.
Context: must support 16/24/32/48 without model explosion.
Decision: target-rate embedding + additive branch gating.
Consequence: compute scales with requested quality.

- ADR-07 Model serving topology.
Context: realtime agents need strict p95 latency.
Decision: synchronous realtime inference for base/cascade, async queue for HQ tier.
Consequence: latency isolation and operational safety.

- ADR-08 Queue choice.
Context: optional HQ work must not block realtime.
Decision: durable message queue (NATS JetStream/Kafka class) for async refinements.
Consequence: backpressure control and retry semantics.

- ADR-09 Datastore choice.
Context: artifact lifecycle + experiment traceability.
Decision: object storage for audio artifacts + relational metadata store.
Consequence: cheap storage, strong lineage, manageable queryability.

- ADR-10 Caching strategy.
Context: repeated prompts/voices and shared intermediates.
Decision: cache `vq_code`, base decode, and base STFT keyed by request hash.
Consequence: reduced average compute and improved p95.

- ADR-11 Auth/privacy.
Context: voice data sensitivity.
Decision: service JWT/mTLS + per-tenant policy + retention controls.
Consequence: compliance-ready and lower data-exposure risk.

- ADR-12 Observability.
Context: quality regressions are subtle and latency-sensitive.
Decision: OpenTelemetry traces + structured logs + metrics dashboards.
Consequence: rapid diagnosis and safer rollouts.

- ADR-13 Deployment policy.
Context: multiple architecture options and potential regressions.
Decision: canary + shadow A/B + auto-rollback on SLO breach.
Consequence: controlled adoption of new SR paths.

Section 7: Implementation Plan (phased + checklists w/ suggestion IDs)
**Phase 0: Baseline harness and data contracts**
Milestone: reproducible baselines and paired training corpus.
- [ ] Build paired training pipeline `codec_decoded_input -> high_sr_target` from pre-encoded data. [B6, E16, A11, D9]
- [ ] Add deterministic resampler baseline (E0) for 24/32/48 comparisons. [C15, B7]
- [ ] Add objective suite: MR-STFT, upper-band mel, ViSQOL/LSD/FAD proxies, RTF collection. [A13, B8, C14, E6]

**Phase 1: Native 24k decoder retarget**
Milestone: production-candidate 24k model.
- [ ] Implement head-retarget config path and checkpoint interpolation utility. [A2, A4, E1, E3]
- [ ] Set default 24k geometry (50Hz-preserving), plus one ablation for 25Hz AvgPool path. [A3, C6, E2]
- [ ] Train with staged schedule and discriminator/loss stack from baseline recipe. [A13, D4, E15]
- [ ] Add high-band discriminator focus for 8–12k. [B8, D8, C14]
- [ ] Decision gate: promote if quality and latency criteria pass. [A1, B11, C2]

**Phase 2: Residual HF branch to 32k**
Milestone: controllable 32k with low-band fidelity lock.
- [ ] Add residual HF24/HF32 branch modules with hard low-band bypass. [B9, C8, C10]
- [ ] Add conditioning features (`vq_post_emb`, base STFT, F0/UV/energy). [C9, C11, C4]
- [ ] Upgrade head to dual-stream amplitude/phase outputs. [C3, C7, A9]
- [ ] Train with upper-band-weighted objectives + small adv + band discriminator. [B8, C14, D8]
- [ ] Decision gate: 32k default if MOS gain and p95 latency trigger pass. [B5, B3, C2]

**Phase 3: 48k cascade + multirate gating**
Milestone: stable 48k option with runtime gating.
- [ ] Add HF48 branch and scheduled sampling/teacher-forcing in cascaded training. [C13, C14, E8]
- [ ] Implement runtime gate for `{16,24,32,48}` and resolution dropout in training. [A14, D6, D7, E14]
- [ ] Implement PQMF multiband path and per-band mag/phase heads as secondary strategy. [A6, D1, D2, E12]
- [ ] Add capacity-scale options (projection MLP, trunk widen/deepen) behind config flags. [A5, E5]
- [ ] Hyperparameter sweep for Vocos sensitivity before finalizing 48k default. [E6, E4]

**Phase 4: Serving and platform integration**
Milestone: reliable production rollout.
- [ ] Add realtime/HQ routing controller and path metadata emission. [B3, C15, E15]
- [ ] Integrate external AP-BWE fallback and baseline alternatives (HiFi-GAN+/UBGAN). [A8, A10, E7, E9]
- [ ] Implement queue/cache/storage/auth/observability ADR decisions end-to-end. [ADR-07, ADR-08, ADR-09, ADR-10, ADR-11, ADR-12]
- [ ] Canary + shadow A/B rollout with rollback automation. [ADR-13]

**Phase 5: Optional HQ generative tier**
Milestone: premium quality lane without impacting realtime SLO.
- [ ] Integrate one-step flow/distilled diffusion in async path only. [A12, B12, E10, C15]
- [ ] Evaluate latent-space probabilistic extension prototype track. [E11, A15]
- [ ] Escalate to full decoder replacements only if plateau persists. [C12, D3, D5, E13]

Section 8: Robust Evaluation Plan (metrics + tests + SLOs)
**Unit tests**
- ISTFT/head dimension correctness for each `target_sr`.
- Band-mask and low-band bypass invariants (no low-band drift in residual mode).
- Gating logic tests for branch execution and config compatibility.
- Conditioning feature alignment tests (F0/UV frame-sync with 50Hz decoder frames).

**Integration tests**
- End-to-end decode from cached latents for all SR modes.
- Consistency tests between streaming chunked inference and full-utterance inference.
- Fallback path tests (internal cascade -> external BWE -> base path).
- Model-load and mixed-version compatibility tests (old checkpoints + new heads).

**E2E tests**
- Voice-agent pipeline smoke tests under concurrent sessions.
- Multi-tenant auth and data-retention policy verification.
- Canary shadow comparisons with automatic metric collection.

**Load tests + SLOs**
- SLO-1 Realtime latency: p95 chunk latency <=40 ms for realtime tier.
- SLO-2 RTF budgets (GPU reference): 16k<=0.03, 24k<=0.05, 32k<=0.07, 48k<=0.10.
- SLO-3 Reliability: decode failure rate <0.1%.
- SLO-4 Quality uplift: 24k must improve MOS proxy over 16k by >=0.20; 32k/48k must improve HF-LSD and ViSQOL without low-band degradation.
- SLO-5 Cost: GPU-ms per generated second must stay within configured budget envelope per tier.

**Chaos/failure injection**
- Induce queue backlog and verify realtime path isolation.
- Inject missing/invalid conditioning features (F0/UV) and verify graceful fallback.
- Simulate GPU OOM and assert automatic downgrade to lower-cost mode.
- Corrupt cache entries and verify cache bypass correctness.
- Disable one discriminator stream during training and verify alerting on quality regressions.

**Observability signals**
- Metrics: per-path RTF, p50/p95 latency, branch-hit ratio, fallback rate, HF energy ratio, clipping rate, MOS proxy, discriminator losses by band.
- Logs: request hash, target_sr, selected path, fallback reason, model version, output duration.
- Traces: spans for decode trunk, each HF branch, merger, external fallback, HQ async stage.

**Acceptance criteria per component**
- Native24 head: passes quality uplift and no regression in speaker similarity.
- HF residual branch: improves high-band metrics with low-band error below threshold.
- Gating controller: exact branch activation by mode and stable latency scaling.
- PQMF path: artifact rate not worse than STFT-merge baseline.
- External fallback: seamless takeover under SLO pressure.
- HQ tier: quality improvement measurable, realtime path unaffected.

Section 9: Risks, Failure modes, Mitigations
| Risk / failure mode | Likely cause | Mitigation | Fallback |
|---|---|---|---|
| Metallic HF artifacts | phase inconsistency | dual-stream phase losses + phase discriminators | switch to PQMF path |
| Low-band timbre damage | full-band enhancement drift | hard low-band bypass and identity loss | bypass HF branches |
| 48k underfitting | insufficient trunk/head capacity | projection MLP + width/depth scaling sweeps | keep 32k default |
| Latency breach in 48k | too many active branches | runtime gating + model pruning/quantization | degrade to 32k/24k |
| Domain mismatch | clean-LR training inputs | train on codec-decoded inputs | regenerate paired corpus |
| Cascade compounding errors | stage dependency drift | teacher forcing + scheduled sampling | run fewer stages |
| Overfitting to seen voices | narrow training slices | bandwidth-filtered but speaker-diverse sampling | add regularization/data mix |
| Ops instability | mixed model versions | strict model registry + contract tests | auto-rollback canary |
| Security leakage | raw audio in logs/artifacts | PII-safe logging + TTL + encryption | emergency retention purge |
| HQ path impacting realtime | shared resources contention | async queue isolation + quotas | hard-disable HQ tier |

Section 10: Assumptions & Open questions
- Assumption: target output set is `{16,24,32,48}` only.
- Assumption: encoder, semantic model, and FSQ stay frozen in v1.
- Assumption: pre-encoded HiFi-TTS2 assets are accessible with aligned high-rate references.
- Assumption: realtime tier has dedicated GPU serving capacity.
- Open question: final default rate target for production launch (`24k` vs `32k`) depends on Phase 2 gate.
- Open question: exact hardware SLO envelopes (A10/L4/4090/CPU class) must be finalized for hard latency budgets.
- Open question: whether 44.1k support is required later (impacts gating/head configs).
- Open question: external model licensing constraints for AP-BWE/HiFi-GAN+/UBGAN in commercial deployment.
- Open question: required speaker-similarity threshold for acceptance (define explicit metric cutoffs).
- Open question: appetite for v2 clean-slate decoder replacement (APCodec/Wavehax/ComplexDec) after v1 rollout.
</proposed_plan>