Skip to content

fix(plugins): keep a plugin's tokens and local files across store updates - #755

Open
ChuckBuilds wants to merge 5 commits into
mainfrom
fix/plugin-update-keeps-local-files
Open

ChuckBuilds wants to merge 5 commits into
mainfrom
fix/plugin-update-keeps-local-files

Conversation

@ChuckBuilds

Copy link
Copy Markdown
Owner

Problem

On 2026-10-04, updating calendar 1.2.9 → 1.2.12 from the web UI (POST /api/v3/plugins/update) deleted plugin-repos/calendar/token.pickle and credentials.json, the plugin's Google OAuth files. The hot reload logged "Credentials file not found", and the calendar stayed broken until the files were restored from a backup.

The cause: a monorepo plugin update renames the old directory aside, downloads the new release and then deletes the old copy. No release contains files the plugin writes at runtime, so they went with it.

Fix

Directory-swap paths (_discard_backup in store_install.py): before the set-aside copy is deleted, the plugin's own local files are copied into the new copy. Those are:

  • anything the plugin's .gitignore excludes (old copy's or new copy's), and
  • known secret/state files, kept even if the plugin never gitignored them: token.pickle, *.pickle, token.json, credentials.json, config_secrets.json, .pkce_code_verifier.

A file the new release ships is never overwritten. __pycache__, *.pyc and .git are not carried over. If a copy fails, the old copy is kept rather than deleted, and the log names its path.

This covers every place an existing install is replaced: _reinstall_with_rollback (routine store update and old-remote → monorepo migration), install_plugin over an existing copy, and install_from_url replacing an existing copy. The new copy is found with _existing_install(), so a registry id that differs from the install directory still resolves.

Plugins installed from their own git repo: gitignored files were already safe there. But git stash push -u swept untracked, non-ignored files into an auto-stash that is never popped, so a token the repo forgot to gitignore disappeared. The stash now excludes the known secret files via :(exclude,glob) pathspecs, and those files alone no longer trigger a stash.

The rules live in the new src/plugin_system/plugin_local_files.py, which has a small .gitignore matcher (pathspec isn't a dependency).

Tests

test/test_store_update_keeps_local_files.py:

  • monorepo: install, drop token.pickle, credentials.json and a gitignored cache/events.json, run update_plugin, check all three survive and no backup is left behind
  • monorepo: the token is kept even when the release has no .gitignore
  • release content wins: removed modules and byte code are not carried over
  • reinstall over an existing copy, and install_from_url replacing one
  • git: a real clone updated by git pull, with an untracked, non-ignored token; a token alone does not create a stash
  • unit tests for the known-file list and the .gitignore rules

On the pre-fix store code, 6 of these fail (the "release content wins" guard passes either way). They pass on Windows and on ledpi (Linux, git 2.47). The store, update, install and web-interface tests show the same 38 pre-existing Windows-only failures before and after (test_install_lowmem needs bash, the starlark routes need fcntl).

🤖 Generated with Claude Code

ChuckBuilds and others added 2 commits October 4, 2026 14:21
…ates

A monorepo plugin update replaces the plugin directory with the fresh
download and deletes the old copy, taking with it everything the plugin
wrote beside itself. On 2026-10-04 updating calendar 1.2.9 -> 1.2.12 deleted
token.pickle and credentials.json, and the calendar stopped until they were
restored from a backup.

Before the set-aside copy is discarded (store update, reinstall over an
existing copy, install_from_url replace), carry over files the plugin's
.gitignore excludes plus known secret/state files (*.pickle, token.json,
credentials.json, config_secrets.json, .pkce_code_verifier). Files the new
release ships win; byte code and .git are not carried; if a copy fails the
old copy is kept.

The git-pull path no longer sweeps untracked tokens into its auto-stash,
which is never popped.

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

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

coderabbitai Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 24 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d6eaa166-1a2b-4b1f-b40a-f0bb335e533e
📥 Commits

Reviewing files that changed from the base of the PR and between a74b5a2 and 3cf7347.

📒 Files selected for processing (7)
  • CHANGELOG.md
  • src/plugin_system/plugin_local_files.py
  • src/plugin_system/store_install.py
  • src/plugin_system/store_update.py
  • test/test_on_demand_live_and_restore.py
  • test/test_store_update_keeps_local_files.py
  • test/web_interface/test_starlark_pixlet_routes.py
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 56 complexity

Metric Results
Complexity 56

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

ChuckBuilds and others added 3 commits October 4, 2026 14:38
TestARestoreWithNothingToResume took the last cache_manager.set call to be
the on-demand state, but the controller's font-usage publisher thread writes
font_usage_snapshot to the same mock, and on a slow runner it lands last.
Failing on main since #748 (Python 3.11 job). Same fix for the named-mode
restart test, which had the same race.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…fix/plugin-update-keeps-local-files

# Conflicts:
#	test/test_on_demand_live_and_restore.py
…equest

TestPixletEditorHostDefaultsButDoesNotOverride patched subprocess.Popen for
the whole request. When the captive-portal before_request hook's 30s AP-mode
cache had expired, its `systemctl is-active hostapd` check went through
subprocess.run, got the fake process, and raised TypeError (run() uses the
process as a context manager): a 500 instead of 200. Seen on the Python 3.13
job; reproduced locally by forcing the cache to expire. Other calls now reach
the real Popen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant