Repository navigation
AgentLoop only allowlists error | aborted, so a merge-extended failure finish still assembles an assistant message
#3126
lizhuojunx86
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Splitting this out of #1886 so it doesn't stall that thread.
The invariant token-meter is about to rely on
63688b0 closes a billing attempt on a finish chunk whose reason kind is
errororaborted. That is correct today, and the reason it is correct is not in token-meter. It is in agent-loop:agent-loop/src/agent.tsroutes those finishes throughagent/request-error, then either continues into a retry or throws. Neither path reachescreateAssistantMessage().core/session/README.mdsays the same in prose, and the transport-recovery tests only ever observe the successful attempt's message.So "a failed attempt produces no assistant message" is a real invariant. It is held up by a control flow in one package, a sentence in a README in a second, and an observation in a third package's tests. Nothing asserts it.
Credit where due: @le-soleil-se-couche established this in #1886, and it is the reason the current fix is safe.
Why that matters now
FinishReasonMapis merge-extensible and its own doc says to switch on kind and fall through unknowns. AgentLoop's boundary is an allowlist of two. An adapter that merges in a third failure kind gets a finish carryingfailurethat is noterror | aborted, and that attempt does assemble an assistant message.That creates a fork I got wrong earlier in #1886, so it is worth stating plainly:
'failure' in reason, and the third kind's assistant message lands after the boundary clearedlast, resolves withprevious === undefined, and is added rather than replacing. That is a double count.Widening only token-meter turns an undercount into an overcount. The synthetic fixture in #1886 runs both as counterexamples: the same turn folds to one record of 17/6/19/4/3 under the closed list, two under the widened predicate.
Proposal
Two changes that have to land together, or a decision that they should not:
failuretakes theagent/request-errorpath and assembles no message.'failure' in reason.Until (1), token-meter and anything downstream should stay on
error | aborted. That is what I would ship today.Smaller thing worth doing regardless
Name the invariant in a test. One that asserts a failed attempt produces no assistant message, sitting in token-meter where the fold depends on it, so a future change to agent's control flow fails a test instead of quietly moving numbers.
I understand external PRs aren't being accepted. Happy to supply the fixture or the test in whatever form is useful.
All reactions