Web realtime updates
The web realtime update system delivers task status and log changes from the server to the browser without a page reload. It combines an authenticated WebSocket connection for server events with a local event bus for actions between browser components.
Realtime delivery model
The browser keeps one shared socket for server-originated changes. The server sends events to the users who can see the related task, and interested views decide whether an event affects their current project or task.
The main flow is:
flowchart LR
A[Task runner changes state] --> B[Server event message]
B --> C[User WebSocket connection]
C --> D[Shared socket listeners]
D --> E[Project views filter the event]
E --> F[Update visible data or reload it]
The socket carries data from the server into the browser. The event bus does not carry these socket messages. It handles local UI requests such as showing a snackbar, opening a task log, or changing navigation state (web/…/event-bus.js• L1-6, web/…/App.vue• L1633-1679).
References: web/…/socket.js• L1-8 api/…/handler.go• L150-193 services/…/TaskRunner.go• L117-140
Browser event bus
The application-wide event bus is a small local message channel for loosely coupled Vue components. A component publishes a named event with $emit, while the application shell or another component listens with $on and removes the listener with $off (web/…/event-bus.js• L26-79).
The bus is best suited to transient UI actions. Current uses include:
| Event role | Example | Browser result |
|---|---|---|
| User feedback | i-snackbar | Shows a success or error message |
| Navigation | i-show-task, i-open-last-project | Opens a task or selects a project |
| Layout control | i-show-drawer, i-nav-mini | Changes the navigation shell |
| Resource changes | i-project, i-user | Refreshes related data and reports the result |
Handlers run in subscription order. A handler error is logged and does not stop later handlers, so one UI reaction does not block the others (web/…/event-bus.js• L4-24).
References: web/…/event-bus.js• L4-24 web/…/App.vue• L1641-1766 web/…/ItemListPageBase.js• L120-140
Socket lifecycle
The shared socket connects to /api/ws only after the application confirms an authenticated user session. Before that point, it uses a no-op socket so components can register listeners without opening an unauthenticated connection (web/…/socket.js• L1-8, web/…/Socket.js• L63-77).
The lifecycle has three important states:
| State | Connection behavior | Event behavior |
|---|---|---|
| Session inactive | Uses the no-op socket or stays stopped | No server events reach the UI |
| Session active | Opens the real WebSocket | JSON messages go to shared listeners |
| Running connection closed | Waits two seconds and reconnects while the session remains active | Registered listeners remain available |
The application starts the socket after user data loads and stops it when loading fails or the session becomes inactive. This keeps the connection tied to the authenticated browser session (web/…/App.vue• L1609-1630, web/…/App.vue• L1878-1887, web/…/Socket.js• L18-29).
References: web/…/Socket.js• L12-29 web/…/Socket.js• L35-61 web/…/FakeWebSocket.js• L1-19 web/…/App.vue• L1878-1887
Server event messages
The server sends small JSON messages that identify the event kind and the task scope. The browser uses the identifiers to route one shared stream to the views that need it.
| Message kind | Main data | Browser use |
|---|---|---|
update | Task status, times, version, and project, template, and task IDs | Refreshes or changes task rows and task details |
log | Task ID, project ID, output text, and time | Adds output to the open task log |
Task status changes are sent while the task runner saves the new status. Log output is sent as it is produced. The socket server limits delivery to the target user, or to all connected users when no user target is supplied (services/…/TaskRunner.go• L117-135, services/…/TaskRunner_logging.go• L44-56, api/…/pool.go• L55-83).
In a high-availability deployment, a broadcaster relays the message across nodes before local connections receive it. This allows a browser to stay connected to any node while still receiving events produced elsewhere (api/…/pool.go• L5-25, api/…/pool.go• L94-101).
References: services/…/TaskRunner.go• L117-140 services/…/TaskRunner_logging.go• L44-56 api/…/pool.go• L5-25 api/…/handler.go• L182-193
View update paths
Realtime views register with the shared socket when they mount and remove their listener when they unmount. Each view filters the common stream by the identifiers it owns, so unrelated project activity does not change the current page (web/…/History.vue• L254-266, web/…/TaskList.vue• L276-293, web/…/TaskLogView.vue• L441-448).
Visible data is updated in place when the event identifies a row already on screen. If an event may add a row outside the current page, the view reloads its data. Burst control prevents frequent server events from causing a matching burst of HTTP requests (web/…/History.vue• L275-337, web/…/TaskList.vue• L333-395).
The task log follows a different path because log output can arrive often. It buffers incoming lines and adds them to the displayed output on a short interval. The view keeps the user's scroll position unless the user is already at the bottom (web/…/TaskLogView.vue• L420-440, web/…/TaskLogView.vue• L489-511).
References: web/…/History.vue• L254-337 web/…/TaskList.vue• L276-395 web/…/TaskLogView.vue• L441-511 web/…/Templates.vue• L457-463 web/…/Templates.vue• L525-544
Related browser systems
The realtime stream complements normal API loading. A view uses HTTP requests for its initial state and for a complete reload, then uses socket events as change hints or direct updates between reloads. This means the socket improves freshness but does not replace the API as the source for full page data.
For the wider browser product model, see Web console. For task and project actions that produce the changes, see Web project workflows and Schedule processing.
References: web/…/App.vue• L1878-1907 web/…/History.vue• L275-297 web/…/TaskList.vue• L300-331
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the event fields produced by task services aligned with the filters in
History,TaskList,Templates, andTaskLogView. - Keep socket startup after authentication and socket shutdown on session loss. A lifecycle change can expose an unauthenticated connection or leave a dead connection active.
- Keep listener registration paired with removal in every view. A missing removal can make an unmounted view react to later events.
- When adding an event kind, define whether the browser can update visible data directly or must reload from the API.
- In high-availability mode, preserve both cross-node relay and local delivery when changing the socket broadcaster.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The socket starts before authentication | The browser has no real server connection | App activates the session after user data loads |
| A running socket closes | Realtime updates pause until the connection returns | Socket retries after two seconds while the session is active |
| A view keeps a listener after unmount | Hidden or stale views can process later events | Views remove their listener in beforeUnmount |
| An event has the wrong project, template, or task ID | The target view ignores it or reloads the wrong data | Keep producer fields and view filters aligned |
| Many updates arrive in a short burst | Repeated HTTP reloads can overload the browser or server | List views coalesce requests and throttle reloads |
| A connection send queue becomes full | The server closes that client connection | The client reconnects while its session remains active |
Key files
| File | Why to read it |
|---|---|
| web/…/socket.js | Defines the shared browser connection to /api/ws. |
| web/…/Socket.js | Shows session gating, message delivery, shutdown, and reconnect behavior. |
| web/…/event-bus.js | Defines the local UI event contract. |
| web/…/App.vue | Owns socket startup and the main event-bus reactions. |
| web/…/TaskLogView.vue | Shows realtime task status and log handling. |
| web/…/TaskList.vue | Shows filtered task updates and reload control. |
| web/…/History.vue | Shows project task history updates and reload control. |
| api/…/handler.go | Defines authenticated WebSocket connections and server-to-browser delivery. |
| api/…/pool.go | Defines user-targeted delivery and the high-availability relay boundary. |
| services/…/TaskRunner.go | Defines the task status message shape. |
| services/…/TaskRunner_logging.go | Defines the task log message shape. |