Repository navigation
studio: add download all logs and open log folder to the logs tab - #10271
mahiatlinux wants to merge 20 commits into
Conversation
Squashed from unslothai#9714 by imagineer99, rebased onto main. Settings > Logs gains an authenticated export of every Studio log as one zip, an "Open logs folder" action on desktop, and a flatter layout with the themed Select in place of the native dropdown. Backend: GET /api/settings/debug/logs/export walks the viewer's own allowlist past the picker's per-family window, opens each file by descriptor and checks its device and inode against the enumeration, and copies it through StreamingLogRedactor, which masks credentials that continue onto later lines (YAML block scalars, folded cookie headers, quoted values, PEM blocks) without holding the file in memory. Oversized newline-free records are omitted whole, rotated or replaced files are listed in EXPORT_WARNINGS.txt, member names never carry the host path, and the archive spills to disk past 8 MiB. Browser exports are capped at 256 MB of source; desktop exports have no cap. Desktop: save_native_file_from_url streams the authenticated loopback response straight to the chosen file with an access-only desktop token, rebasing the URL onto the live backend port, and allows the archive's slow first chunk while still timing out headers and later reads. open_logs_dir opens the selected log's directory, falling back to the studio root. The credential environment-name classifier moves to utils/secret_env.py so the sandbox and the exporter share one inventory.
Every masking rule needs one of a small set of fragments (a key word such as token, secret or auth, a known credential prefix, a URL, PEM armor, an ANSI introducer). A line without any is returned before the regex passes, which takes redact_log_text on 100k structured request lines from 17.3 s to 4.7 s and StreamingLogRedactor from 22.5 s to 4.7 s, so the live viewer's one-second poll and a large export both stay cheap. The streaming redactor only takes the shortcut when no earlier record left a value open. Two over-redactions from the shared env classifier are reverted for log text: PWD (the shell's working directory, unlike the odbc Pwd= field) and location variables such as private_key_path, secret_sauce_path or HF_TOKEN_PATH, whose value is a file name rather than the secret in it. The sandbox classifier is unchanged.
591d1af to
8ecc78d
Compare
|
@codex review |
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. |
--token=<value> and --token="<value>" went through unmasked because the flag rules only accepted whitespace before the value, while the generic key/value rules leave the bare token key alone on purpose. The three flag rules now take "=" as well; --token-id 128009 is still untouched. The PWD exemption from the previous commit applied to every uppercase PWD, so an ODBC connection string such as UID=alice;PWD=hunter2 kept its password. PWD is now exempt only when its value starts with a path root, which is what the shell's working directory holds and a password does not.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 52ddcc4203
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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 review |
…hable A "credential" or "credentials" key with a scalar value went through unmasked. It is now masked in quoted and plain form, while a mapping under credentials: keeps its field names so the per-field rules handle them one by one, which the private key and YAML block cases rely on. The Open logs folder button was disabled whenever no log source existed, which made the native command's studio-root fallback unreachable in exactly the no-log case. It is now disabled only while a request is in flight and passes a null path when nothing is selected.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 00b45070fe
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
…crets A TOML triple-quoted value such as password = """opaqueSecret123""" was read by the quoted rule as an empty value, which printed a mask and left the secret after it. A triple-quote rule runs first and the ordinary quoted rules step over a triple quote. X-Amz-Security-Token joins the secret keys, so the header form of the AWS session credential is masked like the query parameter already was. The PWD exemption now also requires a standalone assignment (line start or whitespace before it), so UID=alice;PWD=/hunter2 masks a path-shaped ODBC password while export PWD=/home/dan stays readable. The quote scanner for an omitted oversized record accepts --flag=" as well as --flag ", matching the flag rules.
|
@codex review |
password = r"..." was read as the plain value "r": the python prefix
class now covers raw and unicode literals as well as bytes.
A logged argv such as ['llama-server', '--api-key', '...'] and an env
dump as tuples such as [('OPENAI_API_KEY', '...')] went through unmasked.
The quoted pair rule now accepts --flag keys, and a second rule applies
the env-name classifier to a pair at the start of a tuple or list, where
a json object's value and next key cannot be mistaken for one.
|
@codex review |
YAML writes an apostrophe inside a single-quoted scalar as two quotes, so password: 'it''s-correct-horse-battery' was closed at the first pair and the rest of the value printed after the mask. A doubled quote is now part of the value; an empty value such as password="" still masks as before.
|
@codex review |
|
You have reached your Codex usage limits for security reviews. Please try again later. |
|
@codex review |
|
You have reached your Codex usage limits for security reviews. Please try again later. |
|
You have reached your Codex usage limits for security reviews. Please try again later. |
|
@codex review |
|
You have reached your Codex usage limits for security reviews. Please try again later. |
|
You have reached your Codex usage limits for security reviews. Please try again later. |
|
@codex review |
|
You have reached your Codex usage limits for security reviews. Please try again later. |
|
You have reached your Codex usage limits for security reviews. Please try again later. |
|
Confirmed the oversized-append finding and fixed it in 2c62588. Polling now reads pending bytes in order within the existing 512 KiB budget, using All 24 focused checks pass, including the reported PEM case, YAML and quoted continuations, opener boundaries, oversized records, idle polls, cursor replay, and bounded reads. Ruff and |
|
@codex review |
|
You have reached your Codex usage limits for security reviews. Please try again later. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2c62588fbc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
| r"[a-z][a-z0-9]*(?:api[-_]?key|access[-_]?key|access[-_]?token|auth[-_]?token|" | ||
| r"bearer[-_]?token|client[-_]?secret|private[-_]?key(?:[-_]?data)?|" | ||
| r"refresh[-_]?token|session[-_]?token|(?:secret|signing|encryption|ssh)[-_]?key)" |
There was a problem hiding this comment.
Mask camelCase password-suffix fields
Fresh evidence beyond the earlier camelCase fix is that structured fields such as {"dbPassword":"opaqueCredential123456"} and {"smtpPassphrase":"opaqueCredential123456"} still pass through redact_log_text unchanged. _KEY_START cannot match Password or Passphrase after an alphanumeric prefix, while this provider-prefixed suffix branch omits both alternatives, so common JSON configuration dumps can expose credentials in the viewer and exported support ZIP; include these password suffixes in the normalized/prefixed-key matching.
Useful? React with 👍 / 👎.
| base = _safe_text(Path(source.label).name) or "log.txt" | ||
| family = _safe_text(source.family) | ||
| candidate = f"{family}/{base}" |
There was a problem hiding this comment.
Sanitize Windows separators in ZIP member names
When an export is created on POSIX and a matching log filename contains backslashes, Path(...).name treats them as ordinary characters and places them unchanged in the archive. For example, an allowed filename such as server-x\..\..\payload.log produces the member server/server-x\..\..\payload.log; a Windows extractor that interprets backslashes as separators can normalize this outside the extraction root. Replace or reject both platform separator forms and traversal components before constructing the member name.
Useful? React with 👍 / 👎.
| + r")?(?P<quote>[\"'])(?P<quoted>" | ||
| + _QUOTED_VALUE | ||
| + r")(?P=quote)(?P<suffix>" | ||
| + _SHELL_WORD_SUFFIX | ||
| + r")|(?P<val>(?:\\[^\r\n]|[^\s\\])+))" |
There was a problem hiding this comment.
Consume PowerShell-escaped quoted secret values
When a Windows diagnostic serializes a PowerShell command using backtick-escaped quotes, these branches do not recognize the backtick as part of the quote delimiter and the plain-value fallback stops at the first space. For example, PASSWORD=\"correct horse battery`"becomesPASSWORD= horse battery`"`, exposing most of the credential in both the viewer and support ZIP; recognize PowerShell's escaped quote form and consume through its matching close before applying the unquoted fallback.
Useful? React with 👍 / 👎.
A provider-prefixed camelCase key such as dbPassword or smtpPassphrase missed every key rule, since the bare "password" alternative needs a word boundary and the prefixed branch only listed key and token suffixes. PowerShell logs a quote inside a -Command string as `", so a value written that way was cut at its first space and the tail leaked. The quoted rules now take the escaped pair as the delimiter and the plain-value rules leave it to them, or they would mask the backtick alone. The pre-scan gate had no fragment for a bare "Bearer <token>" line, so the scheme rule never ran on one. "bearer" is now a trigger. A zip member name was the last component under the host's own separator, so a POSIX filename holding backslashes reached a Windows extractor as a traversal. The name is now the last component under either separator, and an empty or dot-only name falls back to log.txt.
|
I went and built the export half on its own to see what it actually costs, and opened it as #10719. It comes to +2377/-20, against +3771/-278 here, and it leaves That is the split I was asking for twice, so this is what I meant by it rather than another round of review comments. Two things I owe you, because building it changed my mind on part of this. The redaction work is not the padding I took it for. Three things I confirmed by running them, all of which are real on
So I withdraw "this is too much work for the feature" as applied to the redactor. It should still land on its own, but on its own merits and with its own tests, not as a dependency of a download button. The In streaming mode the gate is per record, so a header dump split across lines leaks. No test catches it: every Everything else I threw at that gate passed, for the record: On the state of this branch: it is 13 commits behind Where I would like to land this: take #10719 for the button, and reshape this one into the redactor change alone, with Thanks for carrying this forward from #9714 and for the amount of measurement you put into it. The follow-up work on cost and reach is the part I want to keep. |
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.
This PR carries the work from #9714 by @Imagineer99, squashed and rebased onto current
mainwith the author preserved on the commit, plus follow-up fixes that make redaction cheap enough for the live viewer, preserve file paths, and carry multiline masking across viewer polls. Measured against a minimal version of the same feature, #9714 was the better implementation on every axis except the cost and reach of its masking, and both of those are addressed by the follow-up rather than by dropping the work.What changed
Backend
GET /api/settings/debug/logs/exportinroutes/settings.pyandutils/debug_log_export.py: every log on disk, packed into one zip as<family>/<filename>with no host path in the member names. The walk is the viewer's own allowlist (debug_log_sources.list_sources, now with a per-family cap that the export lifts so older runner attempts outside the picker's window of ten are included). Each file is opened by descriptor withO_NOFOLLOWand its device and inode compared with what the walk enumerated, so a symlink or another file dropped in its place between the walk and the read is refused; a file that rotated or shrank meanwhile is named inEXPORT_WARNINGS.txtinstead of failing the bundle. The archive spills to disk past 8 MiB and is streamed, so a long session log is never held in memory. Browser exports refuse more than 256 MB of source with a 413 that points at the desktop app; desktop exports have no cap.utils/log_redaction.py:StreamingLogRedactormasks credentials that continue onto later lines (YAML block scalars and plain continuations, folded cookie headers, quoted values that span records, PEM private key blocks,--flagvalues continued with a backslash) and keeps that state across an oversized newline-free record, which is omitted whole so a secret can never be split across the redaction boundary. The single-line rules gain shared-access, account and private keys, session tokens, passphrases, Python byte strings, quoted header pairs, semicolon-delimited values and every URL userinfo form. Python string prefixes in environment assignments are consumed before masking the complete quoted value. YAML block markers are preserved so uppercase credential keys continue masking every line of their values.utils/debug_log_reader.py: the live viewer carriesStreamingLogRedactorstate across physical records and polls. Large appends are processed in order within the existing 512 KiB read budget, withmore_pendingreporting the backlog. A record larger than one page is omitted with a marker while bounded scans preserve its continuation state. Independent cursor snapshots retain structural state; partial final records resume from their original offset and preceding state. Initial tail reads keep their existing byte limit.secret_key,signing_key,encryption_key,ssh_key) and their camelCase variants are masked. URL userinfo matching respects quoted field boundaries while retaining masking for punctuation inside credentials. Semicolon-delimited connection strings preserve multiword fields such asData SourceandInitial Catalog, including after uppercase environment-style assignments.utils/secret_env.py: the credential environment-name classifier the tool sandbox used privately is now shared with the exporter, so the two inventories cannot drift.redact_log_textgoes from 17.3 s to 4.7 s andStreamingLogRedactorfrom 22.5 s to 4.7 s, which matters because the viewer polls once a second.PWD(the shell's working directory, unlike the ODBCPwd=field) and location variables such asPRIVATE_KEY_PATH,HF_TOKEN_PATHorsecret_sauce_pathare no longer masked in log text; their value is a file name, not the secret in it. The sandbox classifier is unchanged.Desktop
src-tauri/src/native_file_dialogs.rs:save_native_file_from_urlstreams the authenticated loopback response straight to the chosen file instead of crossing the webview IPC as one blob. It requests an access-only desktop token (desktop-login?access_only=true, no unused refresh-token row), rebases the URL onto the live backend port, and allows the archive's slow first chunk while still timing out headers and later reads.src-tauri/src/commands.rs:open_logs_dirwas registered but never called from the UI. It now opens the directory of the selected log, falling back to the studio root that holds every log family.Frontend
features/settings/tabs/debugging-tab.tsx: the section reads as one flat workflow. The selected file is labelled "Log to preview" and picked through the themedSelectthe other tabs use (the native<select>stayed light in dark mode), the Location line sits under it, and an "All logs" group holds "Export all logs (.zip)" and, on desktop only, "Open logs folder", with the note that credentials are masked in exported files. The Refresh header carries the mode pills and shows "Refresh now" only in manual mode.settings.debuggingkeys in all twelve locales.Verification
Two isolated Studio installs (
install.sh --local, separateUNSLOTH_STUDIO_HOME) at the merge base8e26d2c2band at this head, driven through the same Playwright scene: Settings > Logs, the whole tab in light and dark, the log file section at 2x, then the picker opened in dark.Log file section, light theme, 2x
Log file section, dark theme, 2x
Log file picker opened, dark theme
Settings > Logs, light
Settings > Logs, dark
Facts read from the same servers that were photographed:
Copy visible logunder the paneExport all logs (.zip)in the "All logs" groupGET /api/settings/debug/logs/export?browser=trueserver/(one per launch of that home)unsloth-logs-20260904-010939.zipholding the same logsselectbutton(Radix combobox)The pane, "Copy visible log" and the mode pills are on both sides. "Open logs folder" is desktop-only, so it does not appear in the browser screenshots; on desktop it opens the selected log's directory in the file manager.
studio/backend:test_debug_log_redaction.py,test_debug_log_routes.py,test_debug_log_sources.py,test_debug_log_reader.py,test_desktop_auth.py: 551/551 pass. Coverage includes complete masking of prefixed Python strings, preservation of adjacent fields, idempotence, and uppercase YAML credential keys across multiple block styles. Existing path-preservation and streaming-redaction tests also passtests/test_bypass_permissions.py: 117/117 pass with the shared classifiertsc -bandtsc -p tsconfig.test.jsonpass,npm run i18n:check:strictpassescargo checkonsrc-tauricompiles; the 69 Tauri unit tests incommands,native_file_dialogsanddesktop_authpasseslintreports the same four pre-existing errors indebugging-tab.tsxonmainand on this branch; none are in the changed linesThe desktop save and folder actions were exercised on Windows in #9714; macOS and Linux desktop runs are still to be confirmed. No model or GPU paths are touched, so no GPU checks were run.
Viewer follow-up (
cfc04ca4a): 17 focused reader and route checks pass, covering multiline credentials across polls, cursor replay and eviction, partial writes, long credentials, response limits, and bounded reads. Ruff andgit diff --checkpass for the changed files. The broader results above are from earlier validation; full suites were not rerun and CI was not awaited for this follow-up.Append paging fix (
2c62588fb): 24 focused reader and route checks pass, covering large PEM/YAML/quoted credentials, page boundaries, partial initial records, oversized-record continuation state, idle polls, replay, truncation, and bounded reads. Ruff andgit diff --checkpass. The broader results above are from earlier validation; no full suites were rerun and CI was not awaited for this change.