Skip to content

feat(client-updater): standalone service that swaps the client binary CU-86ah4w34y - #1783

Closed
danylo-babenko-flamingo wants to merge 34 commits into
mainfrom
hotfix/create-client-updater-service-v2
Closed

danylo-babenko-flamingo wants to merge 34 commits into
mainfrom
hotfix/create-client-updater-service-v2

Conversation

@danylo-babenko-flamingo

@danylo-babenko-flamingo danylo-babenko-flamingo commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

ClickUp task: CU-86ah4w34y Create OpenFrame client updater service

Change-Set: openframe-client-updater

What

Moves the openframe-client binary swap out of the client into a standalone OS service, openframe-client-updater (com.openframe.client-updater). Windows locks a running executable, so the client cannot replace itself; the updater is a second, independently supervised process that owns client updates and the swap. The client keeps one update duty: installing and updating the updater like any other integrated tool. Neither process ever replaces itself.

Ported from openframe-oss-tenant #2180 and brought up to date with main (delivery engine, ToolOps, per-tenant log key). Client updates come only from the delivery engine. The JetStream CLIENT_UPDATE path, the post-boot auto-rollback (CU-86ajbgc93) and the last-known-good ratchet of the original port are removed; see "Not in this PR".

How an update arrives

Only through the delivery engine, on machine.{id}.client-update.v2. The backend paces the rollout in batches, retries, catches up offline machines and reads the outcome from machine.{id}.delivery.result. The updater handles a delivery as main's in-client handler did:

  • it ACKs at once and answers DONE once the new client has booted, or FAILED with the reason;
  • a repeated dispatch gets its stored result again instead of a second run, and an older sequence is answered DONE without running;
  • a delivery that arrives while another update runs is left to the engine's retry.

Results stay in {secured}/updater_deliveries.json until their stream has stored them, so a crash or a NATS outage can't lose one.

How an update runs

  1. Checks before anything is touched: a malformed version or no download for this OS is answered FAILED. The version the client already runs, or one below the version it booted with, is answered DONE without running, as openframe-client did.
  2. downloading (all attempts within 360 s), verifying, then the new binary is staged next to the client's.
  3. draining: the client stops taking new work and waits for running tool operations and scripts, the same drain and 600 s cap as before its own restart, then confirms through {secured}/client_drained. The updater stops the client on the confirmation, or after 660 s regardless.
  4. stopping_service, replacing_binary (the backup path is persisted before the binary is touched; rename-based swap with retries), starting_service, verifying_boot: the new binary must write boot.marker with the target version within 90 s. An unknown service state after the start is left to the boot marker; only a confirmed stop counts against the new binary.
  5. Success: the backup is removed and completed progress plus installed-agent with the new version are published.
  6. If the new binary does not start, is not running, or writes no or the wrong boot marker, the pre-swap backup is put back and started. Reported as failed with rolledBack: true.

Older clients

A client older than this release still updates itself. On every boot the new client writes {secured}/client_update_delegated with its version, just before boot.marker, and the updater acts only while the two match. Until then it stays silent on client-update.v2 and the running client answers the delivery itself. This also covers a downgrade back to an older client.

Migration: the updater gets installed everywhere and sits idle on old clients, the old clients update themselves into this release, and from then on the updater owns updates.

Crash recovery

On start, before any network access, the updater finishes whatever an interrupted update left:

  • interrupted before the client was stopped (including while it drained): the staged binary is removed, reported failed, nothing changed;
  • interrupted while stopping or swapping: the backup is restored and the client started;
  • interrupted after the start: the client gets one boot-marker window; it counts as updated if the marker matches and the service is running, otherwise the backup is restored.

Updates and recovery share one restore path (client_binary::restore_previous_binary). Once nothing is in flight, staged binaries and backups left next to the client are swept. The outcome is published once NATS is connected, and the interrupted delivery is answered then.

Tokens

The updater reuses the client's shared_token.enc (AES-GCM). If the client is down or the token is unusable, it refreshes on its own via OAuth2 client_credentials from agent_config.json. Tokens are kept in memory only.

