Introducing a new way to review your PRs.

Read the announcement

semaphoreui / semaphore

Modern UI and powerful API for Ansible, Terraform/OpenTofu/Terragrunt, PowerShell and other DevOps tools.

View on GitHub

21 documents · Updated Nov 23, 2026

docs / web-realtime-updates

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 roleExampleBrowser result
User feedbacki-snackbarShows a success or error message
Navigationi-show-task, i-open-last-projectOpens a task or selects a project
Layout controli-show-drawer, i-nav-miniChanges the navigation shell
Resource changesi-project, i-userRefreshes 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:

StateConnection behaviorEvent behavior
Session inactiveUses the no-op socket or stays stoppedNo server events reach the UI
Session activeOpens the real WebSocketJSON messages go to shared listeners
Running connection closedWaits two seconds and reconnects while the session remains activeRegistered 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 kindMain dataBrowser use
updateTask status, times, version, and project, template, and task IDsRefreshes or changes task rows and task details
logTask ID, project ID, output text, and timeAdds 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

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, and TaskLogView.
  • 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

TriggerConsequenceGuard
The socket starts before authenticationThe browser has no real server connectionApp activates the session after user data loads
A running socket closesRealtime updates pause until the connection returnsSocket retries after two seconds while the session is active
A view keeps a listener after unmountHidden or stale views can process later eventsViews remove their listener in beforeUnmount
An event has the wrong project, template, or task IDThe target view ignores it or reloads the wrong dataKeep producer fields and view filters aligned
Many updates arrive in a short burstRepeated HTTP reloads can overload the browser or serverList views coalesce requests and throttle reloads
A connection send queue becomes fullThe server closes that client connectionThe client reconnects while its session remains active

Key files

FileWhy to read it
web/…/socket.jsDefines the shared browser connection to /api/ws.
web/…/Socket.jsShows session gating, message delivery, shutdown, and reconnect behavior.
web/…/event-bus.jsDefines the local UI event contract.
web/…/App.vueOwns socket startup and the main event-bus reactions.
web/…/TaskLogView.vueShows realtime task status and log handling.
web/…/TaskList.vueShows filtered task updates and reload control.
web/…/History.vueShows project task history updates and reload control.
api/…/handler.goDefines authenticated WebSocket connections and server-to-browser delivery.
api/…/pool.goDefines user-targeted delivery and the high-availability relay boundary.
services/…/TaskRunner.goDefines the task status message shape.
services/…/TaskRunner_logging.goDefines the task log message shape.