Skip to main content

Module residue

Module residue 

Source
Expand description

Chunk-safe scanner for dialect markup that reached client-visible text.

Normalization is heuristic: detection can miss a dialect, a template can lie, a model can emit markup its spec does not describe. When that happens the raw markup flows to the client as ordinary text — silently. ResidueScanner watches the post-normalization client-visible text for known tool-call markers so the proxy can turn that silent breakage into a logged, counted, dashboard-visible signal (the “dialect drift alarm”).

The scanner never alters the stream — it only observes. A hit means “a human should look at this model’s dialect handling”, not “the proxy will fix it”.

§Marker set

The scan looks for the union of:

  • the active DialectSpec’s own markers, when the model has one — markup surviving its own parser is the clearest drift signal; and
  • KNOWN_RESIDUE_MARKERS, a curated list of tool-call markers from dialects in the wild. This deliberately duplicates a handful of literals from gglib-gguf’s detection pattern tables: core cannot depend on gglib-gguf, the list is small and changes rarely, and a doc cross-reference keeps the two in sight of each other.

§Chunk safety

Like the delimited parser, the scanner sees SSE-sized fragments: a marker may straddle chunk boundaries. ResidueScanner::feed retains the longest tail of the previous chunk that could be a marker prefix (at most max marker length − 1 bytes, cut on a char boundary) and prepends it to the next chunk, so a split marker is still found. The first hit is sticky; scanning short-circuits afterwards.

Structs§

ResidueScanner
Chunk-safe residue scanner. See the module docs.

Constants§

KNOWN_RESIDUE_MARKERS
Tool-call markers from dialects observed in the wild, scanned in addition to the active spec’s own markers.

Functions§

scan_complete
One-shot scan of a complete (non-streaming) text for residue markers.