Repository navigation
feat(mecatequi): add --max-turns flag; raise default turn/tool budgets - #76
Merged
Merged
Conversation
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
force-pushed
the
mecatequi-max-turns-flag
branch
from
June 17, 2026 10:02
499b721 to
6fc5432
Compare
This was referenced Jun 17, 2026
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.
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-turnsflag oncmd/mecatequi, threaded toCreateSessionviarun(). It is a per-session limit (not an engine-build knob), so it is deliberately not mapped ontoapp.Config.0/unset inherits the deployment default.Per-field limit defaulting (the trap).
createSessionpreviously substitutedDefaultLimitsonly when the passedLimitswas the all-zero value — soLimits{MaxTurns: n}would silently disableMaxToolCallsandMaxConsecutiveFailures(0= unlimited). Replaced the all-or-nothing substitution with per-field defaulting via a newsession.Limits.WithDefaults: each zero field inherits fromDefaultLimits. 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):defaultMaxTurns100 → 1000,defaultMaxToolCalls400 → 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.MaxConsecutiveFailuresunchanged (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-turnsinput on the mecatequi composite action (threaded asMQ_MAX_TURNS, appended to the argv array exactly likemax-run-tokens, conditional on non-empty) and aworkflow_callpassthrough input onmecatequi-reusable.yml.Tests:
session.Limits.WithDefaultsunit table; a server-level test proving the other caps survive when onlyMaxTurnsis set (the trap); arun()-level test proving--max-turnscaps 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 gainmax-turns;subagents-and-teams.mddrops 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.createSessionseam: fill any zero field of the passedLimitsfromDefaultLimitsrather 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 a0field 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.txtis unchanged by the doc edits.Overlap note
A second in-flight PR (branch
mecatequi-toolchain-hook) also editsaction.ymlandmecatequi-reusable.yml(toolchain install + asetup-scriptinput). Edits here are localized to themax-turnsinput/env/argv lines; expect a trivial rebase if that PR lands first.🤖 Generated with Claude Code