Skip to content

Stop the GGUF header and the chat detail polls from filling the log - #10040

Merged
danielhanchen merged 3 commits into
mainfrom
fix/studio-log-noise
Aug 31, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
fix/studio-log-noise

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Measurement

Four chat tabs against unsloth/Qwen3.8-27B-GGUF UD-Q4_K_XL, prompts sent together, twenty seconds of a real session:

before after
structured log lines 296 117
GGUF metadata: block 140 (47% of the log) 5, once for the file
Detected remote GGUF repo 7 0 (debug)
GET /api/chat/threads/{id} 25 6
GET /api/chat/threads/{id}/forks 21 1

The GGUF header block

_read_gguf_metadata has ten call sites, and each builds its own throwaway probe via object.__new__ precisely so the live backend's metadata is never clobbered, so nothing is shared between them. One POST /api/inference/estimate-memory walks the header three to five times through _gguf_memory_breakdown, _gguf_runtime_bytes, _gguf_layer_count, _is_embedding_gguf and _classify_diffusion_gguf, and the Load Model panel fires that route on every slider change.

The five lines say the same thing about the same file every time, so only the first read of a given file says them at info and the repeats go to debug. Keyed on (path, size, mtime) rather than name, so a rebuilt or re-downloaded GGUF at the same path is described again, and failing open to "log it" when the file cannot be stat'd, because an unidentifiable read is better said out loud than silently swallowed. detect_reasoning_flags takes the level from its caller.

Detected remote GGUF repo goes to debug for the same reason: from_identifier is re-resolved on every validate, estimate and load, and the load path already announces the model it actually starts.

The chat detail polls

/api/chat/threads/{id} and /api/chat/threads/{id}/forks are driven by the streaming persistence loop, not a timer: measured 0.57s and 0.40s apart aggregated across the four tabs.

Every suppressor set matches a path exactly. That was deliberate, from #7087, so that thread detail and message reads kept their access line while the list polls were suppressed, which is still the right call for a read a user triggers. What changed is that streaming now drives these two on a loop, and a templated path cannot join any existing class.

normalize_poll_path collapses the id segment. It is used for classification and for the de-duplication bucket only; the line that is emitted still names the real thread. They join the existing 10s heartbeat rather than being dropped outright, so detail reads stay visible, which is what #7087 was protecting. One bucket per template, the same choice the liveness group makes: four tabs polling four different threads are asking one question, so budgeting them per id would expect four lines where the design intends one.

Deeper paths are deliberately out of reach of the pattern, so /threads/{id}/messages/{mid} still logs every time.

log_budget

  • policy.classify and policy.bucket_of call the middleware's own normaliser through getattr, so the class is still derived from loggers/handlers.py at run time rather than duplicated, and the harness still works on a revision without it.
  • Both paths are declared in session.py with measured periods, recorded at the replay's 0.5s tick since that is the grain it can actually poll on.
  • BUSY_LINE_ENVELOPE moves 260 to 325. That rise is an accounting change, not a volume regression, and it is worth being explicit about: these two paths sat in the normal class and were in no scenario at all, so the envelope never saw them. Modelled over the busy window unsuppressed they are 675 lines. They now enter at 59.
  • KNOWN_UNCLASSIFIED_POLLS stays empty.
  • STEADY_IDLE_LINE_ENVELOPE is unchanged: these are busy-only.

Tests

Seven new cases in test_logging_middleware.py: the heartbeat, four tabs sharing one bucket, message reads not collapsing, the list path untouched, a failing poll still logging, mutations still logging, and --verbose restoring every line. Six in a new test_gguf_metadata_log_volume.py: first read speaks, repeats do not, a changed file is described again, an unstattable path fails open, the cache is bounded, and demoting the level does not change what is detected.

The last one matters most: this is a logging change, and a capability that quietly disappeared when the line was demoted would be a real regression hiding behind a quieter log.

test_log_budget.py and test_log_rule_parity.py pass. Wider run over -k "log or logging or gguf or metadata or reasoning or inference or llama": 6314 passed, 10 failed. Clean main with the identical selection: 6301 passed, the same 10 failed. The +13 are the new tests; the 10 are pre-existing test_diffusion_*, test_safetensors_reasoning_stream, test_cached_gguf_routes and test_training_progress_callback failures from a local environment mismatch.

Driving four chat tabs against Qwen3.8-27B UD-Q4_K_XL for twenty seconds wrote
296 structured lines. 140 of them, 47%, were one model's capabilities repeated,
and another 46 were two polls saying a generation in progress was still in
progress. The same session now writes 117.

GGUF metadata, 140 lines to 5. Ten call sites reach _read_gguf_metadata, each
through its own throwaway probe so the live backend's state is never clobbered,
so nothing is shared between them: one POST /api/inference/estimate-memory walks
the header three to five times and the Load Model panel fires that route on
every slider change. The facts are identical every time, so only the first read
of a given file says them out loud and the repeats go to debug. Keyed on
(path, size, mtime), so a rebuilt or re-downloaded GGUF is described again, and
failing open when the file cannot be stat'd. detect_reasoning_flags takes the
level from its caller. Detected remote GGUF repo goes to debug for the same
reason: from_identifier is re-resolved on every validate, estimate and load, and
the load path already announces the model it starts.

Chat detail polls, 46 lines to 7. /api/chat/threads/{id} and its /forks sibling
are driven by the streaming persistence loop, measured 0.57s and 0.40s apart
across the four tabs. Every suppressor set matches a path exactly, which #7087
chose deliberately so detail and message reads kept their access line, so a
templated path could not join any class. normalize_poll_path collapses the id
segment for classification and for the de-duplication bucket only; the line that
is emitted still names the real thread. They join the existing 10s heartbeat
rather than being dropped, so detail reads stay visible, which is what #7087 was
protecting. One bucket per template, like the liveness group: four tabs polling
four threads ask one question. Deeper paths are deliberately out of reach, so a
message read still logs every time.

log_budget follows: policy.classify and bucket_of read the middleware's own
normaliser rather than a second copy, both paths are declared in session.py with
measured periods, and BUSY_LINE_ENVELOPE moves 260 to 325. That rise is an
accounting change, not a volume regression. These two paths sat in the normal
class and were in no scenario at all, so the envelope never saw them; modelled
over the busy window unsuppressed they are 675 lines. They now enter at 59.

Errors, mutations and --verbose are unaffected, and there are tests for each.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-08-31T07:08:14.261117Z b59ef80 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3692a26dbe

ℹ️ 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".

Comment on lines +12788 to +12790
first_read = _note_gguf_metadata_read(gguf_path)
level = "info" if first_read else "debug"
log_at = logger.info if first_read else logger.debug

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Apply the dedupe level to diffusion detection

For a diffusion GGUF, the logger.info at lines 12727–12731 executes before log_at is selected, so every header probe still emits the diffusion-detection line at info. Since the estimate-memory path reads the same header several times per request, DiffusionGemma models retain an unbounded repeated GGUF metadata: line; select the level before this check and route that message through the same dedupe decision.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The observation is right: the diffusion line at llama_cpp.py:12727 is emitted about sixty lines before first_read is computed at :12788, so it is not deduped. It stays as it is. self._is_diffusion is assigned at :12724 on every read and is what routes the model to the diffusion runner, so nothing stops being detected and nothing is lost; this is a level preference on one more line, and it is pre-existing behaviour rather than something this PR introduces. The 140 repeated lines this PR was measured against were the capability block, not this one.

# over one 20s session with four chat tabs, this block was 140 of 296 log
# lines, 47% of everything Studio wrote. The facts are identical every time,
# so only the first read of a given file says them out loud.
first_read = _note_gguf_metadata_read(gguf_path)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Key model-sensitive metadata logs by their identifier

When the first reader is a generic probe, the file-only cache can suppress the first accurate capability description. For example, routes/models.py sets _model_identifier = "kv-estimate" before reading a DeepSeek GGUF; detect_reasoning_flags therefore does not recognize its thinking template, but this call marks the file as logged, and the later live load with the real DeepSeek identifier sends its correct reasoning line only to debug. Include the effective model identity in the dedupe decision or avoid marking these placeholder probes as the authoritative first read.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The setup is real: routes/models.py:3908 sets _model_identifier to kv-estimate right before read_gguf_metadata, and the DeepSeek arm of detect_reasoning_flags is the one gated on the identifier rather than the template. It is not a collision hazard though. The key is (abspath, size, mtime_ns), which identifies a file, and every fact in the block (context_length, chat_template length, and all seven flags) is derived from that file's bytes, so two different models cannot share a key and produce different capabilities. More to the point, detection does not depend on the level: at llama_cpp.py:12795-12808 detect_reasoning_flags runs and all seven self. attributes are assigned whatever log_level is, and _supports_reasoning is surfaced to clients rather than being log-only. The demoted line carries nothing that nothing else carries.

@danielhanchen

Copy link
Copy Markdown
Member Author

Confirmed the header block still logs at info on every probe in studio/backend/core/inference/llama_cpp.py, and that the templated thread and forks reads fall outside the exact-match sets from #7087, so they were never covered. Will get this reviewed.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 69a636c8b4

ℹ️ 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".

@danielhanchen
danielhanchen merged commit 256db97 into main Aug 31, 2026
52 checks passed
@danielhanchen
danielhanchen deleted the fix/studio-log-noise branch August 31, 2026 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant