Skip to content

feat(mecatequi): add --max-turns flag; raise default turn/tool budgets - #76

Merged
JAORMX merged 1 commit into
mainfrom
mecatequi-max-turns-flag
Jun 17, 2026
Merged

JAORMX merged 1 commit into
mainfrom
mecatequi-max-turns-flag

Conversation

@JAORMX

@JAORMX JAORMX commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

What & why

mecatequi's single-shot CI runs kept terminating with stop_reason=max_turns. The turn cap was the global default (100) and the binary had no flag to raise it. This makes max-turns both configurable and much higher by default.

Changes

  • --max-turns flag on cmd/mecatequi, threaded to CreateSession via run(). It is a per-session limit (not an engine-build knob), so it is deliberately not mapped onto app.Config. 0/unset inherits the deployment default.

  • Per-field limit defaulting (the trap). createSession previously substituted DefaultLimits only when the passed Limits was the all-zero value — so Limits{MaxTurns: n} would silently disable MaxToolCalls and MaxConsecutiveFailures (0 = unlimited). Replaced the all-or-nothing substitution with per-field defaulting via a new session.Limits.WithDefaults: each zero field inherits from DefaultLimits. A zero field now means unset, not explicitly unlimited. This mirrors the per-field merge the subagent/team layers already use (defLimits, mergeLimits).

  • Raised the composition defaults (internal/app/build.go): defaultMaxTurns 100 → 1000, defaultMaxToolCalls 400 → 4000. The prior bump (3203239) used a 1:4 turns:tools ratio (100/400); keeping that ratio at 1000 turns gives 4000 tool calls, so a long tool-heavy run isn't capped by the tool-call brake long before the turn cap. MaxConsecutiveFailures unchanged (5). Subagent child defaults (50/200/3) left unchanged — deliberately far below the main default to bound a delegation fan-out.

  • Action stack: a max-turns input on the mecatequi composite action (threaded as MQ_MAX_TURNS, appended to the argv array exactly like max-run-tokens, conditional on non-empty) and a workflow_call passthrough input on mecatequi-reusable.yml.

  • Tests: session.Limits.WithDefaults unit table; a server-level test proving the other caps survive when only MaxTurns is set (the trap); a run()-level test proving --max-turns caps the session (StopMaxTurns); a flag-parse test; action-wrappers contract pins for the new env + argv wiring. Updated the server test that encoded the old all-or-nothing contract.

  • Docs: usage.md + ADR-0028 inputs→flags tables and the reusable passthrough list gain max-turns; subagents-and-teams.md drops the now-stale "half the main session's 100/400" framing.

Design note — the per-field-defaulting decision

The clean fix was at the service.createSession seam: fill any zero field of the passed Limits from DefaultLimits rather than the old all-or-nothing substitution. Limits{MaxTurns: n} keeps the default tool-call / failure caps instead of zeroing them. This is a deliberate, documented contract change — a wire client that sent a 0 field expecting "unlimited" now inherits the default for that field. The codebase already merges limits per-field everywhere else, so the all-or-nothing branch was the odd one out.

Verification

Ran locally and green: task build, task test (full race suite), task lint, task test:actions (incl. the new action-wrappers pins), task lint:actions (actionlint + reusable-pins + action-templates), and the matlatl doc link-health check. llms.txt is unchanged by the doc edits.

Overlap note

A second in-flight PR (branch mecatequi-toolchain-hook) also edits action.yml and mecatequi-reusable.yml (toolchain install + a setup-script input). Edits here are localized to the max-turns input/env/argv lines; expect a trivial rebase if that PR lands first.

🤖 Generated with Claude Code

mecatequi's single-shot CI runs kept hitting stop_reason=max_turns: the
turn cap was the global default (100) and the binary had no flag to raise
it. This makes max-turns both configurable and far higher by default.

- New `--max-turns` flag on cmd/mecatequi (flags.go), threaded to
  CreateSession via run(). It is a per-SESSION limit, not an engine-build
  knob, so it is deliberately NOT mapped onto app.Config. 0/unset inherits
  the deployment default.

- Per-field limit defaulting (the trap). createSession previously
  substituted DefaultLimits ONLY when the passed Limits was the all-zero
  value, so `Limits{MaxTurns: n}` would silently disable MaxToolCalls and
  MaxConsecutiveFailures (0 = unlimited). Replaced the all-or-nothing
  substitution with per-field defaulting via a new
  session.Limits.WithDefaults: each zero field inherits from DefaultLimits.
  A zero field now means "unset", not "explicitly unlimited". This mirrors
  the per-field merge the subagent/team layers already use (defLimits,
  mergeLimits). Pinning only --max-turns keeps the tool-call / failure caps.

- Raised the composition defaults (internal/app/build.go):
  defaultMaxTurns 100 -> 1000, defaultMaxToolCalls 400 -> 4000. The prior
  budget bump (3203239) used a 1:4 turns:tools ratio (100/400); keeping that
  ratio at 1000 turns gives 4000 tool calls, so a long tool-heavy run is not
  capped by the tool-call brake long before the turn cap. MaxConsecutiveFailures
  unchanged (5). Subagent child defaults (50/200/3) left unchanged — they
  stay deliberately far below the main default to bound a delegation fan-out.

- Surfaced the knob through the action stack: a `max-turns` input on the
  mecatequi composite action (threaded as MQ_MAX_TURNS, appended to the argv
  array exactly like max-run-tokens) and as a workflow_call passthrough input
  on mecatequi-reusable.yml.

- Tests: session.Limits.WithDefaults unit table; a server-level test proving
  the other caps survive when only MaxTurns is set (the trap); a run()-level
  test proving --max-turns caps the session (StopMaxTurns); a flag-parse test;
  and the action-wrappers contract pins for the new env + argv wiring. Updated
  the server test that encoded the old all-or-nothing contract.

- Docs: usage.md + ADR-0028 inputs->flags tables and the reusable passthrough
  list gain max-turns; subagents-and-teams.md drops the now-stale "half the
  main session's 100/400" framing.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@JAORMX
JAORMX force-pushed the mecatequi-max-turns-flag branch from 499b721 to 6fc5432 Compare June 17, 2026 10:02
@JAORMX
JAORMX merged commit 83897cc into main Jun 17, 2026
9 checks passed
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.

1 participant