Skip to content

fix(coordinator): recover transiently-derouted providers without restart - #241

Merged
Gajesh2007 merged 3 commits into
masterfrom
fix/transient-deroute-recovery
May 29, 2026
Merged

Gajesh2007 merged 3 commits into
masterfrom
fix/transient-deroute-recovery

Conversation

@Gajesh2007

@Gajesh2007 Gajesh2007 commented May 29, 2026 •

Copy link
Copy Markdown
Member

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 StatusUntrusted until its process restarted:

  • challengeLoop returned as soon as Status == StatusUntrusted, so it received no further challenges and could never prove itself again.
  • RecordChallengeSuccess never restored Status/routing for an untrusted provider.

Observed alongside the -25308 SE-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 MarkUntrusted is 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 Untrusted state, recover only by restart

stateDiagram-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 note
Loading

After — 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 note
Loading

Approach — reason-aware untrust

Strictly additive: all ~19 direct MarkUntrusted sites 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 in handleChallengeFailure. Sets an in-memory untrustedRecoverable flag.
  • challengeLoop keeps challenging recoverable-untrusted providers (ChallengeShouldStop() returns true only for a hard untrust).
  • RecordChallengeSuccess restores a recoverable-untrusted provider to online, mirroring MarkUntrusted's onlineCount/modelProviders bookkeeping 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 RecordChallengeSuccess is 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

  • 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 — 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 Disconnect leaving OnlineCount > 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 — -race invariant: onlineCount always equals non-untrusted registered providers.

go test ./... (coordinator) passes; new tests pass under -race.


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag @codesmith with what you need. Autofix is disabled.

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
@vercel

vercel Bot commented May 29, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
d-inference Ready Ready Preview May 29, 2026 8:36am
d-inference-console-ui-dev Ready Ready Preview May 29, 2026 8:36am
d-inference-landing Ready Ready Preview May 29, 2026 8:36am

Request Review

@github-actions

github-actions Bot commented May 29, 2026 •

Copy link
Copy Markdown
Contributor

No changed files matched any affected_files pattern in the threat model, but several of the modified files are high-value security components that are referenced by threat descriptions yet missing from the pattern list — this is a coverage gap in the threat model itself, not an absence of security relevance.


Trust boundaries touched

The file paths in this PR clearly sit inside:

Boundary Why
TB-002 (Coordinator → Provider WebSocket) coordinator/api/provider.go is the WebSocket upgrade and registration handler described verbatim in TB-002
TB-002 (same) coordinator/registry/registry.go is the active provider registry described in TB-002 and referenced by T-006, T-007, T-009
Meta docs/threat-model.yaml is the threat model document itself

Why the coverage gap exists

The threat model's affected_files patterns use the path prefix coordinator/internal/api/ and coordinator/internal/registry/, but the changed files live at coordinator/api/ and coordinator/registry/ (no internal/ segment). Every threat that lists these components is effectively unmatched by the automated check. Affected threats include at minimum: T-006, T-007, T-008, T-009, T-012, T-013, T-015, T-021, T-036, T-039.

Action required: Update the affected_files patterns in docs/threat-model.yaml (or the CI path-matching logic) to also cover coordinator/api/** and coordinator/registry/**. Until this is fixed, every future PR touching these files will silently bypass automated threat-model gating.


New trust-boundary surface that should be added

Without 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:

  1. coordinator/api/provider.go — Does this change touch the WebSocket upgrade path, provider registration, attestation verification sequencing, or the MarkUntrusted / trust-state machine? If so it is directly in scope for T-006, T-015, T-021, and T-036 (critical severity). The reviewer should confirm no step in the MDM→MDA→challenge chain has been short-circuited.

  2. coordinator/registry/registry.go — Does this change alter the private-text routing gate (the 11-flag conjunction at registry.go:169–197)? That gate is the primary enforcement point for SEC-017 (T-009) and the weight-hash fail-open issue (SEC-007, T-007/T-027). Any relaxation of those conditions is a high-severity regression.

  3. docs/threat-model.yaml — This PR modifies the canonical threat model. The diff should be reviewed to ensure no existing threat has been downgraded, no open finding silently closed without a corresponding code fix, and no affected_files pattern has been narrowed in a way that reduces automated coverage (as appears to have already happened).


Recommended follow-up

  • Fix affected_files path prefixes in the threat model so the CI gate works correctly for these components.
  • Re-run this review once the diff content is available, targeting at minimum T-006, T-015, T-036 (critical), and T-007, T-021, T-039 (high).

🔐 Threat model: docs/threat-model.yaml · Updates on each push to this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +1787 to +1788
if recovered {
r.logger.Info("provider recovered from transient deroute", "provider_id", providerID)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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

This branch had an error being deployed

1 failed and 3 active deployments
Preview – d-inference-console-ui-dev — 46d74e93 Deployed May 29, 2026 by vercel[bot]
Preview – d-inference — 46d74e93 Deployed May 29, 2026 by vercel[bot]
Preview – d-inference-landing — 46d74e93 Deployed May 29, 2026 by vercel[bot]
benchmarks — 46d74e93 Deployed May 29, 2026 by Gajesh2007 via E2E Benchmarks #484
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Coordinator: transiently-derouted providers can't recover without a restart

1 participant