0029 — The toolkit installs its own updates at editor exit, from a signed manifest
Status: Accepted
Date: 2026-11-10
Relates to: ADR 0026 (the server pin a toolkit update moves) and ADR 0027 (the setup step that asks for consent). The keys and their rotation are in docs/dev/trust-chain.md.
Context
Toolkit releases are frequent and carry fixes users want. The update check (1.1) tells users about a release, but installing it is a manual download and unzip, and an addon cannot be replaced like an ordinary file: its scripts are loaded and running in the editor that would replace them. How the files are swapped decides whether the editor survives the swap.
Measured on 2026-10-26 with toolkit 1.0.4 replaced by 1.1.0 inside a running editor, on Godot 4.2, 4.3, 4.4, 4.5, 4.6 and 4.7.2 (Linux, a test-only plugin doing the swap):
- Writing the files while the editor runs. The editor rescans on focus-in (
EditorFileSystem::scan_changes()onNOTIFICATION_APPLICATION_FOCUS_IN) and, on 4.3 and later, hot-reloads the changed scripts with their state kept: members survive by name, new members are empty, and_init,_enter_treeand_enable_plugindo not run again. 1.1.0’s code then ran on the graph 1.0.4’scompose()built, logging a dock error on every refresh, and disabling the plugin afterwards crashed the editor (signal 11) on every version from 4.3. Godot 4.2 (the patch was not recorded) did not reload at all. - Writing, then disabling and enabling the plugin. Only
plugin.gdloaded anew; the scripts it preloads came from the cache, andcompose()failed with the wrong argument count (4.2 and 4.7.2). No server came up. - Writing, then
restart_editor. Clean as long as no dialog comes up. From 4.4 the restart asks about unsaved work: an unsaved script opens “Save changes to the following script(s)?”, the editor stays up on the new files, and the next focus-in reloads them as above. 4.2 and 4.3 restart without asking. - Writing in the plugin’s
_exit_treewhile the editor exits. Clean on all six versions: cancelling the dialog changed nothing, and OK, a restart or a normal quit installed 1.1.0, which started with its server listening and no toolkit error.
Calling restart_editor from the plugin’s own code crashed 4 of 5 runs on 4.3+, because _exit_editor frees the editor’s plugins synchronously (unload_editor_addons(), absent in 4.2) while the calling function is still on the stack.
Decision
The toolkit verifies and stages an update while the editor runs, and swaps it in only from the plugin’s _exit_tree when the editor exits for any reason other than a disable.
- Apply at exit, with a restart. Update downloads and stages the release; when staging ends, the toolkit restarts the editor so the exit installs it. The restart is a deferred
restart_editor(false), so it runs outside the plugin’s call stack, and the toolkit saves nothing (self_update/restart_gate.gd). Restart refuses while a script has unsaved edits, on every version. On 4.4 and later the editor restarts by itself when staging ends only when no script is unsaved, no game is running and no scene was never saved; otherwise, and always on 4.2 and 4.3, the dock’s ready view waits for the user’s Restart. A restart-free install is not in 1.2.0: on 4.2 and 4.3 a re-enable in the same session ran cached scripts, and the code that installs is the one part of the toolkit an update can never fix. A later release may revisit it. - Two renames under a journal, in the update folder. Everything lives in
res://addons/.godot_mcp_toolkit_update/, beside the addon: the journal, the install log, the downloaded zip, manifest and signature, the unpacked stage and the backup (self_update/update_folder.gd). The engine’s scanner, the exporter and the Plugins list skip a folder whose name starts with a dot, and the folder writes its own.gitignore,.p4ignoreand.gdignore. At exit the applier (self_update/update_applier.gd) re-derives what the stage must hold from what is signed (signature, manifest, the zip’s hash, the file list inside the zip), writesapplyingto the journal, renames the installed folder tobackup-<from>/and renames the stage into its place. A failed second rename renames the backup back. The next start reads the journal and reports the result (self_update/update_settler.gd). An editor ended by a signal skips_exit_tree, and the update waits for the next normal exit. A kill in the 0 to 7 ms between the two renames leaves no installed folder, with the old and new copies both whole in the update folder; the recovery plugin below settles it at the next start. Agit clean -fdXin that state deletes both copies, so the toolkit has to be reinstalled (troubleshooting). - A recovery plugin covers the starts the toolkit cannot run. The settler lives in the addon folder, so a start that finds no addon folder, or a version that does not load, runs none of it. While the journal says
staged,applyingorapplied, a second editor plugin lives inres://addons/.godot_mcp_toolkit_recovery/, enabled inproject.godotby its fullplugin.cfgpath; the scanner and the Plugins list skip the folder. Its template ships inself_update/recovery/, and staging copies it out and saves its entry (self_update/recovery_files.gd). It loads nothing from the addon folder and reads the journal with its own code (self_update/recovery/recovery_journal.gd). A few seconds after the first scan, with the toolkit not running, it acts once: a kill between the renames rolls the stage forward when it hashes to the journal’sexpected_tree_hashand otherwise renames the backup back; anappliedversion that did not load is renamed aside, the backup renamed in and the journal writtennot_appliedwithrestored, so the restored toolkit reports it instead of staging that release again; a toolkit enabled but never started, which Godot 4.2 leaves after an update that moves a global class, gets one more restart, asked once. Each of these asks for a restart and enables nothing in the same session. A case it cannot square, such as a missing backup or a third version in the addon folder, gets a dialog with the manual steps. The toolkit’s start removes the recovery plugin once the journal has settled, and a disable removes it too. A release that loads but misbehaves stays a manual rollback. - Two applier additions, frozen in 1.2.0. The recovery plugin needs both, and like the rest of the applier they never change once 1.2.0 ships. The applier writes
applying_at, the Unix time, withapplying(the journal stays format 1); the settler and the recovery plugin act on anapplyingjournal only once it is more than 60 s old or more than 60 s in the future, since an apply in another editor’s exit may still be running. And before it writesapplying, the applier readsproject.godotfrom disk: if the savededitor_plugins/enableddoes not name the recovery plugin, it postpones with “the recovery plugin is not enabled”, and the next start saves the entry again. No apply runs without it. Recovery therefore starts with the updates a 1.2.0 toolkit installs; the install that brings 1.2.0 has none. - Two install modes,
manualandask.mcp_toolkit/updates/install_modeisask(the default: the dock offers a release whose manifest and signature have been verified, and the zip downloads only when the user clicks Update) ormanual(links only); any other value reads asmanual(self_update/install_mode.gd). There is no mode that installs without asking, because an update must stay visible to whoever works in the project. Nothing installs until the update check may run and the setup stepupdate_installhas been seen (core/consent.gd). Switching tomanualdeletes a staged release. - The mode lives in
project.godot, for the reason ADR 0026 gave the server pin: the files an update changes are committed, so which version a project runs is the team’s choice. - What never installs from the editor: a major release, a release whose manifest needs a newer Godot than the running one, and any install in the toolkit’s own repository, into a folder that is a link, into a git checkout or submodule, or from a headless editor (
self_update/install_guards.gd). Those stay links. The exit checks the guards, the signature and the version order again before it renames anything. - Signing is offline. The maintainer signs each release’s manifest by hand, against a draft release, with a key kept off GitHub; no workflow ever holds a trusted release key. Where the keys are kept is in Custody.
- The trust chain. A release embeds a trust document listing root keys and release keys; a release key signs manifests, and root keys sign the next document. The client walks each next document from GitHub, verifies it against the previous roots and keeps it per machine in
godot_mcp_toolkit/trust/inside the OS’s data folder, so a revocation holds across projects. Keys have no expiry, a manifest carries no key id (keys are told apart by their PEM), and a manifest’sexpires_atis read but never refuses. The rules, caps and limits are indocs/dev/trust-chain.md. - The pin moves with the update. After an update the user started has installed, the toolkit moves its own
.mcp.jsonserver pin to the new release’s recommended version, with a notice and Undo, when the pin is one the toolkit owns: the version setting is empty, no local server path is set, and the entry names the old recommended version or this machine’s last write (ui/mcp_json/server_pin_move.gd, C11 in the contract). A pin set by hand stays. This reverses ADR 0026’s “nothing is rewritten silently” for that one case. - The addon folder belongs to the release. An update replaces the folder whole, with no copy-back: a file a user keeps in
res://addons/godot_mcp_toolkit/is lost to any update, manual too. The previous version stays as the backup until the next update is staged, or goes after a successful update whenmcp_toolkit/updates/keep_backupis off. - What the installed applier reads is a contract. The applier in a shipped release installs every later one and can never be patched on a machine that stays on it. So these stay readable by every older toolkit, and breaking one needs a bridge release first:
- the zip’s layout: every file under
addons/godot_mcp_toolkit/, withplugin.cfgnaming the release’s version (self_update/release_archive.gd); - the file list’s grammar:
release_files.sha256in the addon folder, one<sha256> <path>line per file insha256sumformat, naming exactly the zip’s other files (self_update/release_file_list.gd); - the manifest’s schema,
format1 withversion,archive,archive_size,archive_sha256andmin_godotrequired and unknown keys ignored (self_update/release_manifest.gd), and the asset namesgodot-mcp-toolkit-<v>.zip,godot-mcp-toolkit-<v>.update.jsonand its.sig(self_update/release_assets.gd); - the entry cap of 5000 and the name rules: no absolute path,
\,:or empty,.or..segment; no.gdignore,.gitignoreor.p4ignoreat the addon root; noproject.godotat any depth; no name Windows would change or open as a device; no file twice; no two names that differ only in letter case.
- the zip’s layout: every file under
Considered and rejected
- Hot-swapping the files mid-session, or disabling and enabling the plugin. Measured above: new code on old state, or new entry point on old dependencies, and crashes on 4.3+.
- Writing the files, then restarting. Measured above: a save dialog can hold the restart and leave the editor running on the new files.
- Writing the release file by file at exit, with a backup copy. A lab on Godot 4.2.0, 4.3 and 4.7 on Windows, macOS and Linux killed the editor at each step of both strategies. Its worst case for the file-by-file write left the installed folder mixed between the two versions after a window of 148 to 2057 ms over 380 files, with the only full copy of the old version lost. The two renames’ worst case is the 0 to 7 ms window above, with both copies whole.
- Installing without asking. It was built as an
automaticmode and removed: an update must stay visible to whoever works in the project. - Applying at the next start, before the plugin loads.
plugin.gdpreloads the rest of the toolkit at parse time, so the old files are loaded before any code could swap them; it would need a loader plugin with no preloads, and applying at exit does not have the problem. - A checksum without a signature. A hash published in the same release only proves the download matches the release; whoever can change the release can change both.
- Signing in a workflow, with the key as an environment secret. It saves the manual step, but whoever takes the repository or a workflow dependency can sign with it, which is the attack the signature exists to stop.
Consequences
- A release that installs but does not load is undone from outside the toolkit, since the updater is part of what failed: the recovery plugin puts the backup back at the next start and asks for a restart. A release that loads but misbehaves is not undone; the six-minor release gate, the manifest’s Godot floor and the backup, with its troubleshooting entry, limit that.
project.godotchanges while an update is in flight: the recovery plugin’s entry appears at staging and goes once the update settles. A teammate whose checkout has the entry but not the folder sees the editor’s warning that the addon failed to load.- The first release that ships the installer updates itself from then on; older installs update by hand once.
- A stolen release key, with access to the repository, reaches the clients that have not yet seen the trust document that drops it. The
askmode means a user still has to click Update. - Teammates who each install the same update produce the same change to the addon folder, since a release’s files are the same bytes.
scripts/test_framework/update_flow.shruns the flow end to end on scratch projects in CI and in the release workflow against the built zip;scripts/test_framework/update_gui.shchecks what a user clicks, in editors with a window on a virtual display, in the cross-version workflow;test/apply_kill_driver/run_legs.shkills real editors at each step of the swap.