From 1ec25d0229b7666eefd5124fb0b1f7e48a36c86f Mon Sep 17 00:00:00 2001 From: Gajesh Naik <26431906+Gajesh2007@users.noreply.github.com> Date: Fri, 29 May 2026 01:05:27 -0700 Subject: [PATCH 1/2] fix(coordinator): recover transiently-derouted providers without restart MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- coordinator/api/provider.go | 17 ++- coordinator/api/provider_test.go | 57 ++++++++ coordinator/registry/registry.go | 121 +++++++++++++++- coordinator/registry/registry_test.go | 199 ++++++++++++++++++++++++++ 4 files changed, 383 insertions(+), 11 deletions(-) diff --git a/coordinator/api/provider.go b/coordinator/api/provider.go index 7a76a578a2..4d6961757b 100644 --- a/coordinator/api/provider.go +++ b/coordinator/api/provider.go @@ -484,10 +484,10 @@ func (s *Server) challengeLoop(ctx context.Context, conn *websocket.Conn, provid case <-ctx.Done(): return case <-ticker.C: - provider.Mu().Lock() - untrusted := provider.Status == registry.StatusUntrusted - provider.Mu().Unlock() - if untrusted { + // Stop only for a hard (non-recoverable) untrust. A transiently + // untrusted provider (missed-challenge timeouts) keeps being + // challenged so a later passing challenge can restore it. + if provider.ChallengeShouldStop() { return } s.sendChallenge(ctx, conn, providerID, provider, tracker) @@ -964,7 +964,14 @@ func (s *Server) handleChallengeFailure(providerID string, reason string) { severity := protocol.SeverityWarn if failures >= registry.MaxFailedChallenges { severity = protocol.SeverityError - s.registry.MarkUntrusted(providerID) + if transient { + // Missed-challenge timeouts (sleep / network blip) are recoverable: + // keep challenging and let a later passing challenge restore the + // provider without requiring a reconnect. + s.registry.MarkUntrustedTransient(providerID) + } else { + s.registry.MarkUntrusted(providerID) + } if p := s.registry.GetProvider(providerID); p != nil { s.sendTrustStatus(p, p.TrustLevel, string(registry.StatusUntrusted), reason) } diff --git a/coordinator/api/provider_test.go b/coordinator/api/provider_test.go index d2446cfdd2..c64b7eace5 100644 --- a/coordinator/api/provider_test.go +++ b/coordinator/api/provider_test.go @@ -2289,6 +2289,63 @@ func TestHandleChunkRejectsMixedPlaintextAndEncryptedTextChunk(t *testing.T) { } } +// Issue #239: hitting the failure threshold via missed-challenge timeouts marks +// the provider untrusted but *recoverable* (the challenge loop keeps probing it). +func TestHandleChallengeFailureThresholdTransientIsRecoverable(t *testing.T) { + logger := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelError})) + st := store.NewMemory(store.Config{AdminKey: "test-key"}) + reg := registry.New(logger) + srv := NewServer(reg, st, ServerConfig{}, logger) + + p := reg.Register("p1", nil, &protocol.RegisterMessage{ + Type: protocol.TypeRegister, + Hardware: protocol.Hardware{ChipName: "Apple M3 Max", MemoryGB: 64}, + Models: []protocol.ModelInfo{{ID: "test-model", ModelType: "chat", Quantization: "4bit"}}, + Backend: "mlx-swift", + }) + + for range registry.MaxFailedChallenges { + srv.handleChallengeFailure("p1", "timeout") + } + + if p.Status != registry.StatusUntrusted { + t.Fatalf("status = %q, want %q after %d timeouts", p.Status, registry.StatusUntrusted, registry.MaxFailedChallenges) + } + if p.ChallengeShouldStop() { + t.Error("ChallengeShouldStop = true, want false (timeout-threshold deroute must be recoverable)") + } + if reg.OnlineCount() != 0 { + t.Errorf("OnlineCount = %d, want 0", reg.OnlineCount()) + } +} + +// Issue #239: a non-transient reason at the threshold is a hard deroute — the +// challenge loop stops and it cannot self-recover. +func TestHandleChallengeFailureThresholdSecurityIsHard(t *testing.T) { + logger := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelError})) + st := store.NewMemory(store.Config{AdminKey: "test-key"}) + reg := registry.New(logger) + srv := NewServer(reg, st, ServerConfig{}, logger) + + p := reg.Register("p1", nil, &protocol.RegisterMessage{ + Type: protocol.TypeRegister, + Hardware: protocol.Hardware{ChipName: "Apple M3 Max", MemoryGB: 64}, + Models: []protocol.ModelInfo{{ID: "test-model", ModelType: "chat", Quantization: "4bit"}}, + Backend: "mlx-swift", + }) + + for range registry.MaxFailedChallenges { + srv.handleChallengeFailure("p1", "nonce mismatch") + } + + if p.Status != registry.StatusUntrusted { + t.Fatalf("status = %q, want %q", p.Status, registry.StatusUntrusted) + } + if !p.ChallengeShouldStop() { + t.Error("ChallengeShouldStop = false, want true (security-threshold deroute must be hard)") + } +} + // Verification: the coordinator's SSE output for a private text request contains // only the decrypted content — no raw ciphertext, no session keys, no encrypted // payloads leak into the consumer-visible HTTP response. diff --git a/coordinator/registry/registry.go b/coordinator/registry/registry.go index 857c759492..8bdb1dbda3 100644 --- a/coordinator/registry/registry.go +++ b/coordinator/registry/registry.go @@ -213,6 +213,13 @@ type Provider struct { LastChallengeVerified time.Time // last successful challenge verification FailedChallenges int // consecutive failed challenges + // untrustedRecoverable marks an untrust as a *transient* missed-challenge + // deroute (timeout / no-response) that may self-recover on the next passing + // challenge. It is false for every hard/security deroute. In-memory only — + // never persisted, because recoverability is meaningless without a live + // WebSocket and a running challenge loop. + untrustedRecoverable bool + mu sync.Mutex pendingReqs map[string]*PendingRequest } @@ -326,6 +333,16 @@ func (p *Provider) Mu() *sync.Mutex { return &p.mu } +// ChallengeShouldStop reports whether the attestation challenge loop should +// stop for this provider. It stops only for a *hard* (non-recoverable) untrust; +// a transiently-untrusted provider keeps being challenged so a later passing +// challenge can restore it via RecordChallengeSuccess. Thread-safe. +func (p *Provider) ChallengeShouldStop() bool { + p.mu.Lock() + defer p.mu.Unlock() + return p.Status == StatusUntrusted && !p.untrustedRecoverable +} + // SetAttestationResult stores the parsed attestation result (thread-safe). func (p *Provider) SetAttestationResult(result *attestation.VerificationResult) { p.mu.Lock() @@ -1659,10 +1676,41 @@ func (r *Registry) GetProvider(id string) *Provider { return r.providers[id] } -// MarkUntrusted sets a provider's status to untrusted, preventing it from -// receiving new jobs. This is called when a provider fails too many -// challenge-response verifications. +// MarkUntrusted sets a provider's status to untrusted for a hard/security +// reason (bad encrypted chunk, MDM/MDA failure, SIP disabled, binary or model +// hash mismatch, serial impersonation, attestation failure). The deroute is +// non-recoverable: the provider stays untrusted until it reconnects and +// re-registers. This is the default for every direct deroute call site. func (r *Registry) MarkUntrusted(providerID string) { + r.markUntrusted(providerID, false) +} + +// MarkUntrustedTransient sets a provider's status to untrusted for a *transient* +// reason — MaxFailedChallenges consecutive missed-challenge timeouts (screen +// sleep, network blip, momentary Secure Enclave inaccessibility). Unlike +// MarkUntrusted, the provider remains eligible to self-recover: the challenge +// loop keeps challenging it (see ChallengeShouldStop), and a subsequent fully +// passing challenge (RecordChallengeSuccess) restores it to online. +// +// A passing challenge re-verifies signature, SIP, secure boot, binary hash, +// model hash and runtime before RecordChallengeSuccess is reached, so using it +// as the recovery trigger is safe. +func (r *Registry) MarkUntrustedTransient(providerID string) { + r.markUntrusted(providerID, true) +} + +// markUntrusted is the shared implementation. recoverable=true marks the untrust +// as transiently recoverable; recoverable=false is a hard deroute. +// +// Transition rules: +// - not untrusted -> untrusted: decrement online/model counts, set status and +// the recoverable flag. +// - already untrusted + hard (recoverable=false): clear the flag. A hard +// reason always overrides/downgrades a previously-recoverable untrust. +// - already untrusted + transient (recoverable=true): leave the flag as-is, so +// a transient timeout can never *upgrade* a hard deroute to recoverable +// (matters for an in-flight challenge timeout that races a hard deroute). +func (r *Registry) markUntrusted(providerID string, recoverable bool) { r.mu.Lock() p, ok := r.providers[providerID] if !ok { @@ -1676,14 +1724,19 @@ func (r *Registry) MarkUntrusted(providerID string) { for _, m := range p.Models { r.modelProviderDec(m.ID) } + p.Status = StatusUntrusted + p.untrustedRecoverable = recoverable + } else if !recoverable { + p.untrustedRecoverable = false } - p.Status = StatusUntrusted + failed := p.FailedChallenges // read under p.mu (the old code read this unlocked) p.mu.Unlock() r.mu.Unlock() r.logger.Warn("provider marked as untrusted", "provider_id", providerID, - "failed_challenges", p.FailedChallenges, + "failed_challenges", failed, + "recoverable", recoverable, ) } @@ -1704,6 +1757,10 @@ func (r *Registry) SetTrustLevel(providerID string, level TrustLevel) { } // RecordChallengeSuccess records a successful challenge-response verification. +// A fully passing challenge re-verifies signature, SIP, secure boot, binary +// hash, model hash and runtime (see verifyChallengeResponse) before this is +// called, so it doubles as the recovery trigger for a *transiently* untrusted +// provider. func (r *Registry) RecordChallengeSuccess(providerID string) { r.mu.RLock() p, ok := r.providers[providerID] @@ -1712,6 +1769,8 @@ func (r *Registry) RecordChallengeSuccess(providerID string) { return } + recovered := r.recoverIfTransientlyUntrusted(providerID, p) + p.mu.Lock() p.LastChallengeVerified = time.Now() p.FailedChallenges = 0 @@ -1725,10 +1784,60 @@ func (r *Registry) RecordChallengeSuccess(providerID string) { r.persistProviderNow(p) r.persistReputation(p) - // A newly verified provider may unlock queued requests for any model it serves. + if recovered { + r.logger.Info("provider recovered from transient deroute", "provider_id", providerID) + } + + // A newly verified (or newly recovered) provider may unlock queued requests + // for any model it serves. r.drainQueuedRequestsForModels(providerModelIDs(p)) } +// recoverIfTransientlyUntrusted promotes a transiently-untrusted provider back +// to online, mirroring markUntrusted's bookkeeping in reverse. Returns true iff +// a transition occurred. It acquires r.mu (write) then p.mu — the same order as +// markUntrusted/Register/Disconnect — so online/model counts stay consistent and +// the path is deadlock-free. +func (r *Registry) recoverIfTransientlyUntrusted(providerID string, p *Provider) bool { + // Cheap pre-check under p.mu only, so the common (non-recovery) success path + // never contends on the registry write lock. + p.mu.Lock() + eligible := p.Status == StatusUntrusted && p.untrustedRecoverable + p.mu.Unlock() + if !eligible { + return false + } + + r.mu.Lock() + // Re-verify membership: RecordChallengeSuccess looked p up under RLock and + // released it, so Disconnect may have removed (or replaced) it since. A + // transiently-untrusted provider was already decremented out of the counts, + // and Disconnect does not decrement an untrusted provider, so incrementing a + // stale/removed pointer here would permanently corrupt onlineCount and + // modelProviders. Only recover the provider still registered under this ID. + if cur, ok := r.providers[providerID]; !ok || cur != p { + r.mu.Unlock() + return false + } + p.mu.Lock() + // Re-check under the write lock: a hard deroute may have intervened and + // cleared the recoverable flag between the pre-check and here. + if p.Status != StatusUntrusted || !p.untrustedRecoverable { + p.mu.Unlock() + r.mu.Unlock() + return false + } + r.onlineCount.Add(1) + for _, m := range p.Models { + r.modelProviderInc(m.ID) + } + p.Status = StatusOnline + p.untrustedRecoverable = false + p.mu.Unlock() + r.mu.Unlock() + return true +} + // RecordChallengeFailure records a failed challenge-response. Returns the // new consecutive failure count. // diff --git a/coordinator/registry/registry_test.go b/coordinator/registry/registry_test.go index aa1a0badbf..84953526be 100644 --- a/coordinator/registry/registry_test.go +++ b/coordinator/registry/registry_test.go @@ -837,6 +837,205 @@ func TestHeartbeatDoesNotReviveUntrusted(t *testing.T) { } } +// --- Issue #239: reason-aware transient-deroute recovery --- + +const recoverTestModel = "mlx-community/Qwen3.5-9B-Instruct-4bit" + +// A transient (missed-challenge timeout) deroute is recoverable: the provider +// returns to online on the next passing challenge, with all counts restored. +func TestMarkUntrustedTransientRecovers(t *testing.T) { + reg := New(testLogger()) + p := reg.Register("p1", nil, testRegisterMessage()) + + reg.MarkUntrustedTransient("p1") + + if p.Status != StatusUntrusted { + t.Fatalf("status = %q, want %q", p.Status, StatusUntrusted) + } + if reg.OnlineCount() != 0 { + t.Errorf("OnlineCount = %d, want 0 after transient deroute", reg.OnlineCount()) + } + if got := reg.ModelProviderSnapshot()[recoverTestModel]; got != 0 { + t.Errorf("model provider count = %d, want 0 after transient deroute", got) + } + if p.ChallengeShouldStop() { + t.Error("ChallengeShouldStop = true, want false for a transiently-untrusted provider") + } + + reg.RecordChallengeSuccess("p1") + + if p.Status != StatusOnline { + t.Fatalf("status = %q, want %q after recovery", p.Status, StatusOnline) + } + if reg.OnlineCount() != 1 { + t.Errorf("OnlineCount = %d, want 1 after recovery", reg.OnlineCount()) + } + if got := reg.ModelProviderSnapshot()[recoverTestModel]; got != 1 { + t.Errorf("model provider count = %d, want 1 after recovery", got) + } + if p.FailedChallenges != 0 { + t.Errorf("FailedChallenges = %d, want 0 after recovery", p.FailedChallenges) + } + if p.LastChallengeVerified.IsZero() { + t.Error("LastChallengeVerified should be set after recovery") + } + if p.untrustedRecoverable { + t.Error("untrustedRecoverable should be cleared after recovery") + } +} + +// A hard/security deroute is never auto-recovered by a passing challenge. +func TestMarkUntrustedHardNotRecovered(t *testing.T) { + reg := New(testLogger()) + p := reg.Register("p1", nil, testRegisterMessage()) + + reg.MarkUntrusted("p1") // hard + + if !p.ChallengeShouldStop() { + t.Error("ChallengeShouldStop = false, want true for a hard-untrusted provider") + } + + reg.RecordChallengeSuccess("p1") + + if p.Status != StatusUntrusted { + t.Fatalf("status = %q, want %q (hard deroute must not auto-recover)", p.Status, StatusUntrusted) + } + if reg.OnlineCount() != 0 { + t.Errorf("OnlineCount = %d, want 0 (hard deroute must stay derouted)", reg.OnlineCount()) + } +} + +// A later hard deroute downgrades a recoverable untrust; no double-decrement. +func TestHardDerouteOverridesTransient(t *testing.T) { + reg := New(testLogger()) + p := reg.Register("p1", nil, testRegisterMessage()) + + reg.MarkUntrustedTransient("p1") // recoverable... + reg.MarkUntrusted("p1") // ...downgraded to hard + + if !p.ChallengeShouldStop() { + t.Error("ChallengeShouldStop = false, want true after a hard deroute downgrades a transient one") + } + if reg.OnlineCount() != 0 { + t.Errorf("OnlineCount = %d, want 0 (no double-decrement)", reg.OnlineCount()) + } + + reg.RecordChallengeSuccess("p1") + if p.Status != StatusUntrusted { + t.Fatalf("status = %q, want %q (downgraded hard deroute must not recover)", p.Status, StatusUntrusted) + } + if reg.OnlineCount() != 0 { + t.Errorf("OnlineCount = %d, want 0 after non-recovery", reg.OnlineCount()) + } +} + +// A transient deroute must never *upgrade* an existing hard deroute to +// recoverable (matters for an in-flight challenge timeout racing a hard mark). +func TestTransientDoesNotUpgradeHard(t *testing.T) { + reg := New(testLogger()) + p := reg.Register("p1", nil, testRegisterMessage()) + + reg.MarkUntrusted("p1") // hard first + reg.MarkUntrustedTransient("p1") // must NOT upgrade to recoverable + + if !p.ChallengeShouldStop() { + t.Error("ChallengeShouldStop = false, want true (transient must not upgrade a hard deroute)") + } + reg.RecordChallengeSuccess("p1") + if p.Status != StatusUntrusted { + t.Fatalf("status = %q, want %q (hard deroute must stay hard)", p.Status, StatusUntrusted) + } +} + +// Full cycle register -> transient deroute -> recover -> disconnect balances counts. +func TestRecoverThenDisconnectBalancesCounts(t *testing.T) { + reg := New(testLogger()) + reg.Register("p1", nil, testRegisterMessage()) + + reg.MarkUntrustedTransient("p1") + reg.RecordChallengeSuccess("p1") // recover + if reg.OnlineCount() != 1 { + t.Fatalf("OnlineCount = %d, want 1 after recovery", reg.OnlineCount()) + } + reg.Disconnect("p1") + if reg.OnlineCount() != 0 { + t.Errorf("OnlineCount = %d, want 0 after disconnect", reg.OnlineCount()) + } + if got := reg.ModelProviderSnapshot()[recoverTestModel]; got != 0 { + t.Errorf("model provider count = %d, want 0 after disconnect", got) + } +} + +// Regression for the verifier's HIGH finding: a recovery that resolved the +// provider before Disconnect removed it must not increment counts for the stale +// pointer (which would leave OnlineCount > ProviderCount forever). +func TestStaleRecoveryAfterDisconnectDoesNotCorruptCounts(t *testing.T) { + reg := New(testLogger()) + p := reg.Register("p1", nil, testRegisterMessage()) + + reg.MarkUntrustedTransient("p1") + reg.Disconnect("p1") + if reg.OnlineCount() != 0 || reg.ProviderCount() != 0 { + t.Fatalf("pre-state OnlineCount=%d ProviderCount=%d, want 0/0", reg.OnlineCount(), reg.ProviderCount()) + } + + if reg.recoverIfTransientlyUntrusted("p1", p) { + t.Error("recoverIfTransientlyUntrusted recovered a disconnected (stale) provider") + } + if reg.OnlineCount() != 0 { + t.Errorf("OnlineCount = %d, want 0 (stale recovery must not increment)", reg.OnlineCount()) + } + if got := reg.ModelProviderSnapshot()[recoverTestModel]; got != 0 { + t.Errorf("model provider count = %d, want 0 (stale recovery must not increment)", got) + } +} + +// Concurrency invariant (run with -race): after arbitrary interleavings of +// transient/hard deroutes, recoveries, and disconnects, onlineCount must equal +// the number of still-registered, non-untrusted providers — no drift, no panic, +// no deadlock. +func TestTransientRecoveryConcurrentRace(t *testing.T) { + reg := New(testLogger()) + const n = 60 + for i := range n { + reg.Register(fmt.Sprintf("p%d", i), nil, testRegisterMessage()) + } + + var wg sync.WaitGroup + for i := range n { + id := fmt.Sprintf("p%d", i) + ops := []func(){ + func() { reg.MarkUntrustedTransient(id) }, + func() { reg.RecordChallengeSuccess(id) }, + func() { reg.MarkUntrusted(id) }, + func() { reg.RecordChallengeSuccess(id) }, + } + if i%3 == 0 { + // Also exercise the stale-recovery membership guard. + ops = append(ops, func() { reg.Disconnect(id) }) + } + for _, op := range ops { + wg.Add(1) + go func(f func()) { defer wg.Done(); f() }(op) + } + } + wg.Wait() + + var expectedOnline int64 + for i := range n { + if p := reg.GetProvider(fmt.Sprintf("p%d", i)); p != nil { + p.Mu().Lock() + if p.Status != StatusUntrusted { + expectedOnline++ + } + p.Mu().Unlock() + } + } + if got := reg.OnlineCount(); got != expectedOnline { + t.Errorf("OnlineCount = %d, want %d (must equal non-untrusted registered providers)", got, expectedOnline) + } +} + // --- scoring tests --- func TestScoringHigherDecodeTPS(t *testing.T) { From 16b28958a275ad6e49f37cf62c61f90ab32edf8f Mon Sep 17 00:00:00 2001 From: Gajesh Naik <26431906+Gajesh2007@users.noreply.github.com> Date: Fri, 29 May 2026 01:22:07 -0700 Subject: [PATCH 2/2] fix(coordinator): push online trust_status on transient recovery 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 --- coordinator/api/provider.go | 12 +++++++++++- coordinator/registry/registry.go | 11 +++++++++-- coordinator/registry/registry_test.go | 14 ++++++++++---- docs/threat-model.yaml | 8 ++++++-- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/coordinator/api/provider.go b/coordinator/api/provider.go index 4d6961757b..e3e6a45891 100644 --- a/coordinator/api/provider.go +++ b/coordinator/api/provider.go @@ -912,7 +912,17 @@ func (s *Server) verifyChallengeResponse(providerID string, provider *registry.P provider.Mu().Unlock() // Challenge passed. - s.registry.RecordChallengeSuccess(providerID) + recovered := s.registry.RecordChallengeSuccess(providerID) + if recovered { + // The provider was transiently untrusted and is now back online. It was + // last told "untrusted" (handleChallengeFailure) and scheduled a 10-min + // diagnostic auto-report; push a fresh "online" trust_status so it clears + // that local state and cancels the report. + provider.Mu().Lock() + trustLevel := provider.TrustLevel + provider.Mu().Unlock() + s.sendTrustStatus(provider, trustLevel, "online", "recovered after transient deroute") + } s.ddIncr("attestation.challenges", []string{"outcome:passed"}) s.logger.Info("attestation challenge verified", "provider_id", providerID, diff --git a/coordinator/registry/registry.go b/coordinator/registry/registry.go index 8bdb1dbda3..d70ebe6517 100644 --- a/coordinator/registry/registry.go +++ b/coordinator/registry/registry.go @@ -1761,12 +1761,17 @@ func (r *Registry) SetTrustLevel(providerID string, level TrustLevel) { // hash, model hash and runtime (see verifyChallengeResponse) before this is // called, so it doubles as the recovery trigger for a *transiently* untrusted // provider. -func (r *Registry) RecordChallengeSuccess(providerID string) { +// +// Returns true iff this call recovered a transiently-untrusted provider back to +// online. The caller (verifyChallengeResponse) uses that to push a fresh +// "online" trust_status so the provider clears its local untrusted state and +// cancels the pending diagnostic auto-report it scheduled at deroute time. +func (r *Registry) RecordChallengeSuccess(providerID string) bool { r.mu.RLock() p, ok := r.providers[providerID] r.mu.RUnlock() if !ok { - return + return false } recovered := r.recoverIfTransientlyUntrusted(providerID, p) @@ -1791,6 +1796,8 @@ func (r *Registry) RecordChallengeSuccess(providerID string) { // A newly verified (or newly recovered) provider may unlock queued requests // for any model it serves. r.drainQueuedRequestsForModels(providerModelIDs(p)) + + return recovered } // recoverIfTransientlyUntrusted promotes a transiently-untrusted provider back diff --git a/coordinator/registry/registry_test.go b/coordinator/registry/registry_test.go index 84953526be..6aa2b492d8 100644 --- a/coordinator/registry/registry_test.go +++ b/coordinator/registry/registry_test.go @@ -721,8 +721,10 @@ func TestRecordChallengeSuccess(t *testing.T) { reg.RecordChallengeFailure("p1", true) reg.RecordChallengeFailure("p1", true) - // Now record success - reg.RecordChallengeSuccess("p1") + // Now record success (provider was never untrusted -> not a recovery) + if reg.RecordChallengeSuccess("p1") { + t.Error("RecordChallengeSuccess should report recovery=false for a non-untrusted provider") + } if p.FailedChallenges != 0 { t.Errorf("failed_challenges = %d, want 0 after success", p.FailedChallenges) @@ -862,7 +864,9 @@ func TestMarkUntrustedTransientRecovers(t *testing.T) { t.Error("ChallengeShouldStop = true, want false for a transiently-untrusted provider") } - reg.RecordChallengeSuccess("p1") + if !reg.RecordChallengeSuccess("p1") { + t.Error("RecordChallengeSuccess should report recovery for a transiently-untrusted provider") + } if p.Status != StatusOnline { t.Fatalf("status = %q, want %q after recovery", p.Status, StatusOnline) @@ -895,7 +899,9 @@ func TestMarkUntrustedHardNotRecovered(t *testing.T) { t.Error("ChallengeShouldStop = false, want true for a hard-untrusted provider") } - reg.RecordChallengeSuccess("p1") + if reg.RecordChallengeSuccess("p1") { + t.Error("RecordChallengeSuccess must not report recovery for a hard-untrusted provider") + } if p.Status != StatusUntrusted { t.Fatalf("status = %q, want %q (hard deroute must not auto-recover)", p.Status, StatusUntrusted) diff --git a/docs/threat-model.yaml b/docs/threat-model.yaml index 59863e7f6e..573762a781 100644 --- a/docs/threat-model.yaml +++ b/docs/threat-model.yaml @@ -641,8 +641,12 @@ trust_boundaries: it with a UTC RFC3339 timestamp. The provider signs (nonce + timestamp) with the SE key — raw string concatenation with no delimiter. The coordinator verifies the ECDSA signature, checks nonce matches, and checks that SIPEnabled is not nil and - not false. SIP=false triggers immediate MarkUntrusted(); 3 consecutive timeouts or - signature failures trigger MarkUntrusted() via the 3-strike counter. + not false. SIP=false (and other security failures: bad signature, hash mismatch, + impersonation) trigger immediate, non-recoverable MarkUntrusted(). 3 consecutive + challenge *timeouts* (sleep / network blip) trigger MarkUntrustedTransient() via the + 3-strike counter: the provider is derouted but the challenge loop keeps probing it, + and the next fully passing challenge restores it to online (RecordChallengeSuccess). + Signature/SIP/hash failures are never auto-recovered and still require a reconnect. Status signature (attestation.go:378–437): an extended canonical JSON payload covering nonce, timestamp, and all security status fields is signed separately.