Skip to content

No pre-dispatch budget counter check before tool.invoke (§9.6) #158

@nficano

Description

@nficano

Category: spec-conformance Severity: major
Location: src/Internal/Runtime/ToolInvocationHandler.php:54-100
Spec: ARCP v1.1 §9.6

What

§9.6: 'The runtime MUST check all budget counters before authorizing any operation through the lease. If any counter is ≤ 0, the operation MUST fail with BUDGET_EXHAUSTED.' The handler dispatches every tool.invoke without consulting CostBudget::remaining(); exhaustion is only detected post-hoc when the agent reports a cost metric.

Evidence

public function handle(Session $session, Envelope $env, ToolInvoke $msg): void
{
    ...
    try { $lease = $this->credentials->leaseFromArguments($msg->arguments, $resolved, $session); } catch (...) { ... }
    $job = $this->runtime->jobs->start($session, $env, $resolved->name, $resolved->version,
        $lease instanceof LeaseGranted ? $lease->costBudget : CostBudget::fromInvocationArguments($msg->arguments),
        $lease);
    ...
    $this->runtime->jobs->transition($job, JobState::Running);
    $job->future = async(function () ... { $this->runHandler(...); });
}

Proposed fix

Before transitioning the job to Running, iterate the lease's CostBudget remaining counters and, if any is ≤ 0, fail the job with BUDGET_EXHAUSTED before invoking the handler.

Acceptance criteria

  • A tool.invoke against a lease whose budget counter is already ≤ 0 returns a tool.error with code BUDGET_EXHAUSTED and the handler fiber is never started.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions