Skip to content

Dashboard: ANSI color in live logs + fix run-detail loading flash#169

Open
kevinlu1248 wants to merge 1 commit into
modal-projects:mainfrom
kevinlu1248:dashboard-ansi-logs-and-loading-fix
Open

Dashboard: ANSI color in live logs + fix run-detail loading flash#169
kevinlu1248 wants to merge 1 commit into
modal-projects:mainfrom
kevinlu1248:dashboard-ansi-logs-and-loading-fix

Conversation

@kevinlu1248

Copy link
Copy Markdown
Contributor

Summary

Three fixes to the training-gym dashboard's live log streaming on the run detail page.

1. ANSI color rendering in live logs

Modal/Ray/Megatron logs carry raw ANSI SGR codes, and the backend streams lines verbatim — so the dashboard rendered them as escaped plain text (e.g. [32mINFO[0m).

  • New dashboards/frontend/src/lib/ansi.js parses a line into [{text, style}] segments. Supports 16-color fg/bg, bright variants, 256-color (38;5;n), truecolor (38;2;r;g;b), and bold/dim/italic/underline/inverse. Non-SGR sequences (cursor moves, screen clears) and stray control chars are dropped.
  • Parsing happens once at ingestion so the render path stays cheap; segments render as styled <span>s.

2. "Loading run …" flash

run was derived live from the parent's allRuns, which is replaced wholesale every 5s by the auto-refresh. A single poll missing this run flipped run to null — flashing the loading state and tearing down the live log stream. Now the last resolved run is latched; it only drops to null when runId itself changes to one not yet loaded.

3. Stream crash hardening

Wrapped new EventSource(url) in try/catch so a constructor throw surfaces as an error state instead of killing the effect/component. The latch above also stops the unmount/remount thrash that reset the stream mid-flight.

Testing

  • npm run build passes (only pre-existing unused-CSS warnings, unrelated).
  • Unit-tested the parser against plain, 16-color, bold+color, 256-color, truecolor, and cursor/clear sequences.

🤖 Generated with Claude Code

Live training logs from Modal/Ray/Megatron carry raw ANSI SGR codes. The
backend streams lines verbatim, so the dashboard rendered them as escaped
plain text (e.g. "[32mINFO[0m"). Add a small ANSI parser (16-color, bright,
256-color, truecolor, bold/dim/italic/underline/inverse) that converts each
line into styled segments at ingestion, and render those segments as spans.
Non-SGR sequences and stray control chars are dropped.

Also fix two log-stream issues on the run detail page:
- "Loading run …" flash: `run` was derived live from the parent's allRuns,
  which is replaced wholesale every 5s. A poll missing this run flipped it to
  null, flashing the loading state and tearing down the live stream. Latch the
  last resolved run; only drop to null when runId itself changes.
- Wrap EventSource construction in try/catch so a constructor throw surfaces
  as an error state instead of killing the effect.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant