fix: clean up stale asset symlinks to prevent hot reload crash loop#6163
Merged
fix: clean up stale asset symlinks to prevent hot reload crash loop#6163
Conversation
…6159) When a Python module directory using rx.asset(shared=True) is renamed, stale symlinks in assets/external/ cause Granian to enter an infinite reload loop. Clean up broken symlinks and empty directories in assets/external/ in App.__call__ before compilation, so the cleanup runs on every hot reload, not just initial startup. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Greptile SummaryThis PR fixes a hot-reload crash loop (issue #6159) where renaming a Python module that uses Key changes:
Issues found:
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Granian as Granian (file watcher)
participant App as App.__call__
participant Cleanup as remove_stale_external_asset_symlinks
participant FS as assets/external/ (filesystem)
participant Compile as App._compile
Granian->>App: hot reload triggered
App->>Cleanup: remove_stale_external_asset_symlinks()
Cleanup->>FS: rglob("*") — find all paths
FS-->>Cleanup: list of paths (symlinks + dirs)
Cleanup->>FS: unlink broken symlinks (target missing)
Cleanup->>FS: rglob("*") — find remaining dirs
FS-->>Cleanup: remaining directories
Cleanup->>FS: rmdir() empty directories (deepest first)
Cleanup-->>App: done
App->>Compile: _compile(prerender_routes=...)
Compile->>FS: rx.asset(shared=True) recreates symlinks
Note over FS: No stale symlinks → no spurious<br/>file-change events → no reload loop
Compile-->>App: compilation complete
App-->>Granian: ASGI app returned
Last reviewed commit: ff962fc |
- Add `not dirpath.is_symlink()` check before `rmdir()` to avoid NotADirectoryError on symlinks pointing to directories. - Use tmp_path/monkeypatch in no-external-dir test to avoid depending on prior test environment state. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Collaborator
Author
|
@greptile-apps please re-review |
adhami3310
approved these changes
Mar 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix #6159
When a Python module directory using rx.asset(shared=True) is renamed, stale symlinks in assets/external/ cause Granian to enter an infinite reload loop. Clean up broken symlinks and empty directories in assets/external/ in
App.__call__before compilation, so the cleanup runs on every hot reload, not just initial startup.