Skip to content

Engine: journal settings, props and binds; checked backups; room checks - #430

Open
AwsomeFox wants to merge 5 commits into
release/2.0from
fix/journal-backups
Open

AwsomeFox wants to merge 5 commits into
release/2.0from
fix/journal-backups

Conversation

@AwsomeFox

Copy link
Copy Markdown
Contributor

What this changes

Fixes the problems from the 2026-11-26 review of the engine's journal and backups (core/runtime/java/hmgapi/engine/Engine.java, UsbUpdates.java).

  1. Settings, live props and binds are journaled. An apply records each one's value before it writes it, plus binds.txt/binds.failed; engine recover writes them back (and has hmgapid redo the binds). Before, a trial's persist.test.x=1 stayed set after "trial undone", the next apply recorded "stock": "1", and engine restore left it set. An apply cut off between the settings and the state left the same.
  2. Checked backups. Stock backups (and the journal's saved copies) are copied beside, md5-checked, then renamed, as install/common/install.sh backup() does. The odex backup's md5 is recorded in files.json ("odex"). Every backup is checked against its recorded md5 before a restore, uninstall or rebuild. A damaged one is replaced by a NEMESIS copy with that md5 if there is one, else the plan stops and names the backup and the md5 it should have. For older records with no odex md5, a Dalvik odex shorter than its header says is refused.
  3. Room checks. Before the journal is written, the apply checks room on /system (new files; a held app's old apk/odex counts as freed, other files count whole) and /data (journal copies, backups, Dalvik cache). recover removes the cut-off .hmgapi-new copy beside each file and, when /system still has no room, the file before its saved copy goes back.
  4. Damaged journal or missing saved copy. recover sets the journal aside (state/journal.bad.json, copies in state/prev.bad/) with a clear message, so apply, restore and uninstall aren't refused forever. A missing or damaged saved copy is skipped and named, and the rest are still put back. status and keep no longer crash on a bad journal.
  5. Tighter checks, each with a warning plus overrides.allow_critical. build.prop refuses dalvik.* and persist.sys.dalvik.* keys as well as ro.*. Live props refuse persist.sys.dalvik.* ("prop:<key>"). CRITICAL adds framework-res.apk, libz, libcrypto, libssl, libicuuc/libicui18n, icudt51l.dat, libgui, libui, libEGL, libGLESv2, libhardware, libsqlite, libexpat, everything under /system/lib/hw/ and /system/lib/egl/, and netd, mediaserver, logwrapper, e2fsck. The daemon list was picked without a stock init.rc to hand, so it's worth a look against a real one.
  6. No self-update while a journal is pending. update-hmgapi refuses, --force included. The catalogue's updateHmgApi (catalog/app, catalog/engine) goes through UsbUpdates.updateHmgApi, so it's covered on rebase; calling the new UsbUpdates.pendingWhy before downloading would avoid a wasted download.
  7. Dalvik cache. Only the app's own entry (system@app@X.apk@classes.dex) is deleted, not a *X.apk* glob, and priv-apps get system@priv-app@….

Also: an uncommitted trial (cut off mid-apply) now reports "unfinished apply rolled back" instead of "trial undone"; boot.sh restarts on either. Off-car tests can stop the engine dead at a point (HMGAPI_TEST_CUT, host only) and fake free space (HMGAPI_TEST_FREE, host only).

Tested on

  • tools/test-all.sh --fast passes (32 ok, 1 skipped for no ImageMagick). New core/runtime/journal-test.sh (89 checks; 39 of them fail against main's engine, including the "stock": "1" repro), plus new cases in safety-test.sh and usb-test.sh. The rest of the full suite (hmgapid, zygote, lpatch, installers, SDK) can't run on the Mac this was written on (no qemu-arm); those 6 fail the same way on untouched main there, so CI is the check for them.
  • Off-car only.

Tested on cars

Off-car only.

Checklist

  • Anything written to /system keeps a stock check, a backup and an exact restore
  • No manufacturer apps or libraries, no per-car data
  • User-facing change: CHANGELOG.md updated (the wiki has no page on these rules)

🤖 Generated with Claude Code

Recover now puts back the settings, live props and binds an apply or trial
changed, not only its files: a trial's persist.* prop stayed set after
"trial undone", and the next apply took it for stock.

Stock backups are copied beside, checked against the stock md5, then
renamed, as install.sh's backup() does. An app's odex backup has its md5
recorded, and every backup is checked before a restore or rebuild; a
NEMESIS copy with the recorded md5 stands in for a damaged one, else the
engine stops and names it. The journal's saved copies are checked the same
way.

An apply checks room on /system and /data before writing anything; recover
removes a cut-off copy, and on a full /system the file, before its saved
copy goes back. A damaged journal, or a saved copy that's gone, is set
aside (state/journal.bad.json) instead of failing at every start.

build.prop and live props refuse dalvik.* and persist.sys.dalvik.* without
overrides.allow_critical; CRITICAL takes framework-res.apk, libz, libcrypto,
the ICU files, libgui, libEGL, lib/hw and lib/egl, and the boot daemons
Android waits for. update-hmgapi refuses while a journal is pending. The
Dalvik cache clean-up touches only the app's own entry, priv-app included.

Tests: core/runtime/journal-test.sh, plus safety-test.sh and usb-test.sh.
Off-car only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Both sides added a CHANGELOG entry and a test to test-all.sh: kept both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@VysseCodes VysseCodes left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge order note: #434 → #430 → #433. #423, #430, #433 and #434 all rewrite Engine.apply from main, and #430 and #434 both change put() and dalvik() in different ways, so please rebase this on #434 once it's in.

More review on the damaged-backup handling to follow.

@VysseCodes

Copy link
Copy Markdown
Collaborator

@Open-HMG/maintainers, input wanted on one design question before this goes in.

When a stock backup is damaged and no NEMESIS copy fits, what should stop?

As written, restoreFrom adds a plan-wide problem in that case. Every later apply, and possibly the uninstall, then stops until the owner copies a stock file over by hand.

Options:

  1. Only that file: it's left as it is and named (CHANGED in the status); the rest of the plan, restores and the uninstall go on. A bad backup is never written back.
  2. That file, plus an override: as in 1, plus an owner override to write the backup back anyway, at their own risk.
  3. Keep the plan-wide stop: everything waits until the owner supplies a stock copy.

Which do you prefer, and why?

When a stock backup isn't the recorded md5 and no NEMESIS copy has it,
the plan used to stop as a whole, so every later apply and the uninstall
waited until the owner copied a stock file over by hand.

Now only that file waits: it's left as it is and never written from the
bad copy, the warning names the backup and the md5 it should have, and
the rest of the apply or restore goes on. files.json keeps the file's
record with "held" (why), `engine status` shows it as CHANGED, and the
next apply clears it once a stock copy is in place. `engine restore`
ends with code 4 while anything is held, so the uninstall stops before
removing HMG-API and its backups.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AwsomeFox

Copy link
Copy Markdown
Contributor Author

My vote: 1.

  • Stop only that file: leave it as it is and name it (CHANGED in the status, with why). The rest of the plan, the other restores and the uninstall go on. A damaged backup is never written back.
  • I'd leave out the override in 2. Writing a known-bad file into /system can stop the unit booting. The owner gets the same result more safely by copying a stock file over by hand, and the status can say how.
  • A plan-wide stop (3) turns one bad file into no applies and possibly no uninstall.

I won't change anything until the maintainers agree.

DY-Jeong added a commit to DY-Jeong/HMG-API that referenced this pull request Dec 1, 2026
…inds; checked backups; room checks

From AwsomeFox/fix/journal-backups (Open-HMG#430).
@AwsomeFox
AwsomeFox changed the base branch from main to release/2.0 December 1, 2026 16:39
release/2.0 turned the Unreleased section into 1.1.0 (rc.10's code).
This branch's entries, and the root-service entry that came in with
main after 1.1.0, go in a new Unreleased section above it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@VysseCodes

Copy link
Copy Markdown
Collaborator

Decision: option 1, as you voted. A damaged backup with no copy that fits stops only that file: it's left as it is and named (CHANGED in the status, with why), and the rest of the plan, the other restores and the uninstall go on. A damaged backup is never written back, and there's no override to do it.

Please have the status say what the owner can do about that file.

A file held back by a damaged stock backup now carries what the owner
can do, beside why: copy the stock file (its md5 named, or the odex the
app came with) to the backup's path and run `engine apply`, or open an
issue with that line, the car and its software version. The apply's
warning ends with it, files.json keeps it as "fix", and `engine status`
prints it under the CHANGED line until the file is built or put back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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