Skip to content

[M2.6b] Live updates per environment - #179

Merged
samuelmbabhazi merged 3 commits into
mainfrom
feat/m2.6b-live-updates
Nov 7, 2026
Merged

samuelmbabhazi merged 3 commits into
mainfrom
feat/m2.6b-live-updates

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

What changed

M2.6b: live updates per environment.

  • GET …/environments/{e}/events is a server-sent event stream (environment.read, sessions or scoped tokens).
    • Source: it follows audit_events, not the in-process bus, which publishes before commit and could announce a rolled-back change.
    • Content: one change event per committed audit event of the environment: type, target, application and time. No metadata. Clients reload through the normal API, so nothing bypasses its authorization.
    • Access: session and permission are rechecked on every 2 s poll, so revocation or a role change ends the stream.
    • Bounds: one hour per stream, eight per account (429 beyond), and a keep-alive comment every 15 s. Shutdown aborts open streams, which would otherwise hold the HTTP server open.
    • Resume: Last-Event-ID, validated as a UUID.
    • Accept: a request without Accept: text/event-stream answers 406, so nothing hangs on it by accident. The route-role matrix uses this to test the route's guards.
  • Web: LiveEvents wraps EventSource. The application page reloads its deployments when an event names it, and keeps a 15 s poll while connected, or the usual 3 s otherwise.
  • SPEC changed: the documented /api/v1/events is replaced by this per-environment route, which has one clear permission. Organization-wide events are not streamed.

How it was tested

  • Unit tests:
    • the event format, no metadata leak and no way to forge an event with a newline;
    • cursor movement, a failed poll ending the stream, keep-alive, lifetime and client departure;
    • the per-account bound and shutdown.
  • Web test with a fake EventSource: reloads only for its own application, closes on leaving.
  • Full local gate: 302 API and 68 web tests, Go race tests, lint, drift, Semgrep, Prettier.
  • Not run: the new integration test (reader against real PostgreSQL, 406, 404), since Docker is not reachable here. The real streaming path through HTTP, including a browser reconnect, has no automated test. Check it on the first real run.

Known limit

A transaction committing late can carry an older id than the stream's cursor, so an event can be missed. Events are only hints, and the slow poll covers this.

Security considerations

  • No new data exposure: readers with environment.read already see these resources.
  • Each poll costs a few queries per open stream, bounded by the per-account limit. Worth watching at scale.

review added 3 commits November 7, 2026 13:26
GET …/environments/{id}/events follows audit_events rather than the
event bus, which publishes before commit. Each change event carries
identifiers only. Session and permission are rechecked on every poll,
streams are bounded per account and in lifetime, and shutdown ends them.

Signed-off-by: review <[email protected]>
The application page reloads its deployments when an event names it,
falling back to a slower poll while connected and the usual one if the
stream is unavailable.

Signed-off-by: review <[email protected]>
@samuelmbabhazi
samuelmbabhazi merged commit 5b58caf into main Nov 7, 2026
@samuelmbabhazi
samuelmbabhazi deleted the feat/m2.6b-live-updates branch November 7, 2026 11:28
samuelmbabhazi added a commit that referenced this pull request Nov 7, 2026
## What changed

M1.6b3: what agents report (#175) is now visible.

- **`GET …/applications/{a}/replicas`** (`environment.read`) lists
placed replicas with node name, container and the last observed state
(null until seen).
- **Application page:** a Replicas table, with "not reported yet" for a
container the agent has not seen. It reloads with deployments.
- **`allocation.observed`** events now carry `environmentId`, so the
live stream of #179 includes them and the page updates when a container
stops.

## How it was tested

- Web test for the table. Full local gate: 302 API and 69 web tests, Go
race tests, lint, drift, Semgrep, Prettier.
- **Not run:** the integration assertion added to
`allocation-observations.integration.spec.ts`, because Docker is not
reachable here.

## Security considerations

Same read permission as the other application routes. It reveals node
names and container names to `environment.read` holders, and no
environment values.

---------

Signed-off-by: review <[email protected]>
Co-authored-by: review <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant