Repository navigation
Description
Problem
A new Job pod can fail its first connection to the MCP server. Kube-router programs the network policy of a new pod a few seconds after the pod starts. In that time, a connection to mcp-server on port 8001 is rejected at once (curl exit 7), although the policy admits the pod. The MCP client in src/devops_cli/roadmap/mcp.py does not retry a first connection. It raises RoadmapMcpUnavailableError, and the job stops.
Evidence (2026-11-10)
- A throwaway pod with the label
app.kubernetes.io/name=devops-cli-jobrancurlin the same second as its start. It got exit 7 (connection refused) and HTTP code 000. - The same pod form, after
sleep 20, got HTTP 401 from/implementation/mcp(reached, no token sent). A pod with another label got exit 7 after the same wait (blocked, as it must be). roadmap-serviceconnects to the same Service without a fault.
Expected
A Job that starts with roadmap.implement.mcp or roadmap.stage.mcp on does not fail because of the start delay of the network policy. The client retries a refused first connection for a short, bounded time before it raises RoadmapMcpUnavailableError.
Notes
Use the retry library that the HTTP code of the project already uses (see the retry work of #4235), not a new loop. Today the risk is small because both switches are off and a job clones its repository before it calls a tool. Keep the bound in the constants module.
Proposed design
Problem statement
A new roadmap Job pod can fail its first MCP connection before kube-router programs the network policy. The MCP client raises RoadmapMcpUnavailableError on that first refusal and the job stops. Add a short bounded retry with the project's existing retry library so the job survives the policy start delay.
Acceptance criteria
Requirement: Retry a refused first connection
The roadmap MCP client SHALL retry a connection-refused error from the first RoadmapMcpToolset.__aenter__ attempt until the connection succeeds or the retry budget expires.
Scenario: First attempt refused, later attempt succeeds
- WHEN The first
__aenter__attempt raisesConnectionRefusedErrorand a later attempt within the budget succeeds - THEN The toolset enters successfully and no
RoadmapMcpUnavailableErroris raised.
Requirement: Bounded retry budget from constants
The roadmap MCP client MUST read the total first-connection retry budget from ROADMAP_MCP_CONNECT_RETRY_SECONDS in src/devops_cli/config/constants.py.
Scenario: Budget comes from the constants module
- WHEN The retry wrapper is constructed
- THEN The total retry budget equals
ROADMAP_MCP_CONNECT_RETRY_SECONDSandsrc/devops_cli/roadmap/mcp.pyholds no retry-budget literal.
Requirement: Exponential backoff between attempts
The client SHALL wait with exponential backoff between connection attempts, starting at ROADMAP_MCP_CONNECT_RETRY_INITIAL_SECONDS and capping each delay at ROADMAP_MCP_CONNECT_RETRY_MAX_SECONDS.
Scenario: Backoff grows and caps
- WHEN The retry wrapper records each delay before an attempt
- THEN The delays grow from the initial value and never exceed the maximum value.
Requirement: Exhausted retry raises the existing error
When the retry budget expires, the client SHALL raise RoadmapMcpUnavailableError with the target URL and the last connection error as its cause.
Scenario: Every attempt is refused
- WHEN Every first-connection attempt within the budget raises a connection-refused error
- THEN
RoadmapMcpUnavailableErroris raised, names the target URL, and chains the last connection error.
Requirement: Authentication failure is not retried
The client MUST NOT retry a first connection that fails with an authentication error or HTTP 401.
Scenario: Authentication failure fails fast
- WHEN The first
__aenter__attempt raises an authentication error or an HTTP 401 error - THEN
RoadmapMcpUnavailableErroris raised after one attempt and no retry occurs.
Requirement: Existing retry library is used
The client SHALL implement the first-connection retry with tenacity.AsyncRetrying and SHALL NOT add a hand-written retry loop.
Scenario: Retry uses tenacity
- WHEN A test patches
tenacity.AsyncRetryingand calls__aenter__on a refused connection - THEN The patched
AsyncRetryingis called and the retry path contains no hand-written loop.
Requirement: Retry scope is the first connection only
The retry MUST apply only to RoadmapMcpToolset.__aenter__ and MUST NOT change remote tool-call timeout or error handling.
Scenario: Tool call failure is not retried
- WHEN A remote tool call fails after a successful connection
- THEN The existing
roadmap.mcp.timeout_secondsbound andToolReturnerror path run and no connection retry occurs.
Existing Tool Considered
No alternatives check has run. Use tenacity, the open, maintained retry library that the project's HTTP code already uses from #4235, through AsyncRetrying for a bounded exponential retry around RoadmapMcpToolset.__aenter__. It covers async bounded retries. It lacks a built-in MCP connection lifecycle hook, so the client needs a small wrapper and a total-budget constant in src/devops_cli/config/constants.py.
Key questions
- Does the retry cover both stage and implement MCP roles?: Yes.
build_roadmap_mcp_toolsetreturnsRoadmapMcpToolsetfor bothplanningandimplementation, so a retry in__aenter__covers both roles. [sources: src/devops_cli/roadmap/mcp.py] - Which retry library should the first MCP connection use?: Use
tenacity.AsyncRetryingfor the firstRoadmapMcpToolset.__aenter__attempt. The HTTP code already uses this library from fix(ci): retry the download of a release asset #4235. Do not add a hand-written retry loop. (best practice) [sources: src/devops_cli/roadmap/mcp.py]- Chosen: tenacity AsyncRetrying. It is the project's existing retry library and supports async callables with bounded backoff.
- Rejected: hand-written asyncio loop. The issue forbids a new loop and it adds code to keep.
- Rejected: httpx transport retries. Transport retries do not cover the MCP toolset
__aenter__lifecycle.
- What retry budget and backoff should the first connection use?: Retry for at most 30 seconds total. Start at 0.5 seconds, grow exponentially, and cap each delay at 5 seconds. The evidence shows a 20-second wait reaches the server. (best practice) [sources: src/devops_cli/roadmap/mcp.py, src/devops_cli/config/constants.py]
- Chosen: 30 s total, 0.5 s initial, 5 s cap. It covers the observed policy delay with margin and keeps the job start bounded.
- Rejected: 60 s total, fixed 5 s delay. It waits longer than needed after the policy is ready.
- Rejected: no retry. It leaves the reported first-connection failure in place.
- Which failures should the retry handle?: Retry only connection-refused and transient connect errors from the first
__aenter__. RaiseRoadmapMcpUnavailableErrorat once for authentication, HTTP 401, and other non-connection errors. (best practice) [sources: src/devops_cli/roadmap/mcp.py, docs/ERRORS.md:107]- Chosen: connection-refused only. It matches the reported race and avoids hiding auth or configuration faults.
- Rejected: every exception. It repeats auth and configuration failures and delays the stop.
- Rejected: no exception. It does not solve the reported race.
- Where should the retry budget live?: Put
ROADMAP_MCP_CONNECT_RETRY_SECONDSinsrc/devops_cli/config/constants.py. Put the initial delay and the maximum delay beside it. (best practice) [sources: src/devops_cli/config/constants.py, src/devops_cli/roadmap/mcp.py]- Chosen: constants module. The issue requires the bound there and the module already holds shared limits.
- Rejected: settings. The bound is not a per-deployment setting and it adds configuration surface.
- Rejected: literal in mcp.py. It hides the limit and violates the issue note.
- How should the retry be tested?: Add offline tests in
tests/roadmap/test_roadmap_mcp.py. Use a fakeMCPToolset.__aenter__that refuses then succeeds, that exhausts the budget, and that returns HTTP 401. (best practice) [sources: tests/roadmap/test_roadmap_mcp.py, src/devops_cli/roadmap/mcp.py]- Chosen: unit tests with a fake toolset. They run offline and check retry count, budget, and fast auth failure.
- Rejected: cluster integration test. It needs a live pod and network policy and cannot run offline.
- Rejected: no test. It leaves the retry and error paths unverified.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Alternatives check of 2026-11-11: covers.
Tool: jd/tenacity (https://github.com/jd/tenacity), Apache-2.0, last activity 2026-11-01, maintained.
Activity
dan-petty commentedon Nov 10, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
fixprefix of the title gives the type.(roadmap)scope of the title gives the scope.The body states the risk is small today because both feature switches are off.The issue is latent and does not affect current users because the MCP switches are off.The change uses an existing retry library and adds a bounded retry in one client file with a constant.Both deal with MCP server connectivity for Job pods under the same network policy, but #4355 fixes the policy label selector while the candidate adds client-side retry for the transient programming window.devops-cli-service commentedon Nov 10, 2026
Status set to Ready at 1ca0133 (see proposed design in issue body).
devops-cli-service commentedon Nov 11, 2026
Alternatives check: covers
Reason: Searches pointed at tenacity as the retry library and its package/repository facts confirm it is the open, maintained project that the issue names; its async retrying supports a bounded, exponentially backed-off retry around
RoadmapMcpToolset.__aenter__. It covers the whole need because the retry is a client-side wrapper the project must write anyway, and no ADR rejects tenacity (ADR 0007 only names it as the retry library whose parameters supply the waits).Tool: jd/tenacity (https://github.com/jd/tenacity)
Covers:
RoadmapMcpToolset.__aenter__ROADMAP_MCP_CONNECT_RETRY_SECONDSRoadmapMcpUnavailableErrorwith the cause chainedLacks:
__aenter__ToolReturnerror pathTools considered:
Searches run:
Sources:
Checked on 2026-11-11. A person decides what this means for the item. The check changes no label and closes no issue.
chore(main): release 0.138.0 (#5690)
devops-cli-service commentedon Nov 14, 2026
Released in v0.138.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.138.0
devops-cli-service commentedon Nov 14, 2026
Live since 2026-11-14 15:02 UTC