Skip to content

fix(upgrade): one alert names the running agents still on an old base image (#4483) - #4602

Merged
vybe merged 1 commit into
devfrom
feature/4483-fleet-stale-base-image
Nov 16, 2026
Merged

vybe merged 1 commit into
devfrom
feature/4483-fleet-stale-base-image

Conversation

@trinity-ability

Copy link
Copy Markdown
Contributor

Fixes #4483

Why

After an upgrade, agents keep the image they were started from until their next cold start (#1809 — deliberate, unchanged here). Only trinity-system raised a stale-image alert, so agent-side fixes in a release were silently inert on every agent nobody stopped.

What changes

  • services/fleet_image_service.py (new). One pass reads the fleet through the tri-state agent_container_states(), compares each running, non-ephemeral agent with check_base_image_state (the comparison the cold-start path uses) and keeps one platform alert, fleet_base_image_stale:fleet, on the system agent's queue. It names the stale agents and POST /api/ops/fleet/restart, updates as the set changes and ends when a pass proves every agent current.
  • The same alert is raised when trinity-agent-base:latest's trinity.base-image-version label is older than the backend, naming build-base-image.sh (source) and start.sh --hosted (hosted).
  • Could not check — Docker unreadable, a failed comparison, a label that is absent or not X.Y.Z[-rcN] — files nothing and ends nothing; the backend log says the check could not run.
  • Read-only. No container is stopped, started or recreated. Ephemeral agents and trinity-system (own alert, bug: trinity-system never adopts a rebuilt base image — ensure_deployed short-circuits on 'already running' #1816) are left out.
  • Loop. First pass 25s after boot, then every 10 minutes, under the fleetimage:leader lease (fail-open: a duplicated pass updates the same row). start() only schedules, so boot is not blocked.
  • 409 env_unreadable (credential sink, Nevermined delegation) names the older agent image and the restart when the agent's read answer carries no missing list. The reason field and the refusal itself are unchanged.
  • upgrading.md: agents must be restarted to receive agent-side changes; rebuild the base image when anything under docker/base-image/ changed, not only the Dockerfile.

No schema change, no migration, no new route, no MCP tool.

Two things for the reviewer to decide

  1. The version-label alert can fire when no rebuild is needed. update.sh rebuilds the base image only when docker/base-image changed in the range, so a release that does not touch that directory leaves the label older than the backend. The issue asks for this alert as written and I implemented it, at medium priority when it is the only signal. A person's dismissal snoozes it for 7 days, then it returns. A content-hash label would remove the false positive but needs build-script and publish-workflow changes.
  2. "Could not check" is reported in the backend log only. No API or UI surface carries it. The issue says it must never read as "up to date" or "stale", which holds; a visible surface would be a follow-up.

Tests

tests/unit/test_4483_fleet_base_image_check.py — 48 tests: stale agents listed, alert ended when none remain, label older than backend, label absent, Docker unreadable, ephemeral/stopped/system agents skipped, no container touched, leader lease, main.py wiring, the env_unreadable wording on both writers.

Mutation check (each reverted, shown red, restored byte-identical): Docker-unreadable read as an empty fleet; ephemeral or system agent not excluded; unknown readings allowed to clear; the main.py start call removed; the lease ignored; the old-image wording dropped.

Full unit island locally on macOS: 41,442 passed, 45 failed. The same 45 fail on origin/dev without this change (test_ent926_turn_tier_hook, test_4499_vendor_egress_switch, test_1310_auth_consolidation, test_ent679_payments_pin_parity — BSD sed, a read-only /data, a local black version).

Not run: /verify-local (no image build or live agent in this pass). The check has not been exercised against a real Docker daemon.

🤖 Generated with Claude Code

… image (#4483)

After an upgrade, agents keep the image they were started from until their
next cold start (#1809, unchanged), and only trinity-system said so. Agent-side
fixes in a release were silently inert on every agent nobody stopped.

- services/fleet_image_service.py: reads the fleet through the tri-state
  agent_container_states(), compares each running, non-ephemeral agent with
  check_base_image_state, and keeps ONE platform alert
  (fleet_base_image_stale:fleet) naming the stale agents. It updates as the
  set changes and ends when a pass proves every agent current. The same alert
  is raised when trinity-agent-base:latest's version label is older than the
  backend, with the command for a source and for a hosted install.
- Docker unreadable, a failed comparison or a base image with no parseable
  version label is "could not check": nothing is filed and nothing is ended.
- Read-only: no container is stopped, started or recreated. Leader-leased
  (fleetimage:leader, fail-open), first pass 25s after boot, then every 10 min.
- 409 env_unreadable (credential sink, Nevermined delegation) names the older
  agent image and the restart when the agent's read answer has no `missing`
  list.
- upgrading.md: agents must be restarted to receive agent-side changes; the
  base image is rebuilt when anything under docker/base-image/ changed.

Mutation check: with each of these reverted, tests in
tests/unit/test_4483_fleet_base_image_check.py went red and were restored
byte-identical — Docker-unreadable read as an empty fleet
(test_docker_unreadable_is_could_not_check), ephemeral or system agent not
excluded (test_ephemeral_stopped_and_system_agents_are_left_out), unknown
readings allowed to clear (test_an_agent_whose_comparison_failed_is_neither_
stale_nor_current), the main.py start call removed
(test_main_starts_the_loop_with_the_watch_loops), the lease ignored
(test_a_worker_that_does_not_hold_the_lease_runs_nothing), the old-image
wording dropped (test_env_unreadable_on_an_old_image_names_the_image_and_the_
restart).

Fixes #4483

Co-Authored-By: Claude Fable 5.2 <[email protected]>

@dolho dolho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/review — PR #4602 at 847aae7dd

Verdict: approve. No blocking findings. Four informational points, two of which answer the questions the PR asks the reviewer.

Scope: clean. All nine acceptance criteria of #4483 are met in the diff. No schema change, route or MCP tool, as stated.

Execution coverage

Changed symbol Executed by Live consumer
fleet_image_service.run_once / _run_once test_4483_fleet_base_image_check.py (calls it through fakes of the read seams) FleetImageCheckService.run_cycle
FleetImageCheckService.start / stop same file, including an AST check of the main.py wiring main.py::_schedule_watch_loops, _shutdown_loops_and_transports
compare_versions, describe same file, parametrized _run_once
agent_env_read.image_predates_missing same file, both writers credential_sink._read_env, nevermined_delegation_service._read_agent_env
Kind("fleet_base_image_stale", …) test_3246_platform_alerts_* (131 pass) platform_alerts.observe / clear

What I ran on the PR head:

  • test_4483_fleet_base_image_check.py + test_1920_no_hand_rolled_single_flight.py: 69 pass.
  • Four test_3246_platform_alert* files (registry, seam, leaf, emitters): 131 pass.
  • Mutation 1, Docker-unreadable read as a readable fleet: test_docker_unreadable_is_could_not_check goes red.
  • Mutation 2, the "could not check" branch removed so unknown readings clear the alert: 4 tests go red.
  • The tests fake the read seams, so I checked the real targets exist with the names and shapes the service imports: docker_utils.agent_container_states_async, docker_utils.image_get, docker_service.get_agent_container, db.get_agent_ephemeral_info, helpers.check_base_image_state, utils.app_version.resolve_release_version (which strips the +g<sha> suffix, so an rc build's version parses).

Not run: the check against a real Docker daemon. The PR says the same. Nothing in the unit tests can show that a container's attrs["Image"] and the tag's id compare as expected on a real install, so this needs one pass on a test instance before the row for #4483 is closed.

Critical findings

None. SQL, auth boundaries, credential exposure and the enterprise-docs guard pattern (0 hits on added doc lines) are clean. The check does not write to Docker anywhere.

Informational

I1. The stale-agents alert does not end while the base image's version cannot be read (confidence 7/10)
fleet_image_service.py, _run_once:

if unknown or base_image == BASE_UNKNOWN:
    ...
    return {"status": "could_not_check", "reason": "partial", **result}

Take an install where the label is the build script's latest fallback, or the backend version resolves to unknown. The alert is filed for three drifted agents. The operator restarts them. Every agent now reads match, but base_image is still BASE_UNKNOWN, so the pass returns here and never reaches clear. The alert keeps naming three agents that are current. The acceptance criterion says the alert "ends by itself when none are left". Suggested fix: when no agent is stale or unknown and the pending row was filed for agents only, end it; keep the current behaviour only when the row is about the base image. This is narrow (the VERSION file exists on every normal install), so a follow-up is fine.

I2. The lease is released with GET then DEL (confidence 6/10)
_release_leadership reads the key and deletes it in two calls. background-services.md says of the sync-health lease that this shape "lets an expired worker delete a sibling's fresh lease", and that loop uses compare-and-delete for that reason. The effect here is one duplicated pass that updates the same row, so it is harmless. Worth matching the sync-health shape when this file is next touched.

I3. Reviewer question 1, the version-label alert firing when no rebuild is needed: accept for this release, file the follow-up.
The case is real: a release that does not touch docker/base-image/ leaves the label one version behind on a source install, and the alert then tells the operator to rebuild and restart the fleet for nothing. It is medium, it is one row, and a dismissal holds for 7 days. The alternative for v1.0.5 is no signal at all on the update paths that never rebuild, which is the second gap #4483 describes. The content-hash label is the right fix and belongs in its own issue.

I4. Reviewer question 2, "could not check" in the backend log only: accept.
The criterion is that it never reads as "up to date" or "stale", and that holds. A visible surface is a follow-up, and I1 is the case where it would matter most.

Summary

  • Critical: 0.
  • Informational: 4. I1 and I2 can be follow-ups; I3 and I4 are the two decisions the PR asked for.
  • Before closing #4483: one run on a real instance (upgrade the base image under a running agent, confirm the alert names it, restart it, confirm the alert ends).

@vybe
vybe merged commit e0f000f into dev Nov 16, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants