fix(vad): an explicit activation_threshold of 0.0 cannot be requested
Description
VADOptions.activation_threshold is optional, and idl/vad_options.proto puts the presence contract on the field itself:
// Unset = keep the loaded detector's calibrated value. Same normalized
// [0,1] scale as VADConfiguration.activation_threshold.
optional float activation_threshold = 1 [...];
Every reader instead uses the value as the presence test:
const bool has_override = options.activation_threshold() > 0.0f;
0.0 is inside the documented [0,1] range and the setter accepts it. rac_vad_component_set_energy_threshold rejects only out-of-range input:
if (threshold < 0.0f || threshold > 1.0f) { ... return RAC_ERROR_INVALID_PARAMETER; }
and then warns separately at < 0.002 ("may cause false positives"), so a near-zero threshold is plainly contemplated rather than nonsensical.
The energy detector's verdict is mean_sq > energy_threshold_sq (energy_vad.cpp:523), so a threshold of 0.0 means "treat any non-silent frame as speech", which is how a push-to-talk style caller disables gating. Today that request is indistinguishable from leaving the field unset, so it is silently dropped and the calibrated value stays in force.
The change
Four VADOptions readers move to has_activation_threshold(): the override flag in rac_vad_component_process_proto, and both lifecycle-VAD set_threshold guards in vad_module.cpp.
rac_vad_stream.cpp carried the same conflation one level deeper. The session stored the override as a bare float whose 0.0f doubled as "no override", so it needed a real flag rather than a different magic number. Worth noting the sibling field immediately below it already does this correctly:
s.max_speech_ms = parsed.has_max_speech_duration_ms() ? std::max(0, parsed.max_speech_duration_ms()) : 0;
VADConfiguration is deliberately untouched: its fields are not optional, so value-based defaulting is the only thing available there and is correct as written.
Type of Change
- Bug fix
- New feature
- Documentation update
- Refactoring
Testing
cmake --preset macos-debug -DRAC_BUILD_BACKENDS=ON && ninja
ctest -> 100% tests passed out of 130
Both preprocessor configurations were compiled for each edited file, since both guard parts of their bodies on RAC_HAVE_PROTOBUF: the normal build, plus a re-run of each file's own compile command with -DRAC_HAVE_PROTOBUF stripped. All four compiles exit 0.
- Lint passes locally
- Added/updated tests for changes
No test added, and I want to be straight about why rather than imply coverage I do not have. I tried to add a behavioural regression test to test_speech_proto_abi.cpp (configure a high threshold, then process quiet audio with an explicit 0.0 override and assert it flips to speech). rac_vad_component_start returns non-success for a component with no model loaded, so the energy path cannot be driven through rac_vad_component_process_proto in that harness, and the mock-model path restores the original threshold after each call so the override is not observable afterwards. Rather than ship a test that passes on the unfixed code, I dropped it. If you can point me at the right seam I will add one.
clang-format is not installed here, so I matched surrounding style by hand rather than claiming a formatter run.
Labels
-
Commons
Checklist
- Code follows project style guidelines
- Self-review completed
- Documentation updated (if needed)
Summary by CodeRabbit
- Bug Fixes
- Explicitly setting the activation threshold to
0.0now applies it as an override. - When no threshold is provided, VAD processing uses the component’s configured threshold instead of sending zero as an override.
- One-shot, streaming, and lifecycle VAD processing now consistently distinguish omitted thresholds from explicitly provided values.
- Threshold configuration failures are reported instead of being silently ignored.
- Concurrent threshold overrides are handled without interfering with one another.
- Explicitly setting the activation threshold to