budget: count tool usage without rebuilding every call and reply #136

Merged
PerishFire merged 1 commit from land/santi-tui-direct-relationship into main 2026-08-09 14:43:44 +00:00
Owner

budget: count tool usage without rebuilding every call and reply

Reading the context budget took twenty seconds on a strand with five hundred
tool calls. Nearly all of it was one line: usage asked the store for every
call and every reply, decoded each into a domain object, resolved each call's
turn, and deserialised each reply's payload, only to keep two numbers — how
many calls there were, and how many bytes their output came to. Around two and
a half thousand queries were issued and their results thrown away.

The store now answers that question directly. Calls are counted from the entry
ledger that already orders them, and outputs are read in batches keyed by
result, so the work is four queries and a fold rather than a query per row.
Batching is bounded because a strand may hold more results than a statement
may hold variables.

The numbers are unchanged: the same strand reports the same 524 calls and the
same 2346765 bytes before and after, checked against the previous
implementation rather than against a rewritten estimate of it.

Twenty seconds becomes under half a second.

budget: count tool usage without rebuilding every call and reply Reading the context budget took twenty seconds on a strand with five hundred tool calls. Nearly all of it was one line: usage asked the store for every call and every reply, decoded each into a domain object, resolved each call's turn, and deserialised each reply's payload, only to keep two numbers — how many calls there were, and how many bytes their output came to. Around two and a half thousand queries were issued and their results thrown away. The store now answers that question directly. Calls are counted from the entry ledger that already orders them, and outputs are read in batches keyed by result, so the work is four queries and a fold rather than a query per row. Batching is bounded because a strand may hold more results than a statement may hold variables. The numbers are unchanged: the same strand reports the same 524 calls and the same 2346765 bytes before and after, checked against the previous implementation rather than against a rewritten estimate of it. Twenty seconds becomes under half a second.
budget: count tool usage without rebuilding every call and reply
All checks were successful
guard / guard-macos (pull_request) Successful in 50s
guard / guard (pull_request) Successful in 17m18s
guard / guard-macos (push) Successful in 49s
guard / guard (push) Successful in 5m21s
f66a3b1d96
budget: count tool usage without rebuilding every call and reply

Reading the context budget took twenty seconds on a strand with five hundred
tool calls. Nearly all of it was one line: usage asked the store for every
call and every reply, decoded each into a domain object, resolved each call's
turn, and deserialised each reply's payload, only to keep two numbers — how
many calls there were, and how many bytes their output came to. Around two and
a half thousand queries were issued and their results thrown away.

The store now answers that question directly. Calls are counted from the entry
ledger that already orders them, and outputs are read in batches keyed by
result, so the work is four queries and a fold rather than a query per row.
Batching is bounded because a strand may hold more results than a statement
may hold variables.

The numbers are unchanged: the same strand reports the same 524 calls and the
same 2346765 bytes before and after, checked against the previous
implementation rather than against a rewritten estimate of it.

Twenty seconds becomes under half a second.

Land-Source: santi-tui-direct-relationship@04dfa24d8cd562d51dbc6434187b27dfa76a63e7
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
PerishFire/santi!136
No description provided.