Update Handler 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 Update Handler Service finalizes an OpenFrame client self-update after the client process starts again. It is implemented by UpdateHandlerService in the OpenFrame OSS Library's Rust client and is assembled into this repository's OpenFrame client runtime through the openframe_agent_lib dependency. Its responsibility is recovery-oriented: it reads persisted update state, decides whether the running binary proves success, preserves rollback protection, records failures, settles deferred delivery results, and publishes the version now running on the device.
The implementation is in the Update Handler Service source.
UpdateHandlerService from persistence, cleanup, version-reporting, identity, last-known-good, and result-store collaborators.UpdaterLaunched or Verifying, enforcing the configured crash-loop limit.OPENFRAME_VERSION with the persisted target version.Updated or Failed without letting bookkeeping failures prevent recovery.openframe-client version through the installed-agent publisher, retrying publication up to five times.An update command is processed by the client update path before this service runs. The client update service reserves exclusive update work, rejects invalid versions, avoids an already-running version, applies downgrade protection using the last-known-good anchor, writes update state immediately before updater launch, and changes the client status to Updating. The Update Handler Service runs after process startup to reconcile that durable state with the executable that actually started.
flowchart LR
CommandListener["Command listener"] --> ClientUpdateHandler["Client update handler"]
ClientUpdateHandler --> UpdateService["Client update service"]
UpdateService --> StateFile["Persisted update state"]
UpdateService --> Updater["Platform updater"]
Updater --> RestartedClient["Restarted OpenFrame client"]
RestartedClient --> Handler["Update Handler Service"]
Handler --> ClientInfo["Client version and update status"]
Handler --> Lkg["Last-known-good reserve"]
Handler --> ResultStore["Deferred delivery result store"]
Handler --> Publisher["Installed-agent version publisher"]
The Update Handler Service is not the component that downloads or swaps the executable. That work belongs to the client update service and platform updater. It is the post-restart authority that converts persisted update state into an observed outcome.
The service is constructed with seven collaborators. They separate durable state, cleanup, rollback safety, messaging, machine identity, and delivery completion from the decision logic.
flowchart TD
Handler["Update Handler Service"] --> StateService["Update State Service"]
Handler --> ClientInfo["OpenFrame Client Info Service"]
Handler --> Cleanup["Update Cleanup Service"]
Handler --> Lkg["Last-known-good Service"]
Handler --> InstalledPublisher["Installed-agent Message Publisher"]
Handler --> Config["Agent Configuration Service"]
Handler --> Results["Result Store"]
StateService --> StateFile["Update state file"]
Lkg --> Reserve["Reserve binary and anchor"]
Cleanup --> UpdateArtifacts["Staged update artifacts"]
Results --> DeliveryLedger["Delivery ledger"]
InstalledPublisher --> Nats["NATS notification"]
| Collaborator | Role in Update Handler Service |
|---|---|
UpdateStateService |
Loads, saves, clears, and locates the durable UpdateState. Its save operation serializes state as JSON and writes it atomically. |
OpenFrameClientInfoService |
Records the target version and the Updated or Failed update status for client bookkeeping. Failures are logged and do not abort handling. |
UpdateCleanupService |
Removes the pre-swap copy on success and performs broader artifact cleanup after either terminal result. |
LastKnownGoodService |
Promotes a verified running binary to the reserve, supplies paths for updater rollback, and prunes updater transcripts. Promotion copies the running executable into the reserve before writing the version anchor. |
InstalledAgentMessagePublisher |
Publishes the running OpenFrame client version after startup. |
AgentConfigurationService |
Provides the device machine identifier required for version publication and successful delivery-sequence recording. |
ResultStore |
Settles client-update deliveries in AwaitingRestart; successful settlements record their applied delivery sequence. |
UpdateState includes the requested target version, the updater phase, a boot-attempt counter, an optional start timestamp, and an optional error written by the updater. The handler only makes a success decision from the target version and the compiled-in running version; this prevents a state file alone from being treated as proof that a binary replacement succeeded.
The states relevant to post-start processing are:
stateDiagram-v2
[*] --> NoState
NoState --> AwaitingLaunch: "Update request persists state"
AwaitingLaunch --> UpdaterLaunched: "Updater starts"
UpdaterLaunched --> Verifying: "Replacement requires verification"
UpdaterLaunched --> Success: "Running version equals target"
Verifying --> Success: "Running version equals target"
AwaitingLaunch --> Failure: "Client restarts before updater launch"
UpdaterLaunched --> Failure: "Crash-loop limit reached"
Verifying --> Failure: "Crash-loop limit reached"
Success --> Cleaned
Failure --> Cleaned
Cleaned --> [*]
handle_pending_update implements the reconciliation policy:
interrupted by agent restart before the updater started.UpdaterLaunched or Verifying, retain the state for a later boot instead of prematurely declaring failure.record_boot_attempt is intended for startup processing before pending-update reconciliation. It loads state and only accounts for unresolved updates in UpdaterLaunched or Verifying.
boot_attempts, atomically persists the state, and logs the attempt against CRASH_LOOP_MAX_BOOT_ATTEMPTS.flowchart TD
Start["Client startup"] --> Load["Load update state"]
Load --> Exists{"State exists?"}
Exists -->|"No"| Done["No boot accounting"]
Exists -->|"Yes"| Relevant{"Phase is unresolved?"}
Relevant -->|"No"| Done
Relevant -->|"Yes"| TargetMatches{"Target equals running version?"}
TargetMatches -->|"Yes"| Done
TargetMatches -->|"No"| Limit{"Boot limit reached?"}
Limit -->|"No"| Increment["Increment and save boot attempts"]
Increment --> Done
Limit -->|"Yes"| Failed["Handle update failure"]
Failed --> Rollback["Launch reserve rollback on Windows or macOS"]
Rollback --> Done
Reserve rollback is currently attempted only on Windows and macOS. The handler resolves the current executable and launches the platform updater in rollback-only mode with the state-file path, service name, target version, boot-marker path, reserve path, and a new rollback transcript path. Errors launching rollback are logged; they do not undo failure recording.
The success path is entered only when OPENFRAME_VERSION equals the persisted target version. Its ordering favors recovery and cleanup while making external bookkeeping best-effort.
sequenceDiagram
participant Client as "Restarted client"
participant Handler as "Update Handler Service"
participant Lkg as "Last-known-good Service"
participant Info as "Client Info Service"
participant Result as "Result Store"
participant Cleanup as "Cleanup Service"
Client->>Handler: "handle pending update"
Handler->>Lkg: "promote target version"
Handler->>Cleanup: "remove pre-swap copy"
Handler->>Info: "record version and Updated status"
Handler->>Result: "settle waiting delivery as Done"
Handler->>Result: "record applied delivery sequence"
Handler->>Cleanup: "clean update artifacts"
Handler->>Lkg: "prune old updater transcripts"
Handler->>Handler: "clear update state"
Specifically, handle_success:
Updated; either operation is best-effort.Done.UPDATER_TRANSCRIPTS_KEPT, and clears state. Failure to clear state is returned to the caller because stale state would affect later startup processing.handle_failure takes the persisted state as evidence of a terminal update failure. It logs the target, phase, and updater-stamped error when available. If the updater did not provide an error, the log directs operators to the updater transcript in the logs directory.
The handler then:
Failed with the target version, on a best-effort basis.last_error, or falls back to a phase-specific message.Failed.This makes failure terminal from the client's perspective while retaining the updater transcript as the diagnostic source.
A client-update command may be acknowledged as waiting for a restart before the old process exits. The handler uses delivery_settle_awaiting_restart with the client-update delivery type to settle only matching ledger records in the AwaitingRestart state.
On a successful result, it retrieves the machine identifier and records each settled delivery's sequence where one is present. The result store only replaces an existing applied sequence when the new sequence is newer for the same machine. This maintains monotonic applied-sequence bookkeeping and helps prevent duplicate update application after message redelivery.
Delivery settlement is deliberately non-fatal. If the local result store cannot queue a result, the handler logs that the backend will close the delivery on timeout and continues startup recovery.
publish_running_version sends an installed-agent message containing:
openframe-client; andOPENFRAME_VERSION.It retries a failed publication once per second for a maximum of five attempts. A missing machine identifier or a final publication failure is logged. Neither condition changes update state, because running-version publication is observational rather than proof of update success.
UpdaterLaunched or Verifying stays durable across boots until it succeeds or hits the crash-loop guard.When changing this module, preserve the relationship between persisted update phases and startup behavior. In particular, avoid clearing state for an update still in UpdaterLaunched or Verifying when the running version does not match the target, because that would bypass crash-loop detection and defer no diagnostic evidence to the next boot.
Changes to the target-version comparison, boot counter, or result-settlement behavior should be evaluated together with the client update service, update state service, last-known-good service, platform updater launcher, and command listener handler. These components together define request admission, durable handoff to the updater, restart verification, rollback protection, and delivery completion.