Skip to content

fix(cli): name the spec's own call cap in plan's next line - #1220

Merged
Birfy merged 4 commits into
mainfrom
agent/1219-plan-spec-cap
Nov 23, 2026
Merged

Birfy merged 4 commits into
mainfrom
agent/1219-plan-spec-cap

Conversation

@HugoXK

@HugoXK HugoXK commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #1219

What changed

plan's next: line and --json.next advised evolve <spec> --max-calls N
at the structural bound even when the spec declared its own cap, and an
explicit flag wins over a spec knob (runstore.py: "an explicit run option is
the sharper instruction"). Following the advice raised the user's cap.

Before (demo-shaped 8-task fixture + "evolve": {"max_calls": 5}, bound 11):

next: agentdescent plan spec.json --probe, then agentdescent evolve spec.json --max-calls 11

After:

next: agentdescent plan spec.json --probe, then agentdescent evolve spec.json --max-calls 5
  • _declared_cap(spec) reads evolve.max_calls, or the max_usd +
    usd_per_call pair; _capped_evolve_next takes it and prints
    min(bound, declared), or no --max-calls at all for a dollar cap the
    command line cannot express in calls.
  • The dollar pair is checked first: an explicit --max-calls builds its
    own CallLimit and overrides["call_limit"] replaces the spec's
    (runstore.py:1017-1021), so for a spec declaring both caps the advice adds
    no flag and the declared dollar cap still governs. Before that ordering fix
    (tip 7bdbc7f1), the both-declared fixture printed --max-calls 5; now its
    next: reads agentdescent plan spec.json --probe, then agentdescent evolve spec.json, in text and in --json.next.
  • Passed at all three call sites (_cmd_plan cli.py:2613 and its
    already-probed branch :2635, algorithms run :4923), so the text line
    and --json.next are one string by construction.
  • The demo footer keeps its --max-calls <N>: the spec demo writes declares
    no cap.

Out of scope and untouched: estimate.agent_calls_upper_bound in --json
(the engine's structural bound), MCP plan's call_limit (mcp.py:720/728),
the engine, and --usd-per-call in the advice.

Verification at the tip

Tip SHA: 8954a0b043ee24355eb91159d06cf97fe9dee64c

Ran:

  • new test file at base 6accc708, only that file added → 4 failed, 2 passed (the
    three original rows plus the both-caps row; measured with the final six-row file)
  • new both-caps row at the previous tip 7bdbc7f1, before the ordering fix → 1 failed, 5 passed
  • pytest -q -o addopts='' tests/test_plan_next_respects_spec_cap.py at the tip → 6 passed
  • focused: plan_text_output + first_run_caps + plan_probe + cli_json_errors + demo + cli_algorithms_run + the new file → 138 passed
  • python -m tools.gen_api_docs --check → docs/api.md is up to date
  • python -m tools.changelog_fragments check → 19 changelog fragment(s) OK

Not run:

  • full pytest -q — the CI matrix is the line for this CLI-text change
  • mkdocs build --strict — no docs/ page or mkdocs.yml change

Draft on purpose: the review lane is full; the Lead flips it ready when a slot frees.

`runstore.py` states the rule: an explicit run option wins over a spec knob.
`plan`'s `next:` printed `--max-calls` at the structural bound regardless, so
a spec declaring `evolve.max_calls: 5` was advised to run with 11 -- following
the advice raised the user's own cap.

Red at 6accc70 with only this file added: 3 failed, 2 passed. The two that
pass are the controls: no declared cap keeps the bound, and a declaration
larger than the bound cannot raise it. Fails again if the advice stops
agreeing with `--json.next`.
`_declared_cap(spec)` reads `evolve.max_calls` (or the `max_usd` +
`usd_per_call` pair) and `_capped_evolve_next` now takes it: the advice is
`min(bound, declared)`, or carries no `--max-calls` for a dollar cap it cannot
express in calls. The three call sites (`_cmd_plan`, its already-probed
branch, and `algorithms run`) pass it, so `next:` and `--json.next` stay one
string. The demo footer keeps its `--max-calls <N>` placeholder: its own spec
declares no cap.

`estimate.agent_calls_upper_bound`, the engine, and MCP `plan`'s `call_limit`
are untouched (#1219 scope).
A spec that declares `evolve.max_calls` and `max_usd` + `usd_per_call`
was advised `--max-calls min(bound, declared)`; an explicit flag builds
its own `CallLimit` and replaces the spec's, so following the advice
dropped the declared dollar cap. Assert the both-declared spec prints
no `--max-calls` on either surface.
`_declared_cap` returned the `max_calls` branch first, so a spec that
declared both caps was advised `--max-calls min(bound, n)`. An explicit
flag builds its own `CallLimit` and `overrides["call_limit"]` replaces
the spec's (`runstore.py`), so the advice dropped the declared dollar
cap. Check `max_usd` + `usd_per_call` first and recommend no flag: the
spec governs. Fragment and docstring follow.
@HugoXK

HugoXK commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

State change: draft -> ready for review.

Reason: the gate set for tip 8954a0b043ee24355eb91159d06cf97fe9dee64c is complete and the tip has not moved since the reads were dispatched.

  • Test: Blocking: none at that tip — six rows verified (calls-only keeps min(bound, declared); dollar-only advises no flag and the advised command stops on max_usd: $0.0500; both declares dollars-first and the counter-proof shows an added --max-calls 50 kills the dollar cap; no declared cap keeps the bound and the demo footer; --json differs from base only in next, estimate.agent_calls_upper_bound unchanged; no new refusals, exit 0 in every case).
  • Reviewer: PASS (advisory) at that tip — dollars-first holds in all four combinations, text next: == --json.next at all three call sites, blocking none.
  • CI at 8954a0b0: build, test (3.9)-test (3.13), otel-wire success; deploy skipped.
  • Security not applicable: the diff is CLI advice text and one test file, no network/subprocess/key surface.

No tip move with this flip. Merge side unchanged: draft -> ready is the only field changed.

@HugoXK
HugoXK marked this pull request as ready for review November 23, 2026 00:42
@github-actions github-actions Bot added risk:T2 Risk tier T2 (package code or an unnamed path), set by the controller from the diff agent-pr Pull request opened by an agent labels Nov 23, 2026
@Birfy

Birfy commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Review (Birfy)

Tip SHA: 8954a0b
Ran:

  • .github/scripts/risk_gate.py --repo ThinkFlowLab/agentdescent --pr 1220 → T2 (179 lines / 3 files; package path agentdescent/cli.py)
  • pytest -q -o addopts='' tests/test_plan_next_respects_spec_cap.py tests/test_plan_text_output.py tests/test_first_run_caps.py tests/test_plan_probe.py tests/test_cli_json_errors.py tests/test_demo.py tests/test_cli_algorithms_run.py at this tip → 138 passed
  • python -m tools.gen_api_docs --check → docs/api.md is up to date
  • python -m tools.changelog_fragments check → 19 changelog fragment(s) OK
  • Required CI at this tip → build, test (3.9) … test (3.13) SUCCESS
    Not run:
  • Full offline suite locally — the CI test matrix is the line
  • mkdocs build --strict — no docs/ page or mkdocs.yml change
    Findings:
  • No actionable defects. After After #1212, the default demo footer and bare plan next: still omit --probe and --max-calls #1217, plan's next: advised --max-calls at the structural bound even when the spec already declared evolve.max_calls or a priced dollar cap, so following the advice could raise the user's cap; when both were declared, an explicit flag would replace the whole CallLimit and drop the dollar cap. _declared_cap reads the dollar pair first, then max_calls; _capped_evolve_next prints min(bound, declared) or omits the flag for a dollar cap the CLI cannot express in calls. All three call sites (cmd_plan, its already-probed branch, algorithms run) pass the same declared= value, so the text line and --json.next stay one string. estimate.agent_calls_upper_bound and the uncapped demo footer are unchanged.
    Verdict: PASS

@Birfy
Birfy merged commit 29d49ce into main Nov 23, 2026
12 checks passed
@Birfy
Birfy deleted the agent/1219-plan-spec-cap branch November 23, 2026 04:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-pr Pull request opened by an agent risk:T2 Risk tier T2 (package code or an unnamed path), set by the controller from the diff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(cli): plan's next line must not raise a cap the spec already set

2 participants