Skip to content

Stop reloading a local plugin on its own Python bytecode writes - #15093

Merged
omarchybot merged 2 commits into
quattrofrom
fix/issue-11929
Oct 31, 2026
Merged

omarchybot merged 2 commits into
quattrofrom
fix/issue-11929

Conversation

@omarchybot

Copy link
Copy Markdown
Collaborator

The shell's local plugin watcher reloads a plugin on every write under ~/.config/omarchy/plugins/<id>/, and that includes the bytecode a plugin's own Python helper writes. When the helper imports a module from inside the plugin directory, CPython writes __pycache__/<module>.cpython-314.pyc. The watcher sees it and reloads every plugin. The reload restarts the helper, and the helper's next lazy import writes the next .pyc. Reported with b.everything freezing the shell and with thefreshoffice.speaker-calibrator killing its helper mid-measurement.

The 150ms localPluginReloadTimer in shell.qml coalesces a burst of events, but it cannot break this cycle. Each write comes from the helper that the previous reload started.

localPluginIdForPath() now ignores any path with a __pycache__ component, which also covers the temporary name CPython writes before it renames the file into place. It also ignores stray .pyc/.pyo files. Everything else still reloads as before: a helper's .py source, and hidden files inside a plugin, since entry points may live there and the manual promises a reload for any saved file.

This does not cover #12158, where a plugin writes its own data.json beside its QML. Telling plugin state apart from plugin code means deciding what hot reload watches, for example an allow-list of QML, JS and manifests. That would also stop reloads for helper source and assets, so it is left to the maintainer.

test/shell.d/fixtures/plugin-registry/shell.qml asserts the new boundaries. On a worker built from the Omarchy ISO, its six bytecode assertions fail on quattro and pass with this change. In a shell launched from each tree, three real python3 -c "import …" runs inside a local plugin caused 9 reloads on quattro and none with this change, while editing the helper's .py still caused one. Codex Medium reviewed the mechanism and the change. It found that an earlier, broader version (ignoring hidden files at any depth) would have stopped hot reload for hidden entry points, and it asked for the extra path cases. Both are in this change, and its last round had nothing open.

Fixes #11929

The local plugin watcher reloads a plugin on every write under its directory. A plugin whose Python helper imports modules from that directory makes CPython write __pycache__/*.pyc, each write reloads the plugin, the reload restarts the helper, and the helper's next lazy import writes the next .pyc. The 150ms debounce coalesces a burst but cannot break that cycle, since each write comes from the helper the previous reload started.

Ignore paths under __pycache__ (which covers the temp name CPython writes before renaming) and stray .pyc/.pyo files. Hidden files inside a plugin are still watched: entry points may live there, and the manual promises a reload for any saved file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Codex Medium <noreply@openai.com>
@greptile-apps

greptile-apps Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking issue was found.

Summary

Stops Python cache writes inside local plugins from triggering reloads.

  • Local plugin reloads ignore Python bytecode cache paths.

Reviews (2) · Last reviewed commit: "Ignore only __pycache__ below a plugin, ..." · Reviewed by Greptile

…code

Matching .pyc/.pyo and __pycache__ against the whole plugin-relative path also matched plugin directories themselves: moving in a plugin whose id is acme.pyc (a valid id) was ignored, as was every change to a plugin dir named __pycache__. Python 3 writes bytecode only into __pycache__, so the suffix check was never needed for the reload loop; drop it and require __pycache__ to sit inside a plugin.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Codex Medium <noreply@openai.com>
@omarchybot omarchybot added verified Omarchy Triage has verified that this issue is ready for final review ready Good to merge labels Oct 17, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator Author

Reviewed and verified at 61c27da, against quattro at 33783b1.

Fix pushed. Codex Medium's review found that the first commit matched .pyc/.pyo and __pycache__ against the whole plugin-relative path, so a plugin's own directory could be mistaken for bytecode. Moving in a plugin whose id is acme.pyc (a valid id) was ignored, and so was every change under a plugin directory named __pycache__. Python 3 only writes bytecode into __pycache__, so 61c27da drops the suffix check and only ignores __pycache__ when it sits inside a plugin directory. The description above still mentions ignoring stray .pyc/.pyo files; that part no longer applies.

Reproduced on a worker built from the Omarchy ISO, with the shell running from each tree: inside a local plugin, three python3 -c "import …" runs that write bytecode caused 12 reloads on quattro, 0 on this head and 0 on this head merged into current quattro, and 12 again with the fix reverted. Editing the helper's .py still caused one reload in every case, and moving in a plugin named acme.pyc now reloads. The new assertions in test/shell.d/fixtures/plugin-registry/shell.qml fail with the fix reverted and pass with it.

Tests on the worker: test/cli passes, and so do menu-plugin, plugin-add, plugin-clone, plugin-enable, plugin-registry-contract and plugin-validate, on the head and merged into quattro. plugin-auth-boundary-test.sh and plugins-test.sh did not run, because the worker has no node. CI is green.

Second opinion: Codex Medium, two rounds. The first round found the defect above. The second, on 61c27da, found nothing open. Independence is not guaranteed, because the reviewer can read this session's work. No competing pull requests were found. Still out of scope, as the description says: #12158 (a plugin writing its own data.json).

Waiting on the maintainer.

@omarchybot
omarchybot merged commit c726e6a into quattro Oct 31, 2026
2 checks passed
@emirb emirb added this to the 4.5 milestone Nov 5, 2026
berenddeboer pushed a commit to berenddeboer/omarchy that referenced this pull request Nov 6, 2026
…om#15093)

* Stop reloading a local plugin on its own Python bytecode writes

The local plugin watcher reloads a plugin on every write under its directory. A plugin whose Python helper imports modules from that directory makes CPython write __pycache__/*.pyc, each write reloads the plugin, the reload restarts the helper, and the helper's next lazy import writes the next .pyc. The 150ms debounce coalesces a burst but cannot break that cycle, since each write comes from the helper the previous reload started.

Ignore paths under __pycache__ (which covers the temp name CPython writes before renaming) and stray .pyc/.pyo files. Hidden files inside a plugin are still watched: entry points may live there, and the manual promises a reload for any saved file.

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

* Ignore only __pycache__ below a plugin, not names that look like bytecode

Matching .pyc/.pyo and __pycache__ against the whole plugin-relative path also matched plugin directories themselves: moving in a plugin whose id is acme.pyc (a valid id) was ignored, as was every change to a plugin dir named __pycache__. Python 3 writes bytecode only into __pycache__, so the suffix check was never needed for the reload loop; drop it and require __pycache__ to sit inside a plugin.

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

---------

Co-authored-by: Omarchybot <317366263+omarchybot@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Codex Medium <noreply@openai.com>
(cherry picked from commit c726e6a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ready Good to merge verified Omarchy Triage has verified that this issue is ready for final review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shell reloads a local plugin on every write under it, including its own __pycache__ — reload storm freezes the shell

2 participants