Repository navigation
fix(lifecycle): skip credential/skill injection on idempotent start (#421) - #426
Merged
Merged
Conversation
…421) `start_agent_internal` previously invoked `inject_assigned_credentials` and `inject_assigned_skills` unconditionally after `container_start`, even when the target was an already-running container that did not need recreation. Under load, the HTTP injection call to the busy agent would fail with `All connection attempts failed`, retry 3× (2s delay), and log an ERROR — adding noise during exactly the moments the agent was fragile. The workspace volume preserves `.env` and `~/.claude/skills/` across restarts, so the post-start HTTP injections on an idempotent start are redundant. Recreation paths (shared folders, auth env vars, resource limits, capabilities, guardrails) still trigger injection because the container is effectively fresh. Captures `was_already_running` after `container_reload` and gates both injections on `was_already_running and not needs_recreation`. When skipped, the result dict reports `status: "skipped"` with `reason: "container_already_running"` so callers can distinguish. Closes #421 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
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
inject_assigned_credentialsandinject_assigned_skillsinstart_agent_internalonwas_already_running and not needs_recreation, eliminating the 3-retry-plus-ERROR storm that fired on health-check/start calls against busy, already-running containers.credentials_injection: "skipped"withreason: "container_already_running".Changes
src/backend/services/agent_service/lifecycle.py— capturewas_already_runningaftercontainer_reload; branch onskip_injection.tests/unit/test_start_agent_skip_inject.py— 3 unit tests covering the running-skip, stopped-inject, and recreated-inject paths.docs/memory/feature-flows/agent-lifecycle.md— updated embedded snippet and added a bug: credential injection runs on health-check recovery path against already-running containers #421 note under Startup Injection Order.Test plan
pytest tests/unit/test_start_agent_skip_inject.py -v— 3/3 pass.tests/unit/sweep: 625 passed (11 pre-existing failures intest_file_upload.pyare unrelated Telegram tests).start_agentagainst a running container under load — verify noCredential import attemptwarnings./api/agents/{name}/startafter stopping an agent — verify credentials still inject (log should showImported N credential file(s) from .credentials.enc into {name}).use_platform_api_keyand restart — verify recreation path still injects credentials on the fresh container.Closes #421
Generated with Claude Code