Skip to content

telemetry: mirror every UI toast to the logger at DEBUG (issue #194) - #205

Merged
falbany merged 2 commits into
mainfrom
feat/194-toast-debug-logging
Nov 22, 2026
Merged

falbany merged 2 commits into
mainfrom
feat/194-toast-debug-logging

Conversation

@falbany

@falbany falbany commented Nov 22, 2026

Copy link
Copy Markdown
Owner

Closes #194.

What

UI toasts are now traceable in profiles.log through one structured telemetry event:

TOAST source=server kind=config_handoff applied=true msg="Configuration 'X' applied by a new ProFiles launch"
TOAST source=web kind=error msg="Failed to reload configuration: ..."

The leading TOAST token makes the records first-class in the Log Viewer's event filter.

Phase 1 — server choke point

  • New events.toast() emitter (core/telemetry/events.py), house style (logger first arg, lazy %-args, _quote/_bool parts).
  • ServerState.record_external_event emits it at DEBUG after buffering — one choke point covering every current and future producer (odoc applier, instance handoff route) with zero call-site changes. Signature unchanged.

Phase 2 — frontend mirror

  • POST /api/logs/client (server/routes/logs.py): Pydantic body (message 1–500 chars, kind info|error), logs TOAST source=web at DEBUG. Logging only — it never buffers an external event, so there is no toast feedback loop (covered by a dedicated test and verified live: /api/notifications stays empty after a client-log POST).
  • postClientLog() (web/src/api/client.ts): the codebase's first deliberately error-swallowing call — fire-and-forget, failures silent, per the issue's "logging must never break the UI" guard.
  • showToast (web/src/hooks/useToast.ts) relays every toast unless suppressed. Server-originated toasts (useExternalEvents) pass { mirror: false } — the server already logged those at Phase 1; relaying would duplicate the record. The new exported ShowToast type documents the 3-param signature; existing 2-param deps-bag declarations remain valid.

Visibility note (from the issue's design note)

DEBUG by design ("nice to have, zero noise"): these records reach profiles.log when the config sets verbose: DEBUG. At the default INFO the log is unchanged (asserted by a regression test).

Incidental

  • New tests/server/test_state.py fills the 1:1 test-tree gap for server/state.py documented in tests/AGENTS.md (buffer cap, monotonic ids, external_events_after, telemetry).
  • check-added-large-files now exempts src/profiles/web/dist/: the minified bundle legitimately crossed 1 MB and dist is committed on purpose (src/profiles/web/.gitignore).
  • tests/AGENTS.md + tests/README.md synced with the new test file.

Verification

  • Backend: ruff format --check ✓, ruff check ✓, pylint 9.89/10 ✓, pytest 1588 passed (1 skipped), coverage 87.96% ✓
  • Web: vitest 397 passed ✓, tsc --noEmit clean ✓, dist rebuilt
  • Live smoke (--server-only, verbose: DEBUG): curl POST /api/logs/client → {"status":"ok"}, invalid bodies → 422, and TOAST source=web kind=error msg="smoke toast from curl" confirmed in ~/.profiles/profiles.log

…T /api/logs/client

Phase 1 (issue #194): ServerState.record_external_event — the single
choke point for config-handoff UI events — now mirrors every event to
the logger as a structured TOAST record at DEBUG via the new
events.toast() emitter (source=server kind=... applied=... msg=...).

Phase 2 backend: POST /api/logs/client accepts a frontend toast
(message 1..500 chars, kind info|error) and logs TOAST source=web at
DEBUG. Logging only — never buffers an external event, so no toast
feedback loop.

New tests/server/test_state.py fills the documented 1:1 test-tree gap
for state.py.
…lient

showToast — the single choke point behind all ~70 toast call sites —
now relays each toast (message + kind) to the new fire-and-forget
postClientLog, which the server logs as a DEBUG TOAST source=web
record (issue #194). The call is never awaited and every fetch failure
is swallowed: telemetry must never break the UI.

Server-originated toasts (config handoff via useExternalEvents) pass
{ mirror: false } — the server already logged them at the
record_external_event choke point, so relaying would duplicate the
record. The new exported ShowToast type keeps the 3-param signature
explicit; existing 2-param deps-bag declarations stay valid.

dist/ rebuilt (ships with the package); check-added-large-files now
excludes src/profiles/web/dist/ — the minified bundle legitimately
exceeds 1 MB and dist is committed on purpose. Web: 397 tests pass,
tsc clean.
@falbany
falbany merged commit 9a7d0b4 into main Nov 22, 2026
3 checks passed
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.

telemetry: mirror every UI toast message to the logger at DEBUG — toasts are currently invisible in profiles.log

1 participant