fix(logging): keep log records when the project root is on another mount - #1260
Merged
Merged
Conversation
os.path.relpath raises ValueError on Windows when the record's file and PROJECT_ROOT resolve to different mounts. That happens whenever the project is launched through a mapped network drive or a subst drive: the call frame keeps X:\MoneyPrinterTurbo\..., while realpath resolves PROJECT_ROOT back to C:\... Loguru catches the formatter error and discards the record, so the terminal and the WebUI log panel both go silent. Fall back to the absolute path there, and also when the file sits outside the project root, where "./" glued onto a ".." climb is no easier to read than the original path. Render the relative path with forward slashes as well, so Windows logs show "./app/services/task.py" like every other platform instead of the mixed "./app\services\task.py". test_webui_task.py already asserted the POSIX form but is not part of the Windows smoke job, so the drift went unnoticed; add it to that job to keep the regression covered on the platform where it appears.
Owner
|
Thanks for the detailed report, Windows reproduction, and regression coverage. The fix looks good and has been merged. I also verified it against the latest main with the full test suite. Thanks again! |
guo6x
pushed a commit
to guo6x/MoneyPrinterTurbo
that referenced
this pull request
Aug 25, 2026
…unt (harry0703#1260) os.path.relpath raises ValueError on Windows when the record's file and PROJECT_ROOT resolve to different mounts. That happens whenever the project is launched through a mapped network drive or a subst drive: the call frame keeps X:\MoneyPrinterTurbo\..., while realpath resolves PROJECT_ROOT back to C:\... Loguru catches the formatter error and discards the record, so the terminal and the WebUI log panel both go silent. Fall back to the absolute path there, and also when the file sits outside the project root, where "./" glued onto a ".." climb is no easier to read than the original path. Render the relative path with forward slashes as well, so Windows logs show "./app/services/task.py" like every other platform instead of the mixed "./app\services\task.py". test_webui_task.py already asserted the POSIX form but is not part of the Windows smoke job, so the drift went unnoticed; add it to that job to keep the regression covered on the platform where it appears. (cherry picked from commit 6951758)
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.
format_log_recordshortens the absolute source path of every record into a project-relative./...form. Two edge cases in that conversion are only reachable on Windows, and one of them silently kills logging.The dropped records
os.path.relpathraisesValueErrorwhen the two paths sit on different Windows mounts. That is exactly what happens when the project is launched through a mapped network drive (net use Z: \\nas\share) or asubstdrive: the call frame keeps the drive the user launched from, whilePROJECT_ROOTis built withos.path.realpath, which resolves the mapping away.Reproduced with
subst X: <parent of the repo>, then importing the app fromX:\MoneyPrinterTurbo:Loguru catches the formatter exception and discards the record, so the sink receives nothing at all. The terminal prints that dump instead of the log line, and since
webui_task.pyinstalls a second sink with the same formatter to feed the WebUI log panel, the generation log panel stays empty for the whole run.The mixed separators
On Windows
os.path.relpathreturns backslash-separated segments, so the./prefix produces"./app\services\task.py".test_worker_logs_are_available_without_streamlit_session_statealready pins the POSIX form:r'"\./test/services/test_webui_task\.py:\d+": logged_start 'and fails on Windows today. That file is not in the
windows-smokejob, which is why the drift was never caught.The change
app/utils/logging_utils.py_project_relative_path: guard theValueError, keep the absolute path for files outside the project root, normalise separators to/test/services/test_webui_task.pylogging_utilscoverage.github/workflows/ci.ymltest/services/test_webui_task.pyto the Windows smoke jobFiles outside
PROJECT_ROOTkeep their absolute path as well:./..\..\..\AppData\Local\...is no easier to read than the path it replaces.Why the CI file is touched
The formatter change is only observable on Windows, and the test that proves it lives in a file the Windows job does not run. That one line is what keeps the same drift from coming back. Happy to drop it if you would rather keep the smoke list at core services only.
Verification
Full suite on Windows 11, Python 3.12,
uv sync --frozen:ruff check app cli.py main.py webui testandcompileall app cli.py main.py webui testare both clean.Each new test was confirmed to fail without the
logging_utils.pychange. Two of the three fail on Linux as well;test_log_paths_stay_posix_style_on_every_platformis a Windows-only guard, which is what the CI line is for.The remaining failure is unrelated and fails identically on a clean
main:test_headless_open_folder_shows_host_mapped_pathsetssys.platformto"linux"in its fixture, which makes NumPy take its Linux branch on first import and callos.uname(), absent on Windows. It passes on the Linux matrix. Two further failures in the "before" run (test_corrupted_cache_is_removed_without_breaking_search,test_elevenlabs_connection_button_reports_success) are timing-dependent; both pass in isolation and passed in the "after" run.