Repository navigation
fix(client): recover from corrupt secured files and flush writes to disk CU-17tkuw60gmz - #2846
Merged
Merged
Conversation
… 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.
Contributor
🦩 Flamingo Code ReviewNot 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:
Or comment Updated 2026-10-27 11:24 UTC · workflow run |
denys-gif
approved these changes
Oct 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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.openframe_client_info.json, which blocks every client self-update (Failed to get current client info).update_state.jsonerrors at every boot and skips the crash-loop and rollback accounting.update_state.jsonwas 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_writeflushes 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.jsonandlast_known_good.jsonare written withatomic_write. The first two used a plainfs::writebefore..lkg) copy is also flushed before it is moved into place, so a crash-loop rollback can't install a NUL-filled binary.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>.corruptand 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.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
.corruptcopy, and the0o644permissions. 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 lintis clean.cargo test --locked -- --skip test_ensure_admin: 429 passed. The tests cross-compile forx86_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 aDepends-Online, or by carrying the sameChange-Setline.Linked work
Linked by the
Depends-On/Change-Setlines in these descriptions; this block is maintained by the hub.