Client side (openframe-agent-lib)

  • In-client update machinery removed: the JetStream client-update listener, the delivery-engine client-update.v2 handler, the update service and its state, the PowerShell and shell update scripts, the updater launcher, and the cleanup service.
  • Drain for the updater (follow_updater_drains) through the restart gate. While the updater shows a phase from draining to verifying_boot, no new tool operation starts: delivery-engine commands are answered busy, tool messages still on JetStream are parked with progress acks, and ToolOps refuses new locks (also for internal paths such as mesh self-heal).
  • BootMarkerService writes client_update_delegated and boot.marker on every boot, through atomic_write like the other secured files, and deletes the last-known-good anchor and .lkg reserve binary earlier clients kept.
  • Uninstall removes update leftovers again (main's fix(client): remove update leftovers on uninstall and after a verified boot #2343), the updater's staged binary included.
  • The updater's log is tailed and shipped like the MeshCentral agent log (LogSourceKind::Updater), and an openframe-client-updater-version build feature pins the updater version like the other tools.

Not in this PR

  • The JetStream CLIENT_UPDATE path: the updater reads no machine.all.client-update, so an environment needs CLIENT_UPDATE on the delivery engine before it runs this client (see "Before release").
  • Post-boot health watch and automatic rollback: CU-86ajbgc93, in design.
  • The last-known-good ratchet (anchor, .lkg reserve, promotion, rollback: true restore). The engine's sequences handle out-of-order deliveries, and a request below the booted version is answered DONE without running.

Before release

  • CLIENT_UPDATE on the delivery engine wherever this client runs. dev and qa have it since openframe-saas-tenant#4195. Stage and prod still send client updates over JetStream, which this client no longer reads: openframe.delivery.enabled.CLIENT_UPDATE: true must be in configs/stage and configs/prod before this client is published there, or machines that reach it get no further updates until it is.
  • CLIENT_UPDATE needs a longer result timeout than the engine's 600 s default (download + drain + swap): openframe-saas-tenant#2254 sets 1800 s on dev; stage and prod take it with the switch above.
  • NATS device permissions: publish machine.*.client-update-progress (saas-tenant manifests/tenant/templates/nats/configmap.yaml, and the oss-tenant equivalent). Nothing on the backend reads it yet; until it is allowed, NATS rejects the progress messages. The delivery-engine subjects are already allowed on saas.
  • No updater artifact is built or served yet: the saas-tenant thin binary and release entry, and a client-updater entry in the shared gateway's asset map, are needed before openframe-saas-tenant#2254 registers the tool.
  • OSS: openframe-oss-tenant registers no updater and has every delivery type off, with no device permissions for the engine's subjects, so it has to stay on an older client until it has all three.

Commits since review round 2

  • 48809c2d7 drop post-boot observation and auto-rollback
  • 33267bda4 drop the last-known-good ratchet
  • 03a719e1b split the update flow, one restore path, query_running everywhere (review round 2)
  • ab73d1f38 drain the client before a swap; act only for clients that delegate updates
  • f1cd16fec answer delivery-engine client updates on client-update.v2
  • 7cc95f2fb sweep update leftovers on uninstall again
  • 7c200d915 take client updates only from the delivery engine: the JetStream listener, its consumer settings and the reconnect re-provisioning go; outcomes are DONE or FAILED as on main
  • dd0e950d2 write the update markers through atomic_write (main's fix(client): recover from corrupt secured files and flush writes to disk CU-17tkuw60gmz #2846 flushes it to disk)
  • 978c9e56e, 3e20f9d92, 689ee1c6a merge main

Tests

  • updater: 70 unit tests, clippy -D warnings, fmt --check; built and tested on macOS and Windows in test.yml
  • agent-lib: 415 tests, clippy for the lib and --features bin, fmt --check

Change set flamingo-stack/openframe-oss-lib#1783: these pull requests are one change, reviewed together.

  • flamingo-stack/openframe-oss-lib#1783 (this pull request): feat(client-updater): standalone service that swaps the client binary CU-86ah4w34y · closed
  • …and 1 pull request not visible

Linked work

  • …and 2 linked items not shown here

Linked by the Depends-On / Change-Set lines in these descriptions; this block is maintained by the hub.

…en logic

New OS service (com.openframe.client-updater) that owns the openframe-client binary swap — a second process is required because Windows locks a running executable. Reuses the client's shared_token.enc when available and falls back to its own OAuth2 client_credentials refresh from agent_config.json; tokens are held in memory only.
Crate part of oss-tenant 3a409150f; that commit's CI matrix entries were oss-tenant's workflow and land here in a separate CI commit.
…to-rollback

Update phases run Downloading through VerifyingBoot and Observing. The new binary must write a version-matching boot marker within 90s, then survive a 10-minute observation window; failure at either gate rolls back to the last-known-good reserve. Promotion to the LKG anchor happens only after observation passes.
…s from reserve

A message carrying rollback: true is allowed to downgrade; when the target version matches the .lkg reserve it restores offline without a download.
…ng calls, secured-dir perms

Durable state writes, corrected JetStream ACK semantics, blocking filesystem calls moved off the async runtime, and hardened secured-directory permissions.
Sidecar *_tests.rs per module: updater state machine, atomic replace, encryption round-trip, versions_match, archive extraction, and phase-string parity with the client's probe contract.
…recovery

Applies the 11 external review findings: redelivered duplicates can no longer cancel a live observation window; the backup path is precomputed so a failed replace cannot brick the install; macOS service stop tolerates not-loaded and polls for real termination; crash recovery runs before token wait and NATS connect; promotion requires the service to actually be running; dedicated 300s client download timeout; ACK wait raised to 600s; +crt-static for Windows builds.
oss-lib CI enforces cargo fmt --check; the crate arrived verbatim from oss-tenant, which is unformatted.
… client swap

The updater now owns CLIENT_UPDATE end to end: removes the in-client update service, state machine, platform update scripts, and updater launcher. Tool listeners route through park_or_dispatch, which probes the updater's state file and holds messages with AckKind::Progress keep-alives every 60s while a swap is in flight, preserving the JetStream redelivery budget until the new client processes them after restart. Also adds the updater version flag and updater log source. Adapts oss-tenant commits 3813b1443, 6a3851a90, 9afd7f8df, 3346dba1e, and 012127cdb to the agent-lib layout.
Adds the updater's Makefile lint/build/test steps to the test-rust matrix (macOS + Windows), matching the client's steps.
@danylo-babenko-flamingo danylo-babenko-flamingo changed the title feat(clients): port openframe-client-updater from oss-tenant Openframe Client Updater Aug 13, 2026
…updater-service-v2

# Conflicts:
#	clients/openframe-client/src/lib.rs
#	clients/openframe-client/src/listener/openframe_client_update_listener.rs
# Conflicts:
#	clients/openframe-client/src/lib.rs
…updater-service-v2

# Conflicts:
#	clients/openframe-client/src/lib.rs
#	clients/openframe-client/src/listener/openframe_client_update_listener.rs
# Conflicts:
#	clients/openframe-client/Cargo.toml
#	clients/openframe-client/src/config/update_config.rs
#	clients/openframe-client/src/services/openframe_client_update_service.rs
…updater-service-v2

# Conflicts:
#	clients/openframe-client/src/services/tool_run_manager.rs
#	clients/openframe-client/src/services/update_cleanup_service.rs
#	clients/openframe-client/src/services/update_handler_service.rs
…updater-service-v2

# Conflicts:
#	clients/openframe-client/src/lib.rs
#	clients/openframe-client/src/listener/client_update_gate.rs
#	clients/openframe-client/src/listener/mod.rs
#	clients/openframe-client/src/listener/tool_installation_message_listener.rs
#	clients/openframe-client/src/models/mod.rs
#	clients/openframe-client/src/services/mod.rs
#	clients/openframe-client/src/services/openframe_client_update_service.rs
#	clients/openframe-client/src/services/tool_run_manager.rs
#	clients/openframe-client/src/services/tool_run_manager_tests.rs
#	clients/openframe-client/src/services/update_handler_service.rs
@danylo-babenko-flamingo
danylo-babenko-flamingo requested a review from a team as a code owner October 26, 2026 23:59
@github-actions

Copy link
Copy Markdown
Contributor

🦩 Flamingo Code Review

Not reviewed yet. The tests and checks of this commit ran; the review itself starts when you ask.

When it is ready:

  • Review this pull request

Or comment @flamingo-review. Add the flamingo-review-always label to review every push.

🧪 Tests and mutation

Checks

Check Kind Language Project Status Time
Trivy security Rust (Trivy) . ✅ passed 11.3 s
Trivy config security Rust (Trivy) . ✅ passed 9.9 s
YAML syntax lint YAML (YAML and GitHub Actions) . ✅ passed 0.5 s
actionlint lint YAML (YAML and GitHub Actions) . ✅ passed (7 findings on lines this change did not touch) 2.5 s

Updated 2026-10-27 00:00 UTC · workflow run

@danylo-babenko-flamingo danylo-babenko-flamingo changed the title Openframe Client Updater feat(client-updater): standalone service that swaps the client binary CU-86ah4w34y Oct 27, 2026
…updater-service-v2

# Conflicts:
#	clients/openframe-client/src/services/last_known_good_service.rs
#	clients/openframe-client/src/services/openframe_client_update_service.rs
#	clients/openframe-client/src/services/update_state_service.rs
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.

2 participants