Skip to content

feat(api): a server's untracked containers are listed and removed on a typed name (part of #501) - #521

Merged
samuelmbabhazi merged 2 commits into
mainfrom
feat/501-untracked-containers
Nov 26, 2026
Merged

samuelmbabhazi merged 2 commits into
mainfrom
feat/501-untracked-containers

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

What changed

The control-plane part of #501, as decided: list and remove. After a restore, the servers keep running containers of deployments the backup does not know. These containers now show on the server's page as untracked, and an administrator removes them one at a time on a confirmation by name, with an audit trail. The page itself follows in a second pull request, which needs your validation. INSTALL.md already describes it, so the two merge together.

  • Recording (AllocationObservations):
    • From each state report, the managed containers that match no placed replica of the node are kept in unmatched_containers, a new table under tenant RLS that cascades with the node.
    • They are written only when the set changes, and that change is audited as node.unmatched_containers_changed: by the node, with the names added and gone and the count. Names only.
  • Untracked, at read time. An unmatched container counts when all of these hold:
    • its name, as containerName builds it, ends with the last 12 characters of exactly one application of the organization;
    • none of that application's deployments is underway. A deployment underway may still run its release task or drain its previous replicas, and those containers are not leftovers.
  • API (node.manage, session only):
    • GET /organizations/{org}/nodes/{node}/untracked-containers: name, container id, state, since when, application, project, environment, and the release and replica its name states.
    • POST /organizations/{org}/nodes/{node}/untracked-containers/{name}/remove (202):
      • It answers 409 container_not_untracked before spending anything.
      • Otherwise it spends a node.container.remove confirmation and queues RemoveContainer without volumes (key u:<confirmation id>:remove, one hour), in one tenant transaction.
      • It audits node.untracked_container_removal_requested. The agent's result is audited as the action's own events.
  • Confirmation catalog: node.container.remove, with permission node.manage and target <node id>/<container name>. The name to type is the container's, and only an untracked container resolves.
    • The control plane checks it alone. The agent's container.remove token is only for remove_volumes, which this never asks.
  • container_name_taken message (fix: a create refused for a taken container name says so (part of #501) #504): it now says the lost container then shows as untracked on its server's page, where it can be removed (French updated).
  • Docs: SPEC (state reports, the confirmation catalog, fleet routes) and INSTALL.md (restore).

Why

Part of #501. A restore left containers that nothing tracked or removed, and the only advice was "remove it by hand on the server".

How it was tested

  • Domain (untracked-containers.spec.ts, 9 tests):

    • the owner is read from every name containerName builds;
    • no owner is read from 13 other names: padded, upper case, wrong lengths, leading zeros, a newline, -tasks, an environment network name;
    • set comparison ignores order;
    • containers of deploying or unknown applications are left out, and so is a suffix two applications share;
    • the confirmation target is parsed only in its exact form, so .. and upper case are refused.
  • Recorder (allocation-observations.spec.ts): the unmatched set is written and audited once, the same report twice writes nothing, its removal empties it once, and an invalid report keeps nothing.

  • HTTP with PostgreSQL (untracked-containers-http.integration.spec.ts), with a real deployment placing release 1 and a report holding release 2's container, an unknown application's container and sk-postgres:

    • only release 2's container is listed, with its application and release, to administrators only, and the change is audited once;
    • the confirmation refuses a wrong name (400) and a placed container (404);
    • removal refuses a placed container (409) and a malformed token (400);
    • with the right token it answers 202 and queues removeContainer, key u:…:remove, audited with the administrator;
    • the token cannot be spent twice, and once the server reports the container gone, nothing is listed;
    • a second test hides a release task while its deployment runs. Removing that filter fails it.
  • Suites: the full API unit suite (108 files, 934 tests), api:lint and api:typecheck pass. The full integration suite passes apart from its known local failures:

    • the PostgreSQL 18 23001 files, fleet-tenant and tenant-schema;
    • two files needing a container runtime, metrics and s3-transfer.

    All four causes were checked.

Security considerations

  • Destructive action, rule 7. It needs node.manage and a single-use confirmation by the container's exact name, spent in the transaction that queues the removal.
  • Volumes stay. The removal never asks for them, so data is never lost by this route.
  • Limited reach. The agent removes only sk.managed containers, by name.
  • Only stored data is used. Nothing new comes from the agent: names, ids and states were already in its reports. Labels stay stripped on the agent. The audit payloads carry names only.

…a typed name (part of #501)

After a restore, servers keep running the containers of deployments the backup does not know, and nothing removed them. The control plane now keeps, per node, the managed containers its reports hold that match no placed replica, writes and audits them when that set changes, and lists as untracked those named after an application of the organization that is not being deployed. An administrator removes one on a confirmation token for the new node.container.remove action, by its name: RemoveContainer without volumes, audited.

Signed-off-by: samuel mbabhazi <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 55 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 3b7df65 and 9c0faa4.

Files ignored due to path filters: 3

  • apps/api/openapi.json is excluded by !apps/api/openapi.json
  • docs/generated/route-role-matrix.md is excluded by !**/generated/**, !docs/generated/**
  • packages/api-client/src/gen/openapi.ts is excluded by !**/gen/**, !packages/api-client/src/gen/**
Files selected for processing: 23

  • apps/api/prisma/migrations/20261126160000_unmatched_containers/migration.sql
  • apps/api/prisma/schema.prisma
  • apps/api/src/audit-coverage.spec.ts
  • apps/api/src/modules/confirmations/domain/confirmation-token.ts
  • apps/api/src/modules/deployments/application/allocation-observations.spec.ts
  • apps/api/src/modules/deployments/application/allocation-observations.ts
  • apps/api/src/modules/deployments/application/ports.ts
  • apps/api/src/modules/deployments/application/untracked-containers.ts
  • apps/api/src/modules/deployments/deployments.module.ts
  • apps/api/src/modules/deployments/domain/pipeline.spec.ts
  • apps/api/src/modules/deployments/domain/pipeline.ts
  • apps/api/src/modules/deployments/domain/untracked-containers.spec.ts
  • apps/api/src/modules/deployments/domain/untracked-containers.ts
  • apps/api/src/modules/deployments/infrastructure/prisma-observation.store.ts
  • apps/api/src/modules/deployments/interface/node-replica.dto.ts
  • apps/api/src/modules/deployments/interface/node-replicas.controller.ts
  • apps/api/src/modules/deployments/untracked-containers-http.integration.spec.ts
  • apps/api/src/platform/prisma/tenant-database-role.ts
  • apps/web/src/app/delivery/agent-action-rows.spec.ts
  • apps/web/src/app/ui/fr.ts
  • deploy/postgres/runtime-role.sql
  • docs/INSTALL.md
  • docs/SPEC.md
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator Author

CodeRabbit is rate limited (review limit reached). Self-reviewed before merge:

  • The raw query is parameterized, and its suffixes are validated as 12 hex characters.
  • Every read runs under runTenant with row security.
  • Node existence is checked before listing or removing.
  • The confirmation is spent in the same transaction as the enqueue.
  • The removal never asks for volumes.

Lab-verified with a real backup.sh restore (see #522). UI validated by the maintainer.

@samuelmbabhazi
samuelmbabhazi merged commit 7feedf0 into main Nov 26, 2026
27 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the feat/501-untracked-containers branch November 26, 2026 16:21
samuelmbabhazi added a commit that referenced this pull request Nov 26, 2026
… one on its name (closes #501) (#522)

## What changed

The page part of #501, stacked on #521: a server's page lists its
untracked containers and removes one on its typed name.

- **`sk-untracked-containers`**: in the server page's *Resources*
section, under the replicas, hidden while there are none.
- Each container shows its name, its application, its release, since
when it is unmatched, and its state.
- **Remove** opens the existing confirm-by-name dialog
(`ConfirmByName`), which says the server stops and removes the container
and that its volumes stay.
- Confirming issues a `node.container.remove` confirmation by the typed
name, then asks for the removal.
- On success the page says the server removes it within a minute, and
stops offering that container.
  - Changing server or organization clears everything.
- **API client:** `FleetApi.untrackedContainers`,
`confirmContainerRemoval` and `removeUntrackedContainer`.
- **French translations**, including container states that had none
(exited, dead, created, restarting).

## Why

Closes #501. After a restore, an administrator sees the containers left
behind and removes them from the server's page.

## How it was tested

- **Unit tests** in `untracked-containers.spec.ts` (4 tests):
  - nothing is shown while there are none;
  - each container is named with its application and release;
- removal goes through the typed name: a partial name keeps the button
disabled, both API calls carry the right arguments, the success text
shows, and the container is no longer offered;
  - another server clears the list.
- **Full web suite:** 59 files, 371 tests. Web lint and typecheck pass.
- **Real lab, the issue's own scenario** (run28, this branch's image,
Chromium):
1. `third` ran release 2 on `node-b`, and `./backup.sh create` saved it.
  2. Deploying `third` again gave release 3.
  3. `./backup.sh restore` brought the database back to release 2.
4. `node-b` reported `sk-third-8a40e589f52c-r3-0`, listed as untracked:
application third, release 3, running.
5. Typing the name in the dialog and confirming removed it from the
server, and the list emptied.
6. Deploying `third` again succeeded at the first attempt, reusing
number 3, which used to fail on the name. The route served the new
container.

Screenshots are on the review page linked in the conversation. **This
changes the UI: it waits for the maintainer's validation, then merges
with #521 (retargeted to main first).**

## Security considerations

- **No new capability.** The page calls #521's routes: `node.manage`, a
single-use confirmation by the container's exact name, and an audit
trail.
- **Data stays.** The removal never asks for the volumes.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **New Features**
* View untracked containers in a server’s Resources section, with status
and container details.
* Remove a container after confirming its exact name. The confirmation
explains that removal stops the container and leaves its volumes intact.
  * See removal status and refresh the list; retry loading if it fails.
* If the server no longer considers a container untracked, start the
removal process again.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: samuel mbabhazi <[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