Repository navigation
fix: renamed agent re-bakes AGENT_NAME and its label on recreate (#3813) - #3831
Merged
Merged
Conversation
recreate_container_with_updated_config replays the old container's Config.Env and Labels and re-derived only TRINITY_AGENT_AUTH_TOKEN. A renamed agent kept AGENT_NAME and trinity.agent-name under the old name, so /health, heartbeat, pull worker ids, the result callback and git auto-sync called the backend under the dead name and got 403. After that recreate the token matched, so nothing recreated the agent again. - recreate sets AGENT_NAME and the trinity.agent-name label from the live name, beside the token re-derive - check_agent_name_env_matches: present-and-different env or label drifts; absent values and unreadable attrs match. Cold start only, so an ensure-running start never kills a live execution, and never-renamed agents are not recreated - registered in the readiness-probe stub and the #1816 convergence list Mutation: reverting the recreate override reds test_recreate_after_rename_bakes_the_live_name; reverting the start wiring reds test_cold_start_recreates_an_agent_stuck_under_its_old_name; dropping the cold-start gate reds test_start_on_a_running_agent_does_not_recreate_for_name_drift. Fixes #3813 Co-Authored-By: Claude Opus 5.5 <[email protected]>
dolho
approved these changes
Oct 20, 2026
dolho
left a comment
Contributor
There was a problem hiding this comment.
Validated (/validate-pr, lane C). Recreate now re-derives AGENT_NAME + trinity.agent-name beside the token; cold-start-only drift predicate repairs already-stuck agents without killing running ones. Ran test_3813 + 1816 convergence + readiness probe locally: 27 passed. Mutation: dropping the recreate override turns test_recreate_after_rename_bakes_the_live_name red. Security greps clean; Tier 1 + journey-smoke/e2e green; dev-ci green. LGTM.
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AGENT_NAMEand thetrinity.agent-namelabel kept the old name. The agent server readsAGENT_NAMEfor/health, heartbeat, pull worker ids (<name>#wN), the refactor: fire-and-forget dispatch — a hung turn holds zero backend resource #1083 result callback and git auto-sync, so all of them called in under the dead name and got 403.AGENT_NAMEand the label from the live name, beside the token.check_agent_name_env_matchesrepairs agents already stuck in that state (token current, name stale) on their next cold start. Absent values and unreadable attrs match, so never-renamed agents are not recreated. A start of a running agent never recreates for name drift.Changes
src/backend/services/agent_service/lifecycle.py: recreate override; cold-start-gated predicate instart_agent_internalsrc/backend/services/agent_service/helpers.py:check_agent_name_env_matchessrc/backend/dependencies.py,src/backend/routers/agent_rename.py: comments onlytests/unit/test_3813_rename_agent_name_env.py(new); predicate added totest_agent_readiness_probe.pystub and the bug: trinity-system never adopts a rebuilt base image — ensure_deployed short-circuits on 'already running' #1816 convergence listagent-lifecycle.md,agent-rename.md; learnings fragment;/cso --diffreport (0 findings)Test Plan
cd tests && pytest unit/test_3813_rename_agent_name_env.py -v(11/11; 8 red before the fix)oracle-5-energy;/healthreportsoracle-5-energy, heartbeat 0 × 403. Re-adding it toPULL_MODE_PILOT_AGENTSis an ops step.Local note:
test_subscription_auto_switch_no_cred_importfails only when run in one session withtest_inject_assigned_credentials; it fails identically ondev(order-dependent, unrelated).Fixes #3813
🤖 Generated with Claude Code