Skip to content

[M1.6b2] Record what agents observe for their replicas - #175

Merged
samuelmbabhazi merged 2 commits into
mainfrom
feat/m1.6b2-state-observations
Nov 7, 2026
Merged

samuelmbabhazi merged 2 commits into
mainfrom
feat/m1.6b2-state-observations

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

What changed

M1.6b2: agents now send their state reports, and the control plane records what they observe. The owner approved the separate observed-state model on 2026-11-07.

  • allocation_observations table: one row per allocation with container id, observed state and time, under forced tenant RLS. It is separate from allocations.state, so an observation never frees or takes scheduler capacity. assertTenantDatabaseRole now covers 17 tables.
  • observationChanges (domain):
    • containers matching no replica of the node are ignored;
    • a seen container now absent reads as missing;
    • a replica never seen stays unobserved, because its container may not exist yet;
    • an unchanged state is refreshed at most once a minute, and only real changes are audited.
  • AllocationObservations handles a report in one tenant transaction, using the node identity from its certificate. A report with any invalid container (name, id, state, duplicate, over 256 containers) is ignored whole, keeping the last good state. Changes are audited as allocation.observed, with the node as actor.
  • NodeStream refuses a report with a stale epoch. It hands valid ones to StateReports, a small fleet registry, because deployments depends on fleet and fleet cannot import it back.
  • Agent daemon: the reporter from [M1.6b1] Collect and transport managed-container state reports #172 is now switched on.

How it was tested

  • Domain and service unit tests: first sighting, changes, missing versus never seen, the refresh boundary, foreign containers, malicious reports (traversal name, short id, unknown state, duplicates, 257 containers), registry delivery.
  • Stream test: a state report reaches the registry.
  • Full local gate passes: 287 API tests, Go race tests, lint, drift, Semgrep, Prettier.
  • Not run: the new allocation-observations.integration.spec.ts (another node's report touches nothing, audit sequence, reservation unchanged), because Docker is not reachable from this environment. It needs a run on a machine with Docker.

Security considerations

  • A node can only affect its own placed allocations.
  • Reports hold no labels other than sk.managed, no environment and no commands.
  • Audit volume: a container in a restart loop produces one event per transition. This is bounded by the agent's 1 Hz sampling, and worth revisiting if it proves noisy.

review added 2 commits November 7, 2026 12:48
What the agent last saw for an allocation, apart from the scheduler's
reservation in allocations, with forced tenant RLS.

Signed-off-by: review <[email protected]>
The node stream hands state reports with the current epoch to the
deployments context through a small fleet registry. Invalid reports are
ignored whole; valid ones update only the reporting node's placed
replicas, auditing changes as allocation.observed by the node. The
agent daemon now sends its reports.

Signed-off-by: review <[email protected]>
@samuelmbabhazi
samuelmbabhazi merged commit 4e67973 into main Nov 7, 2026
@samuelmbabhazi
samuelmbabhazi deleted the feat/m1.6b2-state-observations branch November 7, 2026 10:50
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