[fix] kimi_cli failed to find CHANGELOG.md#1277
[fix] kimi_cli failed to find CHANGELOG.md#1277ClSlaid wants to merge 4 commits intoMoonshotAI:mainfrom
Conversation
Pyinstaller packed binary will extract itself and then run. However, it does not extract the CHANGELOG.md at the first place, thus lead to instant failure on starting the program. This patch makes reading CHANGELOG.md file lazy, then the file will only be read once when running instead of starting. Signed-off-by: cl <[email protected]>
Signed-off-by: cl <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR fixes an issue where PyInstaller-packed binaries fail at startup because CHANGELOG.md is not immediately available when the module is imported. The solution converts the eager loading of CHANGELOG.md (at module import time) to lazy loading (on first access), preventing the startup failure.
Changes:
- Replaced module-level
CHANGELOGconstant with a lazy-loadingget_changelog()function that caches the parsed changelog on first access - Updated the
/changelogcommand to callget_changelog()instead of using theCHANGELOGconstant - Added graceful FileNotFoundError handling that returns an empty changelog if the file is missing
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/kimi_cli/utils/changelog.py | Introduced lazy loading for CHANGELOG.md with caching and error handling; minor formatting change to ReleaseEntry construction |
| src/kimi_cli/ui/shell/slash.py | Updated import and usage from CHANGELOG constant to get_changelog() function |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def get_changelog() -> dict[str, ReleaseEntry]: | ||
| """Lazily load and parse the changelog on first access.""" | ||
| global _cached_changelog | ||
| if _cached_changelog is None: | ||
| path = Path(__file__).parent.parent / "CHANGELOG.md" | ||
| try: | ||
| _cached_changelog = parse_changelog( | ||
| path.read_text(encoding="utf-8")) | ||
| except FileNotFoundError: | ||
| _cached_changelog = {} | ||
| return _cached_changelog |
There was a problem hiding this comment.
The new lazy loading mechanism lacks test coverage. While the existing test for parse_changelog will continue to work, there's no test that verifies the lazy loading behavior, the caching mechanism, or the FileNotFoundError handling. Consider adding a test that verifies: 1) the changelog is only loaded once (caching works), 2) calling get_changelog multiple times returns the same cached result, and 3) graceful handling when CHANGELOG.md is missing.
Co-authored-by: Copilot <[email protected]> Signed-off-by: ClSlaid <[email protected]>
| @@ -121,7 +122,7 @@ Only write entries that are worth mentioning to users. | |||
| - Web: Fix authentication token persistence by switching from sessionStorage to localStorage with 24-hour expiry | |||
| - Web: Add server-side pagination for session list with virtualized scrolling for better performance | |||
| - Web: Improve session and work directories loading with smarter caching and invalidation | |||
There was a problem hiding this comment.
🟡 v1.7.0 changelog entry replaced with duplicate of v1.6 entry
In CHANGELOG.md, the v1.7.0 entry Web: Fix WebSocket errors during history replay by checking connection state before sending was replaced with Web: Fix WebSocket disconnect when creating new sessions. However, that exact same text already exists in the v1.6 section at line 133. This means v1.7.0 now has a duplicate of the v1.6 fix note, and the original v1.7.0 fix description (which described a different bug fix — checking connection state before sending during history replay) is lost. The same duplication occurs in docs/en/release-notes/changelog.md at line 118 vs line 127.
| - Web: Improve session and work directories loading with smarter caching and invalidation | |
| - Web: Fix WebSocket errors during history replay by checking connection state before sending |
Was this helpful? React with 👍 or 👎 to provide feedback.
Pyinstaller packed binary will extract itself
and then run. However, it does not extract the
CHANGELOG.md at the first place, thus lead to
instant failure on starting the program.
This patch makes reading CHANGELOG.md file lazy,
then the file will only be read once when running
instead of starting.
Related Issue
Discribed in PR.
Checklist
make gen-changelogto update the changelog.make gen-docsto update the user documentation.