Repository navigation
Studio: add a Download all logs button to Settings > Logs - #10719
Conversation
Settings > Logs could only copy the visible tail of one file. Sharing a problem meant collecting the server log and each runner's log by hand, and the desktop app had no way to reach the log folder at all. Backend - utils/debug_log_export.py packs every log the picker already lists into one ZIP, each record passed through the existing redact_log_text. The allowlist is debug_log_sources.list_sources, unchanged, so the bundle can never contain a file the tab would not have shown. - GET /api/settings/debug/logs/export carries the same two dependencies as the debug log routes beside it, so an API key or keyless caller is refused with 403 exactly as it is for the single file viewer. The archive is bounded three ways, because the 10 per family cap in debug_log_sources caps files and not bytes and the session log is never rotated: an 8 MB tail per file, a 32 MB budget across all of them, and a 15 second ceiling on the whole build. The tail is kept rather than the head, and the families are taken round robin so a large server log cannot spend the whole budget before the runner logs are reached. Anything left out is named in EXPORT_WARNINGS.txt rather than dropped silently. Desktop - download_logs_to_downloads streams the archive to the OS Downloads folder and returns its real path. It reuses require_loopback_url and stream_url_to_path, mints its own session rather than accepting one over IPC, and rewrites host, port and path before minting, so the webview names the endpoint but never chooses it. - open_logs_dir was already registered and never called from the UI. It is now wired to a button, unchanged. Frontend - Two buttons beside Copy visible log, with Open logs folder gated on desktop. On desktop the toast shows the saved path and reveals that folder; in a browser the file lands in the browser's own downloads. - Four new settings.debugging keys across all twelve locales. Safety properties, each with a regression test that fails without its fix: a tail seek never begins mid record, since redact_log_text is anchored on a key name next to its value and a cut between the two hands out the credential in the clear; a record the redactor cannot read as UTF-8 is refused rather than decoded with replacement, because a UTF-16 log decoded that way keeps a NUL between every character and every masking rule stops matching; archive member names are family and basename only; EXPORT_WARNINGS.txt never carries a host path or a wall clock. studio/backend/utils/log_redaction.py, debug_log_sources.py, debug_log_reader.py, core/inference/tools.py, routes/auth.py and the loopback_http.rs, desktop_auth.rs and commands.rs Tauri files are untouched.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
The four failing checks split into three causes, all reproduced locally before being changed. pre-commit.ci and Repo tests (CPU) were the same cause: debug_log_export.py and test_debug_log_export.py were not a fixed point of the repo's own ruff-format-with-kwargs hook, and tests/test_formatter_fixed_point.py exists to catch exactly that. Running that guard with the pinned ruff 0.6.9 named those two files and no others; it passes now. CodeQL reported one new high-severity py/clear-text-storage-sensitive-data alert on the test fixtures. The query classifies a local by its NAME -- maybeSecret() is `(?is).*((?<!is|is_)secret|...).*` -- so three locals called `secret` were the taint source, not the synthetic AWS and HF strings they held. Renamed to planted_value, anchor and link_target. The tests assert the same things about the same values. The Python 3.13 leg was not this branch. Backend CI on main was red from 09-10 to 09-12 and went green on 09-13; the same suite run here against the merge base and against this head gives 393 failed / 38463 passed and 392 failed / 38507 passed, with no failure in any debug-log, export or settings test, and the three test_desktop_auth.py failures present identically on both sides. Then three defects, each with a regression test confirmed to fail without its fix. A record cut short by the byte allowance was emitted as though it were whole. Reachable rather than theoretical: when _seek_to_tail takes the forward-scan path it starts later than size - allowance, so on a log being appended to -- the active session log, which is live by definition while someone is exporting it -- the read ends on the allowance instead of on EOF. The trailing bytes are then the front of a record, and redact_log_text needs several characters of value before it masks, so a cut landing just past a key ships the first few in the clear. The two ways the loop ends cannot be told apart afterwards, so it now records which one happened and emits a marker rather than the fragment. _member_name deduplicated case-sensitively, but the volume the archive is EXTRACTED on decides what collides. On Windows and default APFS, Server.log and server.log are one name, so two members landed on top of each other and one log was silently lost, which is the failure that function exists to prevent. The collision key is folded with .lower(); casefold over-folds for a filename. Member names keep their real spelling. A source whose window was shrunk by the remaining budget was reported as "no complete record in the last N bytes", blaming the file for a condition owned by the budget -- and because that path deliberately does not spend remaining, the wrong message repeated for every later source. It now says which of the two caps produced the window. Also: Cache-Control: no-store on the export response, so a bundle of every log on the host is not written to the browser's on-disk cache and a second export is not answered from it (raised in review). strip_verbatim_prefix moved its body to a function compiled on every platform, because gating the whole thing behind cfg(windows) left the UNC branch covered on no platform at all, and the prefix match is now case-insensitive so a lowercase \\?\unc\ cannot degrade to something that reads as a relative path. Verification: 250 pass across test_debug_log_export.py and the four existing debug-log suites, up from 245. cargo check --all-targets clean and 531 Rust tests pass, up from 530. Frontend 7286/7286, tsc and i18n:check:strict clean, and eslint reports the same four pre-existing errors as main with none on changed lines. 500 simulation scenarios across the backend, the cross-platform surface and the frontend all pass. Two things this host cannot answer and which staging CI should: a real Windows or macOS compile of src-tauri (aws-lc-sys needs MSVC lib.exe or a macOS SDK), and the Windows filesystem cases -- os.fstat on FAT32, the ReFS FileIdInfo fallback, and a UNC-mounted Downloads folder. One residual is now documented rather than implied: O_NOFOLLOW does not exist on Windows, so _open_verified cannot refuse a non-symlink file reparse point. It is bounded by the realpath check in debug_log_sources, and a hard link into the log directory is accepted on every platform anyway.
Verification of d030677The four red checksThree were this branch's fault, one was not. All reproduced locally before anything was changed.
The formatter guard is the clean proof: run with the pinned ruff 0.6.9 it fails on the head as opened, naming those two files and no others, and passes after the fix. CodeQL classifies a local by its name, not by what it holds: The Python 3.13 leg was not this branch. Backend CI on
One fewer failure, and no failure in any debug-log, export or settings test. The only PR-adjacent failures, three in Before and afterOne script, run against both trees with the same seeded log home:
Three defects found by simulationAbout 500 scenarios were written against this branch: 348 backend, 152 cross-platform, plus frontend probes. Each defect below has a regression test confirmed to fail without its fix. A record cut short by the byte allowance was emitted as though it were whole. Reachable rather than theoretical: when
A source whose window was shrunk by the remaining budget was blamed for it, reported as Cross-platformThe worst case I could think of was that One residual is now documented rather than implied.
Browsers and old installsThe diff to Old installs are safe in the way that matters: a backend too old to have the route returns a real 404, because Totals
No model or GPU path is touched, so no GPU checks were run. What this host cannot answerA real Windows or macOS compile of Left for a separate changeThe two sibling debug-log routes also set no cache directive, and |
Conflict was in studio/backend/routes/settings.py, where per-account isolation (#10588) added the three include_router calls at the end of the module and this branch added the export route in the same place. Both kept, with main's includes last where it put them. Not a textual conflict, and the reason this merge needed a person: #10588 also moved /debug/logs and /debug/logs/sources onto _owner_settings_router, which carries _require_installation_owner. Left on the bare router, the export would have been reachable on a shared install by an account that is refused each of those logs individually -- a bundle of every log on the host being easier to get than one file. Moved onto the same router. test_the_export_is_owner_gated_exactly_like_the_routes_it_sits_beside pins it by comparing against the sibling routes rather than by naming a router, so the three cannot drift apart again; confirmed to fail with the route back on the bare router. 251 pass across the five debug-log suites.
The Tauri Linux build caught this and my local run did not: I ran cargo before merging main and not after. DesktopAuthResponse is no longer a struct with an access_token field, it is an enum, so download_logs_to_downloads stopped compiling. The new variant is not a formality. On a shared install desktop auth can legitimately answer LoginRequired instead of returning tokens, and there is no token to spend in that case, so the command stops with a message rather than attempting an unauthenticated download. It is classified as `forbidden` on the TypeScript side, which is the copy that already says a signed-in Studio session is what this needs, so no new locale key is required. The sentinel is matched by its exact text across the language boundary, the way the existing status pattern is. A test reads debug-logs.ts and fails if the two ever drift, since a reworded constant would otherwise silently downgrade the toast to a generic failure. Also marked strip_verbatim_prefix_inner dead_code off Windows: keeping it compiled everywhere is what lets the UNC case be tested here, but the only non-Windows caller is that test, so an ordinary build warned. 537 Rust tests pass, cargo check --all-targets clean with no warning in this file. Frontend 7409/7409, tsc -b and tsc -p tsconfig.test.json clean, i18n:check:strict passes.
Found by re-running the simulation suites against the merged head rather than against the commit they were written for. Marking a size-cut record was right, but reading the flag alone was not: the loop stops as soon as the allowance is spent, so a file whose last byte lands exactly on that boundary never gets the read that would have reported EOF, and its final newline-less record is complete rather than cut. It was being replaced by the marker. The descriptor is what separates the two. Bytes beyond what was consumed mean the record continues into them; none means the file ended there. An fstat that fails takes the side that cannot mislead. The regression test now covers all three positions: an allowance inside the record, an allowance past the end, and an allowance landing exactly on it, which is the case that was wrong. 251 pass across the five debug-log suites. Of the 348 backend simulations, 343 pass and the 5 that fail are DEFECT PROBE tests asserting the behaviour these commits changed, plus one that looks the export route up on the bare router rather than the owner router it now sits on. Of the 152 cross-platform simulations, 143 pass and the 3 that fail are the ones written to document the case-collision bug.
|
@codex security review |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
Post-convergence comment pass. Delete first, shorten second: 346 comment and docstring lines removed against 182 added, so the five files carry 164 fewer lines and say the same things. What went: restatements of the next line, measured numbers that belong in the PR description rather than the source, and multi-paragraph rationales that were one fact plus three sentences of throat-clearing. What stayed: every claim a reader would otherwise get wrong. The Windows O_NOFOLLOW residual, why the tail seek must resync forward rather than stop at the first probe, why a NUL-bearing record is refused rather than replaced, why the collision key is folded with lower() and not casefold(), and why the route sits on the owner router are all still stated, just once each. The two Rust files are deliberately untouched: comment_tools.py has no lexer for Rust, so `check --strict-ext` reports them NOT CHECKED and the AST gate cannot verify a pass over them. An unverifiable comment edit is worth less than the lines it saves. Gate: comment_tools.py check --strip-docstrings --strict-ext, 5/5 code unchanged (comments only). 251 pass across the five debug-log suites, 48 in the export suite alone; frontend 7409/7409 with tsc -b clean; pre-commit is a fixed point.
… real log folder Two review findings, both reproduced against the code before being fixed. The export could never run on a multi-account desktop. `desktop_login` in routes/auth.py returns login_required UNCONDITIONALLY when installation_is_multi_user(), because the desktop secret proves which SHELL owns the backend, not which account is driving it. The command only ever used that minted session, so on the configuration per-account isolation just introduced it failed permanently, for an owner who is signed in and looking at the owner-only tab, with no way to resolve it by signing in again. It now falls back to the caller's own UI session. That grants the webview nothing: the token is the one it already holds, and the command pins host, port and path, so the only thing it can be spent on is this one route on this install's backend. A minted desktop session is still preferred, and the mint is still attempted either way because it is also what resolves the live port. The folder button opened the wrong directory. `open_logs_dir` hard-codes ~/.unsloth/studio while the picker resolves UNSLOTH_STUDIO_HOME and STUDIO_HOME, so on a custom home it opened something unrelated or errored on a path that does not exist. It now opens the parent of the selected log's own realpath, which is the same root the picker read, and falls back to open_logs_dir only when no source is selected yet. That command is untouched; this PR is simply the first caller it has ever had. Tests: the invoke assertion now pins uiToken, so dropping it fails rather than silently reinstating the multi-account dead end; openLogsFolder is covered for a configured POSIX home, a Windows path, and the no-selection fallback. A Rust test reads debug-logs.ts and fails if the tab stops sending the token. 538 Rust tests pass, cargo check --all-targets clean. Frontend 7411/7411, both tsc configs clean, i18n:check:strict passes.
… without a selection Two follow-ups on the previous fix, both reproduced before being changed, plus the cross-platform test failures a real Windows and macOS run turned up. Rust uses the token once and as-is; it cannot retry a 401 by refreshing the way authFetch does. So a multi-account desktop left idle past the access-token lifetime exported with a dead token while holding a perfectly good refresh token. The tab now refreshes before handing it over, and ignores a failed refresh rather than skipping the attempt, since the stored token may still be valid and the backend is the real judge. The folder button still had a wrong branch. Taking the directory from the selected log fixed the common case but not the one where a custom home holds no readable log at all, which is precisely when file logging is off: realpath stays null and the fallback went back to the hard-coded ~/.unsloth/studio. /debug/logs/sources now reports log_root, taken from the first candidate root the walk itself prefers, and the button uses the selected log, then that root, then the old command. The field is additive and optional, so an older client ignores it. From the Windows and macOS runs: - The owner-gating test read `route.path` over `.routes`, which also holds _IncludedRouter entries with no path. It raised on both runners and passed here purely by FastAPI version, so this was a latent break on any upgrade. - The seed helpers wrote with write_text, which translates \n to \r\n on Windows and moved every byte offset the seek and budget tests compute. newline = "" makes those tests mean the same thing on every platform. - The case-collision round trip cannot be BUILT on a case-insensitive volume, since the second write lands on the first file. It now detects that rather than failing, and the unit-level test covers the property everywhere. - Three tests assert POSIX-only premises (mkfifo, a newline in a filename, an undecodable filename). They skip where the premise cannot hold, gated on the capability rather than the platform name, because macOS has every call the surrogate test needs and still refuses the byte sequence. 251 pass across the five backend suites, frontend 7414/7414, both tsc configs clean, i18n:check:strict passes.
|
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Resolve conflicts with main and rescope to the logging changes: - llama-server lines reach the INFO session log when llama.cpp tags them W or E (keyword fallback for builds without level letters) or on readiness, sharing the predicate the 64 MiB tee trim already used, instead of a keyword list. - Open failures warn on the primary spawn path too; a failing tee warns once per attempt and a closed file no longer warns. - Drop troubleshooting_source_ids and the picker markers: Download all logs (unslothai#10719) already collects the session and llama logs together. - Fold the startup context into the existing startup line.
Settings > Logs could only copy the visible tail of one file. Sharing a problem meant collecting the server log and each runner's log by hand, and the desktop app had no way to reach the log folder at all.
One button now packs every log into a ZIP. On desktop it saves straight to the Downloads folder and the toast shows the full path of the file, with a Show in folder action. In a browser it downloads the normal way, into the browser's own downloads folder.
This is a deliberately small version of what #9714 and #10271 set out to do. Most of what those need already exists on
main, so this reuses it instead:require_loopback_urlandstream_url_to_pathfor the desktop transfer,browserDownloadfor the web one,debug_log_sources.list_sourcesfor the allowlist, andredact_log_textfor the masking.open_logs_dirin particular was already a registered Tauri command that opens~/.unsloth/studioand had simply never been called from the UI, so wiring it up needed no Rust at all.What changed
Backend
utils/debug_log_export.py: every log the picker already lists, packed as<family>/<filename>with no host path in the member names, each record through the existingredact_log_text. Sources are opened withO_NOFOLLOW | O_NONBLOCKand the descriptor's device and inode are compared against the pre-open stat, so an entry swapped for a link, a FIFO or another file between the walk and the read is refused rather than followed.GET /api/settings/debug/logs/exportinroutes/settings.py: the sameget_current_subjectplus_require_ui_sessionpair as the two debug log routes above it, so an API key or keyless caller gets 403 exactly as it does for the single file viewer.Desktop
download_logs_to_downloadsinnative_file_dialogs.rsstreams the archive intodirs::download_dir()and returns the real path. It mints its own session inside the command rather than accepting a token over IPC, and rewrites host, port and path before minting, so the webview names the endpoint but never chooses it.open_logs_diris used exactly as it is onmain.Frontend
isTauri. No redesign of the tab.settings.debuggingkeys across all twelve locales.How the archive is bounded
The 10 per family cap in
debug_log_sourcesbounds files, not bytes, and the active session log is never rotated, so it is routinely many GB on its own. Three limits, all of which name what they left out inEXPORT_WARNINGS.txtrather than dropping it silently:Families are taken round robin rather than in list order, so a large server log cannot spend the whole budget before the runner logs are reached. The route also holds a process wide semaphore and answers 429 rather than queueing, because it is a sync
defon the shared 40 thread pool and a second concurrent build would starve every other sync endpoint.Safety properties
Each of these has a regression test that was confirmed to fail without its fix.
redact_log_textis anchored on a key name sitting next to its value, so a read starting in the middle of a record hands out a credential whose key was in the part that got skipped. The seek scans forward to a real newline, bounded by the size taken from the descriptor, and refuses the file if the tail holds no boundary at all. Anaws_secret_access_keyhas no prefix for a shape rule to catch, so that anchor is the only defence it has.errors="replace"keeps a NUL between every character, soHF_TOKEN=hf_...becomesH\x00F\x00_\x00T..., every masking rule stops matching, and the record is copied through with the credential still readable to anyone who opens the archive or runsstringson it. PowerShell redirection writes UTF-16LE by default.EXPORT_WARNINGS.txtcarries neither a host path nor a wall clock. Warnings are built fromtype(exc).__name__anderrnorather thanstr(exc), sinceOSError.__str__appends the filename.Not in this PR
studio/backend/utils/log_redaction.py,debug_log_sources.py,debug_log_reader.py,core/inference/tools.py,routes/auth.pyand theloopback_http.rs,desktop_auth.rsandcommands.rsTauri files are byte identical tomain. That is checked on every test run rather than assumed.Two pre-existing gaps in
log_redaction.pyturned up while testing this and are worth their own change rather than being folded in here:_ANSI_REbacktracks quadratically on an unterminated OSC introducer. 40k such characters take about 15.8 s against 0.005 s for the same length of ordinary text. This affects the live viewer today, not just the export. Sent separately.Verification
studio/backend: 245 pass acrosstest_debug_log_export.pyand the existingtest_debug_log_redaction.py,test_debug_log_routes.py,test_debug_log_sources.pyandtest_debug_log_reader.py. The 203 pre-existing ones pass untouched, which is the point.studio/src-tauri:cargo check --all-targetsclean, 530 tests pass.tests/studio/test_desktop_reliability_frontend_contract.py: 36 pass.studio/frontend:tsc -bandtsc -p tsconfig.test.jsonclean,npm run i18n:check:strictpasses, 7286 tests pass.eslintreports the same four pre-existing errors indebugging-tab.tsxasmain, none on changed lines.ruffclean on the changed Python.Measured end to end on this host: 600 MB of ordinary logs across three families builds in 12.4 s and yields 32 MB kept; a 12 MB log of pathological ANSI content builds in 16.8 s where it takes about 16 minutes without the wall clock limit.
The desktop path was exercised on Linux. macOS and Windows desktop runs are still to be confirmed. No model or GPU paths are touched, so no GPU checks were run.
Screenshots
Two isolated Studio installs (
install.sh --local, separateUNSLOTH_STUDIO_HOME), one at this PR's merge base743471746and one at head0ba8a4bba, driven through the same scene. BEFORE is the merge base rather thanmain, so the pair credits this PR with its own change and nothing else that landed today.Settings > Logs, whole tab
The action area, same clip on both sides
Facts read from the same two servers that were photographed:
Download all logs (.zip)buttonEXPORT_WARNINGS.txtGET /api/settings/debug/logs/exportapplication/zipCache-Controlno-store, no-cache, must-revalidate, privateCopy visible log, the pre-existing "masked in this view" note, the log pane, Location and the Mode pills are on both halves unchanged.Open logs folderis absent from both halves and that is correct, not a missed click: it is gated onisTauriand these shots are a browser. On desktop it callsopen_logs_dir, which was already registered inmain.rsonmainand had no call site anywhere in the frontend.