Skip to content

fix(lifecycle): readiness probe gates post-start injections (#406) - #419

Merged
vybe merged 1 commit into
mainfrom
fix/406-agent-readiness-probe
Apr 21, 2026
Merged

vybe merged 1 commit into
mainfrom
fix/406-agent-readiness-probe

Conversation

@dolho

@dolho dolho commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #406.

Docker reports a container as `running` several seconds before the in-container FastAPI server accepts connections. The existing credential-injection retry loop (3 × 2s = ~6s) exhausts before the agent server is listening under multi-agent deploys, producing a flood of `ConnectError` log lines and a batch of failed scheduled executions in the first 1–5 minutes after deploy.

Fix

Add `wait_for_agent_ready(agent_name, timeout_s, poll_interval_s)` in `services/agent_service/lifecycle.py`. Polls `GET http://agent-{name}:8000/health\` at 1s intervals with a 60s default timeout. Gated between `container_start` and the credential / skill / read-only injection block in `start_agent`.

  • On ready: silently returns `True` (no noise for happy path); logs informative line only if the probe needed more than one poll.
  • On timeout: logs warning and returns `False` — caller proceeds anyway; existing retry loops remain as backstop.
  • On unexpected exception during poll: swallowed by design. The probe must never raise.

Configurable via env:

  • `AGENT_READINESS_TIMEOUT_S` (default `60`)
  • `AGENT_READINESS_POLL_INTERVAL_S` (default `1.0`)

Test plan

  • Unit (`tests/unit/test_agent_readiness_probe.py`): 5 tests — immediate-ready, ready-after-N-connect-errors, timeout path, unexpected-exception swallowed, non-200 responses keep polling. All pass.
  • Live: Created fresh blank agent and started it. Readiness probe ran silently (agent ready on first poll, expected). Credential inject reached the server with no `ConnectError` (pre-fix: flood of connect errors in startup window).

Out of scope (noted)

While verifying, observed an unrelated pre-existing bug in `inject_assigned_credentials`: the `if "not found" in str(e).lower():` check was intended to short-circuit the retry loop when `.credentials.enc` doesn't exist, but the actual error text is `"No .credentials.enc file found in agent workspace"` — no literal "not found" substring. Result: blank agents retry 3× unnecessarily. Not fixed here (different root cause, different ticket).

🤖 Generated with Claude Code

@dolho
dolho requested a review from vybe April 20, 2026 09:12
Docker reports a container as "running" several seconds before the in-container
FastAPI server accepts connections. The existing credential-injection retry
loop (3 attempts × 2s) exhausts before the server is listening under
multi-agent deploys, resulting in a wall of ConnectError log lines and a
batch of failed scheduled executions in the first 1–5 minutes after deploy.

Add wait_for_agent_ready() polling GET /health at 1s intervals with a 60s
default timeout. Gate it between container_start and the credential/skill/
read-only injection block in start_agent. On timeout, log warning and
continue — existing retry logic remains as backstop.

Configurable via AGENT_READINESS_TIMEOUT_S and AGENT_READINESS_POLL_INTERVAL_S
env vars. Probe is best-effort: any exception during polling is swallowed.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@dolho
dolho force-pushed the fix/406-agent-readiness-probe branch from b431815 to 8a9366c Compare April 21, 2026 07:30

@vybe vybe 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 via /validate-pr: closes startup race, non-blocking on failure. ✅

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.

bug: credential injection fails on fresh agents before HTTP server is ready

2 participants