Skip to content

[P1.35] Cost cap is unenforced for the plan engine and delegated adapters #1004

Description

@frankbria

Follow-up from #911 (PR #1003).

Problem

#911 made max_cost_usd real for the built-in ReAct engine — it reads the setting and blocks the run once _estimate_total_cost() reaches the cap. The other execution paths still ignore it entirely:

  • Plan engine (--engine plan, core/executor.py) — has no token or cost tracking at all. It sets max_tokens on its calls and records nothing, so there is no accumulated spend to compare against a cap.
  • Delegated adapters (--engine claude-code/codex/opencode) — the external CLI does its own spending and reports no token usage back, so CodeFRAME cannot see what a run cost.

A user on a non-default engine who sets a $5 cap still gets no cost limiting. #911 was scoped to "the field is read by something" rather than "the field is honoured everywhere"; the Settings control now carries a note naming the limitation, but the gap is real.

Why it was not fixed in #911

Both need work that dwarfs the original issue:

Suggested approach

  1. Give core/executor.py the same token-record + _estimate_total_cost treatment as ReactAgent, then reuse _resolve_cost_cap — the resolver is already engine-agnostic.
  2. For delegated engines, decide explicitly: either parse usage where the CLI reports it, or keep the control disabled for those engines in the UI rather than showing a cap that cannot bind.
  3. Test: a low cap on --engine plan terminates the run and leaves the task not DONE, mirroring tests/core/test_cost_cap_enforced_911.py.

Evidence

  • codeframe/core/executor.py — no token/cost tracking
  • codeframe/core/adapters/subprocess_adapter.py — no usage capture
  • codeframe/core/react_agent.py:_resolve_cost_cap — the reusable resolver

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1-high-betaHigh priority - should fix before beta for best experienceenhancementNew feature or requestpriority:high

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions