Repository navigation
Description
Component
CLI (cli/src/format.ts), agent runtime (agent/src/pipeline.py, agent/src/models.py)
Describe the bug
One task carries three different turn numbers, and the pair shown to an operator — turns_attempted / max_turns — compares two quantities that are not the same thing. So turns_attempted can exceed max_turns on a task that terminated COMPLETED and never breached the cap.
Observed on a live lambda-microvm run of three tasks:
| Task | max_turns |
persisted turns_attempted |
bgagent status displayed |
terminal status |
|---|---|---|---|---|
01M35TNKCWKFFE9T1WS8BPG2M5 |
80 | 90 | 171 | COMPLETED |
01M35TNMAYD0T8BM8GTM1EBGR9 |
60 | 47 | 83 | COMPLETED |
01M35SWBR3RNY6WZAQ9H1MJWDQ |
12 | 5 | 9 | COMPLETED |
Every displayed value disagrees with the persisted one, and in the middle row the display invents an overrun (83 / ~60) for a task that used 47 of 60.
The cap itself is fine. agent/src/pipeline.py:409 passes config.max_turns into the Claude Agent SDK, which terminates with error_max_turns; _compute_turns_completed (pipeline.py:730-750) exists precisely because the SDK reports num_turns = max_turns + 1 on that path. This is not a containment failure and not substrate-specific — the same container image runs on agentcore, ECS and lambda-microvm. Budget enforcement, by contrast, is exact: a deliberate probe with --max-budget 0.25 failed with error_max_budget_usd as designed.
Two distinct defects
1. turns_attempted and max_turns are not commensurable, but are printed as a ratio.
pipeline.py:397 sets turns_attempted = agent_result.num_turns or agent_result.turns, documented at models.py:400 as "the SDK's authoritative counter". The first row above ran a single agent session — 1 session_started, 1 step:implement:start, so this is not several sessions summing — reported 90, and still ended COMPLETED rather than error_max_turns. Whatever num_turns counts there, it is not the quantity the SDK caps at 80.
Consequence: an operator who sets --max-turns 80 and is shown 90 / ~80 concludes the cap leaks. It does not. The number we display simply is not the number we bound.
2. The CLI prefers a live counter that matches neither.
cli/src/format.ts:606-617:
// Prefer the live ``turn`` from the most recent ``agent_turn`` event
// over the persisted ``turns_attempted`` — the former updates mid-task
const liveTurn = readNumberField(turnEvent?.metadata, 'turn');
const currentTurn = liveTurn ?? task.turns_attempted ?? null;
...
return `${left} / ~${right}`;For the first row this renders 171, while the persisted record says 90 and the visible agent_turn events top out at 19. Separately, agent_cost_update events carry their own turn field that disagrees with the neighbouring agent_turn (observed agent_turn turn=7 immediately followed by agent_cost_update turn=4 in another task), so "the live turn" is not one well-defined series.
The ~ in / ~80 hints that something is approximate without saying what, which is how this stayed invisible.
Expected behavior
- A displayed ratio compares like with like: either show the counter the SDK caps, or stop presenting them as a ratio and label them separately.
turns_attemptedexceedingmax_turnson a non-error_max_turnstask should be impossible by construction, or documented at the field with the reason it is possible.- One turn series. If
agent_turn.turnandagent_cost_update.turnare different counters, they need different names. - Replace the unexplained
~with either an exact value or a stated reason for the estimate.
Additional context
- Found while stress-testing the lambda-microvm substrate on a fork; substrate is incidental, the code path is shared.
- Related-but-separate finding from the same run:
platform doctorreports a GitHub token as healthy when it is expired, revoked, or blocked by enterprise policy, because it checks the secret's presence rather than making a repo-scoped call. Filing separately.
Activity
krokoko commentedon Nov 24, 2026
What is left of this issue after #1075.
With #1075,
turns_completedis the runner's count of the model's answers, which is whatmax_turnslimits.bgagent statusnow shows it, as the web console already did.The completion comments on Linear and Jira still print
turns_attempted, so one task can show two counts:cdk/src/handlers/fanout-task-events.ts, the two places that readtask.turns_attemptedfor the Linear and the Jira comment;cdk/src/handlers/shared/jira-iteration-comment.ts, theturnsmetric of the iteration comment;cdk/src/handlers/orchestration-reconciler.ts, whereparseTerminalTaskRecordreadsturns_attemptedfor the final status that the reconciler writes into the Jira iteration comment.Switching those four to
turns_completed, with the fallback the CLI uses for a task record that has none, would close the issue.fix: quick wins from a sweep of the open issues (aws-samples#1075)
refactor(observability): share one no count rule for turns_completed
test(observability): cover turns_completed on the Linear agent sessio…