Repository navigation
feat(usage): a run's colleagues, its env triggers' executors, count in its cost - #976
Open
earakely-scale wants to merge 6 commits into
Open
earakely-scale wants to merge 6 commits into
earakely-scale wants to merge 6 commits into
Conversation
…n its cost An env's gateway calls a trigger's executor (an AI-played contact) when the trigger fires. No prompt step prompts it, so no step recorded its usage and a run's ledger never held what its colleagues spent. - The gateway keeps every executor call with the usage its final message reported, as sent, and serves the list at GET /triggers/usage (the triggers extension's new `usage` method) under the engine's own boot id. `clear` keeps it: it was spent. - `prompt_agent` and `always_on` as they end, and the teardown, write the list as one `colleague` entry per env and gateway boot (`task_step/colleagues.py`), with no attempt, under the `register_env_triggers` step that set the executors up. A call that reported nothing makes the entry a lower bound, never $0; calls are priced by model from their per-model rows. - The ledger keys an entry by `gateway_boot` too, so each write is the whole list and replaces the last: a call counts once whichever step or attempt wrote it, and a gateway a retry redeployed is kept beside the first. - A step's completion takes the context's colleague entries into the ledger with its own; the teardown writes its own through the new `record_usage()`, which merges finished entries into a run's ledger alone, for any embedder. - `UsageRole` adds `colleague`, `validator` (a step that checks a run without grading it) and `playground` (an embedder's chat with a run's agent outside its steps). They aren't `[model.roles]` keys; `summarize` lists them after the solver, user simulator and judge, and `StepUsage` takes them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…of a gateway's list, count real attempts - The gateway lists a call to an executor as it starts, with no usage until its reply ends, so a teardown that reads while a colleague is still answering counts that call, as one of unknown usage, and the entry is a lower bound rather than exact. - `GET /triggers/usage` carries a `version` every change to the list raises, kept on the entry (`gateway_version`). The ledger, and a step's context, never replace a gateway's colleague entry with one read from an earlier copy of its list (`older`), which a parallel step's completion write can land with after a newer one. - `summarize` counts the attempts entries name; an attempt-less colleague entry isn't one of its own. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An executor that answers past its time limit is still working, and still spending. Its call was recorded with no usage, so its run's colleague entry stayed a lower bound with those dollars unknown. The gateway now hands that call's read to the background when it gives up on it: the send still waiting for its reply, or the task still to poll, up to `_LATE_REPLY_S` (10 minutes) more. When the task ends, the usage its final message reports goes on the call and raises the list's version, so the next write of the run's colleague entry prices it. The fire sees what it always did: `ReadTimeout` for a send held past its window, no reply for a task still working at its deadline. A `clear` leaves the reads to finish. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… for its usage A fire that `clear` or `remove` cancelled while it polled its executor's task closed the client and left the call unpriced. The poll now hands the task to the background read (`_read_late`), as a cancelled send already does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Why
An env's gateway calls a trigger's executor when the trigger fires; the executor is an AI-played contact such as a colleague who replies to an email. No prompt step prompts it, so no step recorded its usage, and a run's ledger never held what its colleagues spent. On runs whose colleagues reply often, that's a large share of the real cost.
What
Gateway.
ReadTimeoutfor a send held past its window, or no reply for a task still working at its deadline. Aclearleaves these reads to finish.GET /triggers/usage, the triggers extension's newusagemethod, under the engine's own boot id and aversionthat every change to the list raises./triggers/state, because steps pollstatewhile they wait for triggers to settle.clearkeeps the list: those calls were spent.Recording.
prompt_agentandalways_onrecord when they end (the existing trigger-state capture), and so does teardown (tear_down, so theteardown_sandboxesstep too). Each writes the gateway's list as onecolleagueentry per env and gateway boot (task_step/colleagues.py).register_env_triggersstep that set the executors up, with no attempt.partial), never $0.Each call counts once.
gateway_boottoo, as well as attempt, step and role.gateway_version) never replaces a later one, in the ledger or in a step's context. Parallel steps' completion writes can land out of order.Ledger writes.
record_usage(). It merges finished entries into a run's ledger and nothing else, so an embedder can use it too.Roles.
UsageRoleadds three roles:colleague;validator, for a step that checks a run without grading it;playground, for an embedder's chat with a run's agent outside its steps.None of them is a
[model.roles]key.summarizelists them after the solver, user simulator and judge, and counts only the attempts entries name.StepUsageaccepts the new roles.Tests
clearkeeps the list and its boot id; the route serves the list; the card offersusage.usagemethod is skipped; a failed read is logged.Task.runon a real SQLite store: the entry joins the ledger as each step completes; a retried span over the same gateway leaves one entry of 4 calls for 4 calls; teardown writes the calls that came after the last step.gateway_boot;prompt_agent's capture records the entry;summarize's role order.computer_exectests, which fail the same way onmainon macOS (BSDbase64).plugin-api: no break.End to end
Each run: a real local gateway, a Claude Code colleague with its own model endpoint, and a Claude Code solver. Each agent's model calls went through its own logging pass-through to the real model gateway, so each role's truth is that gateway's per-call usage.
partial, unpriced (no_tokens); the colleague kept working and spent $0.078283, which the entry flags as unknown rather than $0That's 8 of 8 matching, plus one earlier cut-off attempt whose reply came back within the read window and matched exactly. Total spend $1.49 at list.
Rerun on the review fixes (
ebbabfb12):gateway_version2 (the call started, then ended)gateway_version4gateway_version1: the call is listed with no usage, so the entry ispartialand unpriced, and the run's cost line reads "at least" where it would have read exact before the fix. The colleague went on to spend $0.078683.Rerun on the late-read change (
34cbfb95e):partialand unpriced, with $0.078 unknown.partial, unpriced: the run's teardown closes the gateway, and the late read with itTotal spend across all runs: $2.98 at list.
For the docs
GET /triggers/usageand the triggers extension'susagemethod.colleague,validatorandplaygroundusage roles, and how a run's cost line shows them.record_usage()for embedders.🤖 Generated with Claude Code


Confidence Score: 5/5
The PR appears safe to merge; no new actionable issue was found in the latest change.Summary
This PR adds colleague usage to a run’s costs without counting repeated snapshots twice.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart LR A[Executor call starts] --> B[Gateway lists unknown usage] B --> C[Reply reports usage] B --> D[Cancelled or timed-out call] D --> E[Background read] E --> C C --> F[Step or teardown reads snapshot] B --> F F --> G[Ledger keeps newest gateway version]Reviews (9) · Last reviewed commit: "fix(gateway): a call cancelled while its..." · Reviewed by Greptile