Repository navigation
fix(upgrade): one alert names the running agents still on an old base image (#4483) - #4602
Conversation
… 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
left a comment
There was a problem hiding this comment.
/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_checkgoes 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).
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-systemraised 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-stateagent_container_states(), compares each running, non-ephemeral agent withcheck_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 andPOST /api/ops/fleet/restart, updates as the set changes and ends when a pass proves every agent current.trinity-agent-base:latest'strinity.base-image-versionlabel is older than the backend, namingbuild-base-image.sh(source) andstart.sh --hosted(hosted).X.Y.Z[-rcN]— files nothing and ends nothing; the backend log says the check could not run.trinity-system(own alert, bug: trinity-system never adopts a rebuilt base image — ensure_deployed short-circuits on 'already running' #1816) are left out.fleetimage:leaderlease (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 nomissinglist. Thereasonfield and the refusal itself are unchanged.upgrading.md: agents must be restarted to receive agent-side changes; rebuild the base image when anything underdocker/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
update.shrebuilds the base image only whendocker/base-imagechanged 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, atmediumpriority 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.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.pywiring, theenv_unreadablewording 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.pystart 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/devwithout this change (test_ent926_turn_tier_hook,test_4499_vendor_egress_switch,test_1310_auth_consolidation,test_ent679_payments_pin_parity— BSDsed, a read-only/data, a localblackversion).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