Skip to content

Catalogue, dependencies and updates in the engine - #423

Open
AwsomeFox wants to merge 13 commits into
engine/httpsfrom
catalog/engine
Open

AwsomeFox wants to merge 13 commits into
engine/httpsfrom
catalog/engine

Conversation

@AwsomeFox

@AwsomeFox AwsomeFox commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Stack: 4 of 5, on #422. The engine side of the catalogue; the app screens are #424.

Ops

engine catalog [--refresh] the catalogue and what each mod would do here (JSON)
engine catalog-plan <id>... [--update] | --update --all what installing (updating) them takes, in order (JSON)
engine catalog-install <id>... download, check, install, with what they require
engine updates [--refresh] installed mods and HMG-API with something newer (JSON)
engine update <id>... | --all | hmgapi [--force] update; hmgapi runs HMG-API's own installer
engine update-check wifi.sh, when Home Wi-Fi comes up, at most every 6 hours
engine update-source <id> catalogue | releases | off | default where an installed mod's updates come from (the owner's choice)

The owner's overrides are per mod: --any-car=<id>,... (not listed for this head unit) and --any-author=<id>,... (a first install by an author key that isn't on the unit's trusted list). --any-car alone still means every mod in the batch, for adb.

hmgapid passes them to the app; the reads don't take the engine lock. Two new owner switches: no_update_check and auto_stage_updates (off by default; see Staging). HMG-API itself is never updated automatically.

No server of our own

The catalogue is catalog/ on GitHub: catalog/index.json if present (tools/catalog.py index writes it), else one call to GitHub's contents API for the listing, then each entry from raw. It's cached in /data/hmgapi/catalog/, and the update count is also in public/updates.json for the app (rewritten after any install or removal, USB and adb too).

  • A plan or install refreshes a catalogue over 15 minutes old when Home Wi-Fi is up.
  • An entry that doesn't come keeps the last check's, with a note.
  • A malformed index.json is an error, and the old cache stays.

HMG-API's own updates come from the releases API: the newest non-draft release, its -update.zip, and the SHA-256 from that release's SHA256SUMS. A unit on a pre-release is offered only that version's next ones (on 1.1.0-rc.10: 1.1.0 or 1.1.0-rc.11, never 1.2.0-alpha), unless "catalog": {"prereleases": true}. The release notes are kept for the app. A fork or a test can point hmgapi.json "catalog": {"base": ...} elsewhere.

Trust

The fetch (#422) doesn't verify certificates, so whoever controls the network path could answer for GitHub. The catalogue isn't signed either, so this PR treats an entry as a hint and checks everything that matters on the unit:

  • First installs need a key the unit already trusts. The entry's author key must be on the unit's own maps/authors.json. Only HMG-API's signed releases bring that file, and nothing here writes it. Otherwise the plan says so and the owner says yes for that mod (--any-author=<id>). The package must then be signed by that key.
  • Updates need the installed mod's key, as before. HMG-API releases go through UsbUpdates.updateHmgApi, so they need the release key.
  • Every package is checked before the first one goes in: SHA-256 against the entry, id and version, then Packages.check (signature, key, HMG-API range, car).
  • So a hostile network can't get code installed without the owner's explicit yes per mod. It can still withhold or delay updates, or point at a different version of a mod by a key already on the unit's list.
  • Signing index.json with the release key would close the rest. That's a separate change.

Dependencies

  • Each requires is met by what's installed (and turned on if it's off), or by the catalogue's version, installed first. optional requires (NEMESIS's) are skipped.
  • The result is checked as a whole. Every mod that will be on must have what it requires, on and in range. Conflicts count from either side: an installed mod's conflicts naming a planned one is refused too. Only what the plan changes is checked; something already broken doesn't block an unrelated install.
  • update --all (and catalog-plan --update --all) plans each mod on its own. A mod that can't go now is listed with why (for example, it would break another mod's range). The rest are updated.
  • A package that adds requires gets a second OK. The downloaded package's mod.json is read again, and what it adds is kept in learned.json for later plans. If that changes the plan, nothing is installed and the new plan comes back (exit 5) for the owner to confirm.
  • Refused before anything changes: loops, conflicts, unreadable ranges, a range the catalogue can't meet, a mod for a newer HMG-API, a first install by an unknown author, and another car. The owner's any-car choice counts, both the one recorded earlier (overrides.ignore_system) and --any-car=<id>. A hotspot mod's unpowered chip counts for that mod.
  • engine remove names the installed mods that require what's removed.
  • update hmgapi refuses while a mod that's on wouldn't take the new version (applying would stop on it). --force gives a warning instead.

Staging

update-check stages only pure updates: nothing else installed or turned on, signed with the installed key, checked as an install would be.

  • Staged updates go into /data/hmgapi/pending/<id>. The hook loader, LiveState and apps never read that folder, so no staged code runs before an apply.
  • engine plan lists them. engine apply checks each one again and puts it in place right before it plans. The previous version is kept in /data/hmgapi/previous/<id>, and an apply that's refused puts everything back.
  • A manual install or removal of that mod drops its staged copy.

Mods outside the catalogue: their own GitHub releases

An installed mod the catalogue doesn't list (from USB or adb, private, or waiting for its catalogue PR) is offered updates from the repo in its own mod.json ("repo": "https://github.com/<owner>/<repo>"). That file came inside the signed package, so the author's key chose the repo. Design notes: Releases.java's header.

  • Source per mod (Catalog.source), in this order:

    • the owner's choice (engine update-source, kept in hmgapi.json catalog.update_source);
    • otherwise the catalogue, if it lists the mod;
    • otherwise its releases, if the repo is on GitHub;
    • otherwise none.

    This lets a tester follow a fork's releases for a listed mod, or turn a mod's updates off.

  • The check:

    • One API call per repo (/releases?per_page=10); mods from the same repo share it. At most 10 repos per refresh, the ones checked longest ago first; the rest keep their last answer.
    • It takes the newest non-draft release that is newer than the installed version and has the zip. The zip is named by "release_asset" ("my-mod-v{version}.zip"), otherwise it's the one <id>-....zip (or <id>-<version>.zip when the release has several).
    • Finals only, unless the installed version is itself a pre-release (a beta tester stays on that mod's betas) or the owner opted in.
    • A repo GitHub moved (a transfer to Open-HMG) is followed. Its downloads must come from the repo the release is in.
  • The result is an entry shaped like a catalogue entry ("source": "release", kept in catalog/releases.json). Planning, staging into pending/, update --all and the install all run unchanged.

  • Trust is the installed key. A release is only ever an update by that key: never a first install, a key change or a downgrade (Packages.check).

    • The package's mod.json must have the tag's id and version.
    • Size is capped at 64 MB.
    • The SHA-256 is checked when the release gives one (SHA256SUMS, otherwise GitHub's asset digest); otherwise the signature alone decides, as for a USB install.
    • That is what catalog-automerge.yml already merges for a catalogue bump with no one reviewing it.
  • catalog/withdrawn.json: {"withdrawn": [{"id", "versions": range, "why"}]}.

    • Versions a maintainer stopped are skipped for both sources. An installed version that's withdrawn is listed in updates, with why.
    • It is unsigned like the rest of the catalogue, so it can only stop an update, never add one.
    • catalog.py check validates it and never takes it for an entry.
  • GitHub's API limit (60 an hour without an account): a 403 or 429 is reported, and the last answers are kept.

  • updates gives each row's source, repo, release page, notes and pre-release flag, and every installed mod's source, for the app.

  • catalog.py add copies requires/conflicts and wifi.hotspot from mod.json.

  • add and check refuse downloads that aren't on GitHub's hosts (the unit only fetches from there). check validates ranges the way the engine reads them.

  • bump allows these fields to change only to what the package's mod.json says.

  • index writes index.json. Once the repo keeps one, add writes it again, check refuses a stale one, and bump allows it alongside the entry.

Tested

  • catalog-test.sh (201 checks; GitHub played by files). Covers:
    • listing and index, a bad index, an entry that doesn't come, a stale cache refreshed
    • offline and not-yet-joined
    • a dependency installed first, a required mod turned on, requires only the package names (exit 5, then the second run)
    • unmet, newer, looped, conflicting and unreadable requires
    • trust: an unknown author refused, the owner's yes per mod, its update by the installed key, authors.json untouched
    • the result as a whole: an update breaking another mod's range, the diamond case, a conflict listed by the installed side
    • every package checked first (a mis-signed mod leaves its dependency uninstalled)
    • any-car per mod and kept, with update --all (run without HMGAPI_TEST_ANY_CAR); a hotspot mod on an unpowered chip
    • updates with a new dependency version; HMG-API's releases (drafts, pre-release rules, a bad SHA256SUMS, mods it would leave behind)
    • update-check: the 6-hour gap; staging aside, listed by plan, put in at apply, kept staged when the apply is refused; not staging what needs a new mod or one turned on
    • releases of unlisted mods: drafts and betas skipped, a beta tester's next beta offered, two zips in one release, notes kept
    • the release's SHA-256 (digest or SHA256SUMS): matched, mismatched, or not given
    • refused: a package by another key (as a key change), or one that isn't the tag's version
    • not offered: a zip too large, missing, or from outside the repo
    • a moved repo followed
    • withdrawn.json for both sources
    • staged by the automatic check
    • update-source: off, default, the releases of a listed mod; refusals when it can't apply
    • the API limit, with the last answers kept
    • a removal's warning
  • tools/catalog-test.sh (117): withdrawn.json's form; GitHub-only downloads, ranges, wifi, index.json kept current.
  • test-all.sh --fast: 33 ok, 1 skipped (no ImageMagick).
  • Before these fixes, from a computer against the real GitHub (the host build of The engine's HTTPS: the unit's own libssl, home Wi-Fi only #422's library): the real catalogue's 7 entries through the listing API, with correct statuses for a car's installed mods.
  • Not on a car yet.

🤖 Generated with Claude Code

engine catalog [--refresh], catalog-plan <id>..., catalog-install <id>... [--any-car],
updates [--refresh], update <id>... | --all | hmgapi, update-check (wifi.sh runs it each time
home Wi-Fi comes up; the owner switches no_update_check and auto_stage_updates).

- The catalogue: catalog/ on GitHub, from index.json (tools/catalog.py index) or GitHub's
  listing of the folder; cached in /data/hmgapi/catalog, updates also in public/updates.json.
  HMG-API's own release: its newest from the releases API (pre-releases only on one), the
  update zip's SHA-256 from SHA256SUMS.
- Dependencies: requires met by what's installed, or by the catalogue's version installed
  first; a required mod that's off is turned on; the downloaded package's mod.json is read again
  for requires its entry doesn't name. Loops, conflicts, unmet ranges, a mod for a newer
  HMG-API (and, without --any-car, another car) are refused; everything is downloaded and
  checked before the first install. Removing a mod others require says which.
- Trust: the entry's SHA-256, then Packages' signature check with the entry's author key
  (--uuid) on a first install; HMG-API's release key for HMG-API (UsbUpdates). Nothing applied.
- tools/catalog.py: entries carry requires/conflicts (from mod.json, checked in bumps);
  catalog.py index.

catalog-test.sh plays GitHub from files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AwsomeFox and others added 3 commits November 27, 2026 09:28
…pply

From the review of 2026-11-26:

- Trust: the catalogue isn't signed, so a first install's author key must
  already be on the unit's maps/authors.json (only HMG-API's releases bring
  it), or the owner says yes for that mod (--any-author=<id>). Nothing here
  writes authors.json.
- The plan is checked as a whole: every mod that will be on keeps what it
  requires, in range and on, and conflicts count from either side (an
  installed mod's list naming a planned one too). update --all leaves out
  each mod that can't go now, with why, and updates the rest.
- unfit() honours the owner's any-car choice (overrides.ignore_system) and
  a hotspot mod's unpowered chip; --any-car=<id>,... per mod.
- Every package is checked (Packages.check: signature, key, HMG-API, car)
  before the first install, and installed from the unzipped folder.
- An unreadable range is a plan problem, not an exception.
- Requires a package adds are kept (learned.json); if they change the
  plan, nothing is installed and the new plan comes back (exit 5) for a
  second OK.
- update-check stages only pure updates signed with the installed key,
  into /data/hmgapi/pending/<id>, which nothing loads; engine apply puts
  them in place before it plans (previous version kept in previous/<id>),
  and puts them back if the apply is refused. engine plan lists them.
- A plan or install refreshes a catalogue over 15 minutes old when
  online; one entry that doesn't come keeps the last check's; a bad
  index.json is an error, not a crash; per-run temporary names.
- update-check at most every 6 hours.
- A unit on a pre-release is offered only that version's next ones (rc.10:
  1.1.0, not 1.2.0-alpha), unless the owner opts in.
- update hmgapi refuses while a mod that's on wouldn't take the new
  version (--force: a warning instead).
- Installs and removals outside the catalogue update the Updates count.
- catalog.py: downloads only from GitHub's hosts, ranges checked, copies
  wifi.hotspot, writes index.json again on add when the repo keeps one and
  check refuses a stale one; bump allows an index written with the entry.

catalog-test.sh 154 checks (was 71), tools/catalog-test.sh 113;
test-all.sh --fast passes. Not on a car.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
stagedIn puts them in mods/ right before an apply plans, and they went back only when the plan
was refused. An apply that fails part-way (an exception, the files rolled back or left for recover)
left them in mods/, where their code loads at the next boot, on /system files built for the
versions before them. Found combining the open PRs: with #433's gear check and #434's in-run
rollback there are more such paths; whichever lands after this puts them back there too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AwsomeFox and others added 2 commits November 28, 2026 10:38
A mod the catalogue doesn't list (USB or adb, private, waiting for its PR) gets updates
from the repo its own mod.json names ("repo", inside the signed package, so the author's key
chose it). One API call per repo, at most 10 a refresh (longest unchecked first); the newest
release newer than what's installed, with its zip ("release_asset", else <id>-<version>.zip),
becomes an entry like the catalogue's ("source": "release"), so planning, staging and
installing are unchanged. Finals only, unless the installed version is a pre-release or the
owner opted in.

Trust is the installed key: a release is only ever an update by it (never a first install, a
key change or a downgrade), its package must be the tag's id and version, its SHA-256 is
checked when the release gives one (SHA256SUMS, or GitHub's digest), size capped. That is what
catalog-automerge already merges for a catalogue entry with no one looking.

- engine update-source <id> catalogue | releases | off | default: the owner's choice per mod
  (a listed mod from a fork's releases, or no updates), in hmgapi.json catalog.update_source.
- catalog/withdrawn.json: versions maintainers stopped, for both sources; installed ones are
  listed in updates. catalog.py checks it and never takes it for an entry.
- updates: each row's source, repo, release page and notes; every installed mod's source.
- GitHub's API limit: said, and the last answers kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
GitHub's API follows a transfer or rename, but the downloads it lists are the new repo's. The
repo is taken from the release's page, and the zip (and SHA256SUMS) must be from that same repo;
the package still has to be signed by the installed key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AwsomeFox added a commit to Open-HMG/projection-ev-routing that referenced this pull request Nov 28, 2026
HMG-API checks a mod's own GitHub releases for updates when its mod.json names the repo
(Open-HMG/HMG-API#423). Both builds carry it; each release's zips are named by id
(egmp-aa-ev-<version>.zip, egmp-aa-ev-standalone-<version>.zip), which is what it looks for.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AwsomeFox added a commit to Open-HMG/projection-ev-routing that referenced this pull request Nov 28, 2026
…eases

HMG-API checks a mod's own GitHub releases for updates when its mod.json names the repo
(Open-HMG/HMG-API#423); it looks for egmp-carplay-ev-routing-<version>.zip in a release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AwsomeFox added a commit to Open-HMG/hmgapi-wireless-cp-aa that referenced this pull request Nov 28, 2026
HMG-API checks a mod's own GitHub releases for updates when its mod.json names the repo
(Open-HMG/HMG-API#423), for owners who installed it from USB or follow its pre-releases.
The release zips are already named wireless-carplay-aa-<version>.zip, with SHA256SUMS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AwsomeFox
AwsomeFox marked this pull request as ready for review November 28, 2026 15:50
@AwsomeFox
AwsomeFox requested review from a team and VysseCodes as code owners November 28, 2026 15:50
@isaacwisdom
isaacwisdom added this pull request to stack #443 November 28, 2026 17:44
isaacwisdom

This comment was marked as duplicate.

@isaacwisdom isaacwisdom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P1] Staged updates escape trial and crash recovery — core/runtime/java/hmgapi/engine/Engine.java:451
Pending updates replace installed mod directories before the recovery journal is created. Recovery restores system files and settings but leaves the updated mod code installed. A reverted trial or interrupted apply can therefore leave incompatible code and system files. Persist the mod swaps in the transaction and restore them during recovery.

[P2] Withdrawn updates can still be applied — core/runtime/java/hmgapi/engine/Catalog.java:1623
A staged version remains eligible for promotion after a catalogue refresh withdraws it. Applying an unrelated settings change can install that withdrawn package. Recheck withdrawal status before promotion.

[P2] Automatic checks can run before Wi-Fi is marked connected — core/runtime/java/hmgapi/engine/HomeWifi.java:322
The update checker starts before "state":"up" is published. If it runs first, it rejects the connection as offline; the recorded lease prevents another attempt during that connection. Start the check after publishing connected state.

…ed; the check after Wi-Fi is up

Review fixes (isaacwisdom):
- Staged updates moved into mods/ are recorded (state/staged-swap.json) before the first move
  until the apply is final. engine recover puts them back with the /system files: a cut-off
  apply (with or without its journal yet, even between the two moves) and an undone trial.
  engine keep and a finished apply drop the record; an apply or install waits while it's there,
  and boot.sh runs recover for it as for a journal.
- A staged version withdrawn since (catalog/withdrawn.json) is dropped at the apply, not put in.
- wifi.sh starts the update check only after wifi.json says "up": the engine reads that to know
  it's online, and the check runs once per connection.

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

Copy link
Copy Markdown
Contributor Author

Thanks, all three fixed in d4f5245:

  • [P1] Staged updates escape trial and crash recovery.
    • The staged updates an apply moves into mods/ are now recorded in state/staged-swap.json, written before the first move. The record stays until the apply is final.
    • engine recover puts them back with the /system files. That covers a cut-off apply (whether or not its journal had been written yet, and even between the two moves) and an undone trial.
    • A finished apply and engine keep drop the record. Applies and installs wait while it exists, and boot.sh runs recover for it as it does for a journal.
  • [P2] Withdrawn updates can still be applied. Promotion now drops a staged version that catalog/withdrawn.json has withdrawn since, and says why.
  • [P2] Automatic checks can run before Wi-Fi is marked connected. wifi.sh now starts the update check only after wifi.json says up.

Tests: catalog-test.sh 213, with new checks for each cut-off point, a kept trial, an undone trial and a withdrawn staged version. homewifi-test.sh 199 now checks that wifi.json already says up when the check starts. install/common/test.sh passes.

🤖 Addressed by Claude Code

The messages, docs and comments this PR adds call the file a mod zip
(or just the zip), so it isn't confused with a NEMESIS package. Lines
from main are left as they are.

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.

The trust chain holds: a first install needs a key on authors.json, the package must be signed by the entry's key, and Signing.verify checks the installed key.

One fix needed, a power-cut window: a non-trial apply() deletes the journal, and only afterwards does run() call Catalog.stagedDone() to remove staged-swap.json. A cut between the two makes the next boot run recover, and stagedRecover puts the old mod code back over the new /system files, so mod code and /system don't match.

Suggested fix: keep the staged ids in the journal itself, so deleting the journal makes the apply final in one step. staged-swap.json then only covers the moment before the journal is written.

Merge order: after #422, before #457.

AwsomeFox and others added 2 commits November 30, 2026 16:39
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ut window)

Review: a non-trial apply deleted its journal, and only afterwards did run() remove
staged-swap.json; a cut between the two made recover put the old mod code back over the new
/system files. Now apply() writes the staged ids into the journal ("staged") and deletes
staged-swap.json right after, so deleting the journal makes the staged updates final with the
files in one step, and recover puts them back from the journal. staged-swap.json only covers the
moments before the journal is written. Tests: a cut-off apply with the ids only on the journal,
and a finished apply (no journal, no record) that recover leaves alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AwsomeFox added a commit that referenced this pull request Nov 30, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AwsomeFox added a commit that referenced this pull request Nov 30, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AwsomeFox

Copy link
Copy Markdown
Contributor Author

Fixed as suggested in 0b82eaa. apply() writes the staged ids into the journal ("staged") and deletes staged-swap.json right after. Deleting the journal therefore makes the staged updates final with the /system files in one step, and recover puts them back from the journal. staged-swap.json now only covers the moments before the journal is written.

New tests: a cut-off apply with the ids only on the journal (recover puts the update back), and a finished apply (no journal, no record) that recover leaves alone. The catalogue, engine, safety and Home Wi-Fi tests pass.

AwsomeFox and others added 2 commits December 2, 2026 11:22
The only conflict was tools/test-all.sh: this branch's catalog-test.sh and
release/2.0's core/client/test.sh both go in ALL and FAST.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
release/2.0 carries version 1.1.0, so a fake 1.1.0 release was no
longer newer and the update offer, its notes and the SHA256SUMS refusal
weren't tested. 8.0.0 stays newer through 2.x; the 9.0.0 draft is still
there to be skipped.

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.

3 participants