Skip to content

fix(client): recover from corrupt secured files and flush writes to disk CU-17tkuw60gmz - #2846

Merged
mikhailm-coder merged 4 commits into
mainfrom
hotfix/client-corrupt-secured-files
Oct 27, 2026
Merged

mikhailm-coder merged 4 commits into
mainfrom
hotfix/client-corrupt-secured-files

Conversation

@mikhailm-coder

@mikhailm-coder mikhailm-coder commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

ClickUp task: CU-17tkuw60gmz Bug: client tool connections file gets corrupted and never recovers

Change-Set: hotfix-client-corrupt-secured-files

Why

An unclean OS shutdown (power loss, a laptop battery dying while asleep, a hard reset) shortly after the client writes a file in the secured directory can leave that file NUL-filled or empty. In the last 10 days of prod logs:

  • 36 Windows devices on 29 tenants were stuck with a broken tool_connections.json. Every save failed, and the publish loop retried every 15 s instead of hourly, re-running the agentId commands and re-publishing both tool connections each time. None of them recovered on its own.
  • 9 devices had a broken openframe_client_info.json, which blocks every client self-update (Failed to get current client info).
  • A broken update_state.json errors at every boot and skips the crash-loop and rollback accounting.

update_state.json was already written with a temp file + rename and still came back NUL-filled. The rename survives a power loss, but the data only survives if it was flushed before the rename.

What

  • atomic_write flushes the temp file (sync_all) before the rename. This also covers the config, token and feature-flag files that already use it.
  • tool_connections.json, openframe_client_info.json, update_state.json and last_known_good.json are written with atomic_write. The first two used a plain fs::write before.
  • The rollback reserve binary (.lkg) copy is also flushed before it is moved into place, so a crash-loop rollback can't install a NUL-filled binary.
  • New read_json_or_quarantine: a file that doesn't parse is logged (path, size, whether it is all zeros, the serde error), renamed to <name>.corrupt and then read as missing. That gives an empty list, the default client info (startup writes the running version back), no update in progress, or no last-known-good anchor.
  • The updater's early-exit path still tells a corrupt update state from a missing one. A missing state means "uninstalled" and returns; a corrupt one records the failure on a fresh state, as before.
  • After a successful publish, a failed tool-connection save is logged with the full error, and the loop keeps the normal hourly cadence instead of retrying every 15 s. Nothing reads the local record; the backend only needs the publish.
  • A failed last-known-good load is now logged instead of being silently treated as "no anchor".
  • The raw update-state content is still logged on load.

Not changed: installed_tools.json, the agent config and the initial config are not reset on corruption, because that would drop the tool registry or the device's credentials. Devices already stuck on a corrupt client info file can't self-update to this fix; their cleanup is a separate ops task.

Testing

  • Helper unit tests: NUL-filled, empty, truncated and non-UTF-8 files, an older .corrupt copy, and the 0o644 permissions. Per-service tests: recovery from a corrupt file, save and delete over a corrupt file, and a corrupt update state told apart from a missing one.
  • make lint is clean. cargo test --locked -- --skip test_ensure_admin: 429 passed. The tests cross-compile for x86_64-pc-windows-gnu.

Change set flamingo-stack/hotfix-client-corrupt-secured-files: this pull request is the only one in it so far. Another pull request joins by naming this one in a Depends-On line, or by carrying the same Change-Set line.

Linked work

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

… to disk

An unclean shutdown shortly after a write leaves NUL-filled files in the
secured directory. tool_connections.json then fails every save and the
connection loop republishes every 15s; a corrupt openframe_client_info.json
blocks every client update.

- tool connections, client info, update state and the last-known-good anchor
  move an unparsable file aside to <name>.corrupt and continue as if it were
  missing
- atomic_write flushes the temp file before the rename, and these four files
  are written with it
- a failed local save after a successful publish no longer restarts the
  15s cycle
The updater's early-exit path reads a missing state as "uninstalled" and
returns, so a corrupt state must not look missing: it now records the
failure on a fresh state as before. The raw update-state content is logged
before parsing again, and a failed last-known-good load is logged instead
of silently treated as no anchor.
@github-actions

Copy link
Copy Markdown
Contributor

🦩 Flamingo Code Review

Not reviewed yet. Reviews start when you ask, so the reviewer reads this pull request when it is ready, not when it is opened.

When it is ready:

  • Review this pull request

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

Updated 2026-10-27 11:24 UTC · workflow run

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