AI Technician: Streaming, recovery, and persistence
I built the AI Technician frontend and backend session services for long-running vehicle diagnostics. I designed streaming recovery and delivered the production upgrade that moved final-result persistence entirely to the backend.
- Problem
- Technicians need to switch investigations while an analysis runs. When they return, they need to see its progress or read the answer without submitting the same analysis again.
- Decision
- I separated execution from the HTTP stream, gave the backend responsibility for saving results, and built a client that reattaches to existing work.
- Result
- The backend saves the answer even if the browser misses the final update. Returning users can reattach to a live run or read the answer in conversation history.
- Context
- Sonatus - AI Technician
- Period
- 2025–2026
- My focus & role
- Frontend architecture, streaming recovery, backend session services, production persistence upgrade, and administrative tooling.
- Technology
- React · TypeScript · SSE · FastAPI
Provisional output A
Generated output A
- Persistence owner
- Backend
- Stored result
- None
The stream is connected. The browser has provisional output A.
Failure scenarios
Event log
No events recorded.
Context and ownership
Long-running work in a conversation interface
AI Technician presented analysis through a conversation interface, with progress, uploaded files, partial output, and completed responses. Users could switch conversations or navigate away before an answer finished. The product needed to distinguish an interrupted connection from an interrupted job.
I also built the administrative views and the platform endpoints that let operators inspect conversations and feedback. The conversation indicators show how I surfaced background activity in the chat list.
A follow-up in the conversation workspace
Adapted test screenshot
Streaming architecture
The backend runs and saves the analysis
I ran the analysis graph as an asynchronous Python task and kept accumulated progress and output on the server session. The HTTP response subscribes to that session. Closing the response releases its subscriber while the task can continue running and save its answer through the platform.
The browser sends user commands and renders provisional output. I implemented a streaming POST to start work and a separate GET to attach to an existing session. Both use server-sent events (SSE) to send diagnostic steps and partial answers to the conversation interface.
Who handles a run from start to saved answer?
Two frames from a diagnostic replay
Frames from a test replay
One session client for start, attach, status, and stop
I consolidated URL construction, request headers, event handling, and polling in a shared session client. It tracks the answer-end event so a premature stream close can enter recovery. The earlier transport retry could send another start POST, replace the analysis already in progress, and make the user wait for a new run.
Attach-first recovery
Recover live progress before starting new work
I designed reconnection to try attaching to the existing work first. A conversation groups the history, a user turn requests an analysis, and a run is the execution that produces its answer. The attach request uses the conversation ID to find the existing server session.
- Replace stale progress. Each attach attempt clears the client’s partial state. The server replays a snapshot with the available title, diagnostic steps, and answer so far. The client applies those events through the same reducer as ordinary streaming.
- Follow live events. The replay stream marks the switch from the snapshot to live events, which the server relays through a bounded queue for each subscriber. In the model above, a browser that left with AB replaces it with ABC on return, then adds D as it arrives.
- Read the saved answer. The client refreshes conversation history and renders the answer when it is available.
If the client cannot attach, it checks session status and refreshes conversation history within a bounded wait. When those checks find neither live work nor a saved answer, the conversation can show an interruption and keep the original prompt and attachment visible for a retry. Submitting the question again starts a new analysis.
Backend finalization
Confirm the save through conversation history
I made the backend responsible for saving the final answer through the platform. The write happens whether the original browser is still connected, another client has attached, or nobody is viewing the conversation. A user who misses the final update can reopen the conversation and retrieve the saved answer.
Generation can finish while the save is still pending. When a stream closes or a session reports itself inactive, a history read can confirm whether the answer is available to reopen and review.
Recover a saved answer after a missed notification
Concept model - synthetic data- Generation finishesThe backend has the full answer. History has no saved result yet.
- The first save failsThe result remains uncommitted.
- Finalization succeedsThe answer is stored. The browser misses the completion event.
- The browser refreshes historyThe client retrieves the canonical answer from history.
The stream is connected. The browser has provisional output A.
How I traced the lost follow-up answer
During an earlier iteration, letting both the browser and backend save produced duplicate replies. The next design gave the original browser the write while it appeared attached. The backend took over after detach.
I traced a lost follow-up to a title keepalive that held the stream open after the chat page had gone. The backend still expected that page to save. I limited the keepalive to turns still waiting for a title, then shipped backend-owned finalization so saving was independent of disconnect detection.
Failure and stop semantics
Distinguish leaving a chat from stopping an analysis
Leaving the page ends the browser’s subscription. An explicit Stop request goes through the session client to the backend. A stored stop notice records the user’s action. The backend determines the execution outcome, including when a Stop request arrives just as the analysis finishes.
I bounded status polling and paused it in hidden tabs so the interface could leave stale working states without polling indefinitely. Reattachment can restore progress while the backend still has the live session. An answer already saved in conversation history remains readable after that session is gone.
An interrupted request with a file attached
Adapted interface capture
Administrative workflows
Give operators conversation and feedback context
I built administrative views for users, conversation lists, conversation detail, and feedback. The platform endpoints and response schemas supplied these views so support, product, and engineering teams could review records through an application interface.
I used paginated lists to help reviewers find a conversation, then loaded its messages and feedback in a detail view. A reviewer can read the original question and the assistant’s reply together with the feedback. User creation was a separate action.
Conversation and feedback review
Concept interface - synthetic data- Conversation
- Demo A
- Response excerpt
- A synthetic response excerpt for reviewing feedback in conversation context.
- Associated feedback
- The response needs more context.
The frontend used a feature gate and admin-role guard, while platform endpoints applied server-side access checks. Regular application records were scoped to users; a project grouped a user’s work rather than acting as an organization-wide tenant boundary. Keeping these concepts distinct was important when adding operational access.
Project artifacts
To tell users when a background answer was ready, I used saved replies in the sidebar’s unread check. A status probe could prompt a history refresh. The green dot appeared when the latest saved reply differed from the last one viewed in that browser and cleared when the user opened the conversation.
For the experience inside a conversation, see the multi-turn workspace, step-by-step response replay, and interrupted request with an attachment.
Activity in the conversation list
Paired test captures
Delivery and verification
Users can leave an analysis running, come back to retained progress, or find the saved answer after completion. The same stored conversation is available to operators reviewing feedback in the administrative views I built.
I tested attachment to a live session, replay of accumulated events, and the platform endpoint that writes the answer. To verify the keepalive fix on a local stack, I switched chats during a follow-up, let the analysis finish, and reopened the conversation to find the full answer in history.
Based on my work at Sonatus. The interactive models use synthetic records. Project artifacts show original test-interface states.