# Todo 19 Latency-Oriented Polish Plan **Status:** done ## Goal Reduce perceived reply wait time with earlier event visibility and clearer frontend waiting feedback. ## Design - Emit `event` output as soon as ChatAgent streaming produces an event, instead of waiting for the full model stream to finish. - Keep EventAgent execution after the assistant turn is finalized so history remains provider-compatible. - Show the user's submitted message immediately, disable the run button while streaming, and update elapsed time while waiting for the first token. - Add lightweight WebSocket logger entries for backend session boundaries. ## Files - Modify: `src/agent_lab/application/runtime.py` - Modify: `src/agent_lab/presentation/web.py` - Modify: `src/agent_lab/presentation/static/index.html` - Modify: `src/agent_lab/presentation/static/app.js` - Modify: `src/agent_lab/presentation/static/styles.css` - Modify: `tests/test_debug_runtime.py` - Modify: `tests/test_websocket_api.py` - Modify: `docs/plans/todos.md` ## Verification - Runtime test proves event messages reach the output queue before the ChatAgent stream is released. - WebSocket test proves backend logger records session lifecycle events. - Static UI tests prove immediate user echo, waiting state, disabled run button, and live elapsed timer hooks. - Full suite passes with `uv run pytest`. ## Result - Runtime now emits `event` output immediately when the ChatAgent stream detects an event. - WebSocket service logs accepted, validated, terminal, rejected, failed, disconnected, and closed lifecycle states. - Frontend now echoes the submitted user message immediately, disables Run while active, shows "Waiting for first token", and keeps elapsed time moving before the first token. - Review follow-up: elapsed no longer freezes when an event-only first round emits `round_stats` before the first assistant token. - Tools management is moved to the top of the sidebar so it is visible in the first viewport. - Verified with focused tests, `uv run pytest` (`49 passed`), and local browser checks at `http://127.0.0.1:8001`.