Repository navigation
fix(coordinator): recover transiently-derouted providers without restart - #241
Conversation
Providers derouted for a transient reason (3 consecutive missed-challenge timeouts from sleep / network blips) were stuck StatusUntrusted until the process restarted: challengeLoop stopped challenging untrusted providers and RecordChallengeSuccess never restored routing. Make untrust reason-aware. MarkUntrusted stays a hard, non-recoverable deroute for all ~19 security call sites (bad chunk, MDM/MDA, SIP/hash mismatch, impersonation, attestation). A new MarkUntrustedTransient marks only the missed-challenge-timeout threshold deroute as recoverable: the challenge loop keeps probing it (ChallengeShouldStop), and a fully passing challenge — which re-verifies signature/SIP/secure-boot/binary/model/runtime before RecordChallengeSuccess is reached — restores it to online, mirroring MarkUntrusted's online/model bookkeeping in reverse. Safety: - A transient mark never upgrades an existing hard deroute; a later hard deroute downgrades a recoverable one. - Recovery re-checks registry membership under the write lock, so a success that races Disconnect cannot increment counts for a removed provider. - untrustedRecoverable is in-memory only (recoverability is meaningless without a live connection + challenge loop). Tests cover transient recovery, hard non-recovery, downgrade/no-upgrade ordering, the stale-after-disconnect accounting regression, the API transient-vs-security threshold split, and a -race concurrency invariant. Refs #239
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No changed files matched any Trust boundaries touchedThe file paths in this PR clearly sit inside:
Why the coverage gap existsThe threat model's Action required: Update the New trust-boundary surface that should be addedWithout the actual diff content, a full line-level review cannot be completed. However, the following standing questions apply to any change in these files and should be answered in the PR description or a follow-up review:
Recommended follow-up
🔐 Threat model: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1ec25d0229
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if recovered { | ||
| r.logger.Info("provider recovered from transient deroute", "provider_id", providerID) |
There was a problem hiding this comment.
Send online trust_status after transient recovery
When recovered is true, the registry has just moved the provider back to online, but the coordinator never tells the provider that its prior trust_status=untrusted has been cleared. The Swift provider only cancels the pending auto-report when it receives a non-untrusted trust status (provider-swift/Sources/ProviderCore/ProviderLoop.swift:1026-1030), so a provider that transiently times out and then recovers will still upload diagnostic logs ten minutes later and keep stale local trust state. Send an online trust_status on this recovery path.
Useful? React with 👍 / 👎.
Addresses Codex review (P2) on #241. When a transiently-untrusted provider recovers, the coordinator now sends a fresh "online" trust_status so the provider clears its local untrusted state and cancels the 10-minute diagnostic log auto-report it scheduled when it was told "untrusted" at deroute time. Without this, a provider that briefly times out and then recovers would still upload logs ~10 min later and show stale local trust (ProviderLoop.swift handleTrustStatus only cancels on a non-untrusted status). RecordChallengeSuccess now returns whether it recovered the provider; verifyChallengeResponse sends the online trust_status on that signal. All other callers ignore the return value (Go), so behavior elsewhere is unchanged. Also refresh the threat-model.yaml challenge-response narrative: timeouts now trigger the recoverable MarkUntrustedTransient(); signature/SIP/hash failures remain hard, non-recoverable MarkUntrusted(). Refs #239
Closes #239.
Problem
A provider derouted for a transient reason — 3 consecutive missed attestation-challenge timeouts (screen sleep, network blip, momentary SE inaccessibility) — got stuck
StatusUntrusteduntil its process restarted:challengeLoopreturned as soon asStatus == StatusUntrusted, so it received no further challenges and could never prove itself again.RecordChallengeSuccessnever restoredStatus/routing for an untrusted provider.Observed alongside the
-25308SE-key deroute. #238 fixed that root cause on the provider side (v1→v2 key migration); this fixes the general transient-deroute non-recovery on the coordinator side.A prior blanket auto-recovery attempt was reverted from #238 because
MarkUntrustedis overloaded — it is also the deroute for hard security failures (bad encrypted chunk, background MDM/MDA re-verify, SIP disabled, binary/model hash mismatch, serial impersonation, attestation failure), several of which fire mid-connection. A blanket heal could silently undo those.State machine: before vs after
Before — one sticky
Untrustedstate, recover only by restartstateDiagram-v2 state "Untrusted" as U [*] --> Online: register / reconnect Online --> U: MarkUntrusted() U --> [*]: disconnect, then reconnect note right of U Transient timeouts AND hard security failures both land here via the single MarkUntrusted(). challengeLoop returns on Untrusted (no more challenges), and RecordChallengeSuccess does not restore Status. No recovery while connected: only a process restart and re-register heals the provider. end noteAfter — reason-aware; transient self-heals, hard still needs reconnect
stateDiagram-v2 state "Untrusted (recoverable)" as T state "Untrusted (hard)" as H [*] --> Online: register / reconnect Online --> T: 3 missed-challenge timeouts Online --> H: security failure T --> T: keeps being challenged T --> Online: passing challenge T --> H: later hard deroute (downgrade) H --> [*]: disconnect, then reconnect note right of T MarkUntrustedTransient() sets recoverable = true. challengeLoop keeps probing (ChallengeShouldStop = false); RecordChallengeSuccess() restores it to Online, with registry membership re-checked under r.mu so a Disconnect race cannot corrupt onlineCount / modelProviders. end note note right of H MarkUntrusted() sets recoverable = false: bad chunk, SIP/hash, MDM/MDA, impersonation, attestation. ChallengeShouldStop = true, so it needs a reconnect. A transient mark never upgrades this back to recoverable. end noteApproach — reason-aware untrust
Strictly additive: all ~19 direct
MarkUntrustedsites stay hard/non-recoverable. Only the consecutive-failure threshold path becomes recoverable, and only for"timeout"/"no response"reasons.MarkUntrusted→ hard deroute (default; unchanged semantics for every existing caller).MarkUntrustedTransient→ used only at the missed-challenge threshold inhandleChallengeFailure. Sets an in-memoryuntrustedRecoverableflag.challengeLoopkeeps challenging recoverable-untrusted providers (ChallengeShouldStop()returns true only for a hard untrust).RecordChallengeSuccessrestores a recoverable-untrusted provider to online, mirroringMarkUntrusted'sonlineCount/modelProvidersbookkeeping in reverse.Recovery is safe because it is triggered by a fully passing challenge, which re-verifies signature + SIP + secure boot + binary hash + model hash + runtime before
RecordChallengeSuccessis reached. (Confirmed: the Swift provider sends nothing on any signing/SE failure, so the coordinator always sees a recoverable"timeout"; bad/malicious responses produce non-transient reasons that stay hard.)Safety invariants
Disconnectcannot increment counts for a removed provider.untrustedRecoverableis in-memory only — never persisted (recoverability is meaningless without a live connection + challenge loop).Verification
Design was stress-tested by an adversarial review agent (verdict: pass-with-changes). It found one HIGH accounting bug — stale-pointer recovery after
DisconnectleavingOnlineCount > ProviderCount— which is fixed by the membership recheck and has a dedicated regression test (TestStaleRecoveryAfterDisconnectDoesNotCorruptCounts).Tests
TestMarkUntrustedTransientRecovers— transient deroute → recovery restores status + counts.TestMarkUntrustedHardNotRecovered— hard deroute is never auto-recovered.TestHardDerouteOverridesTransient/TestTransientDoesNotUpgradeHard— ordering/precedence, no double-decrement.TestRecoverThenDisconnectBalancesCounts— full-cycle count balance.TestStaleRecoveryAfterDisconnectDoesNotCorruptCounts— the HIGH regression.TestHandleChallengeFailureThreshold{TransientIsRecoverable,SecurityIsHard}— API-level reason split.TestTransientRecoveryConcurrentRace—-raceinvariant:onlineCountalways equals non-untrusted registered providers.go test ./...(coordinator) passes; new tests pass under-race.Need help on this PR? Tag
@codesmithwith what you need. Autofix is disabled.