Deregistration Service
OpenFrame Documentation
Get the most out of OpenFrame · Book 30 minutes with Conrad, 25 years in IT. He'll show you what Mingo and Fae can take off your list.
OpenFrame Documentation
The Deregistration Service is the OpenFrame Client agent's uninstall-reporting boundary. Before local uninstall removes the agent's files, it makes a bounded, best-effort authenticated request to tell the platform that the machine has been removed. A reporting failure never prevents the local uninstall from completing.
The implementation is supplied by the openframe_agent_lib artifact from the OpenFrame OSS Library and runs with this repository's OpenFrame Client deployment. Its source is deregistration_service.rs.
The service does not delete files, stop the operating-system service, or uninstall integrated tools. Those operations belong to the platform uninstaller and are deliberately sequenced around deregistration.
The service is created by the client service-management path after administrative privileges have been checked. The platform-specific macOS and Windows uninstall flows stop and remove the agent service first, call the Deregistration Service, remove tools and local state, then make a final report attempt when needed.
flowchart LR
ServiceManagement["Client service management"] -->|"creates unless reinstall"| DeregistrationService["Deregistration Service"]
MacUninstaller["macOS uninstaller"] -->|"initial and final calls"| DeregistrationService
WindowsUninstaller["Windows uninstaller"] -->|"initial and final calls"| DeregistrationService
DeregistrationService -->|"reads configuration"| InitialConfig["Initial Configuration Service"]
DeregistrationService -->|"reads credentials"| AgentConfig["Agent Configuration Service"]
DeregistrationService -->|"fallback read"| PersistedInfo["Persisted machine-info store"]
DeregistrationService -->|"authenticated HTTPS request"| RegistrationClient["Registration Client"]
RegistrationClient -->|"POST uninstall endpoint"| ClientApi["OpenFrame Client API"]
Stopping the service precedes deregistration. This prevents the stopped agent from emitting a heartbeat that could make a just-deleted machine appear active again. Both operating-system flows preserve this ordering.
flowchart TD
Start["Uninstall requested"] --> Privileges{"Administrator privileges?"}
Privileges -->|"no"| Reject["Return uninstall error"]
Privileges -->|"yes"| Reinstall{"Reinstall in progress?"}
Reinstall -->|"yes"| Skip["Skip platform deregistration"]
Reinstall -->|"no"| Build["Create Deregistration Service"]
Build --> StopService["Stop and remove agent service"]
Skip --> StopService
StopService --> FirstReport["Run best-effort deregistration"]
FirstReport --> Cleanup["Uninstall tools and remove local state"]
Cleanup --> FinalReport["Retry only when unreported"]
FinalReport --> Complete["Finish local uninstall"]
A construction failure is logged and causes the caller to proceed without a Deregistration Service. Likewise, missing credentials cause the service to skip reporting rather than interrupt the uninstall.
DeregistrationService::new takes a DirectoryManager and derives every runtime dependency from it:
| Dependency | Purpose in deregistration |
|---|---|
| Initial Configuration Service | Reads the configured server host and whether the client runs in local mode. |
| Agent Configuration Service | Retrieves the registered machine identifier and client secret from agent configuration. |
| Persisted machine-info store | Fallback credential source that can survive a partial local wipe. |
| HTTP client | Applies a 15-second request timeout, disables proxy use, disables idle connection pooling, and accepts invalid certificates only in local mode. |
| Registration Client | Owns the API-specific request construction and response classification. |
The service formats the configured server host as an HTTPS base URL. The HTTP client uses no_proxy, so deregistration is attempted directly rather than through environment-configured proxies. Disabling per-host idle pooling avoids relying on a reusable connection during a process that is shutting down.
Credential loading happens during construction, not at the moment of the last request. The primary source is the agent configuration's (machine_id, client_secret) pair. Both values must be non-empty after trimming. If that source is unavailable, empty, or unreadable, the service reads PersistedMachineInfo from the machine-info store. Read errors from either source are logged and result in no report when no usable fallback exists.
flowchart TD
Construct["Construct Deregistration Service"] --> ReadConfig["Read agent configuration credentials"]
ReadConfig --> Valid{"Both values present?"}
Valid -->|"yes"| Snapshot["Store machine ID and client secret in memory"]
Valid -->|"no"| ReadFallback["Read persisted machine info"]
ReadConfig -->|"read error"| ReadFallback
ReadFallback --> Available{"Persisted credentials available?"}
Available -->|"yes"| Snapshot
Available -->|"no"| NoCredentials["Service skips deregistration"]
The in-memory snapshot is intentionally retained after cleanup begins. It provides the credentials required by retry_if_unreported even if the corresponding on-disk records have been deleted.
The Registration Client sends an HTTPS POST request to the following path relative to the configured server:
/clients/api/agents/uninstall
The request supplies these authentication headers:
| Header | Value source |
|---|---|
X-Machine-Id |
Persisted machine identifier |
X-Client-Secret |
Persisted client secret |
It also includes a JSON body with a deletedAt timestamp in UTC, formatted with microsecond precision. The body is included because the client implementation documents that an upstream load balancer rejects body-less POST requests; the backend uninstall contract itself does not require this data.
The client-side Registration Client classifies outcomes into Deregistered for successful HTTP statuses and AlreadyGone for status codes that mean the platform no longer knows the machine or does not expose the uninstall endpoint. Both outcomes mark the report as complete. Other non-success responses include the response body in an error, while transport errors are surfaced to the retry loop.
deregister_best_effort is the normal entry point. It returns without an error to its caller in all outcomes: no credentials, success, an already-absent platform record, transient failure, and exhausted retries. Errors are retained in logs for operational diagnosis.
Each invocation uses up to three attempts. Between failed non-final attempts it waits five seconds. Each HTTP request is limited to 15 seconds, so reporting is bounded and cannot indefinitely block removal of the local agent.
flowchart TD
Invoke["deregister_best_effort"] --> Credentials{"Credentials available?"}
Credentials -->|"no"| SkipReport["Log and continue uninstall"]
Credentials -->|"yes"| Request["Send authenticated uninstall request"]
Request --> Outcome{"Response outcome"}
Outcome -->|"success"| MarkReported["Set reported flag"]
Outcome -->|"already absent"| MarkReported
Outcome -->|"error and attempts remain"| Wait["Wait five seconds"]
Wait --> Request
Outcome -->|"final error"| LogFailure["Log warning and continue uninstall"]
The service maintains an atomic reported flag. A successful or already-gone response sets the flag with release ordering. retry_if_unreported reads it with acquire ordering:
This means the final retry is a recovery opportunity rather than an unconditional duplicate request. It is invoked after most cleanup on macOS and before Windows schedules its process-exit cleanup script.
sequenceDiagram
participant Service as Client Service
participant Uninstaller as Platform Uninstaller
participant Dereg as Deregistration Service
participant Config as Local Configuration
participant Api as Registration API
Service->>Dereg: Create with directory manager
Dereg->>Config: Read server mode and credentials
Dereg->>Dereg: Snapshot usable credentials
Service->>Uninstaller: Start operating-system uninstall
Uninstaller->>Uninstaller: Stop and remove agent service
Uninstaller->>Dereg: deregister_best_effort()
Dereg->>Api: POST authenticated uninstall request
alt Accepted or already absent
Api-->>Dereg: Deregistered or AlreadyGone
Dereg->>Dereg: Set reported flag
else Request fails
Dereg->>Dereg: Retry within bounded attempt limit
end
Uninstaller->>Uninstaller: Remove tools and local files
Uninstaller->>Dereg: retry_if_unreported()
When changing this module, preserve these behavioral invariants: