Files
LocalAI/core/http/react-ui/e2e/traces.spec.js
LocalAI [bot] 1198d10b58 fix(traces): cap backend trace Data to keep admin UI responsive (#9960)
* fix(traces): cap backend trace Data field so the admin UI stays responsive

The previous fix (#9946) capped API trace bodies but missed backend traces,
which carry the same blast radius:

  - LLM backend traces store the full chat messages JSON, full response, and
    full streaming deltas. Every agent-pool reasoning step ships the full
    RAG-augmented history (50-500 KiB per trace, often 100+ traces queued).
  - TTS / audio_transform / transcript traces embed a 30s audio snippet as
    base64, around 1.3 MiB per trace.

Both blow the /api/backend-traces JSON past tens of MiB. The admin Traces
page then keeps re-downloading and re-parsing the buffer faster than the
5s auto-refresh and stays in the loading state forever, the same symptom
the API-side fix addressed.

Apply two complementary caps, both honoring LOCALAI_TRACING_MAX_BODY_BYTES:

Option A (safety net in core/trace): RecordBackendTrace walks the Data map
recursively and replaces any string value larger than the cap with
"<truncated: N bytes>". Catches anything a future producer forgets.

Option B (head-preserving at the producer):
  - core/backend/llm.go: TruncateToBytes on messages, response, and
    chat_deltas content/reasoning_content so the leading content stays
    readable in the UI.
  - core/trace/audio_snippet.go: omit audio_wav_base64 when the encoded
    blob would exceed the cap (truncated base64 is undecodable). The
    quality metrics still ship and the UI's WaveformPlayer simply skips
    when the field is absent.

TruncateToBytes is bounded to <= maxBytes so Option A leaves the producer's
head-preserving output alone instead of replacing it with the bare marker.

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Assisted-by: Claude:claude-opus-4-7

* fix(react-ui): expose tracing_max_body_bytes in Settings and Traces panels

The setting was already plumbed through env (LOCALAI_TRACING_MAX_BODY_BYTES),
CLI flag, and the runtime_settings.json GET/PUT schema, but neither the main
Settings page nor the inline Traces panel offered an input for it. Admins
hitting the "Traces UI stuck loading" symptom had to know to set an env var
or PUT raw JSON to /api/settings to dial the cap.

Add a "Max Body Bytes" row next to "Max Items" in both places. Same input
type, same disabled-when-tracing-off semantics, placeholder shows the 65536
default so users see what they're inheriting.

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Assisted-by: Claude:claude-opus-4-7

* test(react-ui): disambiguate Max Items locator after adding Max Body Bytes

The Tracing settings panel now has two number inputs. The previous spec
matched 'input[type="number"]' which became ambiguous and triggered a
Playwright strict-mode violation in CI. Switch to getByPlaceholder('100')
for Max Items and add a parallel spec for the new Max Body Bytes field
using getByPlaceholder('65536').

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Assisted-by: Claude:claude-opus-4-7

---------

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Co-authored-by: Ettore Di Giacinto <mudler@localai.io>
2026-05-23 14:50:40 +02:00

109 lines
4.0 KiB
JavaScript

import { test, expect } from '@playwright/test'
test.describe('Traces Settings', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/app/traces')
// Wait for settings panel to load
await expect(page.locator('text=Tracing is')).toBeVisible({ timeout: 10_000 })
})
test('settings panel is visible on page load', async ({ page }) => {
await expect(page.locator('text=Tracing is')).toBeVisible()
})
test('expand and collapse settings', async ({ page }) => {
// The test server starts with tracing enabled, so the panel starts collapsed
const settingsHeader = page.locator('button', { hasText: 'Tracing is' })
// Click to expand
await settingsHeader.click()
await expect(page.locator('text=Enable Tracing')).toBeVisible()
// Click to collapse
await settingsHeader.click()
await expect(page.locator('text=Enable Tracing')).not.toBeVisible()
})
test('toggle tracing on and off', async ({ page }) => {
// Expand settings
const settingsHeader = page.locator('button', { hasText: 'Tracing is' })
await settingsHeader.click()
await expect(page.locator('text=Enable Tracing')).toBeVisible()
// The Toggle component is a <label> wrapping a hidden checkbox.
// Use .first() on the checkbox to target the Enable Tracing toggle
// (it appears before the Enable Backend Logging toggle in the DOM).
const checkbox = page.locator('input[type="checkbox"]').first()
// Initially enabled (server starts with tracing on)
await expect(checkbox).toBeChecked()
// Click the label (parent) to toggle off
await checkbox.locator('..').click()
await expect(checkbox).not.toBeChecked()
// Click again to re-enable
await checkbox.locator('..').click()
await expect(checkbox).toBeChecked()
})
test('set max items value', async ({ page }) => {
// Expand settings
await page.locator('button', { hasText: 'Tracing is' }).click()
await expect(page.locator('text=Enable Tracing')).toBeVisible()
// The Tracing panel has two numeric inputs (Max Items and Max Body Bytes).
// Disambiguate by placeholder so adding a third field later doesn't break this.
const maxItemsInput = page.getByPlaceholder('100')
await maxItemsInput.fill('500')
await expect(maxItemsInput).toHaveValue('500')
})
test('set max body bytes value', async ({ page }) => {
await page.locator('button', { hasText: 'Tracing is' }).click()
await expect(page.locator('text=Enable Tracing')).toBeVisible()
const maxBodyBytesInput = page.getByPlaceholder('65536')
await maxBodyBytesInput.fill('16384')
await expect(maxBodyBytesInput).toHaveValue('16384')
})
test('save shows toast', async ({ page }) => {
// Expand settings
await page.locator('button', { hasText: 'Tracing is' }).click()
// Click save
await page.locator('button', { hasText: 'Save' }).click()
// Verify toast appears
await expect(page.locator('text=Tracing settings saved')).toBeVisible({ timeout: 5_000 })
})
test('panel collapses after save when tracing is enabled', async ({ page }) => {
// Expand settings
await page.locator('button', { hasText: 'Tracing is' }).click()
await expect(page.locator('text=Enable Tracing')).toBeVisible()
// Tracing is already enabled; save
await page.locator('button', { hasText: 'Save' }).click()
// Panel should collapse
await expect(page.locator('text=Enable Tracing')).not.toBeVisible()
})
test('panel stays expanded after save when tracing is off', async ({ page }) => {
// Expand settings
await page.locator('button', { hasText: 'Tracing is' }).click()
await expect(page.locator('text=Enable Tracing')).toBeVisible()
// Toggle tracing off (first checkbox is the Enable Tracing toggle)
await page.locator('input[type="checkbox"]').first().locator('..').click()
// Save
await page.locator('button', { hasText: 'Save' }).click()
// Panel should stay expanded since tracing is now disabled
await expect(page.locator('text=Enable Tracing')).toBeVisible()
})
})