Skip to content

feat(mcp): spend the operator call ceiling per Ticket, not per run (#1213) - #1214

Draft
HugoXK wants to merge 2 commits into
mainfrom
agent/1082-ticket-cap
Draft

HugoXK wants to merge 2 commits into
mainfrom
agent/1082-ticket-cap

Conversation

@HugoXK

@HugoXK HugoXK commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1213.

What changed

A worker's Ticket can start a second run, and the MCP surface handed the whole
operator ceiling to each one. Measured at base 1aa816e0: with
AGENTDESCENT_MAX_CALLS=1, two start calls from one Tools server each ran
one model call and stopped budget, so the Ticket billed 2 under a ceiling of
1 — the caller never had to raise anything to exceed it.

One worker session is one Ticket (docs/dsh-super-agent.md), so the ceiling is
that session's budget now:

  • Tools keeps the ids of the runs it started and _ticket_spent() reads what
    they charged (calls + pending_calls, so work still in flight is not
    budget the next run may hand out twice; an unreadable run counts 0).
  • _call_limit_payload takes spent and clamps to ceiling - spent, reporting
    call_limit.ticket: {ceiling, spent, remaining} once there is earlier spend.
    Shape stability: a fresh session's first run returns exactly the payload it
    returned before this key existed.
  • A spent Ticket refuses start before a run is created, with the arithmetic in
    the sentence (AGENTDESCENT_MAX_CALLS=1 is already spent by this worker's Ticket (1 call over 1 run); no run may start.), and the reply still carries
    call_limit. A caller's own max_calls=0 is not that case and keeps its
    existing path.

Not in this PR: the store as the Ticket (a store-wide aggregate would cap
campaign and pilot runs that legitimately share one), max_concurrency, and the
USD ceiling question — those stay open on #1082.

5 files, +206/−13 (219 changed lines).

Verification

Tip SHA: 115edc746af4dac4e849f7db77f117efe05d76c1 (branch
agent/1082-ticket-cap, a --no-ff merge of live main 1aa816e0 into the
branch).

Red first, at base 1aa816e0 with only the new test file present:
3 failed, 1 passed -- test_second_run_is_clamped_to_what_the_ticket_has_left,
test_a_spent_ticket_refuses_another_start and
test_plan_reports_what_the_ticket_has_left (the plan row asks for 9, gets
the untouched ceiling of 3 instead of the 2 the Ticket has left). The fourth
row passes at base by design: a caller's own max_calls=0 is not the
spent-Ticket case.

Ran:

  • pytest -q tests/test_mcp_ticket_cap.py tests/test_mcp_call_limit.py tests/test_mcp.py tests/test_mcp_write_confinement.py -> 71 passed, 6 skipped
  • full suite, 8 shards on each tree; tests/test_docs_links.py run
    separately on both (22 passed each -- the system python here has no
    markdown module): tip 8029 + 22 = 8051 tests, 33 failed, 10 errors,
    29 skipped; base 8025 + 22 = 8047, 33 failed, 10 errors, 31 skipped.
    The failed+error id sets are identical (43 each, 0 tip-only, 0 base-only);
    the 4 extra tip tests are this PR's rows, and the 2-skip delta is the base
    worktree's .git-is-a-file shape.
  • python -m tools.gen_api_docs --check -> docs/api.md is up to date
  • python -m tools.changelog_fragments check -> 15 changelog fragment(s) OK
  • mkdocs build --strict -> rc 0 in 16.48 s with the social plugin excluded; the unmodified config hangs on this host at material/social post_page, which is a host limitation, and CI's build job runs the unmodified config

Not run:

  • no real model call: the two starts in the guard use the offline skill_dir fixture and stop at the cap

A worker session is one Ticket in docs/dsh-super-agent.md, but the MCP
surface re-granted AGENTDESCENT_MAX_CALLS to every start: with the ceiling
at 1, two starts each ran one call and the Ticket billed two.

The server now counts the calls its earlier runs charged (calls plus
pending_calls, read from the store) against the ceiling, clamps a second
start to the remainder, reports call_limit.ticket {ceiling, spent,
remaining} when there is earlier spend, and refuses a start once the
Ticket's ceiling is spent, naming the variable and the arithmetic.

Shape stability: a fresh session's first run reports exactly the payload it
reported before this key existed; a caller's own max_calls=0 is not the
spent-Ticket case.
@HugoXK HugoXK added agent-pr Pull request opened by an agent area:cli The agentdescent command line (cli.py, doctor, plan/evolve/status/apply) area:plugins Host plugins and installers: Claude Code, Codex, DSH, OpenCode, MCP server enhancement New feature or request labels Nov 21, 2026

This branch has not been deployed

No deployments
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 area:cli The agentdescent command line (cli.py, doctor, plan/evolve/status/apply) area:plugins Host plugins and installers: Claude Code, Codex, DSH, OpenCode, MCP server enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(mcp): spend the operator call ceiling per Ticket, not per run

1 participant