Skip to content

fix: renamed agent re-bakes AGENT_NAME and its label on recreate (#3813) - #3831

Merged
obasilakis merged 1 commit into
devfrom
feature/3813-rename-agent-env
Oct 20, 2026
Merged

obasilakis merged 1 commit into
devfrom
feature/3813-rename-agent-env

Conversation

@obasilakis

Copy link
Copy Markdown
Contributor

Summary

  • A recreate replays the old container's env and labels. After a rename it re-derived only the auth token, so AGENT_NAME and the trinity.agent-name label kept the old name. The agent server reads AGENT_NAME for /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.
  • The recreate now sets AGENT_NAME and the label from the live name, beside the token.
  • New check_agent_name_env_matches repairs 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 in start_agent_internal
  • src/backend/services/agent_service/helpers.py: check_agent_name_env_matches
  • src/backend/dependencies.py, src/backend/routers/agent_rename.py: comments only
  • tests/unit/test_3813_rename_agent_name_env.py (new); predicate added to test_agent_readiness_probe.py stub and the bug: trinity-system never adopts a rebuilt base image — ensure_deployed short-circuits on 'already running' #1816 convergence list
  • Feature flows agent-lifecycle.md, agent-rename.md; learnings fragment; /cso --diff report (0 findings)

Test Plan

  • New tests pass: cd tests && pytest unit/test_3813_rename_agent_name_env.py -v (11/11; 8 red before the fix)
  • Mutation: reverting the recreate override, the start wiring, or the cold-start gate each turns one named test red
  • Neighbouring lifecycle suites (1816, 1809, 3590, 2186, ent752, 1560, 1854, 3106, 2092, ent109, readiness probe): green
  • Live, after deploy on eu2: cold-restart oracle-5-energy; /health reports oracle-5-energy, heartbeat 0 × 403. Re-adding it to PULL_MODE_PILOT_AGENTS is an ops step.

Local note: test_subscription_auto_switch_no_cred_import fails only when run in one session with test_inject_assigned_credentials; it fails identically on dev (order-dependent, unrelated).

Fixes #3813

🤖 Generated with Claude Code

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]>
@obasilakis obasilakis added the ui PR touches the frontend UI — triggers Playwright e2e tests label Oct 20, 2026

@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.

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.

@obasilakis
obasilakis merged commit 8abac3b into dev Oct 20, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ui PR touches the frontend UI — triggers Playwright e2e tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants