Repository navigation
refactor(native N-MOD-19): isolate DIRECT recovery coordinator and fault evidence #813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
masarray
wants to merge
3
commits into
main
Choose a base branch
from
refactor/nmod19-direct-device-recovery-coordinator-20261119
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
9ae228b
refactor(native N-MOD-19): extract DIRECT device recovery coordinator…
masarray 7e83c8d
test(native N-MOD-19): pin actual Device coordinator after ownership …
masarray 535d3f4
test(native N-MOD-19): pin independent-clock coordinator and fault te…
masarray File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| // SPDX-License-Identifier: AGPL-3.0-only | ||
| #pragma once | ||
| #include "../engine/device/DirectRestoreBackoff.h" | ||
| #include <juce_core/juce_core.h> | ||
|
|
||
| // N-MOD-19: ONE control-thread DIRECT restore coordinator. Does not own a | ||
| // device, callback, PCM renderer, driver binding, or recovery timer. The | ||
| // existing LiveAudioEngine still exclusively owns JUCE device transactions. | ||
| // The caller supplies diagnostics and operator notification sinks. | ||
| namespace armix::device { | ||
| class NativeDirectRestoreCoordinator final { | ||
| public: | ||
| using Gate=DirectRestoreBackoff; | ||
| static void annotate(juce::var& state,const Gate& gate, | ||
| const juce::String& previousError, | ||
| bool pending,std::uint64_t nowMs) { | ||
| auto* obj=state.getDynamicObject(); | ||
| if(!obj)return; | ||
| const auto snapshot=gate.snapshot(); | ||
| const char* stateName=snapshot.state==Gate::State::idle?"IDLE": | ||
| snapshot.state==Gate::State::waiting?"WAITING":"EXHAUSTED"; | ||
| obj->setProperty("directRestoreState",stateName); | ||
| obj->setProperty("directRestoreAttempts", | ||
| static_cast<int>(snapshot.attempts)); | ||
| obj->setProperty("directRestoreNextMs", | ||
| static_cast<double>(gate.remainingMs(nowMs))); | ||
| obj->setProperty("directRestoreGeneration", | ||
| static_cast<double>(snapshot.generation)); | ||
| obj->setProperty("directRestoreError",previousError); | ||
| obj->setProperty("directRestorePending",pending); | ||
| } | ||
|
|
||
| template<class Engine,class Diagnostic,class Notice> | ||
| static void service(Gate& gate,juce::String& previousError, | ||
| bool& settingsDirty,std::uint64_t nowMs, | ||
| Engine& engine,Diagnostic&& record,Notice&& notify) { | ||
| // Control thread only. Polling observes independent callback atomic | ||
| // progress but never executes or blocks inside either audio callback. | ||
| engine.pollIndependentClockHealth(nowMs); | ||
| auto snapshot=gate.snapshot(); | ||
| if(snapshot.state==Gate::State::idle && | ||
| (engine.independentClockFaulted() || | ||
| (!engine.independentClockActive() && | ||
| engine.hasPendingDirectRestore()))) { | ||
| const auto generation=gate.begin(nowMs); | ||
| record("DIRECT_RESTORE_BEGIN", | ||
| juce::String("Generation ") + | ||
| juce::String(static_cast<juce::int64>(generation))); | ||
| snapshot=gate.snapshot(); | ||
| } | ||
| if(!gate.due(snapshot.generation,nowMs))return; | ||
|
|
||
| const bool wasIndependent=engine.independentClockActive(); | ||
| const auto stateBeforeRestore=engine.status(); | ||
| const auto faultStatus=juce::JSON::toString(stateBeforeRestore,false); | ||
| // Keep field diagnostics FIRST: recorder truncation must not erase | ||
| // stream watchdog evidence when the device is disposed. | ||
| const auto watchdogSummary=juce::String("format=") | ||
| + stateBeforeRestore.getProperty("bridgeNegotiationFault","NONE").toString() | ||
| + " watchdog=" | ||
| + stateBeforeRestore.getProperty("bridgeWatchdogFault","NONE").toString() | ||
| + " captureSilentMs=" | ||
| + stateBeforeRestore.getProperty("bridgeCaptureSilentMs",0).toString() | ||
| + " renderSilentMs=" | ||
| + stateBeforeRestore.getProperty("bridgeRenderSilentMs",0).toString() | ||
| + " continuity=" | ||
| + stateBeforeRestore.getProperty("bridgeContinuityFault","NONE").toString() | ||
| + " lossBp=" | ||
| + stateBeforeRestore.getProperty("bridgeContinuityLossBp",0).toString() | ||
| + " badWindows=" | ||
| + stateBeforeRestore.getProperty("bridgeContinuityBadWindows",0).toString(); | ||
| // The actual restore call remains on the one existing engine owner. | ||
| const auto error=engine.setIndependentClockEnabled(false); | ||
| if(error.isEmpty()) { | ||
| gate.recovered(snapshot.generation); | ||
| previousError.clear(); | ||
| settingsDirty=true; | ||
| record("SMART_CLOCK_RECOVERY", | ||
| juce::String("DIRECT_RESTORED after ") + | ||
| juce::String(snapshot.attempts+1) + | ||
| " attempt(s) | " +watchdogSummary+" | "+faultStatus); | ||
| if(engine.isOutputMuted()) | ||
| notify("DIRECT device reopened. Output remains muted for safety; unmute only when ready.",true); | ||
| else | ||
| notify(wasIndependent? | ||
| "Independent device fault: safe DIRECT audio restored.": | ||
| "DIRECT audio device restored after a bounded retry.",true); | ||
| return; | ||
| } | ||
| gate.failed(snapshot.generation,nowMs); | ||
| previousError=error; | ||
| const auto next=gate.snapshot(); | ||
| record("SMART_CLOCK_RECOVERY", | ||
| juce::String("RESTORE_FAIL ") + | ||
| juce::String(next.attempts) + "/" + | ||
| juce::String(static_cast<int>(Gate::maxAttempts)) + | ||
| ": " +error+" | "+watchdogSummary+" | "+faultStatus); | ||
| if(next.state==Gate::State::exhausted) | ||
| notify("Automatic DIRECT recovery exhausted; audio remains safe/muted. " | ||
| "Check AUDIO SETUP or retry DIRECT manually. "+error,true); | ||
| else if(next.attempts==1) | ||
| notify("Device interrupted. DIRECT restore is retrying with bounded backoff.",true); | ||
| } | ||
| }; | ||
| } // namespace armix::device |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.